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 static CSEntryChangeResult PutCSEntryChange(CSEntryChange csentry, SchemaType type, IManagementAgentParameters config)
        {
            try
            {
                return(ExportProcessor.PutCSEntryChangeObject(csentry, type, config));
            }
            catch (Google.GoogleApiException ex)
            {
                string errortype = ex.Message;
                string detail    = ex.StackTrace;
                Logger.WriteException(ex);

                if (ex.HttpStatusCode == System.Net.HttpStatusCode.Forbidden)
                {
                    return(CSEntryChangeResult.Create(csentry.Identifier, null, MAExportError.ExportErrorPermissionIssue, errortype, detail));
                }
                else
                {
                    return(CSEntryChangeResult.Create(csentry.Identifier, null, MAExportError.ExportErrorCustomContinueRun, errortype, detail));
                }
            }
        }
        public PutExportEntriesResults PutExportEntries(IList <CSEntryChange> csentries)
        {
            ParallelOptions po = new ParallelOptions
            {
                MaxDegreeOfParallelism = MAConfigurationSection.Configuration.ExportThreads,
                CancellationToken      = this.cancellationToken.Token
            };

            PutExportEntriesResults results = new PutExportEntriesResults();

            try
            {
                Parallel.ForEach(csentries, po, (csentry) =>
                {
                    try
                    {
                        Interlocked.Increment(ref this.opCount);
                        Logger.StartThreadLog();
                        Logger.WriteSeparatorLine('-');
                        Logger.WriteLine("Starting export {0} for {1} with {2} attribute changes", csentry.ObjectModificationType, csentry.DN, csentry.AttributeChanges.Count);
                        SchemaType type = this.operationSchemaTypes.Types[csentry.ObjectType];

                        CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(csentry, type, this.Configuration);
                        lock (results)
                        {
                            results.CSEntryChangeResults.Add(result);
                        }
                    }
                    catch (AggregateException ex)
                    {
                        Logger.WriteLine("An unexpected error occurred while processing {0}", csentry.DN);
                        Logger.WriteException(ex);
                        CSEntryChangeResult result = CSEntryChangeResult.Create(csentry.Identifier, null, MAExportError.ExportErrorCustomContinueRun, ex.InnerException?.Message ?? ex.Message, ex.InnerException?.StackTrace ?? ex.StackTrace);
                        lock (results)
                        {
                            results.CSEntryChangeResults.Add(result);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLine("An unexpected error occurred while processing {0}", csentry.DN);
                        Logger.WriteException(ex);
                        CSEntryChangeResult result = CSEntryChangeResult.Create(csentry.Identifier, null, MAExportError.ExportErrorCustomContinueRun, ex.Message, ex.StackTrace);
                        lock (results)
                        {
                            results.CSEntryChangeResults.Add(result);
                        }
                    }
                    finally
                    {
                        Logger.WriteSeparatorLine('-');
                        Logger.EndThreadLog();
                    }
                });
            }
            catch (OperationCanceledException)
            {
            }

            return(results);
        }