internal static void NotificationPhoneNumberSetter(object value, IPropertyBag propertyBag)
        {
            TextMessagingSettingsVersion1Point0 textMessagingSettingsVersion1Point = (TextMessagingSettingsVersion1Point0)propertyBag[TextMessagingAccountSchema.TextMessagingSettings];

            if (value == null)
            {
                PossibleRecipient.MarkEffective(textMessagingSettingsVersion1Point.MachineToPersonMessagingPolicies.PossibleRecipients, false);
                return;
            }
            bool flag = false;
            PossibleRecipient writablePossibleRecipient = TextMessagingAccount.GetWritablePossibleRecipient(textMessagingSettingsVersion1Point, out flag);

            if (flag)
            {
                writablePossibleRecipient.PhoneNumber = (E164Number)value;
            }
            else
            {
                PossibleRecipient mathed = PossibleRecipient.GetMathed(textMessagingSettingsVersion1Point.MachineToPersonMessagingPolicies.PossibleRecipients, (E164Number)value, false);
                PossibleRecipient.MarkEffective(textMessagingSettingsVersion1Point.MachineToPersonMessagingPolicies.PossibleRecipients, false);
                if (mathed == null)
                {
                    textMessagingSettingsVersion1Point.MachineToPersonMessagingPolicies.PossibleRecipients.Add(new PossibleRecipient(true, DateTime.UtcNow, writablePossibleRecipient.Region, writablePossibleRecipient.Carrier, (E164Number)value, false, null, null, null));
                }
                else
                {
                    mathed.Region  = writablePossibleRecipient.Region;
                    mathed.Carrier = writablePossibleRecipient.Carrier;
                    mathed.MarkEffective(true);
                }
            }
            PossibleRecipient.PurgeNonEffectiveBefore(textMessagingSettingsVersion1Point.MachineToPersonMessagingPolicies.PossibleRecipients, DateTime.UtcNow - TimeSpan.FromDays(7.0), 10);
        }
        private void Write4_PossibleRecipient(string n, string ns, PossibleRecipient o, bool isNullable, bool needType)
        {
            if (o == null)
            {
                if (isNullable)
                {
                    base.WriteNullTagLiteral(n, ns);
                }
                return;
            }
            if (!needType)
            {
                Type type = o.GetType();
                if (!(type == typeof(PossibleRecipient)))
                {
                    throw base.CreateUnknownTypeException(o);
                }
            }
            base.WriteStartElement(n, ns, o, false, null);
            if (needType)
            {
                base.WriteXsiType("PossibleRecipient", "");
            }
            base.WriteElementStringRaw("Effective", "", XmlConvert.ToString(o.Effective));
            base.WriteElementStringRaw("EffectiveLastModificationTime", "", XmlSerializationWriter.FromDateTime(o.EffectiveLastModificationTime));
            base.WriteElementString("Region", "", o.Region);
            base.WriteElementString("Carrier", "", o.Carrier);
            base.WriteSerializable(o.PhoneNumber, "PhoneNumber", "", false, true);
            base.WriteElementStringRaw("PhoneNumberSetTime", "", XmlSerializationWriter.FromDateTime(o.PhoneNumberSetTime));
            base.WriteElementStringRaw("Acknowledged", "", XmlConvert.ToString(o.Acknowledged));
            base.WriteElementString("Passcode", "", o.Passcode);
            List <DateTime> passcodeSentTimeHistory = o.PasscodeSentTimeHistory;

            if (passcodeSentTimeHistory != null)
            {
                base.WriteStartElement("PasscodeSentTimeHistory", "", null, false);
                for (int i = 0; i < ((ICollection)passcodeSentTimeHistory).Count; i++)
                {
                    base.WriteElementStringRaw("SentTime", "", XmlSerializationWriter.FromDateTime(passcodeSentTimeHistory[i]));
                }
                base.WriteEndElement();
            }
            List <DateTime> passcodeVerificationFailedTimeHistory = o.PasscodeVerificationFailedTimeHistory;

            if (passcodeVerificationFailedTimeHistory != null)
            {
                base.WriteStartElement("PasscodeVerificationFailedTimeHistory", "", null, false);
                for (int j = 0; j < ((ICollection)passcodeVerificationFailedTimeHistory).Count; j++)
                {
                    base.WriteElementStringRaw("FailedTime", "", XmlSerializationWriter.FromDateTime(passcodeVerificationFailedTimeHistory[j]));
                }
                base.WriteEndElement();
            }
            base.WriteEndElement(o);
        }
