示例#1
0
        private static byte[] CreateFreeBusyMessage(MailboxSession session, out FolderSaveResult result)
        {
            StoreId defaultFolderId = session.GetDefaultFolderId(DefaultFolderType.FreeBusyData);

            if (defaultFolderId == null)
            {
                ExTraceGlobals.CalendarLoggingTracer.TraceError(0L, "FreeBusyUtil::CreateFreeBusyMessage. No FreeBusyData folder found.");
                throw new DelegateUserNoFreeBusyFolderException(ServerStrings.NoFreeBusyFolder);
            }
            ExTraceGlobals.CalendarLoggingTracer.TraceDebug(0L, "FreeBusyUtil::CreateFreeBusyMessage. Creating the message");
            byte[] providerLevelItemId;
            using (MessageItem messageItem = MessageItem.Create(session, defaultFolderId))
            {
                messageItem.Subject   = FreeBusyUtil.LocalFbSubject;
                messageItem.ClassName = FreeBusyUtil.LocalFbMessageClass;
                messageItem.Save(SaveMode.ResolveConflicts);
                messageItem.Load(null);
                providerLevelItemId = messageItem.Id.ObjectId.ProviderLevelItemId;
            }
            result = null;
            ExTraceGlobals.CalendarLoggingTracer.TraceDebug(0L, "FreeBusyUtil::CreateFreeBusyMessage. Stamping the entry id on the inbox");
            FolderSaveResult folderSaveResult = FreeBusyUtil.StampFreeBusyMsgId(session, providerLevelItemId, DefaultFolderType.Inbox);

            if (folderSaveResult.OperationResult != OperationResult.Succeeded)
            {
                result = folderSaveResult;
            }
            ExTraceGlobals.CalendarLoggingTracer.TraceDebug(0L, "FreeBusyUtil::CreateFreeBusyMessage. Stamping the entry id on the configuration folder");
            folderSaveResult = FreeBusyUtil.StampFreeBusyMsgId(session, providerLevelItemId, DefaultFolderType.Configuration);
            if (folderSaveResult.OperationResult != OperationResult.Succeeded)
            {
                result = folderSaveResult;
            }
            return(providerLevelItemId);
        }
示例#2
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;
            }
        }
示例#3
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);
        }
示例#4
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()));
            }
        }
示例#5
0
        public static bool LinkViewFolder(MailboxSession session, StoreId folderId, SearchFolder viewFolder, OwaViewFilter filter)
        {
            bool      flag = false;
            Exception ex   = null;

            if (OwaFilterState.FilterToLinkPropertyDefinitionsMap.ContainsKey(filter))
            {
                try
                {
                    using (Folder folder = Folder.Bind(session, folderId))
                    {
                        bool    flag2 = true;
                        StoreId linkedFolderIdForFilteredView = OwaFilterState.GetLinkedFolderIdForFilteredView(session, folderId, filter);
                        if (linkedFolderIdForFilteredView != null && viewFolder.StoreObjectId.Equals(linkedFolderIdForFilteredView))
                        {
                            flag2 = false;
                            flag  = true;
                        }
                        if (flag2)
                        {
                            folder.SafeSetProperty(OwaFilterState.FilterToLinkPropertyDefinitionsMap[filter], viewFolder.Id.ObjectId.ProviderLevelItemId);
                            FolderSaveResult folderSaveResult = folder.Save();
                            if (folderSaveResult.OperationResult == OperationResult.Succeeded)
                            {
                                ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "[OwaFilterState::LinkViewFolder] Search Folder Name = {0} linked to physical folder", viewFolder.DisplayName);
                                flag = true;
                            }
                            else
                            {
                                ex = folderSaveResult.Exception;
                            }
                        }
                    }
                }
                catch (ObjectNotFoundException ex2)
                {
                    ex = ex2;
                }
                if (!flag)
                {
                    string arg     = (ex != null) ? ex.ToString() : "[OwaFilterState::LinkViewFolder] FolderSaveResult.OperationResult != OperationResult.Succeeded";
                    string message = string.Format("Linking the view folder ({0}) failed. Details= {1}", viewFolder.DisplayName, arg);
                    ExTraceGlobals.StorageTracer.TraceError(0L, message);
                }
            }
            else
            {
                ExTraceGlobals.StorageTracer.TraceDebug <OwaViewFilter>(0L, "[OwaFilterState::LinkViewFolder] The specified OwaViewFilter {0} is not supported for linking to the source folder.", filter);
            }
            return(flag);
        }
示例#6
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;
        }
