Esempio n. 1
0
		public void AnnonceOnlineOfflineNoBinding ()
		{
			var ac = new AnnouncementClient (new AnnouncementEndpoint () { Address = new EndpointAddress ("http://localhost:37564")});
			var edm = new EndpointDiscoveryMetadata ();
			ac.AnnounceOnline (edm);
			// attempt to close the client causes another CommunicationObjectFaultedException - looks like it fails to allow Close() at faulted state unlike other objects.
		}
 public DiscoveryChannelDispatcher(AnnouncementEndpoint endpoint, bool handleAnnounceOnline)
 {
     // The argument endpoint is to indicate "destination".
     // It is different from the destination indicated in
     // "EndpointDiscoveryMetadata" argument in announcement messages sent by the "client".
     this.client = new AnnouncementClient(endpoint);
     this.handle_announce_online = handleAnnounceOnline;
 }
		public DiscoveryChannelDispatcher (AnnouncementEndpoint endpoint, bool handleAnnounceOnline)
		{
			// The argument endpoint is to indicate "destination".
			// It is different from the destination indicated in 
			// "EndpointDiscoveryMetadata" argument in announcement messages sent by the "client".
			this.client = new AnnouncementClient (endpoint);
			this.handle_announce_online = handleAnnounceOnline;
		}
Esempio n. 4
0
		public void AnnonceOnlineOfflineNoEndpointAddress ()
		{
			var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding () });
			var edm = new EndpointDiscoveryMetadata ();
			try {
				ac.AnnounceOnline (edm);
			} finally {
				ac.Close ();
			}
		}
Esempio n. 5
0
		// looks like EndpointAddress is *ignored*
		public void AnnonceOnlineOfflineAddressSchemeMismatch ()
		{
			var ac = new AnnouncementClient (new UdpAnnouncementEndpoint () { Address = new EndpointAddress ("http://localhost:37564")});
			var edm = new EndpointDiscoveryMetadata ();
			try {
				ac.AnnounceOnline (edm);
				ac.AnnounceOffline (edm);
			} finally {
				ac.Close ();
			}
		}
