Example #1
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     using (VersionedXmlDataProvider versionedXmlDataProvider = new VersionedXmlDataProvider(XsoStoreDataProviderBase.GetExchangePrincipalWithAdSessionSettingsForOrg(base.SessionSettings.CurrentOrganizationId, this.DataObject), (base.ExchangeRunspaceConfig == null) ? null : base.ExchangeRunspaceConfig.SecurityAccessToken, "Compare-TextMessagingVerificationCode"))
     {
         TextMessagingAccount textMessagingAccount = (TextMessagingAccount)versionedXmlDataProvider.Read<TextMessagingAccount>(this.DataObject.Identity);
         IList<PossibleRecipient> effectivePossibleRecipients = textMessagingAccount.TextMessagingSettings.MachineToPersonMessagingPolicies.EffectivePossibleRecipients;
         if (effectivePossibleRecipients.Count == 0)
         {
             base.WriteError(new NotificationPhoneNumberAbsentException(this.Identity.ToString()), ErrorCategory.InvalidData, this.Identity);
         }
         PossibleRecipient possibleRecipient = effectivePossibleRecipients[0];
         bool flag = false;
         if (string.IsNullOrEmpty(possibleRecipient.Passcode))
         {
             base.WriteError(new VerificationCodeNeverSentException(this.Identity.ToString()), ErrorCategory.InvalidData, this.Identity);
         }
         DateTime utcNow = DateTime.UtcNow;
         if (6 <= PossibleRecipient.CountTimesSince(possibleRecipient.PasscodeVerificationFailedTimeHistory, utcNow - TimeSpan.FromDays(1.0), true))
         {
             base.WriteError(new VerificationCodeTooManyFailedException(), ErrorCategory.InvalidData, this.Identity);
         }
         if (string.Equals(possibleRecipient.Passcode, this.VerificationCode, StringComparison.InvariantCultureIgnoreCase))
         {
             possibleRecipient.SetAcknowledged(true);
             ADUser dataObject = this.DataObject;
             SmsSqmDataPointHelper.AddNotificationTurningOnDataPoint(SmsSqmSession.Instance, dataObject.Id, dataObject.LegacyExchangeDN, textMessagingAccount);
         }
         else
         {
             possibleRecipient.PasscodeVerificationFailedTimeHistory.Add(utcNow);
             flag = true;
         }
         versionedXmlDataProvider.Save(textMessagingAccount);
         if (flag)
         {
             base.WriteError(new VerificationCodeUnmatchException(this.VerificationCode), ErrorCategory.InvalidData, this.Identity);
         }
         else if (!textMessagingAccount.EasEnabled)
         {
             TextMessagingHelper.SendSystemTextMessage(versionedXmlDataProvider.MailboxSession, textMessagingAccount.NotificationPhoneNumber, Strings.CalendarNotificationConfirmation.ToString(textMessagingAccount.NotificationPreferredCulture ?? TextMessagingHelper.GetSupportedUserCulture(this.DataObject)), true);
         }
     }
     TaskLogger.LogExit();
 }
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     using (VersionedXmlDataProvider versionedXmlDataProvider = new VersionedXmlDataProvider(XsoStoreDataProviderBase.GetExchangePrincipalWithAdSessionSettingsForOrg(base.SessionSettings.CurrentOrganizationId, this.DataObject), (base.ExchangeRunspaceConfig == null) ? null : base.ExchangeRunspaceConfig.SecurityAccessToken, "Send-TextMessagingVerificationCode"))
     {
         TextMessagingAccount      textMessagingAccount        = (TextMessagingAccount)versionedXmlDataProvider.Read <TextMessagingAccount>(this.DataObject.Identity);
         IList <PossibleRecipient> effectivePossibleRecipients = textMessagingAccount.TextMessagingSettings.MachineToPersonMessagingPolicies.EffectivePossibleRecipients;
         if (effectivePossibleRecipients.Count == 0)
         {
             base.WriteError(new NotificationPhoneNumberAbsentException(this.Identity.ToString()), ErrorCategory.InvalidData, this.Identity);
         }
         PossibleRecipient possibleRecipient = effectivePossibleRecipients[0];
         DateTime          utcNow            = DateTime.UtcNow;
         if (3 <= PossibleRecipient.CountTimesSince(possibleRecipient.PasscodeSentTimeHistory, utcNow - TimeSpan.FromMinutes(30.0), false))
         {
             this.WriteWarning(new VerificationCodeSentTooManyTimesException(textMessagingAccount.NotificationPhoneNumber.ToString()).LocalizedString);
             TaskLogger.LogExit();
             return;
         }
         if (PossibleRecipient.CountTimesSince(possibleRecipient.PasscodeSentTimeHistory, utcNow - TimeSpan.FromDays(1.0), true) == 0)
         {
             if (DateTime.UtcNow > SendTextMessagingVerificationCode.timeCreatingRandom + TimeSpan.FromSeconds((double)SendTextMessagingVerificationCode.timeSpan))
             {
                 SendTextMessagingVerificationCode.random             = new Random();
                 SendTextMessagingVerificationCode.timeCreatingRandom = DateTime.UtcNow;
                 SendTextMessagingVerificationCode.timeSpan           = new Random().Next(60);
             }
             possibleRecipient.SetPasscode(SendTextMessagingVerificationCode.random.Next(999999).ToString("000000"));
         }
         possibleRecipient.PasscodeSentTimeHistory.Add(utcNow);
         try
         {
             TextMessagingHelper.SendSystemTextMessage(versionedXmlDataProvider.MailboxSession, textMessagingAccount.NotificationPhoneNumber, Strings.PasscodeInformation(possibleRecipient.Passcode).ToString(textMessagingAccount.NotificationPreferredCulture ?? TextMessagingHelper.GetSupportedUserCulture(this.DataObject)), false);
         }
         catch (SendAsDeniedException innerException)
         {
             base.WriteError(new TextMessageInsufficientPermissionException(innerException), ErrorCategory.InvalidOperation, this.Identity);
         }
         versionedXmlDataProvider.Save(textMessagingAccount);
     }
     TaskLogger.LogExit();
 }
        public static void SaveTextMessagingAccount(TextMessagingAccount account, VersionedXmlDataProvider storeDataProvider, ADRecipient adRecipient, IRecipientSession adSession)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }
            if (storeDataProvider == null)
            {
                throw new ArgumentNullException("storeDataProvider");
            }
            if (adRecipient == null)
            {
                throw new ArgumentNullException("adRecipient");
            }
            if (adSession == null)
            {
                throw new ArgumentNullException("adSession");
            }
            bool notificationPhoneNumberVerified = account.NotificationPhoneNumberVerified;
            bool dupIdentitiesExist = false;

            account.TextMessagingSettings.DeliveryPoints.Sort(delegate(DeliveryPoint x, DeliveryPoint y)
            {
                if (x.Identity == y.Identity)
                {
                    dupIdentitiesExist = true;
                }
                return(x.Identity.CompareTo(y.Identity));
            });
            if (dupIdentitiesExist)
            {
                int num = 0;
                while (account.TextMessagingSettings.DeliveryPoints.Count > num)
                {
                    account.TextMessagingSettings.DeliveryPoints[num].Identity = (byte)num;
                    num++;
                }
            }
            TextMessagingHelper.UpdateTextMessagingState(adRecipient.TextMessagingState, account.TextMessagingSettings.DeliveryPoints);
            storeDataProvider.Save(account);
            adSession.Save(adRecipient);
        }