Exemplo 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a new object to the database
        /// </summary>
        /// <param name="csentry">The CSEntryChange containing the new object and its attributes</param>
        /// <param name="dc">The DBDataContext in use on this thread</param>
        /// <param name="referenceRetryRequired">A value indicating whether a reference update failed due to a missing object and needs to be retried after all other CSEntryChanges have been processed</param>
        /// <returns>A list of anchor attributes for the new object</returns>
        private static IList <AttributeChange> PerformCSEntryExportAdd(CSEntryChange csentry, out bool referenceRetryRequired)
        {
            if (csentry.ObjectType == null)
            {
                throw new InvalidOperationException("No object class was specified for CSEntryChange with DN " + csentry.DN);
            }

            AcmaSchemaObjectClass objectClass = ActiveConfig.DB.GetObjectClass(csentry.ObjectType);
            bool             isUndeleting     = false;
            MAObjectHologram hologram;
            Guid             guidFromDn = new Guid(csentry.DN);

            if (objectClass.IsShadowObject)
            {
                hologram = CSEntryExport.ExportShadowObject(csentry);
            }
            else
            {
                hologram = GetResurrectionObject(csentry);

                if (hologram == null)
                {
                    hologram = ActiveConfig.DB.CreateMAObject(guidFromDn, csentry.ObjectType);
                }
                else
                {
                    Logger.WriteLine("Resurrecting object with ID: " + hologram.ObjectID.ToString());
                    isUndeleting = true;

                    if (hologram.ObjectID != guidFromDn)
                    {
                        Logger.WriteLine("Re-anchoring object with new ID: " + csentry.DN);
                        ActiveConfig.DB.ChangeMAObjectId(hologram.ObjectID, guidFromDn, true);
                        hologram = ActiveConfig.DB.GetMAObject(guidFromDn, objectClass);
                    }

                    csentry = CSEntryChangeExtensions.ConvertCSEntryChangeAddToUpdate(csentry);
                }
            }

            AttributeChange        anchorChange  = AttributeChange.CreateAttributeAdd("objectId", csentry.DN);
            List <AttributeChange> anchorChanges = new List <AttributeChange>()
            {
                anchorChange
            };

            if (!hologram.ObjectClass.IsShadowObject)
            {
                // shadow objects must be provisioned by their parent object, which automatically calls the Commit method
                hologram.CommitCSEntryChange(csentry, isUndeleting);
            }

            referenceRetryRequired = hologram.ReferenceRetryRequired;

            return(anchorChanges);
        }