Esempio n. 6
0
		public void DefaultValues ()
		{
			// default constructor causes IOE unless there is default configuration...
			var ac = new AnnouncementClient (new AnnouncementEndpoint ());
			Assert.AreEqual (ac.ChannelFactory.Endpoint, ac.Endpoint, "#1");
			Assert.AreEqual ("http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01", ac.Endpoint.Contract.Namespace, "#2");
			Assert.AreEqual (2, ac.Endpoint.Contract.Operations.Count, "#2-2");
			Assert.IsTrue (ac.Endpoint.Contract.Operations.Any (od => od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Hello")), "#2-3");
			Assert.IsTrue (ac.Endpoint.Contract.Operations.Any (od => od.Messages.Any (md => md.Action == "http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Bye")), "#2-4");
			Assert.IsNull (ac.Endpoint.Binding, "#3");
			Assert.IsNull (ac.Endpoint.Address, "#4");
		}
        public AnnouncementDispatcherAsyncResult(
            Collection <AnnouncementEndpoint> endpoints,
            Collection <EndpointDiscoveryMetadata> metadatas,
            DiscoveryMessageSequenceGenerator discoveryMessageSequenceGenerator,
            bool online,
            AsyncCallback callback,
            object state
            )
            : base(callback, state)
        {
            if (metadatas.Count == 0)
            {
                Complete(true);
                return;
            }
            bool success = false;

            this.cancelled    = false;
            this.thisLock     = new object();
            this.innerResults = new AnnouncementSendsAsyncResult[endpoints.Count];
            this.onAnnouncementSendsCompletedCallback = Fx.ThunkCallback(new AsyncCallback(OnAnnouncementSendsCompleted));
            Collection <UniqueId> messageIds = AllocateMessageIds(metadatas.Count);

            try
            {
                Random random = new Random();
                for (int i = 0; i < this.innerResults.Length; i++)
                {
                    AnnouncementClient announcementClient = new AnnouncementClient(endpoints[i]);
                    announcementClient.MessageSequenceGenerator = discoveryMessageSequenceGenerator;
                    this.innerResults[i] =
                        new AnnouncementSendsAsyncResult(
                            announcementClient,
                            metadatas,
                            messageIds,
                            online,
                            endpoints[i].MaxAnnouncementDelay,
                            random,
                            this.onAnnouncementSendsCompletedCallback,
                            this);
                }
                success = true;
            }
            finally
            {
                if (!success)
                {
                    this.Cancel();
                }
            }
        }
        public AnnouncementDispatcherAsyncResult(
            Collection<AnnouncementEndpoint> endpoints,
            Collection<EndpointDiscoveryMetadata> metadatas,
            DiscoveryMessageSequenceGenerator discoveryMessageSequenceGenerator,
            bool online,
            AsyncCallback callback,
            object state
            )
            : base(callback, state)
        {
            if (metadatas.Count == 0)
            {
                Complete(true);
                return;
            }
            bool success = false;
            this.cancelled = false;
            this.thisLock = new object();
            this.innerResults = new AnnouncementSendsAsyncResult[endpoints.Count];
            this.onAnnouncementSendsCompletedCallback = Fx.ThunkCallback(new AsyncCallback(OnAnnouncementSendsCompleted));
            Collection<UniqueId> messageIds = AllocateMessageIds(metadatas.Count);

            try
            {
                Random random = new Random();
                for (int i = 0; i < this.innerResults.Length; i++)
                {
                    AnnouncementClient announcementClient = new AnnouncementClient(endpoints[i]);
                    announcementClient.MessageSequenceGenerator = discoveryMessageSequenceGenerator;
                    this.innerResults[i] = 
                        new AnnouncementSendsAsyncResult(
                        announcementClient, 
                        metadatas, 
                        messageIds, 
                        online, 
                        endpoints[i].MaxAnnouncementDelay, 
                        random, 
                        this.onAnnouncementSendsCompletedCallback, 
                        this);
                }
                success = true;
            }
            finally
            {
                if (!success)
                {
                    this.Cancel();
                }
            }
        }
Esempio n. 9
0
        private void HeartBeat(IEnumerable<EndpointDiscoveryMetadata> metadatas, AnnouncementEndpoint announcementEndpoint)
        {
            while (true)
            {
                Thread.Sleep(_interval);

                using (var announcementClient = new AnnouncementClient(announcementEndpoint))
                {
                    foreach (var metadata in metadatas)
                    {
                        announcementClient.AnnounceOnline(metadata);
                    }
                }
            }
        }
 internal AnnouncementSendsAsyncResult(
     AnnouncementClient announcementClient,
     Collection <EndpointDiscoveryMetadata> publishedEndpoints,
     Collection <UniqueId> messageIds,
     bool online,
     TimeSpan maxDelay,
     Random random,
     AsyncCallback callback,
     object state)
     : base(publishedEndpoints.Count, maxDelay, announcementClient, random, callback, state)
 {
     Fx.Assert(publishedEndpoints.Count == messageIds.Count, "There must be one message Ids for each EndpointDiscoveryMetadata.");
     this.announcementClient = announcementClient;
     this.publishedEndpoints = publishedEndpoints;
     this.messageIds         = messageIds;
     this.online             = online;
 }
 internal AnnouncementSendsAsyncResult(
     AnnouncementClient announcementClient, 
     Collection<EndpointDiscoveryMetadata> publishedEndpoints, 
     Collection<UniqueId> messageIds,
     bool online,
     TimeSpan maxDelay,
     Random random,
     AsyncCallback callback,
     object state)
     : base(publishedEndpoints.Count, maxDelay, announcementClient, random, callback, state)
 {
     Fx.Assert(publishedEndpoints.Count == messageIds.Count, "There must be one message Ids for each EndpointDiscoveryMetadata.");
     this.announcementClient = announcementClient;
     this.publishedEndpoints = publishedEndpoints;
     this.messageIds = messageIds;
     this.online = online;
 }
Esempio n. 12
0
        public WcfDiscovery(Self self, IManager engine)
        {
            _self = self;
            _engine = engine;

            var listener = new AnnouncementService();

            listener.OnlineAnnouncementReceived +=
                (sender, args) => handle_hello_message(args.EndpointDiscoveryMetadata);

            _mutex = new Object();
            _serviceEndpoint = new UdpAnnouncementEndpoint();
            _announcementService = new ServiceHost(listener);
            _announcementService.AddServiceEndpoint(_serviceEndpoint);

            _announcementCleint = new AnnouncementClient(new UdpAnnouncementEndpoint());

            _counters = Context.Get<ICountersDb>().NewCounters();
        }
Esempio n. 13
0
        /// <summary>
        /// Starts the module for the given host.
        /// </summary>
        /// <param name="host">The host.</param>
        public void Start(AgentHost host)
        {
            lock (this)
            {
                client = CreateAnnouncementClient();
                client.Open();
                host.TestRunner.PingReceived += PingReceived;
                host.TestRunner.CommunicationStarted += CommunicationStarted;
                host.TestRunner.CommunicationFinished += CommunicationFinished;

                endpointDiscoveryMetadata = EndpointDiscoveryMetadata.FromServiceEndpoint(host.Endpoint);
                announcementTimer = new Timer(o => Announce(), null, Timeout.Infinite, Timeout.Infinite);

                Debug.Assert(endpointDiscoveryMetadata != null);

                if (!endpointDiscoveryMetadata.Scopes.Contains(scope))
                    endpointDiscoveryMetadata.Scopes.Add(scope);

                new Action(Announce).BeginInvoke(null, null);
            }
        }
Esempio n. 14
0
		public void AnnonceOnlineOfflineAddressSchemeMismatch2 ()
		{
			var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding (), Address = new EndpointAddress ("soap.udp://localhost:37564")});
			var edm = new EndpointDiscoveryMetadata ();
			try {
				ac.AnnounceOnline (edm);
			} finally {
				ac.Close ();
			}
		}
