public static void ReplicateFromNeighbors(string targetServer, string partitionName)
        {
            try
            {
                // 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 targetDc =
                    DomainController.GetDomainController(targetContext);


                // invoke the kcc to check the replication topology for the
                // target domain controller
                targetDc.CheckReplicationConsistency();
                Console.WriteLine("\nReplication topology is consistent.\n");


                // sync replica from all neighbors
                targetDc.TriggerSyncReplicaFromNeighbors(partitionName);
                Console.WriteLine("\nTriggered a synchronization of partition {0} " +
                                  "to {1} from all neighbors succeeded.", partitionName, targetServer);
            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n{0}:{1}",
                                  e.GetType().Name, e.Message);
            }
        }
        public static void ReplicateFromSource(string sourceServer, string targetServer, string partitionName)
        {
            try
            {
                // set a directory server context for the target server
                DirectoryContext targetContext = new DirectoryContext(
                    DirectoryContextType.DirectoryServer,
                    targetServer);

                // bind to a specific dc to serve as the replication source
                DomainController targetDc =
                    DomainController.GetDomainController(targetContext);


                // invoke the kcc to check the replication topology of the target dc
                targetDc.CheckReplicationConsistency();
                Console.WriteLine("\nReplication topology is consistent.\n");


                // trigger a synchornization of a replica from a source dc
                // to the target dc
                targetDc.SyncReplicaFromServer(partitionName, sourceServer);

                Console.WriteLine("\nSynchronize partition \"{0}\" " +
                                  "from server {1} to {2} succeed",
                                  partitionName,
                                  sourceServer,
                                  targetServer);
            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n{0}:{1}",
                                  e.GetType().Name, e.Message);
            }
        }
        public static void SyncAllServers(string partitionName)
        {
            try
            {
                // get a domain context
                DirectoryContext context = new DirectoryContext(
                    DirectoryContextType.Domain);

                // bind to an available domain controller in the domain.
                DomainController dc = DomainController.FindOne(context);

                // invoke the kcc to check the replication topology for the
                // current domain controller
                dc.CheckReplicationConsistency();
                Console.WriteLine("\nCheck replication consistency succeed\n");

                // Set the name of the SyncUpdateCallback delegate for this dc
                // see the SyncFromAllServersCallbackDelegate routine
                dc.SyncFromAllServersCallback = SyncFromAllServersCallbackDelegate;

                Console.WriteLine("\nStart sync with all servers:");

                // Call the synch. method and set synch. options
                dc.SyncReplicaFromAllServers(partitionName,
                                             SyncFromAllServersOptions.AbortIfServerUnavailable
                                             | SyncFromAllServersOptions.CrossSite
                                             );

                Console.WriteLine("\nSynchronize partition \"{0}\" " +
                                  "with all servers succeeded", partitionName);
            }
            catch (Exception e)
            {
                Console.WriteLine("\r\nUnexpected exception occured:\n{0}:{1}",
                                  e.GetType().Name, e.Message);
            }
        }
Ejemplo n.º 4
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);
            }
        }