public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
 {
     ValidateArgument(context, name);
     if (sourceServer == null)
     {
         throw new ArgumentNullException("sourceServer");
     }
     if ((transport < ActiveDirectoryTransportType.Rpc) || (transport > ActiveDirectoryTransportType.Smtp))
     {
         throw new InvalidEnumArgumentException("value", (int) transport, typeof(ActiveDirectoryTransportType));
     }
     context = new DirectoryContext(context);
     this.ValidateTargetAndSourceServer(context, sourceServer);
     this.context = context;
     this.connectionName = name;
     this.transport = transport;
     DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
     try
     {
         string str = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName);
         string dn = "CN=NTDS Settings," + str;
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
         string escapedPath = Utils.GetEscapedPath("cn=" + this.connectionName);
         this.cachedDirectoryEntry = directoryEntry.Children.Add(escapedPath, "nTDSConnection");
         DirectoryContext context2 = sourceServer.Context;
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context2, WellKnownDN.RootDSE);
         string str4 = (string) PropertyManager.GetPropertyValue(context2, directoryEntry, PropertyManager.ServerName);
         str4 = "CN=NTDS Settings," + str4;
         this.cachedDirectoryEntry.Properties["fromServer"].Add(str4);
         if (schedule != null)
         {
             this.cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
         }
         string dNFromTransportType = Utils.GetDNFromTransportType(this.TransportType, context);
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dNFromTransportType);
         try
         {
             directoryEntry.Bind(true);
         }
         catch (COMException exception)
         {
             if (((exception.ErrorCode == -2147016656) && Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode)) && (transport == ActiveDirectoryTransportType.Smtp))
             {
                 throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
             }
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
         }
         this.cachedDirectoryEntry.Properties["transportType"].Add(dNFromTransportType);
         this.cachedDirectoryEntry.Properties["enabledConnection"].Value = false;
         this.cachedDirectoryEntry.Properties["options"].Value = 0;
     }
     catch (COMException exception2)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
     }
     finally
     {
         directoryEntry.Close();
     }
 }
Exemplo n.º 2
0
        public ActiveDirectorySchedule(ActiveDirectorySchedule schedule) : this()
        {
            if (schedule == null)
                throw new ArgumentNullException();

            bool[] tmpSchedule = schedule._scheduleArray;
            for (int i = 0; i < 672; i++)
                _scheduleArray[i] = tmpSchedule[i];
        }
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
 {
     DirectoryEntry directoryEntry;
     this.systemDefaultInterval = new TimeSpan(0, 15, 0);
     this.sites = new ActiveDirectorySiteCollection();
     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 str = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
         string dn = null;
         if (transport == ActiveDirectoryTransportType.Rpc)
         {
             dn = "CN=IP,CN=Inter-Site Transports,CN=Sites," + str;
         }
         else
         {
             dn = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + str;
         }
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
     }
     catch (ActiveDirectoryObjectNotFoundException)
     {
         throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
     }
     try
     {
         string escapedPath = Utils.GetEscapedPath("cn=" + this.name);
         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 exception2)
     {
         if (((exception2.ErrorCode == -2147016656) && Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode)) && (transport == ActiveDirectoryTransportType.Smtp))
         {
             throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
         }
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
     }
     finally
     {
         directoryEntry.Dispose();
     }
 }
Exemplo n.º 4
0
        public ActiveDirectorySchedule(ActiveDirectorySchedule schedule) : this()
        {
            ArgumentNullException.ThrowIfNull(schedule);

            bool[] tmpSchedule = schedule._scheduleArray;
            for (int i = 0; i < 672; i++)
            {
                _scheduleArray[i] = tmpSchedule[i];
            }
        }
 public ActiveDirectorySchedule(ActiveDirectorySchedule schedule) : this()
 {
     if (schedule == null)
     {
         throw new ArgumentNullException();
     }
     bool[] scheduleArray = schedule.scheduleArray;
     for (int i = 0; i < 0x2a0; i++)
     {
         this.scheduleArray[i] = scheduleArray[i];
     }
 }
