private int RemoveFromPendingAndConcurrent(AggregatedUserConfiguration.PendingUpdate pending)
        {
            int result = this.memento.Pending.RemoveAll((AggregatedUserConfiguration.PendingUpdate p) => pending.Guid.Equals(p.Guid));

            if (!this.memento.Pending.Exists((AggregatedUserConfiguration.PendingUpdate p) => pending.DescriptorMemento.Equals(p.DescriptorMemento)))
            {
                this.memento.ConcurrentUpdates.Remove(pending.DescriptorMemento);
            }
            return(result);
        }
 private AggregatedUserConfiguration.PendingUpdate PrepareUpdate(UserConfigurationDescriptor descriptor, ICoreObject item)
 {
     UserConfigurationDescriptor.MementoClass descriptorMemento = descriptor.ToMemento(this.manager.MailboxSession);
     if (this.memento.Pending.Exists((AggregatedUserConfiguration.PendingUpdate p) => descriptorMemento.Equals(p.DescriptorMemento)))
     {
         ExTraceGlobals.StorageTracer.TraceWarning <StoreObjectId, string>((long)this.GetHashCode(), "The core item with id=[{0}] and name=[{1}] already has a pending update.  It will be marked for rebuild.", item.StoreObjectId, descriptor.ConfigurationName);
         this.memento.ConcurrentUpdates.Add(descriptorMemento);
     }
     AggregatedUserConfiguration.PendingUpdate pendingUpdate = new AggregatedUserConfiguration.PendingUpdate
     {
         Guid              = Guid.NewGuid().ToString(),
         PreparedUtc       = ExDateTime.UtcNow.ToBinary(),
         Descriptor        = descriptor,
         DescriptorMemento = descriptorMemento
     };
     this.memento.Pending.Add(pendingUpdate);
     this.Parts.Remove(descriptorMemento);
     this.memento.Parts.Remove(descriptorMemento);
     this.SaveMemento(AggregatedUserConfiguration.SaveFailureMode.Fail);
     return(pendingUpdate);
 }
        private void CommitUpdate(AggregatedUserConfiguration.PendingUpdate pending)
        {
            bool flag = true;

            if (this.memento.ConcurrentUpdates.Contains(pending.DescriptorMemento))
            {
                flag = false;
                ExTraceGlobals.StorageTracer.TraceWarning <string>((long)this.GetHashCode(), "The configuration object with name[{0}] will not be committed because it is in the concurrent update list.", pending.Descriptor.ConfigurationName);
            }
            if (this.RemoveFromPendingAndConcurrent(pending) == 0)
            {
                flag = false;
                ExTraceGlobals.StorageTracer.TraceWarning <string>((long)this.GetHashCode(), "The configuration object with name[{0}] will not be committed because it was not found as a pending update.", pending.Descriptor.ConfigurationName);
            }
            if (flag)
            {
                IUserConfiguration userConfiguration = null;
                AggregatedUserConfigurationPart aggregatedUserConfigurationPart = null;
                try
                {
                    if (this.TryInternalLoadConfiguration(() => pending.Descriptor.GetConfiguration(this.manager), null, delegate(IUserConfiguration c)
                    {
                        pending.Descriptor.Validate(c);
                    }, out userConfiguration))
                    {
                        aggregatedUserConfigurationPart = AggregatedUserConfigurationPart.FromConfiguration(userConfiguration);
                        this.memento.Parts.Add(pending.DescriptorMemento, aggregatedUserConfigurationPart.Memento);
                        this.memento.FailedToLoad.Remove(pending.DescriptorMemento);
                    }
                }
                finally
                {
                    DisposeGuard.DisposeIfPresent(userConfiguration);
                    DisposeGuard.DisposeIfPresent(aggregatedUserConfigurationPart);
                }
            }
            this.SaveMemento(AggregatedUserConfiguration.SaveFailureMode.Fail);
        }