Exemplo n.º 1
0
        private void SetPhoneNumber(ADUser user)
        {
            UMMailboxPolicy ummailboxPolicy = this.ReadPolicyObject(user);
            UMDialPlan      dialPlan        = ummailboxPolicy.GetDialPlan();

            if (dialPlan.URIType != UMUriType.E164 || dialPlan.SubscriberType != UMSubscriberType.Consumer)
            {
                base.WriteError(new ArgumentException(Strings.PhoneNumberAllowedOnlyOnE164ConsumerDialplan, "PhoneNumber"), (ErrorCategory)1000, null);
            }
            if (string.IsNullOrEmpty(dialPlan.CountryOrRegionCode))
            {
                base.WriteError(new ArgumentException(Strings.PhoneNumberAllowedOnlyWithDialplanWithCountryCode, "PhoneNumber"), (ErrorCategory)1000, null);
            }
            if (this.PhoneNumber == string.Empty)
            {
                Utils.UMPopulate(user, null, null, ummailboxPolicy, dialPlan);
                return;
            }
            PhoneNumber phoneNumber;

            if (!Microsoft.Exchange.UM.UMCommon.PhoneNumber.TryParse(this.PhoneNumber, out phoneNumber) || phoneNumber.UriType != UMUriType.TelExtn)
            {
                base.WriteError(new ArgumentException(Strings.PhoneNumberNotANumber(dialPlan.NumberOfDigitsInExtension), this.PhoneNumber), (ErrorCategory)1000, null);
            }
            string                       sipResourceIdentifier       = "+" + dialPlan.CountryOrRegionCode + phoneNumber.Number;
            IRecipientSession            tenantLocalRecipientSession = RecipientTaskHelper.GetTenantLocalRecipientSession(user.OrganizationId, base.ExecutingUserOrganizationId, base.RootOrgContainerId);
            LocalizedException           ex = null;
            TelephoneNumberProcessStatus telephoneNumberProcessStatus;

            Utils.ValidateExtensionsAndSipResourceIdentifier(tenantLocalRecipientSession, this.ConfigurationSession, CommonConstants.DataCenterADPresent, user, dialPlan, new string[]
            {
                phoneNumber.Number
            }, new string[]
            {
                this.PhoneNumber
            }, sipResourceIdentifier, out ex, out telephoneNumberProcessStatus);
            if (ex != null)
            {
                base.WriteError(ex, (ErrorCategory)1000, null);
            }
            if (telephoneNumberProcessStatus != TelephoneNumberProcessStatus.PhoneNumberAlreadyRegistered)
            {
                Utils.UMPopulate(user, sipResourceIdentifier, new MultiValuedProperty <string>(phoneNumber.Number), ummailboxPolicy, dialPlan);
            }
        }