Exemplo n.º 6
0
 public ActiveDirectorySchedule(ActiveDirectorySchedule schedule) : this()
 {
     if (schedule == null)
     {
         throw new ArgumentNullException();
     }
     bool[] scheduleArray = schedule.scheduleArray;
     for (int i = 0; i < 0x2a0; i++)
     {
         this.scheduleArray[i] = scheduleArray[i];
     }
 }
Exemplo n.º 7
0
        public ActiveDirectorySchedule(ActiveDirectorySchedule schedule) : this()
        {
            if (schedule == null)
            {
                throw new ArgumentNullException();
            }

            bool[] tmpSchedule = schedule._scheduleArray;
            for (int i = 0; i < 672; i++)
            {
                _scheduleArray[i] = tmpSchedule[i];
            }
        }
Exemplo n.º 8
0
		public ActiveDirectorySchedule(ActiveDirectorySchedule schedule) : this()
		{
			if (schedule != null)
			{
				bool[] flagArray = schedule.scheduleArray;
				for (int i = 0; i < 0x2a0; i++)
				{
					this.scheduleArray[i] = flagArray[i];
				}
				return;
			}
			else
			{
				throw new ArgumentNullException();
			}
		}
Exemplo n.º 9
0
 public ActiveDirectorySchedule(ActiveDirectorySchedule schedule) : this()
 {
     if (schedule != null)
     {
         bool[] flagArray = schedule.scheduleArray;
         for (int i = 0; i < 0x2a0; i++)
         {
             this.scheduleArray[i] = flagArray[i];
         }
         return;
     }
     else
     {
         throw new ArgumentNullException();
     }
 }
Exemplo n.º 10
0
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule) : this(context, name, sourceServer, schedule, ActiveDirectoryTransportType.Rpc)
 {
 }
Exemplo n.º 11
0
		public ActiveDirectorySchedule (ActiveDirectorySchedule schedule) : this()
		{
			throw new NotImplementedException ();
		}