Esempio n. 15
0
 /// <summary>
 /// Announces the hosts' endpoint.
 /// </summary>
 private void Announce()
 {
     lock (this)
     {
         if (announcementTimer != null && communicationsCount==0)
         {
             try
             {
                 log.Debug(string.Format("Announcing endpoint {0}", endpointDiscoveryMetadata.Address));
                 if (client.InnerChannel.State == CommunicationState.Faulted)
                 {
                     client.Close();
                     client = CreateAnnouncementClient();
                 }
                 client.AnnounceOnline(endpointDiscoveryMetadata);
             }
             catch(Exception ex)
             {
                 log.Debug(string.Format("There was an exception while announcing: {0}", ex.Message));
             }
             finally
             {
                 announcementTimer.Change((int) announcementInterval.TotalMilliseconds, Timeout.Infinite);
             }
         }
     }
 }
Esempio n. 16
0
		public void AnnonceOnlineOfflineHttpWSA10 ()
		{
			var binding = new CustomBinding (new HttpTransportBindingElement ());
			var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = binding, Address = http_address });
			var edm = new EndpointDiscoveryMetadata ();
			try {
				ac.AnnounceOnline (edm);
			} finally {
				ac.Close ();
			}
		}
Esempio n. 17
0
 private void _announcementTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         _announcementClient.AnnounceOnline(_endpointDiscoveryMetadata);
     }
     catch (EndpointNotFoundException ex)
     {
         //this error occurs when announcement endpoint is not on the network
     }
     catch (CommunicationException ex)
     {
         _announcementClient.InnerChannel.Abort();
         _announcementClient = new AnnouncementClient(_announcementEndpoint);
     }
     catch (Exception exp)
     {
     }
 }
