Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / C#

Fax Adapter

Rate me:
Please Sign up or sign in to vote.
3.62/5 (13 votes)
28 Sep 2006CPOL4 min read 63.4K   994   31  
Fax Adapter for BizTalk Server 2006
//---------------------------------------------------------------------
// File: ControlledTermination.cs
// 
// Summary: Implementation of an adapter framework sample adapter. 
// This class constitutes one of the BaseAdapter classes, which, are
// a set of generic re-usable set of classes to help adapter writers.
//
// Sample: Base Adapter Class Library v1.0.1
//
// Description: This class is used to keep count of work in flight, an
// adapter should not return from terminate if it has work outstanding
//
//---------------------------------------------------------------------
// This file is part of the Microsoft BizTalk Server 2006 SDK
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft BizTalk
// Server 2006 release and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//---------------------------------------------------------------------

using System;
using System.Threading;

namespace Microsoft.Samples.BizTalk.Adapter.Common
{
    public class ControlledTermination : IDisposable
    {
        private AutoResetEvent e = new AutoResetEvent(false);
        private int activityCount = 0;
        private bool terminate = false;

        //  to be called at the start of the activity
        //  returns false if terminate has been called
        public bool Enter ()
        {
            lock (this)
            {
                if (true == this.terminate)
                {
                    return false;
                }

                this.activityCount++;
            }
            return true;
        }

        //  to be called at the end of the activity
        public void Leave ()
        {
            lock (this)
            {
                this.activityCount--;

                // Set the event only if Terminate() is called
                if (this.activityCount == 0 && this.terminate)
                    this.e.Set();
            }
        }

        //  this method blocks waiting for any activity to complete
        public void Terminate ()
        {
            bool result;

            lock (this)
            {
                this.terminate = true;
                result = (this.activityCount == 0);
            }

            // If activity count was not zero, wait for pending activities
            if (!result)
            {
                this.e.WaitOne();
            }
        }

        public bool TerminateCalled
        {
            get
            { 
                lock (this)
                {
                    return this.terminate;
                }
            }
        }

        public void Dispose()
        {
            ((IDisposable)this.e).Dispose();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
Anil is from Hyderabad, Andhra Pradesh. He is Currently Working with VisualSoft Technologies Ltd., As a Software Engineer.

Anil has more than 4 yrs of experience in the IT industry working on Microsoft Technologies. He is involved in various project activities like System Architecture, Design, and Development. Technical experience most specifically ASP.NET , Javascript, Biztalk 2004/2006, Webservices, C# and .NET framework. He has have worked on various language and platforms. He is Microsoft Certified professional.

The author has won several programming awards within the organizations worked and is well-recognized.


--

Comments and Discussions