Exemplo n.º 12
0
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
        public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
        {
            ValidateArgument(context, siteLinkName, transport);

            //  work with copy of the context
            context = new DirectoryContext(context);

            this.context = context;
            _name = siteLinkName;
            _transport = transport;

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);

                string parentDN = null;
                if (transport == ActiveDirectoryTransportType.Rpc)
                    parentDN = "CN=IP,CN=Inter-Site Transports,CN=Sites," + config;
                else
                    parentDN = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + config;

                de = DirectoryEntryManager.GetDirectoryEntry(context, parentDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                string rdn = "cn=" + _name;
                rdn = Utils.GetEscapedPath(rdn);
                cachedEntry = de.Children.Add(rdn, "siteLink");
                cachedEntry.Properties["cost"].Value = appDefaultCost;
                cachedEntry.Properties["replInterval"].Value = appDefaultInterval;
                if (schedule != null)
                    cachedEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(Res.GetString(Res.NotSupportTransportSMTP));
                    }
                }

                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Dispose();
            }
        }
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule)
 {
   Contract.Requires(context != null);
   Contract.Requires(!string.IsNullOrEmpty(name));
 }
        // How to create a site link. Note, that this example assigns a single site to this site link
        public static void CreateSiteLink(string siteName, string siteLinkName)
        {
            try
            {
                DirectoryContext forestContext = new DirectoryContext(
                                            DirectoryContextType.Forest);

                //bind to a specific site in the forest
                ActiveDirectorySite site = ActiveDirectorySite.FindByName(
                                                                forestContext,
                                                                siteName);

                // rpc is the default transport type (smtp is the other,
                // this is how you can create a transport type variable to
                // later assign to the link
                ActiveDirectoryTransportType adTpt =
                                            ActiveDirectoryTransportType.Rpc;

                // using the overload requiring the transport type to
                // demonstrate how to assign a transport type to this link.
                ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(
                                                    forestContext,
                                                    siteLinkName,
                                                    adTpt);

                // configure the ActiveDirectorySiteLink object
                link.Cost = 100;
                link.DataCompressionEnabled = true;

                // create an AD schedule object for setting intersite replication
                ActiveDirectorySchedule linkSchedule =
                                                new ActiveDirectorySchedule();

                // set the schedule for 5:30 am to 6:30 am
                linkSchedule.SetDailySchedule(HourOfDay.Zero,
                                              MinuteOfHour.Zero,
                                              HourOfDay.TwentyThree,
                                              MinuteOfHour.FortyFive);

                // set the schedule for 5:30 pm to 6:30 pm
                /*linkSchedule.SetDailySchedule(HourOfDay.Seventeen,
                                              MinuteOfHour.Thirty,
                                              HourOfDay.Eighteen,
                                              MinuteOfHour.Thirty);
                */
                // apply the replication schedule to the link
                link.InterSiteReplicationSchedule = linkSchedule;

                // enable inter-site change notification. Typically used for fast,
                // uncongested links between sites
                link.NotificationEnabled = true;

                // replicate every twelve hours
                TimeSpan linkTimeSpan = new TimeSpan(0, 15, 0);

                // assign the TimeSpan object to the ReplicationInterval property
                link.ReplicationInterval = linkTimeSpan;

                // configure the link so there is no reciprocal replication
                link.ReciprocalReplicationEnabled = false;

                // assign a site to this site link.
                link.Sites.Add(site);

                // commit the link to the directory
                link.Save();

                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("\nLink \"{0}\" was created successfully", link.Name);
                Console.ResetColor();

            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n\t{0}\n{1}",
                      e.GetType().Name, e.Message);

            }
        }
        public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
        {
            DirectoryEntry directoryEntry;

            this.systemDefaultInterval = new TimeSpan(0, 15, 0);
            this.sites = new ActiveDirectorySiteCollection();
            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 str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
                string dn  = null;
                if (transport == ActiveDirectoryTransportType.Rpc)
                {
                    dn = "CN=IP,CN=Inter-Site Transports,CN=Sites," + str;
                }
                else
                {
                    dn = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + str;
                }
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
            }
            try
            {
                string escapedPath = Utils.GetEscapedPath("cn=" + this.name);
                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 exception2)
            {
                if (((exception2.ErrorCode == -2147016656) && Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode)) && (transport == ActiveDirectoryTransportType.Smtp))
                {
                    throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
                }
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
            }
            finally
            {
                directoryEntry.Dispose();
            }
        }
Exemplo n.º 17
0
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
 {
 }
Exemplo n.º 18
0
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
 {
     ReplicationConnection.ValidateArgument(context, name);
     if (sourceServer != null)
     {
         if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
         {
             throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
         }
         else
         {
             context = new DirectoryContext(context);
             this.ValidateTargetAndSourceServer(context, sourceServer);
             this.context        = context;
             this.connectionName = name;
             this.transport      = transport;
             DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
             try
             {
                 try
                 {
                     string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName);
                     string str           = string.Concat("CN=NTDS Settings,", propertyValue);
                     directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
                     string escapedPath = string.Concat("cn=", this.connectionName);
                     escapedPath = Utils.GetEscapedPath(escapedPath);
                     this.cachedDirectoryEntry = directoryEntry.Children.Add(escapedPath, "nTDSConnection");
                     DirectoryContext directoryContext = sourceServer.Context;
                     directoryEntry = DirectoryEntryManager.GetDirectoryEntry(directoryContext, WellKnownDN.RootDSE);
                     string propertyValue1 = (string)PropertyManager.GetPropertyValue(directoryContext, directoryEntry, PropertyManager.ServerName);
                     propertyValue1 = string.Concat("CN=NTDS Settings,", propertyValue1);
                     this.cachedDirectoryEntry.Properties["fromServer"].Add(propertyValue1);
                     if (schedule != null)
                     {
                         this.cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
                     }
                     string dNFromTransportType = Utils.GetDNFromTransportType(this.TransportType, context);
                     directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dNFromTransportType);
                     try
                     {
                         //TODO: REVIEW: URGENT!!: directoryEntry.Bind(true);
                     }
                     catch (COMException cOMException1)
                     {
                         COMException cOMException = cOMException1;
                         if (cOMException.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, cOMException);
                     }
                     this.cachedDirectoryEntry.Properties["transportType"].Add(dNFromTransportType);
                     this.cachedDirectoryEntry.Properties["enabledConnection"].Value = false;
                     this.cachedDirectoryEntry.Properties["options"].Value           = 0;
                 }
                 catch (COMException cOMException3)
                 {
                     COMException cOMException2 = cOMException3;
                     throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
                 }
             }
             finally
             {
                 directoryEntry.Close();
             }
             return;
         }
     }
     else
     {
         throw new ArgumentNullException("sourceServer");
     }
 }
Exemplo n.º 19
0
        public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
        {
            ValidateArgument(context, name);

            if (sourceServer == null)
                throw new ArgumentNullException("sourceServer");

            if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
                throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));

            //  work with copy of the context
            context = new DirectoryContext(context);

            ValidateTargetAndSourceServer(context, sourceServer);

            this.context = context;
            _connectionName = name;
            _transport = transport;

            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
            try
            {
                string serverDN = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName);
                string connectionContainer = "CN=NTDS Settings," + serverDN;
                de = DirectoryEntryManager.GetDirectoryEntry(context, connectionContainer);

                // create the connection entry
                string rdn = "cn=" + _connectionName;
                rdn = Utils.GetEscapedPath(rdn);
                cachedDirectoryEntry = de.Children.Add(rdn, "nTDSConnection");

                // set all the properties

                // sourceserver property               
                DirectoryContext sourceServerContext = sourceServer.Context;
                de = DirectoryEntryManager.GetDirectoryEntry(sourceServerContext, WellKnownDN.RootDSE);
                string serverName = (string)PropertyManager.GetPropertyValue(sourceServerContext, de, PropertyManager.ServerName);
                serverName = "CN=NTDS Settings," + serverName;

                cachedDirectoryEntry.Properties["fromServer"].Add(serverName);

                // schedule property
                if (schedule != null)
                    cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();

                // transporttype property
                string transportPath = Utils.GetDNFromTransportType(TransportType, context);
                // verify that the transport is supported
                de = DirectoryEntryManager.GetDirectoryEntry(context, transportPath);
                try
                {
                    de.Bind(true);
                }
                catch (COMException e)
                {
                    if (e.ErrorCode == unchecked((int)0x80072030))
                    {
                        // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                        DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                        if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                        {
                            throw new NotSupportedException(Res.GetString(Res.NotSupportTransportSMTP));
                        }
                    }

                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }

                cachedDirectoryEntry.Properties["transportType"].Add(transportPath);

                // enabledConnection property
                cachedDirectoryEntry.Properties["enabledConnection"].Value = false;

                // options
                cachedDirectoryEntry.Properties["options"].Value = 0;
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Close();
            }
        }
Exemplo n.º 20
0
		public ReplicationConnection (DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
		{
			throw new NotImplementedException ();
		}
Exemplo n.º 21
0
        public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
        {
            ValidateArgument(context, name);

            if (sourceServer == null)
            {
                throw new ArgumentNullException("sourceServer");
            }

            if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
            {
                throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
            }

            //  work with copy of the context
            context = new DirectoryContext(context);

            ValidateTargetAndSourceServer(context, sourceServer);

            this.context    = context;
            _connectionName = name;
            _transport      = transport;

            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);

            try
            {
                string serverDN            = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName);
                string connectionContainer = "CN=NTDS Settings," + serverDN;
                de = DirectoryEntryManager.GetDirectoryEntry(context, connectionContainer);

                // create the connection entry
                string rdn = "cn=" + _connectionName;
                rdn = Utils.GetEscapedPath(rdn);
                cachedDirectoryEntry = de.Children.Add(rdn, "nTDSConnection");

                // set all the properties

                // sourceserver property
                DirectoryContext sourceServerContext = sourceServer.Context;
                de = DirectoryEntryManager.GetDirectoryEntry(sourceServerContext, WellKnownDN.RootDSE);
                string serverName = (string)PropertyManager.GetPropertyValue(sourceServerContext, de, PropertyManager.ServerName);
                serverName = "CN=NTDS Settings," + serverName;

                cachedDirectoryEntry.Properties["fromServer"].Add(serverName);

                // schedule property
                if (schedule != null)
                {
                    cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
                }

                // transporttype property
                string transportPath = Utils.GetDNFromTransportType(TransportType, context);
                // verify that the transport is supported
                de = DirectoryEntryManager.GetDirectoryEntry(context, transportPath);
                try
                {
                    de.Bind(true);
                }
                catch (COMException e)
                {
                    if (e.ErrorCode == unchecked ((int)0x80072030))
                    {
                        // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                        DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                        if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                        {
                            throw new NotSupportedException(SR.NotSupportTransportSMTP);
                        }
                    }

                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }

                cachedDirectoryEntry.Properties["transportType"].Add(transportPath);

                // enabledConnection property
                cachedDirectoryEntry.Properties["enabledConnection"].Value = false;

                // options
                cachedDirectoryEntry.Properties["options"].Value = 0;
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Close();
            }
        }
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule)
 {
     Contract.Requires(context != null);
     Contract.Requires(!string.IsNullOrEmpty(name));
 }
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
 {
   Contract.Requires(context != null);
   Contract.Requires(siteLinkName != null);
   // Schedule can be null
 }
Exemplo n.º 24
0
 public ActiveDirectorySchedule(ActiveDirectorySchedule schedule) : this()
 {
     throw new NotImplementedException();
 }
Exemplo n.º 25
0
		public ActiveDirectorySiteLink (DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
		{
		}
Exemplo n.º 26
0
		public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
		{
			ReplicationConnection.ValidateArgument(context, name);
			if (sourceServer != null)
			{
				if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
				{
					throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
				}
				else
				{
					context = new DirectoryContext(context);
					this.ValidateTargetAndSourceServer(context, sourceServer);
					this.context = context;
					this.connectionName = name;
					this.transport = transport;
					DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
					try
					{
						try
						{
							string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName);
							string str = string.Concat("CN=NTDS Settings,", propertyValue);
							directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
							string escapedPath = string.Concat("cn=", this.connectionName);
							escapedPath = Utils.GetEscapedPath(escapedPath);
							this.cachedDirectoryEntry = directoryEntry.Children.Add(escapedPath, "nTDSConnection");
							DirectoryContext directoryContext = sourceServer.Context;
							directoryEntry = DirectoryEntryManager.GetDirectoryEntry(directoryContext, WellKnownDN.RootDSE);
							string propertyValue1 = (string)PropertyManager.GetPropertyValue(directoryContext, directoryEntry, PropertyManager.ServerName);
							propertyValue1 = string.Concat("CN=NTDS Settings,", propertyValue1);
							this.cachedDirectoryEntry.Properties["fromServer"].Add(propertyValue1);
							if (schedule != null)
							{
								this.cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
							}
							string dNFromTransportType = Utils.GetDNFromTransportType(this.TransportType, context);
							directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dNFromTransportType);
							try
							{
								//TODO: REVIEW: URGENT!!: directoryEntry.Bind(true);
							}
							catch (COMException cOMException1)
							{
								COMException cOMException = cOMException1;
								if (cOMException.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, cOMException);
							}
							this.cachedDirectoryEntry.Properties["transportType"].Add(dNFromTransportType);
							this.cachedDirectoryEntry.Properties["enabledConnection"].Value = false;
							this.cachedDirectoryEntry.Properties["options"].Value = 0;
						}
						catch (COMException cOMException3)
						{
							COMException cOMException2 = cOMException3;
							throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
						}
					}
					finally
					{
						directoryEntry.Close();
					}
					return;
				}
			}
			else
			{
				throw new ArgumentNullException("sourceServer");
			}
		}
Exemplo n.º 27
0
        public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
        {
            ValidateArgument(context, siteLinkName, transport);

            //  work with copy of the context
            context = new DirectoryContext(context);

            this.context = context;
            _name        = siteLinkName;
            _transport   = transport;

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);

                string parentDN = null;
                if (transport == ActiveDirectoryTransportType.Rpc)
                {
                    parentDN = "CN=IP,CN=Inter-Site Transports,CN=Sites," + config;
                }
                else
                {
                    parentDN = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + config;
                }

                de = DirectoryEntryManager.GetDirectoryEntry(context, parentDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(String.Format(CultureInfo.CurrentCulture, SR.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                string rdn = "cn=" + _name;
                rdn         = Utils.GetEscapedPath(rdn);
                cachedEntry = de.Children.Add(rdn, "siteLink");
                cachedEntry.Properties["cost"].Value         = appDefaultCost;
                cachedEntry.Properties["replInterval"].Value = appDefaultInterval;
                if (schedule != null)
                {
                    cachedEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked ((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(SR.NotSupportTransportSMTP);
                    }
                }

                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Dispose();
            }
        }
        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 ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
 {
     Contract.Requires(context != null);
     Contract.Requires(siteLinkName != null);
     // Schedule can be null
 }
Exemplo n.º 30
0
 public ActiveDirectorySchedule(ActiveDirectorySchedule schedule !!) : this()
 {
Exemplo n.º 31
0
		public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule) : this(context, name, sourceServer, schedule, 0)
		{
		}
        public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
        {
            ValidateArgument(context, name);
            if (sourceServer == null)
            {
                throw new ArgumentNullException("sourceServer");
            }
            if ((transport < ActiveDirectoryTransportType.Rpc) || (transport > ActiveDirectoryTransportType.Smtp))
            {
                throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
            }
            context = new DirectoryContext(context);
            this.ValidateTargetAndSourceServer(context, sourceServer);
            this.context        = context;
            this.connectionName = name;
            this.transport      = transport;
            DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);

            try
            {
                string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName);
                string dn  = "CN=NTDS Settings," + str;
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
                string escapedPath = Utils.GetEscapedPath("cn=" + this.connectionName);
                this.cachedDirectoryEntry = directoryEntry.Children.Add(escapedPath, "nTDSConnection");
                DirectoryContext context2 = sourceServer.Context;
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context2, WellKnownDN.RootDSE);
                string str4 = (string)PropertyManager.GetPropertyValue(context2, directoryEntry, PropertyManager.ServerName);
                str4 = "CN=NTDS Settings," + str4;
                this.cachedDirectoryEntry.Properties["fromServer"].Add(str4);
                if (schedule != null)
                {
                    this.cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
                }
                string dNFromTransportType = Utils.GetDNFromTransportType(this.TransportType, context);
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dNFromTransportType);
                try
                {
                    directoryEntry.Bind(true);
                }
                catch (COMException exception)
                {
                    if (((exception.ErrorCode == -2147016656) && Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode)) && (transport == ActiveDirectoryTransportType.Smtp))
                    {
                        throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
                    }
                    throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
                }
                this.cachedDirectoryEntry.Properties["transportType"].Add(dNFromTransportType);
                this.cachedDirectoryEntry.Properties["enabledConnection"].Value = false;
                this.cachedDirectoryEntry.Properties["options"].Value           = 0;
            }
            catch (COMException exception2)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
            }
            finally
            {
                directoryEntry.Close();
            }
        }