コード例 #1
0
 private void SendUpdate(UpdateInfo updateInfo, TimeSpan timeout)
 {
     try
     {
         IPeerResolverClient proxy = this.GetProxy();
         try
         {
             proxy.OperationTimeout = timeout;
             RegisterResponseInfo info = proxy.Update(updateInfo);
             proxy.Close();
             this.registrationId  = info.RegistrationId;
             this.defaultLifeTime = info.RegistrationLifetime;
             Interlocked.Exchange(ref this.updateSuccessful, 1);
             this.timer.Set(this.defaultLifeTime);
         }
         finally
         {
             proxy.Abort();
         }
     }
     catch (CommunicationException exception)
     {
         DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
         Interlocked.Exchange(ref this.updateSuccessful, 0);
     }
     catch (Exception exception2)
     {
         if (Fx.IsFatal(exception2))
         {
             throw;
         }
         Interlocked.Exchange(ref this.updateSuccessful, 0);
         throw;
     }
 }
コード例 #2
0
 public override object Register(string meshId, PeerNodeAddress nodeAddress, TimeSpan timeout)
 {
     if (this.opened)
     {
         long scopeId = -1L;
         bool flag    = false;
         if (nodeAddress.IPAddresses.Count == 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("MustRegisterMoreThanZeroAddresses")));
         }
         foreach (IPAddress address in nodeAddress.IPAddresses)
         {
             if (address.IsIPv6LinkLocal)
             {
                 if (scopeId == -1L)
                 {
                     scopeId = address.ScopeId;
                 }
                 else if (scopeId != address.ScopeId)
                 {
                     flag = true;
                     break;
                 }
             }
         }
         List <IPAddress> list = new List <IPAddress>();
         foreach (IPAddress address2 in nodeAddress.IPAddresses)
         {
             if (!flag || (!address2.IsIPv6LinkLocal && !address2.IsIPv6SiteLocal))
             {
                 list.Add(address2);
             }
         }
         if (list.Count == 0)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("AmbiguousConnectivitySpec")));
         }
         ReadOnlyCollection <IPAddress> ipAddresses = new ReadOnlyCollection <IPAddress>(list);
         this.meshId      = meshId;
         this.nodeAddress = new PeerNodeAddress(nodeAddress.EndpointAddress, ipAddresses);
         RegisterInfo        registerInfo = new RegisterInfo(this.clientId, meshId, this.nodeAddress);
         IPeerResolverClient proxy        = this.GetProxy();
         try
         {
             proxy.OperationTimeout = timeout;
             RegisterResponseInfo info2 = proxy.Register(registerInfo);
             this.registrationId = info2.RegistrationId;
             this.timer.Set(info2.RegistrationLifetime);
             this.defaultLifeTime = info2.RegistrationLifetime;
             proxy.Close();
         }
         finally
         {
             proxy.Abort();
         }
     }
     return(this.registrationId);
 }
コード例 #3
0
        void RegistrationExpired(object state)
        {
            if (!opened)
            {
                return;
            }

            try
            {
                IPeerResolverClient proxy = GetProxy();
                RefreshResponseInfo response;
                try
                {
                    int oldValue = Interlocked.Exchange(ref this.updateSuccessful, 1);
                    if (oldValue == 0)
                    {
                        SendUpdate(new UpdateInfo(this.registrationId, this.clientId, this.meshId, this.nodeAddress), ServiceDefaults.SendTimeout);
                        return;
                    }

                    RefreshInfo info = new RefreshInfo(this.meshId, this.registrationId);
                    response = proxy.Refresh(info);

                    if (response.Result == RefreshResult.RegistrationNotFound)
                    {
                        RegisterInfo         registerInfo     = new RegisterInfo(clientId, meshId, nodeAddress);
                        RegisterResponseInfo registerResponse = proxy.Register(registerInfo);
                        registrationId       = registerResponse.RegistrationId;
                        this.defaultLifeTime = registerResponse.RegistrationLifetime;
                    }
                    else
                    {
                        Fx.Assert(response.Result == RefreshResult.Success, "Unrecognized value!!");
                    }
                    proxy.Close();
                }
                finally
                {
                    proxy.Abort();
                    timer.Set(this.defaultLifeTime);
                }
            }
            catch (CommunicationException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
            }
        }
