Example #1
0
        public static void SaveWithUniqueDisplayName(this IFolder folder, int maxSuffix = 50)
        {
            IStoreSession      session      = folder.Session;
            IExchangePrincipal mailboxOwner = session.MailboxOwner;
            string             displayName  = folder.DisplayName;
            string             text         = displayName;
            int num = 1;

            try
            {
IL_1A:
                FolderSaveResult folderSaveResult = folder.Save();
                if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                {
                    ExTraceGlobals.StorageTracer.TraceError <IExchangePrincipal, string, FolderSaveResult>(0L, "{0}: Failed to create folder {1} due to {2}.", mailboxOwner, text, folderSaveResult);
                    throw folderSaveResult.ToException(ServerStrings.ExCannotCreateFolder(folderSaveResult.ToString()));
                }
            }
            catch (ObjectExistedException)
            {
                if (num > maxSuffix)
                {
                    throw;
                }
                text = ServerStrings.SharingFolderNameWithSuffix(displayName, num++);
                folder.DisplayName = text;
                ExTraceGlobals.StorageTracer.TraceDebug <IExchangePrincipal, string>(0L, "{0}: Folder exists. Recalculated folder name: {1}.", mailboxOwner, text);
                goto IL_1A;
            }
        }
Example #2
0
        private static Folder CreateAndSaveFolder(MailboxSession mailboxSession, StoreObjectId containerId, CreateMode createMode, string displayName, string containerClass, Folder folderIn, ISyncLogger syncLogger = null)
        {
            if (syncLogger == null)
            {
                syncLogger = TracingLogger.Singleton;
            }
            Folder folder = null;
            bool   flag   = false;
            Folder result;

            try
            {
                if (folderIn == null)
                {
                    folder = Folder.Create(mailboxSession, containerId, StoreObjectType.Folder, displayName, createMode);
                    folder[SyncStateStorage.airsyncLockProp] = "0";
                }
                else
                {
                    folder = folderIn;
                }
                if (containerClass != null)
                {
                    folder[InternalSchema.ContainerClass] = containerClass;
                }
                StoreObjectId storeObjectId = null;
                if (!folder.IsNew)
                {
                    storeObjectId = folder.Id.ObjectId;
                }
                FolderSaveResult folderSaveResult = folder.Save();
                if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                {
                    syncLogger.TraceDebug <string, FolderSaveResult>(ExTraceGlobals.SyncTracer, 0L, "SyncStateStorage::CreateAndSaveFolder. Failed to create folder {0}, due to {1}.", displayName, folderSaveResult);
                    if (storeObjectId == null)
                    {
                        folder.Load(null);
                        storeObjectId = folder.StoreObjectId;
                    }
                    mailboxSession.Delete(DeleteItemFlags.SoftDelete, new StoreId[]
                    {
                        storeObjectId
                    });
                    throw folderSaveResult.ToException(ServerStrings.ExCannotCreateFolder(folderSaveResult));
                }
                folder.Load(SyncStateStorage.loggingEnabledAndCreateTimeAsArray);
                flag   = true;
                result = folder;
            }
            finally
            {
                if (!flag && folder != null)
                {
                    folder.Dispose();
                    folder = null;
                }
            }
            return(result);
        }
Example #3
0
        internal void Save()
        {
            FolderSaveResult folderSaveResult = ((CoreMailboxObject)base.CoreObject).Save();

            if (folderSaveResult.OperationResult != OperationResult.Succeeded)
            {
                throw folderSaveResult.ToException(ServerStrings.ErrorFolderSave(base.CoreObject.Id.ObjectId.ToString(), folderSaveResult.ToString()));
            }
        }
Example #4
0
        internal void SetProperties(Folder folder)
        {
            this.defaultFolderInfo.FolderValidationStrategy.SetProperties(this.context, folder);
            FolderSaveResult folderSaveResult = folder.Save();

            if (folderSaveResult.OperationResult == OperationResult.Succeeded)
            {
                return;
            }
            ExTraceGlobals.DefaultFoldersTracer.TraceError <DefaultFolder, OperationResult>((long)this.GetHashCode(), "DefaultFolder::SetProperties. We failed to stamp default folder. defaultFolder = {0}, result = {1}.", this, folderSaveResult.OperationResult);
            LocalizedException ex = folderSaveResult.ToException(ServerStrings.ExCannotCreateFolder(folderSaveResult));

            if (ex.InnerException != null && ex.InnerException is ObjectNotFoundException)
            {
                throw new CannotCompleteOperationException(ex.LocalizedString, ex.InnerException);
            }
            throw ex;
        }
Example #5
0
        public static StoreObjectId Recreate(MailboxSession session, Guid searchFolderClsId)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (searchFolderClsId == Guid.Empty)
            {
                throw new ArgumentException("Guid is empty", "searchFolderClsId");
            }
            using (Folder folder = Folder.Bind(session, DefaultFolderType.SearchFolders))
            {
                using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, new PropertyDefinition[]
                {
                    InternalSchema.OutlookSearchFolderClsId
                }))
                {
                    for (;;)
                    {
                        object[][] rows = queryResult.GetRows(10000);
                        for (int i = 0; i < rows.Length; i++)
                        {
                            if (rows[i][0] is Guid && ((Guid)rows[i][0]).Equals(searchFolderClsId))
                            {
                                goto Block_9;
                            }
                        }
                        if (rows.Length <= 0)
                        {
                            goto Block_11;
                        }
                    }
Block_9:
                    throw new ObjectExistedException(ServerStrings.ExSearchFolderAlreadyExists(searchFolderClsId));
                    Block_11 :;
                }
            }
            VersionedId versionedId = OutlookSearchFolder.FindAssociatedMessageId(session, searchFolderClsId);

            if (versionedId == null)
            {
                throw new ObjectNotFoundException(ServerStrings.ExSearchFolderNoAssociatedItem(searchFolderClsId));
            }
            StoreObjectId objectId;

            using (MessageItem messageItem = MessageItem.Bind(session, versionedId))
            {
                bool                 deepTraversal;
                StoreId[]            folderScope;
                Restriction          restriction          = OutlookSearchFolder.ReadOutlookSearchFolderDefinitionBlob(messageItem, out deepTraversal, out folderScope);
                QueryFilter          searchQuery          = FilterRestrictionConverter.CreateFilter(session, session.Mailbox.MapiStore, restriction, true);
                SearchFolderCriteria searchFolderCriteria = new SearchFolderCriteria(searchQuery, folderScope);
                searchFolderCriteria.DeepTraversal = deepTraversal;
                string valueOrDefault = messageItem.GetValueOrDefault <string>(InternalSchema.DisplayName, string.Empty);
                using (OutlookSearchFolder outlookSearchFolder = OutlookSearchFolder.Create(session, valueOrDefault))
                {
                    outlookSearchFolder[InternalSchema.OutlookSearchFolderClsId] = searchFolderClsId;
                    FolderSaveResult folderSaveResult = outlookSearchFolder.Save();
                    if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                    {
                        throw folderSaveResult.ToException(ServerStrings.ExCannotCreateFolder(folderSaveResult));
                    }
                    outlookSearchFolder.Load(null);
                    outlookSearchFolder.ApplyContinuousSearch(searchFolderCriteria);
                    objectId = outlookSearchFolder.Id.ObjectId;
                }
            }
            return(objectId);
        }