Example #3
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();
 }
Example #5
0
        private PossibleRecipient Read4_PossibleRecipient(bool isNullable, bool checkType)
        {
            XmlQualifiedName xmlQualifiedName = checkType ? base.GetXsiType() : null;
            bool             flag             = false;

            if (isNullable)
            {
                flag = base.ReadNull();
            }
            if (checkType && !(xmlQualifiedName == null) && (xmlQualifiedName.Name != this.id16_PossibleRecipient || xmlQualifiedName.Namespace != this.id2_Item))
            {
                throw base.CreateUnknownTypeException(xmlQualifiedName);
            }
            if (flag)
            {
                return(null);
            }
            PossibleRecipient possibleRecipient = new PossibleRecipient();

            if (possibleRecipient.PasscodeSentTimeHistory == null)
            {
                possibleRecipient.PasscodeSentTimeHistory = new List <DateTime>();
            }
            List <DateTime> passcodeSentTimeHistory = possibleRecipient.PasscodeSentTimeHistory;

            if (possibleRecipient.PasscodeVerificationFailedTimeHistory == null)
            {
                possibleRecipient.PasscodeVerificationFailedTimeHistory = new List <DateTime>();
            }
            List <DateTime> passcodeVerificationFailedTimeHistory = possibleRecipient.PasscodeVerificationFailedTimeHistory;

            bool[] array = new bool[10];
            while (base.Reader.MoveToNextAttribute())
            {
                if (!base.IsXmlnsAttribute(base.Reader.Name))
                {
                    base.UnknownNode(possibleRecipient);
                }
            }
            base.Reader.MoveToElement();
            if (base.Reader.IsEmptyElement)
            {
                base.Reader.Skip();
                return(possibleRecipient);
            }
            base.Reader.ReadStartElement();
            base.Reader.MoveToContent();
            int num         = 0;
            int readerCount = base.ReaderCount;

            while (base.Reader.NodeType != XmlNodeType.EndElement && base.Reader.NodeType != XmlNodeType.None)
            {
                if (base.Reader.NodeType == XmlNodeType.Element)
                {
                    if (!array[0] && base.Reader.LocalName == this.id17_Effective && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        possibleRecipient.Effective = XmlConvert.ToBoolean(base.Reader.ReadElementString());
                        array[0] = true;
                    }
                    else if (!array[1] && base.Reader.LocalName == this.id18_EffectiveLastModificationTime && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        possibleRecipient.EffectiveLastModificationTime = XmlSerializationReader.ToDateTime(base.Reader.ReadElementString());
                        array[1] = true;
                    }
                    else if (!array[2] && base.Reader.LocalName == this.id19_Region && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        possibleRecipient.Region = base.Reader.ReadElementString();
                        array[2] = true;
                    }
                    else if (!array[3] && base.Reader.LocalName == this.id20_Carrier && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        possibleRecipient.Carrier = base.Reader.ReadElementString();
                        array[3] = true;
                    }
                    else if (!array[4] && base.Reader.LocalName == this.id9_PhoneNumber && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        possibleRecipient.PhoneNumber = (E164Number)base.ReadSerializable(new E164Number());
                        array[4] = true;
                    }
                    else if (!array[5] && base.Reader.LocalName == this.id21_PhoneNumberSetTime && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        possibleRecipient.PhoneNumberSetTime = XmlSerializationReader.ToDateTime(base.Reader.ReadElementString());
                        array[5] = true;
                    }
                    else if (!array[6] && base.Reader.LocalName == this.id22_Acknowledged && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        possibleRecipient.Acknowledged = XmlConvert.ToBoolean(base.Reader.ReadElementString());
                        array[6] = true;
                    }
                    else if (!array[7] && base.Reader.LocalName == this.id23_Passcode && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        possibleRecipient.Passcode = base.Reader.ReadElementString();
                        array[7] = true;
                    }
                    else if (base.Reader.LocalName == this.id24_PasscodeSentTimeHistory && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        if (!base.ReadNull())
                        {
                            if (possibleRecipient.PasscodeSentTimeHistory == null)
                            {
                                possibleRecipient.PasscodeSentTimeHistory = new List <DateTime>();
                            }
                            List <DateTime> passcodeSentTimeHistory2 = possibleRecipient.PasscodeSentTimeHistory;
                            if (base.Reader.IsEmptyElement)
                            {
                                base.Reader.Skip();
                            }
                            else
                            {
                                base.Reader.ReadStartElement();
                                base.Reader.MoveToContent();
                                int num2         = 0;
                                int readerCount2 = base.ReaderCount;
                                while (base.Reader.NodeType != XmlNodeType.EndElement && base.Reader.NodeType != XmlNodeType.None)
                                {
                                    if (base.Reader.NodeType == XmlNodeType.Element)
                                    {
                                        if (base.Reader.LocalName == this.id25_SentTime && base.Reader.NamespaceURI == this.id2_Item)
                                        {
                                            passcodeSentTimeHistory2.Add(XmlSerializationReader.ToDateTime(base.Reader.ReadElementString()));
                                        }
                                        else
                                        {
                                            base.UnknownNode(null, ":SentTime");
                                        }
                                    }
                                    else
                                    {
                                        base.UnknownNode(null, ":SentTime");
                                    }
                                    base.Reader.MoveToContent();
                                    base.CheckReaderCount(ref num2, ref readerCount2);
                                }
                                base.ReadEndElement();
                            }
                        }
                    }
                    else if (base.Reader.LocalName == this.id26_Item && base.Reader.NamespaceURI == this.id2_Item)
                    {
                        if (!base.ReadNull())
                        {
                            if (possibleRecipient.PasscodeVerificationFailedTimeHistory == null)
                            {
                                possibleRecipient.PasscodeVerificationFailedTimeHistory = new List <DateTime>();
                            }
                            List <DateTime> passcodeVerificationFailedTimeHistory2 = possibleRecipient.PasscodeVerificationFailedTimeHistory;
                            if (base.Reader.IsEmptyElement)
                            {
                                base.Reader.Skip();
                            }
                            else
                            {
                                base.Reader.ReadStartElement();
                                base.Reader.MoveToContent();
                                int num3         = 0;
                                int readerCount3 = base.ReaderCount;
                                while (base.Reader.NodeType != XmlNodeType.EndElement && base.Reader.NodeType != XmlNodeType.None)
                                {
                                    if (base.Reader.NodeType == XmlNodeType.Element)
                                    {
                                        if (base.Reader.LocalName == this.id27_FailedTime && base.Reader.NamespaceURI == this.id2_Item)
                                        {
                                            passcodeVerificationFailedTimeHistory2.Add(XmlSerializationReader.ToDateTime(base.Reader.ReadElementString()));
                                        }
                                        else
                                        {
                                            base.UnknownNode(null, ":FailedTime");
                                        }
                                    }
                                    else
                                    {
                                        base.UnknownNode(null, ":FailedTime");
                                    }
                                    base.Reader.MoveToContent();
                                    base.CheckReaderCount(ref num3, ref readerCount3);
                                }
                                base.ReadEndElement();
                            }
                        }
                    }
                    else
                    {
                        base.UnknownNode(possibleRecipient, ":Effective, :EffectiveLastModificationTime, :Region, :Carrier, :PhoneNumber, :PhoneNumberSetTime, :Acknowledged, :Passcode, :PasscodeSentTimeHistory, :PasscodeVerificationFailedTimeHistory");
                    }
                }
                else
                {
                    base.UnknownNode(possibleRecipient, ":Effective, :EffectiveLastModificationTime, :Region, :Carrier, :PhoneNumber, :PhoneNumberSetTime, :Acknowledged, :Passcode, :PasscodeSentTimeHistory, :PasscodeVerificationFailedTimeHistory");
                }
                base.Reader.MoveToContent();
                base.CheckReaderCount(ref num, ref readerCount);
            }
            base.ReadEndElement();
            return(possibleRecipient);
        }