コード例 #4
0
 private void RegistrationExpired(object state)
 {
     if (this.opened)
     {
         try
         {
             IPeerResolverClient proxy = this.GetProxy();
             try
             {
                 if (Interlocked.Exchange(ref this.updateSuccessful, 1) == 0)
                 {
                     this.SendUpdate(new UpdateInfo(this.registrationId, this.clientId, this.meshId, this.nodeAddress), ServiceDefaults.SendTimeout);
                 }
                 else
                 {
                     RefreshInfo refreshInfo = new RefreshInfo(this.meshId, this.registrationId);
                     if (proxy.Refresh(refreshInfo).Result == RefreshResult.RegistrationNotFound)
                     {
                         RegisterInfo         registerInfo = new RegisterInfo(this.clientId, this.meshId, this.nodeAddress);
                         RegisterResponseInfo info4        = proxy.Register(registerInfo);
                         this.registrationId  = info4.RegistrationId;
                         this.defaultLifeTime = info4.RegistrationLifetime;
                     }
                     proxy.Close();
                 }
             }
             finally
             {
                 proxy.Abort();
                 this.timer.Set(this.defaultLifeTime);
             }
         }
         catch (CommunicationException exception)
         {
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
         }
         catch (Exception exception2)
         {
             if (Fx.IsFatal(exception2))
             {
                 throw;
             }
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
         }
     }
 }
コード例 #5
0
ファイル: ChatServer.cs プロジェクト: alesliehughes/olive
		public override RegisterResponseInfo Register (RegisterInfo registerInfo)
		{
			Node n = new Node ();
			RegisterResponseInfo rri;
			
			if (ControlShape)
			{
				lock (mesh_lock)
				{
					Guid guid = Guid.NewGuid ();
					n.RegistrationId = guid;
					n.Address = registerInfo.NodeAddress;
					n.ClientId = registerInfo.ClientId;
					Console.WriteLine ("Register: {0}", n.ClientId);
					
					if (nodes_count == 0)
						unique_node = n;
					
					nodes_count ++;
					rri = new RegisterResponseInfo (n.RegistrationId, TimeSpan.MaxValue);
				}
			}
			else
				rri = base.Register (registerInfo);
			
			return rri;
		}
コード例 #6
0
        // Register address for a node participating in a mesh identified by meshId with the resolver service
        public override object Register(string meshId, PeerNodeAddress nodeAddress, TimeSpan timeout)
        {
            if (opened)
            {
                long scopeId        = -1;
                bool multipleScopes = false;

                if (nodeAddress.IPAddresses.Count == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MustRegisterMoreThanZeroAddresses)));
                }

                foreach (IPAddress address in nodeAddress.IPAddresses)
                {
                    if (address.IsIPv6LinkLocal)
                    {
                        if (scopeId == -1)
                        {
                            scopeId = address.ScopeId;
                        }
                        else if (scopeId != address.ScopeId)
                        {
                            multipleScopes = true;
                            break;
                        }
                    }
                }

                List <IPAddress> addresslist = new List <IPAddress>();
                foreach (IPAddress address in nodeAddress.IPAddresses)
                {
                    if (!multipleScopes || (!address.IsIPv6LinkLocal && !address.IsIPv6SiteLocal))
                    {
                        addresslist.Add(address);
                    }
                }

                if (addresslist.Count == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.AmbiguousConnectivitySpec)));
                }

                ReadOnlyCollection <IPAddress> addresses = new ReadOnlyCollection <IPAddress>(addresslist);
                this.meshId      = meshId;
                this.nodeAddress = new PeerNodeAddress(nodeAddress.EndpointAddress, addresses);
                RegisterInfo        info  = new RegisterInfo(clientId, meshId, this.nodeAddress);
                IPeerResolverClient proxy = GetProxy();
                try
                {
                    proxy.OperationTimeout = timeout;
                    RegisterResponseInfo response = proxy.Register(info);
                    this.registrationId = response.RegistrationId;
                    timer.Set(response.RegistrationLifetime);
                    this.defaultLifeTime = response.RegistrationLifetime;
                    proxy.Close();
                }
                finally
                {
                    proxy.Abort();
                }
            }
            return(registrationId);
        }