protected void ReturnAllAccounts() { // Write the initial progress // TODO: Extract strings as resources var progress = new ProgressRecord(1, "Replication", "Replicating Active Directory objects."); progress.PercentComplete = 0; this.WriteProgress(progress); // Update the progress after each replication cycle ReplicationProgressHandler progressReporter = (ReplicationCookie cookie, int processedObjectCount, int totalObjectCount) => { int percentComplete = (int)(((double)processedObjectCount / (double)totalObjectCount) * 100); // AD's object count estimate is sometimes lower than the actual count, so we cap the value to 100%. progress.PercentComplete = Math.Min(percentComplete, 100); this.WriteProgress(progress); }; // Replicate all accounts foreach (var account in this.ReplicationClient.GetAccounts(this.NamingContext, progressReporter)) { this.WriteObject(account); } // Write progress completed progress.RecordType = ProgressRecordType.Completed; this.WriteProgress(progress); }
public IEnumerable <DSAccount> GetAccounts(string domainNamingContext, ReplicationProgressHandler progressReporter = null) { Validator.AssertNotNullOrWhiteSpace(domainNamingContext, nameof(domainNamingContext)); ReplicationCookie cookie = new ReplicationCookie(domainNamingContext); return(GetAccounts(cookie, progressReporter)); }
private bool getAccounts() { accs = null; progress = new ProgressRecord(1, "Replication", "Replicating AD Objects"); progress.PercentComplete = 0; ReplicationProgressHandler progressReport = (ReplicationCookie cookie, int processedObjectCount, int totalObjectCount) => { int percentComplete = (int)(((double)processedObjectCount / (double)totalObjectCount) * 100); progress.PercentComplete = Math.Min(percentComplete, 100); }; try { accs = new List <DSAccount>(dRep.GetAccounts(nameContext, progressReport)); progress.RecordType = ProgressRecordType.Completed; } catch (Exception ex) { MessageBox.Show("Error getting accounts\n\n" + ex.ToString()); return(false); } return(true); }
public IEnumerable <DSAccount> GetAccounts(ReplicationCookie initialCookie, ReplicationProgressHandler progressReporter = null) { Validator.AssertNotNull(initialCookie, nameof(initialCookie)); // Create AD schema var schema = BasicSchemaFactory.CreateSchema(); var currentCookie = initialCookie; ReplicationResult result; int processedObjectCount = 0; do { // Perform one replication cycle result = this.drsConnection.ReplicateAllObjects(currentCookie); // Report replication progress if (progressReporter != null) { processedObjectCount += result.Objects.Count; progressReporter(result.Cookie, processedObjectCount, result.TotalObjectCount); } // Process the returned objects foreach (var obj in result.Objects) { obj.Schema = schema; if (!obj.IsAccount) { continue; } var account = new DSAccount(obj, this.SecretDecryptor); yield return(account); } // Update the position of the replication cursor currentCookie = result.Cookie; } while (result.HasMoreData); }