Beispiel #1
0
        internal static List <AdFolderData> GetUserElcFolders(MailboxSession session, ADUser aduser, List <ELCFolder> allAdFolders, bool getFoldersOnly, bool getOrgFoldersOnly)
        {
            if (allAdFolders == null || allAdFolders.Count == 0 || aduser == null)
            {
                return(null);
            }
            string                arg             = session.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString();
            ADSessionSettings     sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(session.MailboxOwner.MailboxInfo.OrganizationId);
            IConfigurationSession tenantOrTopologyConfigurationSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.FullyConsistent, sessionSettings, 258, "GetUserElcFolders", "f:\\15.00.1497\\sources\\dev\\infoworker\\src\\common\\ELC\\AdFolderReader.cs");
            ADObjectId            managedFolderMailboxPolicy           = aduser.ManagedFolderMailboxPolicy;

            if (managedFolderMailboxPolicy == null)
            {
                AdReader.Tracer.TraceDebug <string>(0L, "Mailbox '{0}' does not have an ELC Mailbox policy.", arg);
                return(null);
            }
            ManagedFolderMailboxPolicy managedFolderMailboxPolicy2 = tenantOrTopologyConfigurationSession.Read <ManagedFolderMailboxPolicy>(managedFolderMailboxPolicy);

            if (managedFolderMailboxPolicy2 == null)
            {
                AdReader.Tracer.TraceDebug <string, ADObjectId>(0L, "Mailbox '{0}' no matching ELC Mailbox policy for Template '{1}'.", arg, managedFolderMailboxPolicy);
                return(null);
            }
            MultiValuedProperty <ADObjectId> managedFolderLinks = managedFolderMailboxPolicy2.ManagedFolderLinks;
            List <AdFolderData> list = new List <AdFolderData>();

            using (MultiValuedProperty <ADObjectId> .Enumerator enumerator = managedFolderLinks.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ADObjectId elcFolderId = enumerator.Current;
                    ELCFolder  elcfolder   = allAdFolders.Find((ELCFolder adFolder) => elcFolderId.ObjectGuid == adFolder.Id.ObjectGuid);
                    if (elcfolder == null)
                    {
                        throw new ELCNoMatchingOrgFoldersException(elcFolderId.DistinguishedName);
                    }
                    if (!getOrgFoldersOnly || elcfolder.FolderType == ElcFolderType.ManagedCustomFolder)
                    {
                        AdFolderData adFolderData = new AdFolderData();
                        adFolderData.LinkedToTemplate = true;
                        adFolderData.Synced           = false;
                        adFolderData.Folder           = elcfolder;
                        if (!getFoldersOnly)
                        {
                            adFolderData.FolderSettings = AdFolderReader.FetchFolderContentSettings(elcfolder);
                        }
                        list.Add(adFolderData);
                    }
                }
            }
            return(list);
        }
