internal override void Recover(DefaultFolder defaultFolder, Exception e, ref DefaultFolderData defaultFolderData)
 {
     try
     {
         defaultFolder.RemoveForRecover(ref defaultFolderData);
         defaultFolder.CreateInternal(ref defaultFolderData);
     }
     catch (StoragePermanentException innerException)
     {
         throw new CorruptDataException(ServerStrings.ExCorruptDataRecoverError(defaultFolder.ToString()), innerException);
     }
     catch (StorageTransientException innerException2)
     {
         throw new CorruptDataException(ServerStrings.ExCorruptDataRecoverError(defaultFolder.ToString()), innerException2);
     }
 }
Пример #2
0
 internal virtual void RemoveForRecover(ref DefaultFolderData data)
 {
     if (data.FolderId != null)
     {
         if (this.defaultFolderInfo.StoreObjectType == StoreObjectType.SearchFolder)
         {
             AggregateOperationResult aggregateOperationResult = this.defaultFolderInfo.FolderCreator.Delete(this.context, DeleteItemFlags.HardDelete, data.FolderId);
             if (aggregateOperationResult.OperationResult != OperationResult.Succeeded)
             {
                 ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::Create. The default folder cannot be deleted. defaultFolder = {0}.", this);
             }
         }
         data = new DefaultFolderData(null, data.IdInitialized, data.HasInitialized);
         this.defaultFolderInfo.EntryIdStrategy.UnsetEntryId(this.context);
     }
 }
        internal override void Recover(DefaultFolder defaultFolder, Exception e, ref DefaultFolderData defaultFolderData)
        {
            if (e is DefaultFolderPropertyValidationException && defaultFolderData.FolderId != null)
            {
                using (Folder folder = Folder.Bind(defaultFolder.Session, defaultFolderData.FolderId))
                {
                    defaultFolder.SetProperties(folder);
                }
                return;
            }
            COWSettings cowsettings = new COWSettings(defaultFolder.Session);

            if (cowsettings.HoldEnabled())
            {
                CorruptDataRecoveryStrategy.Throw.Recover(defaultFolder, e, ref defaultFolderData);
                return;
            }
            CorruptDataRecoveryStrategy.Recreate.Recover(defaultFolder, e, ref defaultFolderData);
        }
Пример #4
0
        private DefaultFolderData InitializeFolderIdPrivate()
        {
            ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::InitializeFolderId. The default folder ID is about to be initialized. defaultFolder = {0}.", this);
            byte[] array = this.defaultFolderInfo.EntryIdStrategy.GetEntryId(this.context);
            if (!IdConverter.IsFolderId(array))
            {
                array = null;
                ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::InitializeFolderId. Invalid entry id found. defaultFolder = {0}.", this);
            }
            DefaultFolderData result;

            if (array != null)
            {
                result = new DefaultFolderData(StoreObjectId.FromProviderSpecificId(array, this.StoreObjectType), true, false);
            }
            else
            {
                result = new DefaultFolderData(null, true, false);
            }
            return(result);
        }
Пример #5
0
        internal virtual void Delete(DeleteItemFlags deleteItemFlags)
        {
            ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::Delete. The default folder is about to be deleted. defaultFolder = {0}.", this);
            EnumValidator.ThrowIfInvalid <DeleteItemFlags>(deleteItemFlags, "deleteItemFlags");
            EnumValidator.ThrowIfInvalid <DefaultFolderType>(this.defaultFolderInfo.DefaultFolderType, DefaultFolder.DefaultFoldersThatCanBeDeleted);
            StoreObjectId storeObjectId;

            if (!this.TryGetFolderId(out storeObjectId))
            {
                throw new InvalidOperationException(string.Format("Cannot delete the default folder {0}, because it does not exist.", this.defaultFolderInfo.DefaultFolderType));
            }
            this.defaultFolderInfo.EntryIdStrategy.UnsetEntryId(this.context);
            DefaultFolderData        defaultFolderData        = this.GetDefaultFolderData();
            AggregateOperationResult aggregateOperationResult = this.defaultFolderInfo.FolderCreator.Delete(this.context, deleteItemFlags, defaultFolderData.FolderId);

            if (aggregateOperationResult.OperationResult != OperationResult.Succeeded)
            {
                throw new AggregateOperationFailedException(ServerStrings.ExFailedToDeleteDefaultFolder, aggregateOperationResult);
            }
            this.defaultFolderInfo.EntryIdStrategy.UnsetEntryId(this.context);
            this.SetDefaultFolderData(new DefaultFolderData(null));
        }
 internal void SetDefaultFolder(DefaultFolderType defaultFolderType, DefaultFolderData defaultFolderData)
 {
     this.defaultFolderData[(int)defaultFolderType] = defaultFolderData;
 }
