コード例 #1
0
        internal static string GenerateUniqueAliasForSiteMailbox(IRecipientSession recipientSession, OrganizationId organizationId, string preferredAlias, string prefix, bool isMicrosoftHostedOnlyDatacenter, Task.TaskVerboseLoggingDelegate logHandler, Task.ErrorLoggerDelegate writeError)
        {
            string text = WindowsLiveIDLocalPartConstraint.RemoveInvalidPartOfWindowsLiveID(preferredAlias);

            if (!string.IsNullOrEmpty(text) && text.Length > 3)
            {
                logHandler(Strings.VerboseGenerateAliasBySiteDisplayName(preferredAlias));
                text = RecipientTaskHelper.GenerateUniqueAlias(recipientSession, organizationId, (!string.IsNullOrEmpty(prefix)) ? (prefix + text) : text, logHandler, 63);
            }
            else
            {
                int num = 1000;
                if (string.IsNullOrEmpty(prefix))
                {
                    prefix = (isMicrosoftHostedOnlyDatacenter ? "SMO-" : "SM-");
                }
                do
                {
                    text = TeamMailboxHelper.GenerateRandomString();
                    text = prefix + text;
                    logHandler(Strings.VerboseGenerateAliasByRandomString(preferredAlias, text));
                    if (RecipientTaskHelper.IsAliasUnique(recipientSession, organizationId, null, text, logHandler, writeError, ExchangeErrorCategory.Client))
                    {
                        break;
                    }
                    text = string.Empty;
                }while (num-- > 0);
            }
            if (string.IsNullOrEmpty(text))
            {
                writeError(new ErrorCannotGenerateSiteMailboxAliasException(), ExchangeErrorCategory.Client, null);
            }
            return(text);
        }