示例#1
0
 public static ConsoleResponse GetValue(string name)
 {
     lock (_varables)
         if (ValueContains(name))
         {
             return(ConsoleResponse.Succeeded(_varables[name].Value));
         }
     return(ConsoleResponse.Failed());
 }
示例#2
0
 public static ConsoleResponse SetValue(string name, string value)
 {
     lock (_varables)
         if (_varables.Contains(name))
         {
             if (_varables[name].ValidCheck == null || _varables[name].ValidCheck(value).Sucess)
             {
                 ConsoleVarable cv = _varables[name];
                 cv.Value        = value;
                 _varables[name] = cv;
                 return(ConsoleResponse.Succeeded(value));
             }
             else
             {
                 return(ConsoleResponse.Failed(DefaultLanguage.Strings.GetFormatedString("Console_Validation_Failure", name, value)));
             }
         }
         else
         {
             return(ConsoleResponse.Failed("No such variable " + name));
         }
 }
示例#3
0
        static ConsoleResponse ConsoleHelpFunc(string[] data)
        {
            ConsoleResponse cr = new ConsoleResponse()
            {
                State = ConsoleCommandState.Sucess,
                Value = ""
            };

            if (data.Length == 0)
            {
                foreach (string s in _functions.Keys)
                {
                    cr.Value += s + "\n";
                }
                foreach (string s in _varables.Keys)
                {
                    cr.Value += s + "\n";
                }
            }
            else
            {
                foreach (string s in _varables.Keys)
                {
                    if (s == data[0])
                    {
                        cr.Value = _varables[s].HelpInfo;
                    }
                }
                foreach (string s in _functions.Keys)
                {
                    if (s == data[0])
                    {
                        cr.Value = _functions[s].HelpInfo;
                    }
                }
            }

            return(cr);
        }
示例#4
0
        public static ConsoleResponse ExecuteFunc(string name, params string[] args)
        {
            lock (_varables)
            {
                ConsoleResponse cr = new ConsoleResponse()
                {
                    State = ConsoleCommandState.Failure,
                    Value = ""
                };

                try
                {
                    if (_functions.Contains(name))
                    {
                        return(_functions[name].Function(args));
                    }
                }
                catch (ConsoleException ex)
                {
                    cr.Value = DefaultLanguage.Strings.GetFormatedString("Console_Function_Exception", ex);
                }
                return(cr);
            }
        }
示例#5
0
        public static ConsoleResponse ProcessLine(string line)
        {
            line = line.Trim();
            lock (_varables)
            {
                ConsoleResponse cr = new ConsoleResponse()
                {
                    State = ConsoleCommandState.Sucess,
                };

                if (line == "")
                {
                    cr.Value = "";
                    return(cr);
                }

                string[] split = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   name = split[0], value = "";
                if (split.Length != 1)
                {
                    string[] sptmp = new string[split.Length - 1];
                    Array.Copy(split, 1, sptmp, 0, split.Length - 1);
                    split = sptmp;
                }
                else
                {
                    split = new string[0];
                }

                if (_varables.Contains(name) && split.Length == 0)
                {
                    cr.Value = string.Format("{0} = {1}", name, _varables[name]);
                    return(cr);
                }
                value = String.Join(" ", split);
                if (_varables.Contains(name))
                {
                    if (value.StartsWith("=") || value.StartsWith("\\"))
                    {
                        value = value.Remove(0, 1);

                        value = value.Trim();
                    }
                    if (_varables[name].ValidCheck == null || _varables[name].ValidCheck(value).Sucess)
                    {
                        ConsoleVarable cv = _varables[name];
                        cv.Value        = value;
                        _varables[name] = cv;
                        cr.Value        = string.Format("{0} = {1}", name, _varables[name]);

                        return(cr);
                    }
                    else
                    {
                        cr.State = ConsoleCommandState.Failure;
                        cr.Value = DefaultLanguage.Strings.GetFormatedString("Console_Validation_Failure", name, value);
                        return(cr);
                    }
                }
                else if (_functions.Contains(name))
                {
                    return(ExecuteFunc(name, ArgSplit(value, true)));
                }

                cr.State = ConsoleCommandState.Failure;
                cr.Value = DefaultLanguage.Strings.GetFormatedString("Console_Unknown_Varable", name);

                return(cr);
            }
        }