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

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

namespace System.ServiceModel.Discovery 
{
    using System; 
    using System.Xml; 
    using System.Runtime;
    using System.ServiceModel.Discovery.Version11; 
    using System.ServiceModel.Discovery.VersionApril2005;
    using System.ServiceModel.Discovery.VersionCD1;

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)] 
    public class AnnouncementService :
        IAnnouncementContractApril2005, 
        IAnnouncementContract11, 
        IAnnouncementContractCD1,
        IAnnouncementServiceImplementation 
    {
        DuplicateDetector duplicateDetector;

        public AnnouncementService() 
            : this(DiscoveryDefaults.DuplicateMessageHistoryLength)
        { 
        } 

        public AnnouncementService(int duplicateMessageHistoryLength) 
        {
            if (duplicateMessageHistoryLength < 0)
            {
                throw FxTrace.Exception.ArgumentOutOfRange( 
                    "duplicateMessageHistoryLength",
                    duplicateMessageHistoryLength, 
                    SR.DiscoveryNegativeDuplicateMessageHistoryLength); 
            }
 
            if (duplicateMessageHistoryLength > 0)
            {
                this.duplicateDetector = new DuplicateDetector(duplicateMessageHistoryLength);
            } 
        }
 
        public event EventHandler OnlineAnnouncementReceived; 
        public event EventHandler OfflineAnnouncementReceived;
 
        void IAnnouncementContractApril2005.HelloOperation(HelloMessageApril2005 message)
        {
            Fx.Assert("The [....] method IAnnouncementContractApril2005.HelloOperation must not get invoked. It is marked with PreferAsyncInvocation flag.");
        } 

        IAsyncResult IAnnouncementContractApril2005.BeginHelloOperation(HelloMessageApril2005 message, AsyncCallback callback, object state) 
        { 
            return new HelloOperationApril2005AsyncResult(this, message, callback, state);
        } 

        void IAnnouncementContractApril2005.EndHelloOperation(IAsyncResult result)
        {
            HelloOperationApril2005AsyncResult.End(result); 
        }
 
        void IAnnouncementContractApril2005.ByeOperation(ByeMessageApril2005 message) 
        {
            Fx.Assert("The [....] method IAnnouncementContractApril2005.ByeOperation must not get invoked. It is marked with PreferAsyncInvocation flag."); 
        }

        IAsyncResult IAnnouncementContractApril2005.BeginByeOperation(ByeMessageApril2005 message, AsyncCallback callback, object state)
        { 
            return new ByeOperationApril2005AsyncResult(this, message, callback, state);
        } 
 
        void IAnnouncementContractApril2005.EndByeOperation(IAsyncResult result)
        { 
            ByeOperationApril2005AsyncResult.End(result);
        }

        void IAnnouncementContract11.HelloOperation(HelloMessage11 message) 
        {
            Fx.Assert("The [....] method IAnnouncementContract11.HelloOperation must not get invoked. It is marked with PreferAsyncInvocation flag."); 
        } 

        IAsyncResult IAnnouncementContract11.BeginHelloOperation(HelloMessage11 message, AsyncCallback callback, object state) 
        {
            return new HelloOperation11AsyncResult(this, message, callback, state);
        }
 
        void IAnnouncementContract11.EndHelloOperation(IAsyncResult result)
        { 
            HelloOperation11AsyncResult.End(result); 
        }
 
        void IAnnouncementContract11.ByeOperation(ByeMessage11 message)
        {
            Fx.Assert("The [....] method IAnnouncementContract11.ByeOperation must not get invoked. It is marked with PreferAsyncInvocation flag.");
        } 

        IAsyncResult IAnnouncementContract11.BeginByeOperation(ByeMessage11 message, AsyncCallback callback, object state) 
        { 
            return new ByeOperation11AsyncResult(this, message, callback, state);
        } 

        void IAnnouncementContract11.EndByeOperation(IAsyncResult result)
        {
            ByeOperation11AsyncResult.End(result); 
        }
 
        void IAnnouncementContractCD1.HelloOperation(HelloMessageCD1 message) 
        {
            Fx.Assert("The [....] method IAnnouncementContractCD1.HelloOperation must not get invoked. It is marked with PreferAsyncInvocation flag."); 
        }

        IAsyncResult IAnnouncementContractCD1.BeginHelloOperation(HelloMessageCD1 message, AsyncCallback callback, object state)
        { 
            return new HelloOperationCD1AsyncResult(this, message, callback, state);
        } 
 
        void IAnnouncementContractCD1.EndHelloOperation(IAsyncResult result)
        { 
            HelloOperationCD1AsyncResult.End(result);
        }

        void IAnnouncementContractCD1.ByeOperation(ByeMessageCD1 message) 
        {
            Fx.Assert("The [....] method IAnnouncementContractCD1.ByeOperation must not get invoked. It is marked with PreferAsyncInvocation flag."); 
        } 

        IAsyncResult IAnnouncementContractCD1.BeginByeOperation(ByeMessageCD1 message, AsyncCallback callback, object state) 
        {
            return new ByeOperationCD1AsyncResult(this, message, callback, state);
        }
 
        void IAnnouncementContractCD1.EndByeOperation(IAsyncResult result)
        { 
            ByeOperationCD1AsyncResult.End(result); 
        }
 
        bool IAnnouncementServiceImplementation.IsDuplicate(UniqueId messageId)
        {
            return (this.duplicateDetector != null) && (!this.duplicateDetector.AddIfNotDuplicate(messageId));
        } 

        IAsyncResult IAnnouncementServiceImplementation.OnBeginOnlineAnnouncement( 
            DiscoveryMessageSequence messageSequence, 
            EndpointDiscoveryMetadata endpointDiscoveryMetadata,
            AsyncCallback callback, 
            object state)
        {
            return this.OnBeginOnlineAnnouncement(messageSequence, endpointDiscoveryMetadata, callback, state);
        } 

        void IAnnouncementServiceImplementation.OnEndOnlineAnnouncement(IAsyncResult result) 
        { 
            this.OnEndOnlineAnnouncement(result);
        } 

        IAsyncResult IAnnouncementServiceImplementation.OnBeginOfflineAnnouncement(
            DiscoveryMessageSequence messageSequence,
            EndpointDiscoveryMetadata endpointDiscoveryMetadata, 
            AsyncCallback callback,
            object state) 
        { 
            return this.OnBeginOfflineAnnouncement(messageSequence, endpointDiscoveryMetadata, callback, state);
        } 

        void IAnnouncementServiceImplementation.OnEndOfflineAnnouncement(IAsyncResult result)
        {
            this.OnEndOfflineAnnouncement(result); 
        }
 
        protected virtual IAsyncResult OnBeginOnlineAnnouncement( 
            DiscoveryMessageSequence messageSequence,
            EndpointDiscoveryMetadata endpointDiscoveryMetadata, 
            AsyncCallback callback,
            object state)
        {
            EventHandler handler = this.OnlineAnnouncementReceived; 

            if (handler != null) 
            { 
                handler(this, new AnnouncementEventArgs(messageSequence, endpointDiscoveryMetadata));
            } 
            return new CompletedAsyncResult(callback, state);
        }

        protected virtual void OnEndOnlineAnnouncement(IAsyncResult result) 
        {
            CompletedAsyncResult.End(result); 
        } 

        protected virtual IAsyncResult OnBeginOfflineAnnouncement( 
            DiscoveryMessageSequence messageSequence,
            EndpointDiscoveryMetadata endpointDiscoveryMetadata,
            AsyncCallback callback,
            object state) 
        {
 
            EventHandler handler = this.OfflineAnnouncementReceived; 

            if (handler != null) 
            {
                handler(this, new AnnouncementEventArgs(messageSequence, endpointDiscoveryMetadata));
            }
            return new CompletedAsyncResult(callback, state); 
        }
 
        protected virtual void OnEndOfflineAnnouncement(IAsyncResult result) 
        {
            CompletedAsyncResult.End(result); 
        }
    }
}

// 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