Ejemplo n.º 1
1
		internal ReplicationConnectionCollection GetOutboundConnectionsHelper()
		{
			string siteObjectName;
			string serverObjectName;
			if (this.outbound == null)
			{
				if (this as DomainController != null)
				{
					siteObjectName = ((DomainController)this).SiteObjectName;
				}
				else
				{
					siteObjectName = ((AdamInstance)this).SiteObjectName;
				}
				string str = siteObjectName;
				DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context), str);
				if (this as DomainController != null)
				{
					serverObjectName = ((DomainController)this).ServerObjectName;
				}
				else
				{
					serverObjectName = ((AdamInstance)this).ServerObjectName;
				}
				string str1 = serverObjectName;
				string[] strArrays = new string[2];
				strArrays[0] = "objectClass";
				strArrays[1] = "cn";
				ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection)(fromServer=CN=NTDS Settings,", str1, "))"), strArrays, SearchScope.Subtree);
				SearchResultCollection searchResultCollections = null;
				DirectoryContext newDirectoryContext = Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context);
				try
				{
					try
					{
						searchResultCollections = aDSearcher.FindAll();
						this.outbound = new ReplicationConnectionCollection();
						foreach (SearchResult searchResult in searchResultCollections)
						{
							ReplicationConnection replicationConnection = new ReplicationConnection(newDirectoryContext, searchResult.GetDirectoryEntry(), (string)searchResult.Properties["cn"][0]);
							this.outbound.Add(replicationConnection);
						}
					}
					catch (COMException cOMException1)
					{
						COMException cOMException = cOMException1;
						throw ExceptionHelper.GetExceptionFromCOMException(newDirectoryContext, cOMException);
					}
				}
				finally
				{
					if (searchResultCollections != null)
					{
						searchResultCollections.Dispose();
					}
					directoryEntry.Dispose();
				}
			}
			return this.outbound;
		}
		public int IndexOf(ReplicationConnection connection)
		{
			if (connection != null)
			{
				if (connection.existingConnection)
				{
					string propertyValue = (string)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName);
					int num = 0;
					while (num < base.InnerList.Count)
					{
						ReplicationConnection item = (ReplicationConnection)base.InnerList[num];
						string str = (string)PropertyManager.GetPropertyValue(item.context, item.cachedDirectoryEntry, PropertyManager.DistinguishedName);
						if (Utils.Compare(str, propertyValue) != 0)
						{
							num++;
						}
						else
						{
							return num;
						}
					}
					return -1;
				}
				else
				{
					object[] name = new object[1];
					name[0] = connection.Name;
					throw new InvalidOperationException(Res.GetString("ConnectionNotCommitted", name));
				}
			}
			else
			{
				throw new ArgumentNullException("connection");
			}
		}
    public int IndexOf(ReplicationConnection connection)
    {
      Contract.Requires(connection != null);
      Contract.Ensures(Contract.Result<int>() >= -1);
      Contract.Ensures(Contract.Result<int>() < this.Count);

      return default(int);
    }
        public int IndexOf(ReplicationConnection connection)
        {
            if (connection == null)
                throw new ArgumentNullException("connection");

            if (!connection.existingConnection)
                throw new InvalidOperationException(Res.GetString(Res.ConnectionNotCommitted, connection.Name));

            string dn = (string)PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName);

            for (int i = 0; i < InnerList.Count; i++)
            {
                ReplicationConnection tmp = (ReplicationConnection)InnerList[i];
                string tmpDn = (string)PropertyManager.GetPropertyValue(tmp.context, tmp.cachedDirectoryEntry, PropertyManager.DistinguishedName);

                if (Utils.Compare(tmpDn, dn) == 0)
                {
                    return i;
                }
            }
            return -1;
        }
 public int IndexOf(ReplicationConnection connection)
 {
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     if (!connection.existingConnection)
     {
         throw new InvalidOperationException(Res.GetString("ConnectionNotCommitted", new object[] { connection.Name }));
     }
     string str = (string) PropertyManager.GetPropertyValue(connection.context, connection.cachedDirectoryEntry, PropertyManager.DistinguishedName);
     for (int i = 0; i < base.InnerList.Count; i++)
     {
         ReplicationConnection connection2 = (ReplicationConnection) base.InnerList[i];
         string str2 = (string) PropertyManager.GetPropertyValue(connection2.context, connection2.cachedDirectoryEntry, PropertyManager.DistinguishedName);
         if (Utils.Compare(str2, str) == 0)
         {
             return i;
         }
     }
     return -1;
 }
