ByeOperationAsyncResult.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.ServiceModel.Discovery / System / ServiceModel / Discovery / ByeOperationAsyncResult.cs / 1305376 / ByeOperationAsyncResult.cs

                            //---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------

namespace System.ServiceModel.Discovery 
{
    using System.Diagnostics.CodeAnalysis; 
    using System.Runtime; 
    using System.Xml;
 
    abstract class ByeOperationAsyncResult : AsyncResult
        where TMessage : class
    {
        static AsyncCompletion onOnOfflineAnnoucementCompletedCallback = 
            new AsyncCompletion(OnOnOfflineAnnouncementCompleted);
 
        IAnnouncementServiceImplementation announcementServiceImpl; 

        [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] 
        internal ByeOperationAsyncResult(
            IAnnouncementServiceImplementation announcementServiceImpl,
            TMessage message,
            AsyncCallback callback, 
            object state)
            : base(callback, state) 
        { 
            this.announcementServiceImpl = announcementServiceImpl;
 
            if (this.IsInvalid(message))
            {
                this.Complete(true);
                return; 
            }
 
            IAsyncResult innerAsyncResult = 
                this.announcementServiceImpl.OnBeginOfflineAnnouncement(
                this.GetMessageSequence(message), 
                this.GetEndpointDiscoveryMetadata(message),
                this.PrepareAsyncCompletion(onOnOfflineAnnoucementCompletedCallback),
                this);
 
            if (innerAsyncResult.CompletedSynchronously && OnOnOfflineAnnouncementCompleted(innerAsyncResult))
            { 
                this.Complete(true); 
                return;
            } 
        }

        protected abstract bool ValidateContent(TMessage message);
        protected abstract DiscoveryMessageSequence GetMessageSequence(TMessage message); 
        protected abstract EndpointDiscoveryMetadata GetEndpointDiscoveryMetadata(TMessage message);
 
        static bool OnOnOfflineAnnouncementCompleted(IAsyncResult result) 
        {
            ByeOperationAsyncResult thisPtr = (ByeOperationAsyncResult)result.AsyncState; 
            thisPtr.announcementServiceImpl.OnEndOfflineAnnouncement(result);

            return true;
        } 

        bool IsInvalid(TMessage message) 
        { 
            UniqueId messageId = OperationContext.Current.IncomingMessageHeaders.MessageId;
            if (messageId == null) 
            {
                if (TD.DiscoveryMessageWithNullMessageIdIsEnabled())
                {
                    TD.DiscoveryMessageWithNullMessageId(ProtocolStrings.TracingStrings.Bye); 
                }
 
                return true; 
            }
            else if (this.announcementServiceImpl.IsDuplicate(messageId)) 
            {
                if (TD.DuplicateDiscoveryMessageIsEnabled())
                {
                    TD.DuplicateDiscoveryMessage(ProtocolStrings.TracingStrings.Bye, messageId.ToString()); 
                }
 
                return true; 
            }
            else if (this.ValidateContent(message)) 
            {
                return false;
            }
            else 
            {
                if (TD.DiscoveryMessageWithInvalidContentIsEnabled()) 
                { 
                    TD.DiscoveryMessageWithInvalidContent(ProtocolStrings.TracingStrings.Bye, messageId.ToString());
                } 

                return true;
            }
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK