public static void SetReplicationConnection(string server, string connectionName)
        {
            try
            {
                DirectoryContext context = new DirectoryContext(
                    DirectoryContextType.DirectoryServer,
                    server);

                ReplicationConnection connection =
                    ReplicationConnection.FindByName(
                        context,
                        connectionName);

                Console.WriteLine("\nGet replication connection \"{0}\" information:",
                                  connection.Name);

                Console.WriteLine("ChangeNotificationStatus is {0}",
                                  connection.ChangeNotificationStatus);

                if (connection.ChangeNotificationStatus != NotificationStatus.NoNotification)
                {
                    // this changes the options attribute value of the nTDSConnection object.
                    connection.ChangeNotificationStatus = NotificationStatus.NoNotification;
                    Console.WriteLine("ChangeNotificationStatus set to no notification");
                    connection.Save();
                }
                else
                {
                    Console.WriteLine("ChangeNotificationStatus was not changed. It was " +
                                      "already set to no notification");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n{0}:{1}",
                                  e.GetType().Name, e.Message);
            }
        }
        public static void DeleteReplicationConnection(string server, string connectionName)
        {
            try
            {
                DirectoryContext context = new DirectoryContext(
                    DirectoryContextType.DirectoryServer,
                    server);

                ReplicationConnection connection =
                    ReplicationConnection.FindByName(
                        context,
                        connectionName);

                // delete the replication connection
                connection.Delete();
                Console.WriteLine("\nReplication connection {0} deleted", connectionName);
            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n{0}:{1}",
                                  e.GetType().Name, e.Message);
            }
        }
Пример #3
0
        static void Main()
        {
            try
            {
                string targetDomainName = "fabrikam.com";

                string targetServer  = "server1.fabrikam.com";
                string sourceServer  = "server2.fabrikam.com";
                string partitionName = "CN=Configuration,DC=fabrikam,DC=com";

                // get to the domain controller
                DomainController dc = DomainController.FindOne(
                    new DirectoryContext(
                        DirectoryContextType.Domain,
                        targetDomainName));

                // to use alternate credentials use the below code
                // DomainController dc = DomainController.FindOne(
                //                          new DirectoryContext(
                //                                          DirectoryContextType.Domain,
                //                                          targetDomainName,
                //                                          "alt-username",
                //                                          "alt-password"));
                //
                //


                // invoke kcc to check replication consistency
                dc.CheckReplicationConsistency();
                Console.WriteLine("\nCheck replication consistency succeed\n");

                // sync replica from a source server
                dc.SyncReplicaFromServer(partitionName, sourceServer);
                Console.WriteLine("\nSynchronize naming context \"{0}\" " +
                                  "with server {1} succeed",
                                  partitionName,
                                  sourceServer);

                // sync replica from all neighbors
                dc.TriggerSyncReplicaFromNeighbors(partitionName);
                Console.WriteLine("\nSynchronize naming context \"{0}\" " +
                                  "with all neighbors succeed", partitionName);

                // sync replica from all servers
                dc.SyncFromAllServersCallback = SyncFromAllServersCallbackRoutine;
                Console.WriteLine("\nStart sync with all servers:");
                dc.SyncReplicaFromAllServers(partitionName,
                                             SyncFromAllServersOptions.AbortIfServerUnavailable);

                Console.WriteLine("\nSynchronize naming context \"{0}\" " +
                                  "with all servers succeed", partitionName);

                // replication connection

                // create new replication connections
                DirectoryServer sourceDC = DomainController.GetDomainController(
                    new DirectoryContext(
                        DirectoryContextType.DirectoryServer,
                        sourceServer));

                // to use alternate credentials use the below code
                // DirectoryServer sourceDC = DomainController.GetDomainController(
                //                              new DirectoryContext(
                //                                 DirectoryContextType.DirectoryServer,
                //                                 sourceServer,
                //                                 "alt-username",
                //                                 "alt-password"));
                //



                ReplicationConnection connection =
                    new ReplicationConnection(
                        new DirectoryContext(
                            DirectoryContextType.DirectoryServer,
                            targetServer),
                        "myconnection",
                        sourceDC);

                // to use alternate credentials use the below code
                // ReplicationConnection connection =
                //                      new ReplicationConnection(
                //                              new DirectoryContext(
                //                                 DirectoryContextType.DirectoryServer,
                //                                 targetServer,
                //                                 "alt-username",
                //                                 "alt-password"),
                //                              "myconnection",
                //                              sourceDC);
                //


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

                // create 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;
                connection.Save();
                Console.WriteLine("\nNew replication connection is created successfully");

                connection = ReplicationConnection.FindByName(
                    new DirectoryContext(
                        DirectoryContextType.DirectoryServer,
                        targetServer),
                    "myconnection");

                // to use alternate credentials use the below code
                // connection = ReplicationConnection.FindByName(
                //                             new DirectoryContext(
                //                                 DirectoryContextType.DirectoryServer,
                //                                 targetServer,
                //                                 "alt-username",
                //                                 "alt-password"),
                //                             "myconnection");
                //

                Console.WriteLine("\nGet replication connection \"{0}\" information:",
                                  connection.Name);

                Console.WriteLine("ChangeNotificationStatus is {0}",
                                  connection.ChangeNotificationStatus);
                Console.WriteLine("ReplicationSpan is {0}", connection.ReplicationSpan);
                Console.WriteLine("ReplicationScheduleOwnedByUser is {0}",
                                  connection.ReplicationScheduleOwnedByUser);

                // delete the replication connection
                connection.Delete();
                Console.WriteLine("\nReplication connection is deleted\n");
            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\r\n\t" +
                                  e.GetType().Name + ":" + e.Message);
            }
        }
        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 int IndexOf(ReplicationConnection connection)
 {
 }
 public void CopyTo(ReplicationConnection[] connections, int index)
 {
 }
 // Methods
 public bool Contains(ReplicationConnection connection)
 {
 }
 public int IndexOf(ReplicationConnection connection)
 {
 }
 // Methods
 public bool Contains(ReplicationConnection connection)
 {
 }