public override void Unregister(object registrationId, TimeSpan timeout) { RegistrationHandle handle = registrationId as RegistrationHandle; if ((handle == null) || string.IsNullOrEmpty(handle.PeerName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("PeerInvalidRegistrationId", new object[] { handle }), "registrationId")); } string peerName = handle.PeerName; string str2 = string.Format(CultureInfo.InvariantCulture, "0.{0}", new object[] { peerName }); this.registrar.Unregister(str2, handle.Clouds, timeout); if (DiagnosticUtility.ShouldTraceInformation) { PnrpPeerResolverTraceRecord extendedData = new PnrpPeerResolverTraceRecord(peerName, new List<PeerNodeAddress>()); TraceUtility.TraceEvent(TraceEventType.Information, 0x40049, System.ServiceModel.SR.GetString("TraceCodePnrpUnregisteredAddresses"), extendedData, this, null); } }
public override ReadOnlyCollection<PeerNodeAddress> Resolve(string meshId, int maxAddresses, TimeSpan timeout) { ThrowIfNoPnrp(); UnsafePnrpNativeMethods.PeerNameResolver resolver; List<UnsafePnrpNativeMethods.PeerNameResolver> resolvers = new List<UnsafePnrpNativeMethods.PeerNameResolver>(); List<PnrpRegistration> globalRegistrations = new List<PnrpRegistration>(); List<PnrpRegistration> linkRegistrations = new List<PnrpRegistration>(); List<PnrpRegistration> siteRegistrations = new List<PnrpRegistration>(); List<WaitHandle> handles = new List<WaitHandle>(); Dictionary<uint, string> SiteCloudNames = new Dictionary<uint, string>(); Dictionary<uint, string> LinkCloudNames = new Dictionary<uint, string>(); UnsafePnrpNativeMethods.PnrpResolveCriteria targetScope = resolutionScope; TimeoutHelper timeoutHelper = new TimeoutHelper(TimeSpan.Compare(timeout, MaxResolveTimeout) <= 0 ? timeout : MaxResolveTimeout); if (!HasPeerNodeForMesh(meshId)) targetScope = UnsafePnrpNativeMethods.PnrpResolveCriteria.Any; PnrpResolveScope currentScope = EnumerateClouds(true, LinkCloudNames, SiteCloudNames); if (remoteExtension != null) meshId += remoteExtension; // prepend a 0. for unsecured peername string peerName = string.Format(CultureInfo.InvariantCulture, "0.{0}", meshId); if ((currentScope & PnrpResolveScope.Global) != 0) { resolver = new UnsafePnrpNativeMethods.PeerNameResolver( peerName, maxAddresses, targetScope, 0, GlobalCloudName, timeoutHelper.RemainingTime(), globalRegistrations); handles.Add(resolver.AsyncWaitHandle); resolvers.Add(resolver); } if ((currentScope & PnrpResolveScope.LinkLocal) != 0) { foreach (KeyValuePair<uint, string> linkEntry in LinkCloudNames) { resolver = new UnsafePnrpNativeMethods.PeerNameResolver( peerName, maxAddresses, targetScope, linkEntry.Key, linkEntry.Value, timeoutHelper.RemainingTime(), linkRegistrations); handles.Add(resolver.AsyncWaitHandle); resolvers.Add(resolver); } } if ((currentScope & PnrpResolveScope.SiteLocal) != 0) { foreach (KeyValuePair<uint, string> siteEntry in SiteCloudNames) { resolver = new UnsafePnrpNativeMethods.PeerNameResolver( peerName, maxAddresses, targetScope, siteEntry.Key, siteEntry.Value, timeoutHelper.RemainingTime(), siteRegistrations); handles.Add(resolver.AsyncWaitHandle); resolvers.Add(resolver); } } if (handles.Count == 0) { //could not find any clouds. if (DiagnosticUtility.ShouldTraceWarning) { Exception exception = new InvalidOperationException(SR.GetString(SR.PnrpNoClouds)); PnrpResolveExceptionTraceRecord record = new PnrpResolveExceptionTraceRecord(meshId, string.Empty, exception); TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.PnrpResolvedAddresses, SR.GetString(SR.TraceCodePnrpResolvedAddresses), record, this, null); } return new ReadOnlyCollection<PeerNodeAddress>(new List<PeerNodeAddress>()); } Exception lastException = null; foreach (UnsafePnrpNativeMethods.PeerNameResolver handle in resolvers) { try { handle.End(); } catch (SocketException e) { DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); lastException = e; } } List<PeerNodeAddress> nodeAddressList = new List<PeerNodeAddress>(); MergeResults(nodeAddressList, globalRegistrations, linkRegistrations, siteRegistrations); if ((lastException != null) && (nodeAddressList.Count == 0)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(lastException); if (DiagnosticUtility.ShouldTraceInformation) { PnrpPeerResolverTraceRecord record = new PnrpPeerResolverTraceRecord(meshId, nodeAddressList); TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.PnrpResolvedAddresses, SR.GetString(SR.TraceCodePnrpResolvedAddresses), record, this, null); } return new ReadOnlyCollection<PeerNodeAddress>(nodeAddressList); }
public override ReadOnlyCollection<PeerNodeAddress> Resolve(string meshId, int maxAddresses, TimeSpan timeout) { UnsafePnrpNativeMethods.PeerNameResolver resolver; this.ThrowIfNoPnrp(); List<UnsafePnrpNativeMethods.PeerNameResolver> list = new List<UnsafePnrpNativeMethods.PeerNameResolver>(); List<PnrpRegistration> results = new List<PnrpRegistration>(); List<PnrpRegistration> list3 = new List<PnrpRegistration>(); List<PnrpRegistration> list4 = new List<PnrpRegistration>(); List<WaitHandle> list5 = new List<WaitHandle>(); Dictionary<uint, string> siteCloudNames = new Dictionary<uint, string>(); Dictionary<uint, string> linkCloudNames = new Dictionary<uint, string>(); UnsafePnrpNativeMethods.PnrpResolveCriteria nearestNonCurrentProcess = UnsafePnrpNativeMethods.PnrpResolveCriteria.NearestNonCurrentProcess; TimeoutHelper helper = new TimeoutHelper((TimeSpan.Compare(timeout, MaxResolveTimeout) <= 0) ? timeout : MaxResolveTimeout); if (!HasPeerNodeForMesh(meshId)) { nearestNonCurrentProcess = UnsafePnrpNativeMethods.PnrpResolveCriteria.Any; } PnrpResolveScope scope = this.EnumerateClouds(true, linkCloudNames, siteCloudNames); if (this.remoteExtension != null) { meshId = meshId + this.remoteExtension; } string peerName = string.Format(CultureInfo.InvariantCulture, "0.{0}", new object[] { meshId }); if ((scope & PnrpResolveScope.Global) != PnrpResolveScope.None) { resolver = new UnsafePnrpNativeMethods.PeerNameResolver(peerName, maxAddresses, nearestNonCurrentProcess, 0, "Global_", helper.RemainingTime(), results); list5.Add(resolver.AsyncWaitHandle); list.Add(resolver); } if ((scope & PnrpResolveScope.LinkLocal) != PnrpResolveScope.None) { foreach (KeyValuePair<uint, string> pair in linkCloudNames) { resolver = new UnsafePnrpNativeMethods.PeerNameResolver(peerName, maxAddresses, nearestNonCurrentProcess, pair.Key, pair.Value, helper.RemainingTime(), list3); list5.Add(resolver.AsyncWaitHandle); list.Add(resolver); } } if ((scope & PnrpResolveScope.SiteLocal) != PnrpResolveScope.None) { foreach (KeyValuePair<uint, string> pair2 in siteCloudNames) { resolver = new UnsafePnrpNativeMethods.PeerNameResolver(peerName, maxAddresses, nearestNonCurrentProcess, pair2.Key, pair2.Value, helper.RemainingTime(), list4); list5.Add(resolver.AsyncWaitHandle); list.Add(resolver); } } if (list5.Count == 0) { if (DiagnosticUtility.ShouldTraceWarning) { Exception exception = new InvalidOperationException(System.ServiceModel.SR.GetString("PnrpNoClouds")); PnrpResolveExceptionTraceRecord extendedData = new PnrpResolveExceptionTraceRecord(meshId, string.Empty, exception); TraceUtility.TraceEvent(TraceEventType.Warning, 0x4004a, System.ServiceModel.SR.GetString("TraceCodePnrpResolvedAddresses"), extendedData, this, null); } return new ReadOnlyCollection<PeerNodeAddress>(new List<PeerNodeAddress>()); } Exception exception2 = null; foreach (UnsafePnrpNativeMethods.PeerNameResolver resolver2 in list) { try { resolver2.End(); } catch (SocketException exception3) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information); exception2 = exception3; } } List<PeerNodeAddress> nodeAddressList = new List<PeerNodeAddress>(); this.MergeResults(nodeAddressList, results, list3, list4); if ((exception2 != null) && (nodeAddressList.Count == 0)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception2); } if (DiagnosticUtility.ShouldTraceInformation) { PnrpPeerResolverTraceRecord record2 = new PnrpPeerResolverTraceRecord(meshId, nodeAddressList); TraceUtility.TraceEvent(TraceEventType.Information, 0x4004a, System.ServiceModel.SR.GetString("TraceCodePnrpResolvedAddresses"), record2, this, null); } return new ReadOnlyCollection<PeerNodeAddress>(nodeAddressList); }
public override void Unregister(object registrationId, TimeSpan timeout) { RegistrationHandle regHandle = registrationId as RegistrationHandle; if (regHandle == null || String.IsNullOrEmpty(regHandle.PeerName)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.PeerInvalidRegistrationId, regHandle), "registrationId")); string meshId = regHandle.PeerName; // prepend a 0. for unsecured peername string peerName = string.Format(CultureInfo.InvariantCulture, "0.{0}", meshId); registrar.Unregister(peerName, regHandle.Clouds, timeout); if (DiagnosticUtility.ShouldTraceInformation) { PnrpPeerResolverTraceRecord record = new PnrpPeerResolverTraceRecord(meshId, new List<PeerNodeAddress>()); TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.PnrpUnregisteredAddresses, SR.GetString(SR.TraceCodePnrpUnregisteredAddresses), record, this, null); } }