Пример #7
0
 internal override void Recover(DefaultFolder defaultFolder, Exception e, ref DefaultFolderData defaultFolderData)
 {
     defaultFolder.RemoveForRecover(ref defaultFolderData);
 }
Пример #8
0
 internal abstract void Recover(DefaultFolder defaultFolder, Exception e, ref DefaultFolderData defaultFolderData);
Пример #9
0
 internal override void Recover(DefaultFolder defaultFolder, Exception e, ref DefaultFolderData defaultFolderData)
 {
     throw e;
 }
Пример #10
0
 internal bool CreateInternal(ref DefaultFolderData data)
 {
     if ((this.defaultFolderInfo.Behavior & DefaultFolderBehavior.CanCreate) != DefaultFolderBehavior.CanCreate)
     {
         ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::Create. Cannot create default folder because DefaultFolderBehavior.CanCreate is not set. defaultFolder = {0}.", this);
         throw new NotSupportedException(string.Format("The defaultFolder cannot be created. defaultFolder = {0}.", this));
     }
     if (data.FolderId != null)
     {
         throw new InvalidOperationException(string.Format("Cannot create default folder {0}, because it already exists.", this.defaultFolderInfo.DefaultFolderType));
     }
     for (int i = 0; i <= StorageLimits.Instance.DefaultFolderMaximumSuffix; i++)
     {
         ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder, int>((long)this.GetHashCode(), "DefaultFolder::CreateInternal. About to create the default folder. defaultFolder = {0}. Iteration = {1}.", this, i);
         Folder folder = null;
         bool   flag   = false;
         this.context.Session.Mailbox.Load(DefaultFolder.localeIdPropertyDefinition);
         string        text          = this.defaultFolderInfo.LocalizableDisplayName.ToString(this.cultureInfo);
         StoreObjectId storeObjectId = null;
         if (this.HideUnderNonIpmSubtree)
         {
             storeObjectId = this.context[DefaultFolderType.Configuration];
         }
         else
         {
             storeObjectId = this.context[this.defaultFolderInfo.FolderCreator.DefaultContainer];
         }
         if (i > 0)
         {
             text += i;
         }
         bool flag2 = false;
         try
         {
             folder = this.defaultFolderInfo.FolderCreator.Create(this.context, text, storeObjectId, out flag2);
         }
         catch (ObjectNotFoundException arg)
         {
             ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder, string, ObjectNotFoundException>((long)this.GetHashCode(), "DefaultFolder::CreateInternal. The user may have no permission to the container folder. defaultFolder = {0}, session = {1}, exception = {2}.", this, this.context.Session.DisplayName, arg);
             return(false);
         }
         catch (AccessDeniedException arg2)
         {
             ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder, string, AccessDeniedException>((long)this.GetHashCode(), "DefaultFolder::CreateInternal. The user may have no permission to the container folder. defaultFolder = {0}, session = {1}, exception = {2}.", this, this.context.Session.DisplayName, arg2);
             return(false);
         }
         catch (ObjectExistedException arg3)
         {
             ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder, string, ObjectExistedException>((long)this.GetHashCode(), "DefaultFolder::CreateInternal. The folder already exists. defaultFolder = {0}, session = {1}, exception = {2}.", this, this.context.Session.DisplayName, arg3);
             if (folder != null && folder.Id != null)
             {
                 folder.Dispose();
                 folder = null;
                 data   = new DefaultFolderData(data.HasInitialized);
             }
             folder = DefaultFolderCreator.BindToSubfolderByName(this.context.Session, storeObjectId, text, new PropertyDefinition[0]);
             flag2  = false;
         }
         if (folder != null)
         {
             if (!flag2)
             {
                 data = new DefaultFolderData(folder.StoreObjectId, data.IdInitialized, data.HasInitialized);
             }
             StoreObjectId objectId = folder.Id.ObjectId;
             try
             {
                 if (flag2 || this.defaultFolderInfo.FolderValidationStrategy.EnsureIsValid(this.context, folder))
                 {
                     ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder, bool>((long)this.GetHashCode(), "DefaultFolder::CreateInternal. We created or hijacked a new folder for the missing default folder. defaultFolder = {0}, hasCreatedNew = {1}.", this, flag2);
                     if (flag2)
                     {
                         this.SetProperties(folder);
                         folder.Load(null);
                     }
                     flag = true;
                 }
             }
             catch (DefaultFolderPropertyValidationException)
             {
                 this.SetProperties(folder);
                 folder.Load(null);
                 flag = true;
             }
             finally
             {
                 folder.Dispose();
             }
             if (flag)
             {
                 this.defaultFolderInfo.EntryIdStrategy.SetEntryId(this.context, objectId.ProviderLevelItemId);
                 data = new DefaultFolderData(StoreObjectId.FromProviderSpecificId(objectId.ProviderLevelItemId, this.StoreObjectType), data.IdInitialized, data.HasInitialized);
                 return(true);
             }
             ExTraceGlobals.DefaultFoldersTracer.TraceWarning <DefaultFolder, string, int>((long)this.GetHashCode(), "DefaultFolder::CreateInternal. We failed to create a default folder. We will try with a new name. defaultFolder = {0}, displayName = {1}, iteration = {2}.", this, text, i);
         }
     }
     ExTraceGlobals.DefaultFoldersTracer.TraceError <string, DefaultFolderType>((long)this.GetHashCode(), "DefaultFolder::CreateInternal. Failed to open or create default folder. Folder = {0}, defaultFolderType = {1}.", this.defaultFolderInfo.LocalizableDisplayName.ToString(this.cultureInfo), this.defaultFolderInfo.DefaultFolderType);
     throw new DefaultFolderNameClashException(ServerStrings.ExUnableToOpenOrCreateDefaultFolder(this.defaultFolderInfo.LocalizableDisplayName.ToString(this.cultureInfo)));
 }
