Esempio n. 1
0
        /// <summary>
        /// Exports a single entry
        /// </summary>
        /// <param name="csentry">The entry to export</param>
        /// <param name="dbc">The DBDataContext for the current thread</param>
        /// <param name="referenceRetryRequired">A value indicating whether one or more referenced objects were not found</param>
        /// <returns>A list of anchor attributes if the object was added to the database, otherwise returns an empty list</returns>
        public static IList <AttributeChange> PutExportEntry(CSEntryChange csentry, out bool referenceRetryRequired)
        {
            IList <AttributeChange> anchorchanges = new List <AttributeChange>();

            referenceRetryRequired = false;
            bool hasTransaction = Transaction.Current != null;

            try
            {
                TransactionOptions op = new TransactionOptions();
                op.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
                op.Timeout        = TransactionManager.MaximumTimeout;
                using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, op))
                {
                    MAStatistics.StartTransaction();

                    switch (csentry.ObjectModificationType)
                    {
                    case ObjectModificationType.Add:
                        anchorchanges = CSEntryExport.PerformCSEntryExportAdd(csentry, out referenceRetryRequired);
                        break;

                    case ObjectModificationType.Delete:
                        CSEntryExport.PerformCSEntryExportDelete(csentry);
                        break;

                    case ObjectModificationType.None:
                        break;

                    case ObjectModificationType.Update:
                        CSEntryExport.PerformCSEntryExportUpdate(csentry, out referenceRetryRequired);
                        break;

                    case ObjectModificationType.Replace:
                        CSEntryExport.PerformCSEntryExportReplace(csentry, out referenceRetryRequired);
                        break;

                    default:
                    case ObjectModificationType.Unconfigured:
                        throw new UnknownOrUnsupportedModificationTypeException(csentry.ObjectModificationType);
                    }

                    transaction.Complete();
                    MAStatistics.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                MAStatistics.RollBackTransaction();
                throw;
            }

            MAStatistics.AddExportOperation(csentry.ObjectModificationType);

            return(anchorchanges);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a CSEntryChange of the specified modification type for the supplied MAObjectHologram
        /// </summary>
        /// <param name="maObject">The MAObjectHologram to create the CSEntryChange from</param>
        /// <param name="objectModificationType">The object modification type to apply</param>
        /// <returns>A new CSEntryChange object representing the current state of the specified MAObjectHologram </returns>
        public static AcmaCSEntryChange CreateCSEntryChangeFromMAObjectHologram(this MAObjectHologram maObject, ObjectModificationType objectModificationType)
        {
            AcmaCSEntryChange csentry = new AcmaCSEntryChange();

            csentry.ObjectModificationType = objectModificationType;
            csentry.DN         = maObject.ObjectID.ToString();
            csentry.ObjectType = maObject.ObjectClass.Name;

            if (objectModificationType != ObjectModificationType.Delete)
            {
                AttributeModificationType attributeModificationType = objectModificationType == ObjectModificationType.Update ? AttributeModificationType.Replace : AttributeModificationType.Add;

                foreach (AcmaSchemaAttribute attribute in maObject.ObjectClass.Attributes.Where(t => t.Name != "objectId" && t.Name != "objectClass"))
                {
                    AttributeValues values = maObject.GetAttributeValues(attribute);

                    if (values.IsEmptyOrNull)
                    {
                        continue;
                    }

                    if (attributeModificationType == AttributeModificationType.Add)
                    {
                        AttributeChange change = AttributeChange.CreateAttributeAdd(attribute.Name, values.ToObjectList());
                        csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, values.ToObjectList()));
                    }
                    else
                    {
                        csentry.AttributeChanges.Add(AttributeChange.CreateAttributeReplace(attribute.Name, values.ToObjectList()));
                    }
                }
            }

            if (csentry.ErrorCodeImport == MAImportError.Success)
            {
                MAStatistics.AddImportOperation();
            }
            else
            {
                MAStatistics.AddImportError();
            }

            return(csentry);
        }
Esempio n. 3
0
 /// <summary>
 /// Resets the counters and starts a new operation
 /// </summary>
 /// <param name="operationType">The type of operation in progress</param>
 public static void StartOperation(MAOperationType operationType)
 {
     MAStatistics.Reset();
     MAStatistics.CurrentOperation   = operationType;
     MAStatistics.OperationStartTime = DateTime.Now;
 }