Ejemplo n.º 6
0
        internal ReplicationConnectionCollection GetOutboundConnectionsHelper()
        {
            // this is the first time that user tries to retrieve this property, so get it from the directory
            if (_outbound == null)
            {
                // search base is the site container
                string siteName = (this is DomainController) ? ((DomainController)this).SiteObjectName : ((AdamInstance)this).SiteObjectName;
                DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context), siteName);

                string serverName = (this is DomainController) ? ((DomainController)this).ServerObjectName : ((AdamInstance)this).ServerObjectName;
                ADSearcher adSearcher = new ADSearcher(de,
                                                               "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection)(fromServer=CN=NTDS Settings," + serverName + "))",
                                                               new string[] { "objectClass", "cn" },
                                                               SearchScope.Subtree);

                SearchResultCollection results = null;
                DirectoryContext newContext = Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context);

                try
                {
                    results = adSearcher.FindAll();
                    _outbound = new ReplicationConnectionCollection();

                    foreach (SearchResult result in results)
                    {
                        ReplicationConnection con = new ReplicationConnection(newContext, result.GetDirectoryEntry(), (string)result.Properties["cn"][0]);
                        _outbound.Add(con);
                    }
                }
                catch (COMException e)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(newContext, e);
                }
                finally
                {
                    if (results != null)
                        results.Dispose();

                    de.Dispose();
                }
            }

            return _outbound;
        }
Ejemplo n.º 7
0
        internal ReplicationConnectionCollection GetInboundConnectionsHelper()
        {
            if (_inbound == null)
            {
                // construct the replicationconnection collection
                _inbound = new ReplicationConnectionCollection();
                DirectoryContext newContext = Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context);

                // this is the first time that user tries to retrieve this property, so get it from the directory   
                string serverName = (this is DomainController) ? ((DomainController)this).ServerObjectName : ((AdamInstance)this).ServerObjectName;
                string srchDN = "CN=NTDS Settings," + serverName;
                DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(Name, DirectoryContextType.DirectoryServer, context), srchDN);

                ADSearcher adSearcher = new ADSearcher(de,
                                                      "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection))",
                                                      new string[] { "cn" },
                                                      SearchScope.OneLevel);
                SearchResultCollection srchResults = null;

                try
                {
                    srchResults = adSearcher.FindAll();
                    foreach (SearchResult r in srchResults)
                    {
                        ReplicationConnection con = new ReplicationConnection(newContext, r.GetDirectoryEntry(), (string)PropertyManager.GetSearchResultPropertyValue(r, PropertyManager.Cn));
                        _inbound.Add(con);
                    }
                }
                catch (COMException e)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(newContext, e);
                }
                finally
                {
                    if (srchResults != null)
                        srchResults.Dispose();

                    de.Dispose();
                }
            }

            return _inbound;
        }
