예제 #1
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);
        }