Esempio n. 1
0
        private async Task ParseLetAsync(string[] parts)
        {
            if (parts.Length != 4 && parts.Length != 5)
            {
                ThrowException("ex_syntaxError");
            }
            string key = parts[1];

            if (variables.Any(p => p.Key == key))
            {
                ThrowException("ex_cannotFindVariable");
            }
            //待加入:重复key
            string type      = parts[2];
            string value     = parts[3];
            object realValue = type switch
            {
                "string" => GetString(value),
                "response" => await GetResponseAsync(value),
                "responseText" => await GetResponseTextAsync(value),
                "responseJsonValue" => GetResponseData(value),
                //"responseCookie" => GetResponseCookie(value),
                "webpage" => GetWebPage(value, parts.Length == 5 && parts[4].Contains("clone")),
                _ => throw new ScriptException("ex_wrongType", currentCommand, currentLine, Script),
            };

            Output?.Invoke(this, $"add new variable: {key} = {realValue.ToString()}");

            ScriptVariable variable = new ScriptVariable(key, realValue, type);

            variables.Add(variable);
        }
Esempio n. 2
0
        private T GetVariable <T>(string variableKey)
        {
            ScriptVariable variable = variables.FirstOrDefault(p => p.Key == variableKey && p.Value is T);

            if (variable == null)
            {
                ThrowException("ex_cannotFindVariable");
            }

            return((T)variable.Value);
        }
Esempio n. 3
0
        private object GetVariable(string variableKey, string type)
        {
            ScriptVariable variable = variables.FirstOrDefault(p => p.Key == variableKey && p.Type == type);

            if (variable == null)
            {
                ThrowException("ex_cannotFindVariable");
            }

            return(variable.Value);
        }