Esempio n. 18
0
		public void AnnonceOnlineOfflineHttpMessageVersionMismatch ()
		{
			var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding () { SendTimeout = TimeSpan.FromSeconds (10), ReceiveTimeout = TimeSpan.FromSeconds (10) }, Address = http_address });
			var edm = new EndpointDiscoveryMetadata ();
			try {
				ac.AnnounceOnline (edm);
			} finally {
				ac.Close ();
			}
		}
Esempio n. 19
0
		public void AnnonceOnlineOfflineHttpWSA10 ()
		{
			var binding = new CustomBinding (new HttpTransportBindingElement ()) { SendTimeout = TimeSpan.FromSeconds (10), ReceiveTimeout = TimeSpan.FromSeconds (10) };
			var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = binding, Address = http_address });
			var edm = new EndpointDiscoveryMetadata ();
			try {
				ac.AnnounceOnline (edm);
			} finally {
				ac.Close ();
			}
		}
Esempio n. 20
0
        public void Open(string announcementConnectionUri, int announcementTimerSec, bool enableAnnouncement)
        {
            try
            {
                
                ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();

                EndpointDiscoveryBehavior endpointDiscoveryBehavior = new EndpointDiscoveryBehavior();

                XElement endpointMetadata = new XElement("Root", new XElement(_metaDataElement, _metaDataElementValue));
                XElement aliasMetadata = new XElement("Root", new XElement(_metaDataAlias, _metaDataAliasValue));
                XElement LoginMetadata = new XElement("Root", new XElement(_metaDataLogIn, _metaDataLogInValue));

                endpointDiscoveryBehavior.Extensions.Add(endpointMetadata);
                endpointDiscoveryBehavior.Extensions.Add(aliasMetadata);
                endpointDiscoveryBehavior.Extensions.Add(LoginMetadata);

                _netTcpEndpoint.Behaviors.Add(endpointDiscoveryBehavior);

                _serviceHost.Description.Behaviors.Add(serviceDiscoveryBehavior);
                _serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());

                _serviceHost.Open();

                if (enableAnnouncement)
                {
                    Uri announcementEndpointUri = new Uri(announcementConnectionUri);
                    EndpointAddress announcementEndpointAddress = new EndpointAddress(announcementEndpointUri);
                    NetTcpBinding binding = new NetTcpBinding();
                    binding.Security.Mode = SecurityMode.None;
                    _announcementEndpoint = new AnnouncementEndpoint(binding, announcementEndpointAddress);

                    _announcementClient = new AnnouncementClient(_announcementEndpoint);
                    _endpointDiscoveryMetadata = EndpointDiscoveryMetadata.FromServiceEndpoint(_netTcpEndpoint);

                    //Start a timer that send announcement message
                    _announcementTimer = new Timer(announcementTimerSec * 1000);
                    _announcementTimer.AutoReset = true;
                    _announcementTimer.Elapsed += new ElapsedEventHandler(_announcementTimer_Elapsed);
                    _announcementTimer.Start();

                    _announcementClient.Open();
                }

                IsRunning = true;
               
            }
            catch (EndpointNotFoundException ex)
            {
                //this error occurs when announcement endpoint is not on the network
            }
            catch (CommunicationException ex)
            {
                _serviceHost.Abort();
                // customize this exception to be more specific
                throw;
            }
        }
Esempio n. 21
0
		public void AnnonceOnlineOfflineHttpMessageVersionMismatch ()
		{
			var ac = new AnnouncementClient (new AnnouncementEndpoint () { Binding = new BasicHttpBinding (), Address = http_address });
			var edm = new EndpointDiscoveryMetadata ();
			try {
				ac.AnnounceOnline (edm);
			} finally {
				ac.Close ();
			}
		}