public void CloseExportConnection(CloseExportConnectionRunStep exportRunStep)
        {
            Logger.WriteLine("Closing export connection: {0}", exportRunStep.Reason);
            this.timer.Stop();

            if (exportRunStep.Reason != CloseReason.Normal)
            {
                this.cancellationToken?.Cancel();
            }

            try
            {
                Logger.WriteLine("Writing {0} delta entries to file", CSEntryChangeQueue.Count);
                CSEntryChangeQueue.SaveQueue(this.DeltaPath, this.operationSchemaTypes);
            }
            catch (Exception ex)
            {
                Logger.WriteLine("An error occurred while saving the delta file");
                Logger.WriteException(ex);
                throw;
            }

            Logger.WriteSeparatorLine('*');
            Logger.WriteLine("Operation statistics");
            Logger.WriteLine("Export objects: {0}", this.opCount);
            Logger.WriteLine("Operation time: {0}", this.timer.Elapsed);
            Logger.WriteLine("Ops/sec: {0:N3}", this.opCount / this.timer.Elapsed.TotalSeconds);
            Logger.WriteSeparatorLine('*');
        }
Example #2
0
        public void ContactRename()
        {
            string id = null;

            try
            {
                string       dn = Guid.NewGuid().ToString();
                ContactEntry e  = new ContactEntry();

                e.Emails.Add(new EMail()
                {
                    Address = "*****@*****.**", Label = "work"
                });

                e.ExtendedProperties.Add(new ExtendedProperty(dn, ApiInterfaceContact.DNAttributeName));

                e  = UnitTestControl.TestParameters.ContactsService.Add(e, UnitTestControl.TestParameters.Domain);
                id = e.SelfUri.Content;

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = dn;
                cs.ObjectType = SchemaConstants.Contact;

                string newDN = Guid.NewGuid().ToString();

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("DN", new List <ValueChange>()
                {
                    ValueChange.CreateValueAdd(newDN), ValueChange.CreateValueDelete(dn)
                }));

                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", id));
                CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Contact], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                System.Threading.Thread.Sleep(5000);
                e = UnitTestControl.TestParameters.ContactsService.GetContact(id);
                Assert.AreEqual(newDN, e.ExtendedProperties.Single(t => t.Name == ApiInterfaceContact.DNAttributeName).Value);
                var x = CSEntryChangeQueue.Take();
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ContactsService.Delete(id);
                }
            }
        }
        private GetImportEntriesResults GetImportEntriesDelta()
        {
            GetImportEntriesResults results = new GetImportEntriesResults {
                CSEntries = new List <CSEntryChange>()
            };

            int count = 0;

            while (CSEntryChangeQueue.Count > 0 && (count < this.importRunStep.PageSize))
            {
                Interlocked.Increment(ref this.opCount);
                results.CSEntries.Add(CSEntryChangeQueue.Take());
                count++;
            }

            results.MoreToImport = CSEntryChangeQueue.Count > 0;

            return(results);
        }
        public static CSEntryChangeResult PutCSEntryChangeObject(CSEntryChange csentry, SchemaType type, IManagementAgentParameters config)
        {
            MASchemaType maType = ManagementAgent.Schema[type.Name];

            CSEntryChangeDetached deltaCSEntry = new CSEntryChangeDetached(Guid.NewGuid(), ObjectModificationType.Unconfigured, MAImportError.Success, null);

            foreach (var anchorAttributeName in maType.AnchorAttributeNames)
            {
                AnchorAttribute anchor = csentry.GetAnchorAttribute(anchorAttributeName);

                if (anchor != null)
                {
                    deltaCSEntry.AnchorAttributes.Add(anchor);
                }
            }

            deltaCSEntry.ObjectType = csentry.ObjectType;

            try
            {
                switch (csentry.ObjectModificationType)
                {
                case ObjectModificationType.Add:
                    return(ExportProcessor.PutCSEntryChangeAdd(csentry, deltaCSEntry, maType, type, config));

                case ObjectModificationType.Delete:
                    return(ExportProcessor.PutCSEntryChangeDelete(csentry, deltaCSEntry, maType));

                case ObjectModificationType.Update:
                    return(ExportProcessor.PutCSEntryChangeUpdate(csentry, deltaCSEntry, maType, type, config));

                default:
                case ObjectModificationType.None:
                case ObjectModificationType.Replace:
                case ObjectModificationType.Unconfigured:
                    throw new InvalidOperationException($"Unknown or unsupported modification type: {csentry.ObjectModificationType} on object {csentry.DN}");
                }
            }
            finally
            {
                CSEntryChangeQueue.Add(deltaCSEntry);
            }
        }
        public void OpenExportConnection(KeyedCollection <string, ConfigParameter> configParameters, Schema types, OpenExportConnectionRunStep exportRunStep)
        {
            this.cancellationToken = new CancellationTokenSource();
            this.Configuration     = new ManagementAgentParameters(configParameters);
            this.DeltaPath         = Path.Combine(MAUtils.MAFolder, ManagementAgent.DeltaFile);

            Logger.LogPath = this.Configuration.MALogFile;
            Logger.WriteLine("Opening export connection");
            this.SetHttpDebugMode();

            this.timer = new Stopwatch();

            ManagementAgent.Schema    = SchemaBuilder.GetSchema(this.Configuration);
            this.operationSchemaTypes = types;

            CSEntryChangeQueue.LoadQueue(this.DeltaPath);

            this.LoadInternalDomainsIfRequired(types);
            this.timer.Start();
        }
        public CloseImportConnectionResults CloseImportConnection(CloseImportConnectionRunStep importRunStep)
        {
            Logger.WriteLine("Closing import connection: {0}", importRunStep.Reason);

            try
            {
                if (importRunStep.Reason != CloseReason.Normal)
                {
                    this.cancellationToken?.Cancel();
                }

                if (this.importRunStep.ImportType == OperationType.Full)
                {
                    CSEntryChangeQueue.Clear();
                    CSEntryChangeQueue.SaveQueue(this.DeltaPath, this.operationSchemaTypes);
                    Logger.WriteLine("Cleared delta file");
                }
                else
                {
                    Logger.WriteLine("Writing {0} delta entries to file", CSEntryChangeQueue.Count);
                    CSEntryChangeQueue.SaveQueue(this.DeltaPath, this.operationSchemaTypes);
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLine("An unexpected error occurred");
                Logger.WriteException(ex);
                throw;
            }

            Logger.WriteSeparatorLine('*');
            Logger.WriteLine("Operation statistics");
            Logger.WriteLine("Import objects: {0}", this.opCount);
            Logger.WriteLine("Operation time: {0}", this.timer.Elapsed);
            Logger.WriteLine("Ops/sec: {0:N3}", this.opCount / this.timer.Elapsed.TotalSeconds);
            Logger.WriteSeparatorLine('*');

            return(new CloseImportConnectionResults(null));
        }
        public OpenImportConnectionResults OpenImportConnection(KeyedCollection <string, ConfigParameter> configParameters, Schema types, OpenImportConnectionRunStep importRunStep)
        {
            try
            {
                this.cancellationToken = new CancellationTokenSource();
                this.Configuration     = new ManagementAgentParameters(configParameters);
                Logger.LogPath         = this.Configuration.MALogFile;

                this.importRunStep        = importRunStep;
                this.operationSchemaTypes = types;
                this.timer = new Stopwatch();

                this.DeltaPath = Path.Combine(MAUtils.MAFolder, ManagementAgent.DeltaFile);

                Logger.WriteLine("Opening import connection. Page size {0}", this.importRunStep.PageSize);

                if (this.importRunStep.ImportType == OperationType.Delta)
                {
                    CSEntryChangeQueue.LoadQueue(this.DeltaPath);
                    Logger.WriteLine("Delta full import from file started. {0} entries to import", CSEntryChangeQueue.Count);
                }
                else
                {
                    this.OpenImportConnectionFull(types);

                    Logger.WriteLine("Background full import from Google started");
                }

                this.timer.Start();
                return(new OpenImportConnectionResults("<placeholder>"));
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                throw;
            }
        }
Example #8
0
 public static void AssemblyCleanup()
 {
     CSEntryChangeQueue.SaveQueue(Path.Combine(Path.GetTempPath(), "test-run.xml"), UnitTestControl.MmsSchema);
 }