public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport) { DirectoryEntry directoryEntry; ActiveDirectorySiteLink activeDirectorySiteLink; ActiveDirectorySiteLink.ValidateArgument(context, siteLinkName, transport); context = new DirectoryContext(context); try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", propertyValue); if (transport != ActiveDirectoryTransportType.Rpc) { str = string.Concat("CN=SMTP,", str); } else { str = string.Concat("CN=IP,", str); } directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } try { try { string[] strArrays = new string[1]; strArrays[0] = "distinguishedName"; ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=siteLink)(objectCategory=SiteLink)(name=", Utils.GetEscapedFilterValue(siteLinkName), "))"), strArrays, SearchScope.OneLevel, false, false); SearchResult searchResult = aDSearcher.FindOne(); if (searchResult != null) { DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry(); ActiveDirectorySiteLink activeDirectorySiteLink1 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, directoryEntry1); activeDirectorySiteLink = activeDirectorySiteLink1; } else { Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName); throw exception; } } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; if (cOMException2.ErrorCode != -2147016656) { throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2); } else { DirectoryEntry directoryEntry2 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); if (!Utils.CheckCapability(directoryEntry2, Capability.ActiveDirectoryApplicationMode) || transport != ActiveDirectoryTransportType.Smtp) { throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName); } else { throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP")); } } } } finally { directoryEntry.Dispose(); } return(activeDirectorySiteLink); }
public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule) { DirectoryEntry directoryEntry; string str; this.systemDefaultInterval = new TimeSpan(0, 15, 0); this.sites = new ActiveDirectorySiteCollection(); ActiveDirectorySiteLink.ValidateArgument(context, siteLinkName, transport); context = new DirectoryContext(context); this.context = context; this.name = siteLinkName; this.transport = transport; try { directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext); if (transport != ActiveDirectoryTransportType.Rpc) { str = string.Concat("CN=SMTP,CN=Inter-Site Transports,CN=Sites,", propertyValue); } else { str = string.Concat("CN=IP,CN=Inter-Site Transports,CN=Sites,", propertyValue); } directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str); } catch (COMException cOMException1) { COMException cOMException = cOMException1; throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException); } catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException) { object[] name = new object[1]; name[0] = context.Name; throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name)); } try { try { string escapedPath = string.Concat("cn=", this.name); escapedPath = Utils.GetEscapedPath(escapedPath); this.cachedEntry = directoryEntry.Children.Add(escapedPath, "siteLink"); this.cachedEntry.Properties["cost"].Value = 100; this.cachedEntry.Properties["replInterval"].Value = 180; if (schedule != null) { this.cachedEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule(); } } catch (COMException cOMException3) { COMException cOMException2 = cOMException3; if (cOMException2.ErrorCode == -2147016656) { DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE); if (Utils.CheckCapability(directoryEntry1, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp) { throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP")); } } throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2); } } finally { directoryEntry.Dispose(); } }