Exemplo n.º 2
0
        protected override void DoValidate()
        {
            LocalizedException ex = null;

            if (this.ShouldInitUMMailbox && UMSubscriber.IsValidSubscriber(this.DataObject))
            {
                ex = new UserAlreadyUmEnabledException(this.DataObject.Id.Name);
            }
            else if (!this.IsUserAllowedForUnifiedMessaging(this.DataObject))
            {
                ex = new UserNotAllowedForUMEnabledException();
            }
            else
            {
                MailboxPolicyIdParameter ummailboxPolicy = this.UMMailboxPolicy;
                this.mailboxPolicy = (UMMailboxPolicy)base.GetDataObject <UMMailboxPolicy>(ummailboxPolicy, this.ConfigurationSession, null, new LocalizedString?(Strings.UMMailboxPolicyIdNotFound(ummailboxPolicy.ToString())), new LocalizedString?(Strings.MultipleUMMailboxPolicyWithSameId(ummailboxPolicy.ToString())));
                this.dialPlan      = this.mailboxPolicy.GetDialPlan();
                if (this.DialPlan.SubscriberType != UMSubscriberType.Consumer || this.DialPlan.URIType != UMUriType.E164 || !string.IsNullOrEmpty(this.SIPResourceIdentifier) || (this.Extensions != null && this.Extensions.Count != 0))
                {
                    if (this.Extensions == null || this.Extensions.Count == 0)
                    {
                        string      text = null;
                        PhoneNumber phoneNumber;
                        if (PhoneNumber.TryParse(this.DataObject.Phone, out phoneNumber))
                        {
                            text = this.DialPlan.GetDefaultExtension(phoneNumber.Number);
                        }
                        if (!string.IsNullOrEmpty(Utils.TrimSpaces(text)))
                        {
                            this.Extensions = new MultiValuedProperty <string>(text);
                        }
                    }
                    if (this.DialPlan.URIType == UMUriType.SipName)
                    {
                        ProxyAddress proxyAddress = this.DataObject.EmailAddresses.Find((ProxyAddress p) => string.Equals(p.PrefixString, "sip", StringComparison.OrdinalIgnoreCase));
                        string       text2        = (proxyAddress != null) ? proxyAddress.AddressString : null;
                        if (string.IsNullOrEmpty(this.SIPResourceIdentifier))
                        {
                            this.SIPResourceIdentifier = ((text2 != null) ? text2 : null);
                        }
                        else if (text2 != null && !string.Equals(this.SIPResourceIdentifier, text2, StringComparison.OrdinalIgnoreCase))
                        {
                            ex = new SIPResouceIdConflictWithExistingValue(this.SIPResourceIdentifier, text2);
                            base.WriteError(ex, ErrorCategory.InvalidArgument, null);
                        }
                    }
                    IRecipientSession            tenantLocalRecipientSession = RecipientTaskHelper.GetTenantLocalRecipientSession(this.DataObject.OrganizationId, base.ExecutingUserOrganizationId, base.RootOrgContainerId);
                    LocalizedException           ex2 = null;
                    TelephoneNumberProcessStatus telephoneNumberProcessStatus;
                    Utils.ValidateExtensionsAndSipResourceIdentifier(tenantLocalRecipientSession, this.ConfigurationSession, CommonConstants.DataCenterADPresent, this.DataObject, this.DialPlan, (this.Extensions != null) ? this.Extensions.ToArray() : null, null, this.SIPResourceIdentifier, out ex2, out telephoneNumberProcessStatus);
                    if (ex2 != null)
                    {
                        this.DataObject.EmailAddresses.Clear();
                        ex = ex2;
                    }
                }
            }
            if (ex == null || this.ValidateOnly)
            {
                this.DataObject.UMEnabledFlags |= UMEnabledFlags.UMEnabled;
                if (base.Fields.IsModified("ASREnabled"))
                {
                    bool flag = (bool)base.Fields["ASREnabled"];
                    if (flag)
                    {
                        this.DataObject.UMEnabledFlags |= UMEnabledFlags.ASREnabled;
                    }
                    else
                    {
                        this.DataObject.UMEnabledFlags = (this.DataObject.UMEnabledFlags & ~UMEnabledFlags.ASREnabled);
                    }
                }
                this.DataObject.PopulateDtmfMap(true);
                if (!this.ValidateOnly)
                {
                    Utils.UMPopulate(this.DataObject, this.SIPResourceIdentifier, this.Extensions, this.mailboxPolicy, this.DialPlan);
                    if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled)
                    {
                        RecipientTaskHelper.ValidateSmtpAddress(this.ConfigurationSession, this.DataObject.EmailAddresses, this.DataObject, new Task.ErrorLoggerDelegate(base.WriteError), base.ProvisioningCache);
                    }
                    if (this.ShouldSavePin)
                    {
                        base.PinInfo            = base.ValidateOrGeneratePIN(this.Pin, this.mailboxPolicy.Guid);
                        base.PinInfo.PinExpired = this.PinExpired;
                        base.PinInfo.LockedOut  = false;
                    }
                }
                else if (this.Extensions != null)
                {
                    this.DataObject.AddEUMProxyAddress(this.Extensions, this.DialPlan);
                }
            }
            if (ex == null)
            {
                if (this.ValidateOnly)
                {
                    this.WriteResult();
                }
                return;
            }
            if (this.ValidateOnly)
            {
                this.WriteResult();
                base.WriteError(ex, ErrorCategory.InvalidArgument, null, false, null);
                return;
            }
            base.WriteError(ex, ErrorCategory.InvalidArgument, null);
        }