예제 #1
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Inputs
            var    phonenumber = PhoneNumber.Get(context);
            var    countrycode = CountryCode.Get(context);
            var    valid       = false;
            string e164        = null;
            var    util        = PhoneNumberUtil.GetInstance();

            try
            {
                var number = util.Parse(phonenumber, countrycode == null ? null : $"{countrycode:G}");
                valid = util.IsValidNumber(number);
                e164  = util.Format(number, PhoneNumberFormat.E164);
            }
            catch (NumberParseException)
            {
                valid = false;
            }
            // Outputs
            return((ctx) => {
                IsValidNumber.Set(ctx, valid);
                FormattedNumber.Set(ctx, e164);
            });
        }