Beispiel #2
0
        internal VersionedId[] CreateOrganizationalFolders(string[] folderNames)
        {
            OptInFolders.< > c__DisplayClass2 CS$ < > 8__locals1 = new OptInFolders.< > c__DisplayClass2();
            CS$ < > 8__locals1.folderNames = folderNames;
            if (CS$ < > 8__locals1.folderNames == null)
            {
                throw new ArgumentNullException();
            }
            if (CS$ < > 8__locals1.folderNames.Length == 0)
            {
                throw new ArgumentException("The number of input folders cannot be zero.");
            }
            if (CS$ < > 8__locals1.folderNames.Length > 1000)
            {
                throw new ArgumentException("The number of input folders exceeded allowable limit.");
            }
            List <VersionedId> list = new List <VersionedId>();
            int folderIndex;

            for (folderIndex = 0; folderIndex < CS$ < > 8__locals1.folderNames.GetLength(0); folderIndex++)
            {
                int length = Array.FindAll <string>(CS$ < > 8__locals1.folderNames, (string matchedFolderName) => string.Compare(CS$ < > 8__locals1.folderNames[folderIndex], matchedFolderName, StringComparison.OrdinalIgnoreCase) == 0).GetLength(0);
                if (length > 1)
                {
                    OptInFolders.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Input folder list contains duplicate entry of '{0}'.", CS$ < > 8__locals1.folderNames[folderIndex]);
                    throw new ELCDuplicateFolderNamesArgumentException(CS$ < > 8__locals1.folderNames[folderIndex]);
                }
            }
            this.ConfirmCanActAsOwner();
            OptInFolders.Tracer.TraceDebug <string>((long)this.GetHashCode(), "WindowsPrincipal validation for mailbox '{0}' successful.", this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString());
            using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(this.mailboxToAccess, CultureInfo.InvariantCulture, "Client=ELC;Action=Create Managed Folders"))
            {
                if (this.budget != null)
                {
                    mailboxSession.AccountingObject = this.budget;
                }
                Folder folder = null;
                try
                {
                    List <AdFolderData> adFoldersFromFolderNames = this.GetAdFoldersFromFolderNames(CS$ < > 8__locals1.folderNames);
                    MailboxFolderData   mailboxFolderData        = null;
                    OptInFolders.Tracer.TraceDebug <int, string>((long)this.GetHashCode(), "Need to create '{0}' Managed Custom Folders for mailbox '{1}'.", adFoldersFromFolderNames.Count, this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString());
                    List <MailboxFolderData> list2;
                    ProvisionedFolderReader.GetProvisionedFoldersFromMailbox(mailboxSession, true, out mailboxFolderData, out list2);
                    if (list2 != null && list2.Count != 0)
                    {
                        using (List <AdFolderData> .Enumerator enumerator = adFoldersFromFolderNames.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                AdFolderData folderToCreate = enumerator.Current;
                                int          num            = list2.FindIndex((MailboxFolderData mbxFolder) => mbxFolder.ElcFolderGuid == folderToCreate.Folder.Guid);
                                if (num >= 0)
                                {
                                    OptInFolders.Tracer.TraceDebug <string, SmtpAddress>((long)this.GetHashCode(), "Folder '{0}' exists in mailbox '{1}'.", folderToCreate.Folder.FolderName, this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress);
                                    throw new ELCOrgFolderExistsException(folderToCreate.Folder.FolderName);
                                }
                            }
                        }
                    }
                    VersionedId versionedId = (mailboxFolderData == null) ? null : mailboxFolderData.Id;
                    if (versionedId == null)
                    {
                        string elcRootUrl = AdFolderReader.GetElcRootUrl(this.budget);
                        folder = ProvisionedFolderCreator.CreateELCRootFolder(mailboxSession, elcRootUrl);
                        if (folder == null)
                        {
                            OptInFolders.Tracer.TraceError <SmtpAddress>((long)this.GetHashCode(), "{0}: Unable to create the ELC root folder in the mailbox.", this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress);
                            throw new ELCRootFailureException(Strings.descFailedToCreateELCRoot(mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString()), null);
                        }
                        versionedId = folder.Id;
                    }
                    if (versionedId == null)
                    {
                        OptInFolders.Tracer.TraceDebug <SmtpAddress>((long)this.GetHashCode(), "Unable to create the Managed Folders root folder in mailbox '{0}'.", this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress);
                        throw new ELCRootFailureException(Strings.descFailedToCreateELCRoot(this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString()), null);
                    }
                    try
                    {
                        if (folder == null)
                        {
                            folder = Folder.Bind(mailboxSession, versionedId);
                        }
                    }
                    catch (ObjectNotFoundException innerException)
                    {
                        OptInFolders.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Failed to bind to the Managed Folders root folder in mailbox '{0}'.", this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString());
                        throw new ELCRootFailureException(Strings.descCannotBindToElcRootFolder(versionedId.ToString(), this.mailboxToAccess.MailboxInfo.PrimarySmtpAddress.ToString()), innerException);
                    }
                    foreach (AdFolderData adFolderInfo in adFoldersFromFolderNames)
                    {
                        ProvisionedFolderCreator.CreateOneELCFolderInMailbox(adFolderInfo, mailboxSession, folder);
                    }
                    list = this.GetIdsFromFolderNames(mailboxSession, CS$ < > 8__locals1.folderNames);
                }
                finally
                {
                    if (folder != null)
                    {
                        folder.Dispose();
                        folder = null;
                    }
                }
            }
            return(list.ToArray());
        }
Beispiel #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);
        }