Esempio n. 1
0
 internal static void UpgradeElcFolder(bool userIsOnRetentionPolcyTags, MailboxSession mailboxSession, StoreId folderId, Dictionary <Guid, AdTagData> allAdTags)
 {
     using (Folder folder = Folder.Bind(mailboxSession, folderId, ProvisionedFolderReader.ElcFolderProps))
     {
         ElcMailboxHelper.UpgradeElcFolder(userIsOnRetentionPolcyTags, mailboxSession, folder, allAdTags);
         ProvisionedFolderCreator.SaveELCFolder(folder, false);
     }
 }
Esempio n. 2
0
        internal static bool RemoveElcFolder(bool userIsOnRetentionPolcyTags, MailboxSession mailboxSession, StoreId folderId, Dictionary <Guid, AdTagData> allAdTags, out UpgradeStatus status)
        {
            status = UpgradeStatus.None;
            Stack <ElcMailboxHelper.FolderNode> stack = new Stack <ElcMailboxHelper.FolderNode>(50);

            ElcMailboxHelper.FolderNode folderNode = new ElcMailboxHelper.FolderNode(folderId, null);
            stack.Push(folderNode);
            while (stack.Count > 0)
            {
                ElcMailboxHelper.FolderNode folderNode2 = stack.Peek();
                if (folderNode2.ChildCount == -1)
                {
                    using (Folder folder = Folder.Bind(mailboxSession, folderNode2.FolderId, ProvisionedFolderReader.ElcFolderProps))
                    {
                        folderNode2.ChildCount = folder.ItemCount + folder.SubfolderCount;
                        using (QueryResult queryResult = folder.FolderQuery(FolderQueryFlags.None, null, null, ProvisionedFolderReader.ElcFolderProps))
                        {
                            for (;;)
                            {
                                object[][] rows = queryResult.GetRows(100);
                                if (rows.Length <= 0)
                                {
                                    break;
                                }
                                foreach (object[] array in rows)
                                {
                                    stack.Push(new ElcMailboxHelper.FolderNode((VersionedId)array[0], folderNode2));
                                }
                            }
                        }
                        if (ElcMailboxHelper.IsElcFolder(folder))
                        {
                            status |= ElcMailboxHelper.UpgradeElcFolder(userIsOnRetentionPolcyTags, mailboxSession, folder, allAdTags);
                            ProvisionedFolderCreator.SaveELCFolder(folder, false);
                        }
                        continue;
                    }
                }
                if (folderNode2.ChildCount == 0)
                {
                    if (folderNode2.Parent != null)
                    {
                        folderNode2.Parent.ChildCount--;
                    }
                    mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                    {
                        folderNode2.FolderId
                    });
                }
                stack.Pop();
            }
            return(folderNode.ChildCount == 0);
        }
Esempio n. 3
0
        internal static string CreateOneELCFolderInMailbox(AdFolderData adFolderInfo, MailboxSession itemStore, Folder elcRootFolder)
        {
            Folder    folder  = null;
            ELCFolder folder2 = adFolderInfo.Folder;
            string    text    = itemStore.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString();
            string    text2   = (folder2.FolderType == ElcFolderType.ManagedCustomFolder) ? folder2.FolderName : folder2.FolderType.ToString();
            string    result;

            try
            {
                if (folder2.FolderType != ElcFolderType.ManagedCustomFolder)
                {
                    ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Need to provision a default folder '{0}' in mailbox '{1}'.", text2, text);
                    try
                    {
                        folder = ElcMailboxHelper.GetDefaultFolder(itemStore, folder2);
                    }
                    catch (ObjectNotFoundException innerException)
                    {
                        ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Default folder '{0}' does not exist in mailbox '{1}'.", text2, text);
                        throw new ELCDefaultFolderNotFoundException(text2, text, innerException);
                    }
                    ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Default folder '{0}' exists in mailbox '{1}' and will be provisioned.", text2, text);
                    result = '/' + ProvisionedFolderCreator.NormalizeFolderName(text2);
                }
                else
                {
                    ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Creating organizational folder '{0}' in mailbox '{1}'.", text2, text);
                    folder = Folder.Create(itemStore, elcRootFolder.Id, StoreObjectType.Folder, folder2.FolderName, CreateMode.OpenIfExists);
                    ProvisionedFolderCreator.SaveELCFolder(folder, true);
                    folder.Load();
                    result = string.Concat(new object[]
                    {
                        '/',
                        ProvisionedFolderCreator.NormalizeFolderName(elcRootFolder.DisplayName),
                        '/',
                        ProvisionedFolderCreator.NormalizeFolderName(text2)
                    });
                }
                ELCFolderFlags elcfolderFlags = ELCFolderFlags.None;
                ulong          num            = folder2.StorageQuota.IsUnlimited ? 0UL : folder2.StorageQuota.Value.ToKB();
                if (folder2.FolderType == ElcFolderType.ManagedCustomFolder)
                {
                    elcfolderFlags = ELCFolderFlags.Provisioned;
                    if (adFolderInfo.LinkedToTemplate)
                    {
                        elcfolderFlags |= ELCFolderFlags.Protected;
                    }
                    if (folder.ItemCount == 0 && !folder.HasSubfolders)
                    {
                        elcfolderFlags |= ELCFolderFlags.TrackFolderSize;
                    }
                    if (num > 0UL)
                    {
                        elcfolderFlags |= ELCFolderFlags.Quota;
                    }
                }
                if (folder2.MustDisplayCommentEnabled)
                {
                    elcfolderFlags |= ELCFolderFlags.MustDisplayComment;
                }
                ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.AdminFolderFlags, elcfolderFlags);
                ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.ELCPolicyIds, folder2.Guid.ToString());
                string localizedFolderComment = folder2.GetLocalizedFolderComment(itemStore.MailboxOwner.PreferredCultures);
                if (!string.IsNullOrEmpty(localizedFolderComment))
                {
                    ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.ELCFolderComment, localizedFolderComment);
                }
                else
                {
                    ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.ELCFolderComment, Globals.BlankComment);
                }
                if (folder2.FolderType == ElcFolderType.ManagedCustomFolder && num > 0UL)
                {
                    ElcMailboxHelper.SetPropAndTrace(folder, FolderSchema.FolderQuota, (int)num);
                }
                ProvisionedFolderCreator.SaveELCFolder(folder, true);
                if (folder2.FolderType == ElcFolderType.All)
                {
                    ProvisionedFolderCreator.CreateAllOthersConfigMsg(adFolderInfo.Folder, itemStore);
                }
                ProvisionedFolderCreator.Tracer.TraceDebug <string, string>(0L, "Successfully created/provisioned folder '{0}' in mailbox '{1}'.", text2, text);
            }
            finally
            {
                if (folder != null)
                {
                    folder.Dispose();
                    folder = null;
                }
            }
            return(result);
        }