Ejemplo n.º 8
0
		public static ReplicationConnection FindByName(DirectoryContext context, string name)
		{
			ReplicationConnection replicationConnection;
			ReplicationConnection.ValidateArgument(context, name);
			context = new DirectoryContext(context);
			DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
			try
			{
				string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName);
				string str = string.Concat("CN=NTDS Settings,", propertyValue);
				directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
				string[] strArrays = new string[1];
				strArrays[0] = "distinguishedName";
				ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=nTDSConnection)(objectCategory=NTDSConnection)(name=", Utils.GetEscapedFilterValue(name), "))"), strArrays, SearchScope.OneLevel, false, false);
				SearchResult searchResult = null;
				try
				{
					searchResult = aDSearcher.FindOne();
				}
				catch (COMException cOMException1)
				{
					COMException cOMException = cOMException1;
					if (cOMException.ErrorCode != -2147016656)
					{
						throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
					}
					else
					{
						throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name);
					}
				}
				if (searchResult != null)
				{
					DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry();
					replicationConnection = new ReplicationConnection(context, directoryEntry1, name);
				}
				else
				{
					Exception activeDirectoryObjectNotFoundException = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ReplicationConnection), name);
					throw activeDirectoryObjectNotFoundException;
				}
			}
			finally
			{
				directoryEntry.Dispose();
			}
			return replicationConnection;
		}
    public void CopyTo(ReplicationConnection[] connections, int index)
    {
      Contract.Requires(connections != null);
      Contract.Requires(index >= 0);
 
    }
		public int IndexOf (ReplicationConnection connection)
		{
			throw new NotImplementedException ();
		}
		public bool Contains (ReplicationConnection connection)
		{
			throw new NotImplementedException ();
		}
 internal ReplicationConnectionCollection GetOutboundConnectionsHelper()
 {
     if (this.outbound == null)
     {
         string dn = (this is DomainController) ? ((DomainController) this).SiteObjectName : ((AdamInstance) this).SiteObjectName;
         DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context), dn);
         string str2 = (this is DomainController) ? ((DomainController) this).ServerObjectName : ((AdamInstance) this).ServerObjectName;
         ADSearcher searcher = new ADSearcher(directoryEntry, "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection)(fromServer=CN=NTDS Settings," + str2 + "))", new string[] { "objectClass", "cn" }, SearchScope.Subtree);
         SearchResultCollection results = null;
         DirectoryContext context = Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context);
         try
         {
             results = searcher.FindAll();
             this.outbound = new ReplicationConnectionCollection();
             foreach (SearchResult result in results)
             {
                 ReplicationConnection connection = new ReplicationConnection(context, result.GetDirectoryEntry(), (string) result.Properties["cn"][0]);
                 this.outbound.Add(connection);
             }
         }
         catch (COMException exception)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
         }
         finally
         {
             if (results != null)
             {
                 results.Dispose();
             }
             directoryEntry.Dispose();
         }
     }
     return this.outbound;
 }
 internal ReplicationConnectionCollection GetInboundConnectionsHelper()
 {
     if (this.inbound == null)
     {
         this.inbound = new ReplicationConnectionCollection();
         DirectoryContext context = Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context);
         string str = (this is DomainController) ? ((DomainController) this).ServerObjectName : ((AdamInstance) this).ServerObjectName;
         string dn = "CN=NTDS Settings," + str;
         DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(Utils.GetNewDirectoryContext(this.Name, DirectoryContextType.DirectoryServer, this.context), dn);
         ADSearcher searcher = new ADSearcher(directoryEntry, "(&(objectClass=nTDSConnection)(objectCategory=nTDSConnection))", new string[] { "cn" }, SearchScope.OneLevel);
         SearchResultCollection results = null;
         try
         {
             results = searcher.FindAll();
             foreach (SearchResult result in results)
             {
                 ReplicationConnection connection = new ReplicationConnection(context, result.GetDirectoryEntry(), (string) PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.Cn));
                 this.inbound.Add(connection);
             }
         }
         catch (COMException exception)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
         }
         finally
         {
             if (results != null)
             {
                 results.Dispose();
             }
             directoryEntry.Dispose();
         }
     }
     return this.inbound;
 }
        public static void CreateNewConnection(string sourceServer, string targetServer, string connectionName)
        {
            try
            {

                // set a directory server context for the source server
                DirectoryContext sourceContext = new DirectoryContext(
                                                    DirectoryContextType.DirectoryServer,
                                                    sourceServer);

                // set a directory server context for the target server
                DirectoryContext targetContext = new DirectoryContext(
                                                    DirectoryContextType.DirectoryServer,
                                                    targetServer);

                // bind to a specific domain controller to serve as the
                // source of a replication connection
                DomainController sourceDc =
                                    DomainController.GetDomainController(sourceContext);

                ReplicationConnection connection = new ReplicationConnection(
                                                        targetContext,
                                                        connectionName,
                                                        sourceDc);

                // set change notification status
                connection.ChangeNotificationStatus = NotificationStatus.IntraSiteOnly;

                // create a customized replication schedule
                ActiveDirectorySchedule schedule = new ActiveDirectorySchedule();
                schedule.SetDailySchedule(HourOfDay.Twelve,
                                          MinuteOfHour.Zero,
                                          HourOfDay.Fifteen,
                                          MinuteOfHour.Zero);

                schedule.SetSchedule(DayOfWeek.Sunday,
                                     HourOfDay.Eight,
                                     MinuteOfHour.Zero,
                                     HourOfDay.Eleven,
                                     MinuteOfHour.Zero);

                schedule.SetSchedule(DayOfWeek.Saturday,
                                     HourOfDay.Seven,
                                     MinuteOfHour.Zero,
                                     HourOfDay.Ten,
                                     MinuteOfHour.Zero);

                connection.ReplicationSchedule = schedule;
                connection.ReplicationScheduleOwnedByUser = true;

                // save the new connection to the directory
                connection.Save();
                Console.WriteLine("\nNew replication connection created successfully\n" +
                  "from server {0} to {1}.\n The connection appears in the NTDS " +
                  "settings of {1}", sourceServer, targetServer);

            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n{0}:{1}",
                                  e.GetType().Name, e.Message);
            }
        }
 public void CopyTo(ReplicationConnection[] connections, int index)
 {
     InnerList.CopyTo(connections, index);
 }
		public void CopyTo (ReplicationConnection[] connections, int index)
		{
			throw new NotImplementedException ();
		}
 internal int Add(ReplicationConnection value)
 {
     return InnerList.Add(value);
 }
    public bool Contains(ReplicationConnection connection)
    {
      Contract.Requires(connection != null);

      return default(bool);
    }