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()); }
private TMailboxAssociation GetAssociationByIdProperty <TMailboxAssociation>(Func <VersionedId, TMailboxAssociation> bindFunction, string associationItemClass, ICollection <PropertyDefinition> propertiesToRetrieve, PropertyDefinition idProperty, params object[] idValues) where TMailboxAssociation : class, IMailboxAssociationBaseItem { this.CheckDisposed("GetAssociationByIdProperty"); if (idValues.Length == 0) { return(default(TMailboxAssociation)); } IPropertyBag[] array = this.SeekInAssociationFolder <object>(associationItemClass, idProperty, idValues, new PropertyDefinition[] { idProperty, StoreObjectSchema.ItemClass, ItemSchema.Id }).ToArray <IPropertyBag>(); string text = null; if (LocalAssociationStore.Tracer.IsTraceEnabled(TraceType.DebugTrace) || LocalAssociationStore.Tracer.IsTraceEnabled(TraceType.ErrorTrace) || array.Length > 1) { text = string.Join(", ", idValues); } if (array.Length == 0) { LocalAssociationStore.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "LocalAssociationStore::GetAssociationByIdProperty. Found no association item searching by property {0} with values {1}.", idProperty.Name, text); this.performanceTracker.IncrementFailedAssociationsSearch(); return(default(TMailboxAssociation)); } if (array.Length > 1) { this.performanceTracker.IncrementNonUniqueAssociationsFound(); this.LogWarning("LocalAssociationStore::GetAssociationByIdProperty", string.Format("Found more than 1 association item searching by property {0} with values {1}.", idProperty.Name, text)); this.LogWarning("LocalAssociationStore::GetAssociationByIdProperty", string.Format("Keeping association with ID: {0}.", array[0][ItemSchema.Id])); for (int i = 1; i < array.Length; i++) { VersionedId versionedId = array[i][ItemSchema.Id] as VersionedId; using (TMailboxAssociation tmailboxAssociation = bindFunction(versionedId)) { if (tmailboxAssociation != null) { this.LogWarning("LocalAssociationStore::GetAssociationByIdProperty", string.Format("Keeping association with ID: {0}, Removing association {1}", array[0][ItemSchema.Id], tmailboxAssociation.ToString())); this.DeleteAssociation(versionedId); } else { this.LogError("LocalAssociationStore::GetAssociationByIdProperty", string.Format("Couldn't bind to association with ID: {0}.", versionedId.ToString())); } } } } VersionedId versionedId2 = array[0][ItemSchema.Id] as VersionedId; LocalAssociationStore.Tracer.TraceDebug((long)this.GetHashCode(), "LocalAssociationStore::GetAssociationByIdProperty. Found association item searching by property {0} with values {1}. ItemId: {2}. Found value: {3}.", new object[] { idProperty.Name, text, versionedId2, array[0][idProperty] }); return(bindFunction(versionedId2)); }