public override object Register(string meshId, PeerNodeAddress nodeAddress, TimeSpan timeout)
 {
     this.ThrowIfNoPnrp();
     PnrpRegistration global = null;
     PnrpRegistration[] linkRegs = null;
     PnrpRegistration[] siteRegs = null;
     RegistrationHandle registrationId = new RegistrationHandle(meshId);
     Dictionary<uint, string> siteCloudNames = new Dictionary<uint, string>();
     Dictionary<uint, string> linkCloudNames = new Dictionary<uint, string>();
     PnrpResolveScope scope = this.EnumerateClouds(false, linkCloudNames, siteCloudNames);
     if (scope == PnrpResolveScope.None)
     {
         PeerExceptionHelper.ThrowInvalidOperation_PnrpNoClouds();
     }
     if (this.localExtension != null)
     {
         meshId = meshId + this.localExtension;
     }
     try
     {
         this.PeerNodeAddressToPnrpRegistrations(meshId, linkCloudNames, siteCloudNames, nodeAddress, out linkRegs, out siteRegs, out global);
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("PeerPnrpIllegalUri"), exception));
     }
     TimeoutHelper helper = new TimeoutHelper(timeout);
     try
     {
         PnrpResolveScope none = PnrpResolveScope.None;
         if (((global != null) && (global.Addresses.Length > 0)) && ((scope & PnrpResolveScope.Global) != PnrpResolveScope.None))
         {
             this.registrar.Register(global, helper.RemainingTime());
             registrationId.AddCloud(global.CloudName);
             none |= PnrpResolveScope.Global;
         }
         if (linkRegs.Length > 0)
         {
             foreach (PnrpRegistration registration2 in linkRegs)
             {
                 if (registration2.Addresses.Length > 0)
                 {
                     this.registrar.Register(registration2, helper.RemainingTime());
                     registrationId.AddCloud(registration2.CloudName);
                 }
             }
             none |= PnrpResolveScope.LinkLocal;
         }
         if (siteRegs.Length > 0)
         {
             foreach (PnrpRegistration registration3 in siteRegs)
             {
                 if (registration3.Addresses.Length > 0)
                 {
                     this.registrar.Register(registration3, helper.RemainingTime());
                     registrationId.AddCloud(registration3.CloudName);
                 }
             }
             none |= PnrpResolveScope.SiteLocal;
         }
         if (none == PnrpResolveScope.None)
         {
             PeerExceptionHelper.ThrowInvalidOperation_PnrpAddressesUnsupported();
         }
     }
     catch (SocketException)
     {
         try
         {
             this.Unregister(registrationId, helper.RemainingTime());
         }
         catch (SocketException exception2)
         {
             DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
         }
         throw;
     }
     if (DiagnosticUtility.ShouldTraceInformation)
     {
         PnrpRegisterTraceRecord extendedData = new PnrpRegisterTraceRecord(meshId, global, siteRegs, linkRegs);
         TraceUtility.TraceEvent(TraceEventType.Information, 0x40048, System.ServiceModel.SR.GetString("TraceCodePnrpRegisteredAddresses"), extendedData, this, null);
     }
     return registrationId;
 }
コード例 #2
0
        public override object Register(string meshId, PeerNodeAddress nodeAddress, TimeSpan timeout)
        {
            ThrowIfNoPnrp();

            PnrpRegistration globalEntry = null;
            PnrpRegistration[] linkEntries = null;
            PnrpRegistration[] siteEntries = null;

            RegistrationHandle regHandle = new RegistrationHandle(meshId);
            Dictionary<uint, string> SiteCloudNames = new Dictionary<uint, string>();
            Dictionary<uint, string> LinkCloudNames = new Dictionary<uint, string>();

            PnrpResolveScope availableScope = EnumerateClouds(false, LinkCloudNames, SiteCloudNames);

            if (availableScope == PnrpResolveScope.None)
            {
                //could not find any clouds.
                PeerExceptionHelper.ThrowInvalidOperation_PnrpNoClouds();
            }

            if (localExtension != null)
                meshId += localExtension;

            try
            {
                PeerNodeAddressToPnrpRegistrations(meshId, LinkCloudNames, SiteCloudNames, nodeAddress, out linkEntries, out siteEntries, out globalEntry);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e)) throw;
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.PeerPnrpIllegalUri), e));
            }
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            try
            {
                PnrpResolveScope currentScope = PnrpResolveScope.None;
                if (globalEntry != null)
                {
                    if (globalEntry.Addresses.Length > 0 && (availableScope & PnrpResolveScope.Global) != 0)
                    {
                        registrar.Register(globalEntry, timeoutHelper.RemainingTime());
                        regHandle.AddCloud(globalEntry.CloudName);
                        currentScope |= PnrpResolveScope.Global;
                    }
                }
                if (linkEntries.Length > 0)
                {
                    foreach (PnrpRegistration entry in linkEntries)
                    {
                        if (entry.Addresses.Length > 0)
                        {
                            registrar.Register(entry, timeoutHelper.RemainingTime());
                            regHandle.AddCloud(entry.CloudName);
                        }
                    }
                    currentScope |= PnrpResolveScope.LinkLocal;
                }
                if (siteEntries.Length > 0)
                {
                    foreach (PnrpRegistration entry in siteEntries)
                    {
                        if (entry.Addresses.Length > 0)
                        {
                            registrar.Register(entry, timeoutHelper.RemainingTime());
                            regHandle.AddCloud(entry.CloudName);
                        }
                    }
                    currentScope |= PnrpResolveScope.SiteLocal;
                }
                if (currentScope == PnrpResolveScope.None)
                {
                    // We have addresses but no cloud that corresponds to them
                    // so we should throw an exception
                    PeerExceptionHelper.ThrowInvalidOperation_PnrpAddressesUnsupported();
                }
            }
            catch (SocketException)
            {
                try
                {
                    Unregister(regHandle, timeoutHelper.RemainingTime());
                }
                catch (SocketException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
                throw;
            }

            if (DiagnosticUtility.ShouldTraceInformation)
            {
                PnrpRegisterTraceRecord record = new PnrpRegisterTraceRecord(meshId, globalEntry, siteEntries, linkEntries);
                TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.PnrpRegisteredAddresses,
                    SR.GetString(SR.TraceCodePnrpRegisteredAddresses),
                    record, this, null);
            }

            return regHandle;
        }