示例#7
0
 public static byte[] GetFreeBusyMsgId(MailboxSession session, out FolderSaveResult result)
 {
     result = null;
     byte[] array = null;
     using (Folder folder = Folder.Bind(session, DefaultFolderType.Inbox, new PropertyDefinition[]
     {
         InternalSchema.FreeBusyEntryIds
     }))
     {
         byte[][] array2 = folder.TryGetProperty(InternalSchema.FreeBusyEntryIds) as byte[][];
         if (array2 != null)
         {
             if (array2.Length > 1)
             {
                 array = array2[1];
                 try
                 {
                     StoreObjectId storeObjectId = StoreObjectId.FromProviderSpecificId(array);
                     if (!IdConverter.IsMessageId(storeObjectId))
                     {
                         ExTraceGlobals.CalendarLoggingTracer.TraceError(0L, "FreeBusyUtil::GetFreeBusyMsgId. The extracted storeObjectId is not a valid MessageId");
                         array = null;
                     }
                 }
                 catch (CorruptDataException)
                 {
                     ExTraceGlobals.CalendarLoggingTracer.TraceError(0L, "FreeBusyUtil::GetFreeBusyMsgId. The localFreeBusyMsgId is not a valid entry id");
                     array = null;
                 }
             }
             if (array == null || array.Length == 0)
             {
                 array = FreeBusyUtil.FindFreeBusyMsgId(session);
                 if (array == null)
                 {
                     ExTraceGlobals.CalendarLoggingTracer.TraceDebug(0L, "FreeBusyUtil::GetFreeBusyMsgId. Couldn't find a free busy message. Attempting to create one.");
                     array = FreeBusyUtil.CreateFreeBusyMessage(session, out result);
                 }
             }
         }
     }
     return(array);
 }
        protected Folder CreateInternal(DefaultFolderContext context, string displayName, StoreObjectId parentFolderId, out bool hasCreatedNew)
        {
            hasCreatedNew = false;
            bool   flag   = false;
            Folder folder = null;

            try
            {
                folder = this.CreateNewFolder(context, displayName, parentFolderId);
                FolderSaveResult folderSaveResult = folder.Save();
                if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                {
                    return(null);
                }
                folder.Load(null);
                hasCreatedNew = true;
                flag          = true;
            }
            catch (ObjectExistedException)
            {
                ExTraceGlobals.DefaultFoldersTracer.TraceDebug <DefaultFolderCreator, string>((long)this.GetHashCode(), "DefaultFolderCreator::CreateInternal. We found the folder has existed. strategy = {0}, displayName = {1}.", this, displayName);
                if (folder != null)
                {
                    folder.Dispose();
                    folder = null;
                }
                if (this.bindByNameIfAlreadyExists)
                {
                    folder = DefaultFolderCreator.BindToSubfolderByName(context.Session, parentFolderId, displayName, new PropertyDefinition[0]);
                    flag   = true;
                }
            }
            finally
            {
                if (!flag && folder != null)
                {
                    folder.Dispose();
                    folder = null;
                }
            }
            return(folder);
        }
示例#9
0
 public FolderSaveException(LocalizedString message, FolderSaveResult folderSaveResult) : base(message, folderSaveResult.Exception)
 {
     this.folderSaveResult = folderSaveResult;
 }
示例#10
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);
        }
 internal FolderSaveTransientException(LocalizedString message, FolderSaveResult folderSaveResult) : base(message, folderSaveResult.Exception)
 {
     this.folderSaveResult = folderSaveResult;
 }
示例#12
0
        public void UpdateHistory(CallbackContext callbackContext)
        {
            if (this.ShouldSkipAudit)
            {
                return;
            }
            MailboxSession mailboxSession = (MailboxSession)this.currentFolder.Session;
            CoreFolder     coreFolder     = null;
            StoreObjectId  objectId       = this.currentFolder.Id.ObjectId;

            if (mailboxSession.LogonType == LogonType.Delegated || mailboxSession.LogonType == LogonType.DelegatedAdmin)
            {
                Exception ex = null;
                try
                {
                    coreFolder         = CoreFolder.Bind(callbackContext.SessionWithBestAccess, objectId);
                    this.currentFolder = coreFolder;
                }
                catch (StoragePermanentException ex2)
                {
                    ex = ex2;
                }
                catch (StorageTransientException ex3)
                {
                    ex = ex3;
                }
                if (ex != null)
                {
                    ExTraceGlobals.SessionTracer.TraceWarning <StoreObjectId, Exception>((long)this.currentFolder.Session.GetHashCode(), "Failed to rebind folder {0} with Admin logon. The cached RecentBindingHistory data will not be updated. Error: {1}", objectId, ex);
                    ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorBindingFolderForFolderBindHistory, objectId.ToString(), new object[]
                    {
                        objectId,
                        mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(),
                        mailboxSession.MailboxGuid,
                        mailboxSession.LogonType,
                        IdentityHelper.SidFromLogonIdentity(mailboxSession.Identity),
                        COWTriggerAction.FolderBind,
                        ex
                    });
                    this.currentFolder = null;
                }
            }
            if (this.currentFolder != null)
            {
                try
                {
                    this.currentFolder.PropertyBag.SetProperty(FolderSchema.RecentBindingHistory, this.bindingHistory.ToArray());
                    FolderSaveResult folderSaveResult = this.currentFolder.Save(SaveMode.NoConflictResolutionForceSave);
                    if (coreFolder == null)
                    {
                        this.currentFolder.PropertyBag.Load(null);
                    }
                    if (folderSaveResult.OperationResult != OperationResult.Succeeded)
                    {
                        ExTraceGlobals.SessionTracer.TraceWarning <StoreObjectId, LocalizedException>((long)this.currentFolder.Session.GetHashCode(), "Failed to save RecentBindingHistory on folder {0}. Error: {1}.", objectId, folderSaveResult.Exception);
                        ProcessInfoEventLogger.Log(StorageEventLogConstants.Tuple_ErrorSavingFolderBindHistory, objectId.ToString(), new object[]
                        {
                            objectId,
                            mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(),
                            mailboxSession.MailboxGuid,
                            mailboxSession.LogonType,
                            IdentityHelper.SidFromLogonIdentity(mailboxSession.Identity),
                            COWTriggerAction.FolderBind,
                            folderSaveResult.Exception
                        });
                    }
                }
                finally
                {
                    if (coreFolder != null)
                    {
                        coreFolder.Dispose();
                    }
                }
            }
        }