示例#1
0
        public static bool TryGetValueFromUrl(string url, ParseParameter parameter, out string value)
        {
            var parameterName = parameter.ToString();
            var regex         = new Regex($"[&?]{parameterName}=[a-zA-Z0-9._+-]+");

            value = regex.Match(url)?.Value?.Replace($"{parameterName}=", string.Empty).Replace("&", string.Empty).Replace("?", string.Empty);

            switch (parameter)
            {
            case ParseParameter.error_code:
            case ParseParameter.error_description:
                if (value != null)
                {
                    value = value.Replace("+", " ");
                }
                break;

            default:
                Debug.Log($"Trying to find {parameterName} in URL:{url}");
                break;
            }

            return(!string.IsNullOrEmpty(value));
        }
示例#2
0
 private void ParseParameterArgument( 
     string arg, 
     out List<KeyValuePair<object, Type>> paramValues,  
     out ParameterModifier paramModifier, 
     out string paramModifierAtt)
 {
     const string INDEX_ALL = "IndexAll";
     const string INDEX_FROM = "IndexFrom";
     const string INDEX_TO = "IndexTo";
     const string MODIFIER = "Modifier";
     const string MODIFIER_ATT = "ModifierAtt";
     var regex = new ParseParameter();
     var match = regex.Match(arg);
     if (!match.Success)
         throw new Exception("Неправильный синтаксис параметра");
     paramValues = new List<KeyValuePair<object,Type>>();
     if (match.Groups[INDEX_ALL].Success)
     {
         for (int i = 0; i < Parameters.Length; i++)
             paramValues.Add(GetTypedParamValueAndType(i));
     }
     else
     {
         var paramIndexFrom = Convert.ToInt32(match.Groups[INDEX_FROM].Value);
         var paramIndexTo = paramIndexFrom;
         if (match.Groups[INDEX_TO].Success)
         {
             var paramIndexToValue = match.Groups[INDEX_TO].Value;
             paramIndexTo =
                 string.CompareOrdinal(paramIndexToValue, "*") == 0
                 ? Parameters.Length - 1
                 : Convert.ToInt32(paramIndexToValue);
         }
         if (paramIndexFrom > paramIndexTo || paramIndexTo >= Parameters.Length)
             throw new Exception("Некорректный диапазон индексов параметров");
         for (int i = paramIndexFrom; i <= paramIndexTo; i++)
             paramValues.Add(GetTypedParamValueAndType(i));
     }
     var modifierGroup = match.Groups[MODIFIER];
     if (modifierGroup.Success)
     {
         paramModifier = (ParameterModifier)Enum.Parse(typeof(ParameterModifier), modifierGroup.Value);
         var modifierAttGroup = match.Groups[MODIFIER_ATT];
         if (modifierAttGroup.Success)
             paramModifierAtt = modifierAttGroup.Value;
         else
             paramModifierAtt = null;
     }
     else
     {
         paramModifier = ParameterModifier.None;
         paramModifierAtt = null;
     }
 }
示例#3
0
        private void ParseParameterArgument(
            string arg,
            out List <KeyValuePair <object, Type> > paramValues,
            out ParameterModifier paramModifier,
            out string paramModifierAtt)
        {
            const string INDEX_ALL    = "IndexAll";
            const string INDEX_FROM   = "IndexFrom";
            const string INDEX_TO     = "IndexTo";
            const string MODIFIER     = "Modifier";
            const string MODIFIER_ATT = "ModifierAtt";
            var          regex        = new ParseParameter();
            var          match        = regex.Match(arg);

            if (!match.Success)
            {
                throw new Exception("Неправильный синтаксис параметра");
            }
            paramValues = new List <KeyValuePair <object, Type> >();
            if (match.Groups[INDEX_ALL].Success)
            {
                for (int i = 0; i < Parameters.Length; i++)
                {
                    paramValues.Add(GetTypedParamValueAndType(i));
                }
            }
            else
            {
                var paramIndexFrom = Convert.ToInt32(match.Groups[INDEX_FROM].Value);
                var paramIndexTo   = paramIndexFrom;
                if (match.Groups[INDEX_TO].Success)
                {
                    var paramIndexToValue = match.Groups[INDEX_TO].Value;
                    paramIndexTo =
                        string.CompareOrdinal(paramIndexToValue, "*") == 0
                        ? Parameters.Length - 1
                        : Convert.ToInt32(paramIndexToValue);
                }
                if (paramIndexFrom > paramIndexTo || paramIndexTo >= Parameters.Length)
                {
                    throw new Exception("Некорректный диапазон индексов параметров");
                }
                for (int i = paramIndexFrom; i <= paramIndexTo; i++)
                {
                    paramValues.Add(GetTypedParamValueAndType(i));
                }
            }
            var modifierGroup = match.Groups[MODIFIER];

            if (modifierGroup.Success)
            {
                paramModifier = (ParameterModifier)Enum.Parse(typeof(ParameterModifier), modifierGroup.Value);
                var modifierAttGroup = match.Groups[MODIFIER_ATT];
                if (modifierAttGroup.Success)
                {
                    paramModifierAtt = modifierAttGroup.Value;
                }
                else
                {
                    paramModifierAtt = null;
                }
            }
            else
            {
                paramModifier    = ParameterModifier.None;
                paramModifierAtt = null;
            }
        }