HelloOperationAsyncResult.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 / HelloOperationAsyncResult.cs / 1305376 / HelloOperationAsyncResult.cs

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

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

        [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] 
        internal HelloOperationAsyncResult(
            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.OnBeginOnlineAnnouncement(
                this.GetMessageSequence(message), 
                this.GetEndpointDiscoveryMetadata(message),
                this.PrepareAsyncCompletion(onOnOnlineAnnoucementCompletedCallback),
                this);
 
            if (innerAsyncResult.CompletedSynchronously && OnOnOnlineAnnouncementCompleted(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 OnOnOnlineAnnouncementCompleted(IAsyncResult result) 
        {
            HelloOperationAsyncResult thisPtr = (HelloOperationAsyncResult)result.AsyncState; 
            thisPtr.announcementServiceImpl.OnEndOnlineAnnouncement(result);

            return true;
        } 

        bool IsInvalid(TMessage message) 
        { 
            UniqueId messageId = OperationContext.Current.IncomingMessageHeaders.MessageId;
            if (messageId == null) 
            {
                if (TD.DiscoveryMessageWithNullMessageIdIsEnabled())
                {
                    TD.DiscoveryMessageWithNullMessageId(ProtocolStrings.TracingStrings.Hello); 
                }
 
                return true; 
            }
            else if (this.announcementServiceImpl.IsDuplicate(messageId)) 
            {
                if (TD.DuplicateDiscoveryMessageIsEnabled())
                {
                    TD.DuplicateDiscoveryMessage(ProtocolStrings.TracingStrings.Hello, messageId.ToString()); 
                }
 
                return true; 
            }
            else if (this.ValidateContent(message)) 
            {
                return false;
            }
            else 
            {
                if (TD.DiscoveryMessageWithInvalidContentIsEnabled()) 
                { 
                    TD.DiscoveryMessageWithInvalidContent(ProtocolStrings.TracingStrings.Hello, 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