Пример #11
0
 private bool CheckShouldRefreshFolderId(DefaultFolderData defaultFolderData)
 {
     return(defaultFolderData.FolderId == null && (this.defaultFolderInfo.Behavior & DefaultFolderBehavior.RefreshIfMissing) == DefaultFolderBehavior.RefreshIfMissing);
 }
Пример #12
0
 private void SetDefaultFolderData(DefaultFolderData data)
 {
     this.sharableDataManager.SetDefaultFolder(this.defaultFolderType, data);
 }
Пример #13
0
        private bool Initialize(ref DefaultFolderData data)
        {
            bool      flag = true;
            Exception ex   = null;

            if (!data.IdInitialized)
            {
                DefaultFolderData defaultFolderData = this.InitializeFolderIdPrivate();
                if (defaultFolderData != null)
                {
                    data = defaultFolderData;
                }
            }
            ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::Initialize. The default folder is about to be initialized. defaultFolder = {0}.", this);
            if (this.defaultFolderInfo.DefaultFolderType == DefaultFolderType.None)
            {
                if (!data.HasInitialized)
                {
                    data = new DefaultFolderData(true);
                }
                return(true);
            }
            try
            {
                if (DefaultFolder.TestInjectInitFailure != null)
                {
                    DefaultFolder.TestInjectInitFailure(this);
                }
                bool flag2 = true;
                if (data.FolderId != null && !this.Validate(data))
                {
                    flag2 = false;
                    data  = new DefaultFolderData(null, data.IdInitialized, data.HasInitialized);
                }
                if (data.FolderId == null && (this.IsOwnerSession || (!flag2 && this.context.Session.Capabilities.MustHideDefaultFolders)) && (this.defaultFolderInfo.Behavior & DefaultFolderBehavior.CreateIfMissing) == DefaultFolderBehavior.CreateIfMissing)
                {
                    flag = this.CreateInternal(ref data);
                }
                if (flag && data.FolderId != null && this.HideUnderNonIpmSubtree)
                {
                    using (Folder folder = Folder.Bind(this.context.Session, data.FolderId))
                    {
                        if (!this.IsParentFolderConfigurationFolder(folder))
                        {
                            ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::Initialize. defaultFolder={0} is not under the non-IPM subtree(aka. Configuration folder). Move it to the non-IPM subtree.", this);
                            AggregateOperationResult aggregateOperationResult = this.context.Session.Move(this.context[DefaultFolderType.Configuration], new StoreId[]
                            {
                                data.FolderId
                            });
                            if (aggregateOperationResult.OperationResult != OperationResult.Succeeded)
                            {
                                LocalizedException exception = aggregateOperationResult.GroupOperationResults[0].Exception;
                                ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder, LocalizedException>((long)this.GetHashCode(), "DefaultFolder::Initialize. Moving defaultFolder={0} to the non-IPM subtree(aka. Configuration folder) fails with exception={1}.", this, exception);
                                if (exception.ErrorCode == -2146233088 && exception is ObjectExistedException)
                                {
                                    folder.PropertyBag.Reload();
                                    if (this.IsParentFolderConfigurationFolder(folder))
                                    {
                                        ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::Initialize. After reloading, defaultFolder={0} is under the non-IPM subtree(aka. Configuration folder).", this);
                                    }
                                    else
                                    {
                                        data = new DefaultFolderData(null, data.IdInitialized, data.HasInitialized);
                                        flag = false;
                                        ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder>((long)this.GetHashCode(), "DefaultFolder::Initialize. After reloading, defaultFolder={0} is still NOT under the non-IPM subtree(aka. Configuration folder).", this);
                                    }
                                }
                                else
                                {
                                    data = new DefaultFolderData(null, data.IdInitialized, data.HasInitialized);
                                    flag = false;
                                    ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder, LocalizedException>((long)this.GetHashCode(), "DefaultFolder::Initialize. Unable to move defaultFolder={0} to the Configuration node. Exception={1}.", this, exception);
                                }
                            }
                        }
                    }
                }
                if (flag && data.FolderId != null && this.context.Session.MailboxOwner.RecipientTypeDetails == RecipientTypeDetails.TeamMailbox && this.IsHiddenTeamMailboxFolder)
                {
                    using (Folder folder2 = Folder.Bind(this.context.Session, data.FolderId))
                    {
                        folder2.PropertyBag[FolderSchema.IsHidden] = true;
                        folder2.Save();
                    }
                }
                if (this.CheckShouldRefreshFolderId(data))
                {
                    data = this.InitializeFolderIdPrivate();
                    if (data.FolderId != null)
                    {
                        if (this.Validate(data))
                        {
                            flag = true;
                        }
                        else
                        {
                            data = new DefaultFolderData(null, data.IdInitialized, data.HasInitialized);
                        }
                    }
                }
            }
            catch (CorruptDataException ex2)
            {
                ex = ex2;
            }
            this.SetDefaultFolderData(data);
            if (ex != null)
            {
                this.defaultFolderInfo.CorruptDataRecoveryStrategy.Recover(this, ex, ref data);
            }
            if (!data.HasInitialized)
            {
                data = new DefaultFolderData(data.FolderId, data.IdInitialized, true);
                this.SetDefaultFolderData(data);
            }
            return(flag);
        }