public static void SetIfNotExsistValue(string name, ConsoleVarable value) { lock (_varables) if (!_varables.Contains(name)) { _varables.Add(name, value); } }
public static void SetValue(string name, ConsoleVarable value) { lock (_varables) if (_varables.Contains(name)) { _varables[name] = value; } else { _varables.Add(name, value); } }
public static ConsoleResponseBoolean GetOnOff(string name) { lock (_varables) if (ValueContains(name)) { var test = ConsoleVarable.OnOff(_varables[name].Value); if (test.Sucess) { return(ConsoleResponseBoolean.NewSucess(test.Result)); } } return(ConsoleResponseBoolean.NewFailure()); }
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)); } }
public static void ProcessFile(string filename, bool isFullPath = false, bool hardfail = false) { if (!isFullPath) { filename = Environment.CurrentDirectory + "/" + filename; } lock (_varables) { if (!File.Exists(filename)) { if (hardfail) { throw new FileNotFoundException("Could not load file.", filename); } else { WriteLine("Could not find {0}.", filename); return; } } WriteLine("Loading file {0}", filename); string line, varableName, VarableArguments; int pos, pos2, linenumber = 0; foreach (string l in File.ReadAllLines(filename)) { linenumber++; line = l.Trim(); if (line.StartsWith("#")) { continue; } if (!line.Contains(" ") && !line.Contains("\t") && !line.Contains("=")) { continue; } // We need to stop at the first space, \t, or =. for (pos = 0; pos < line.Length; pos++) { if (line[pos] == ' ' || line[pos] == '\t' || line[pos] == '=') { break; } } bool isequals = false; if (line[pos] == '=') { isequals = true; } // Now we keep counting until we hit a non delimer for (pos2 = pos + 1; pos2 < line.Length; pos2++) { if (line[pos2] != ' ' && line[pos2] != '\t' && (line[pos2] != '=' || (isequals && line[pos2] == '='))) { break; } if (line[pos2] == '=') { isequals = true; } } varableName = line.Substring(0, pos); VarableArguments = line.Substring(pos2); VarableArguments = VarableArguments.Trim(); if (_varables.Contains(varableName)) { if (_varables[varableName].ValidCheck != null) { ExecutionState Check = _varables[varableName].ValidCheck(VarableArguments); if (!Check) { WriteLine("Failed to parse line {0}: {1}", linenumber.ToString(), Check.Reason); continue; } } ConsoleVarable cv = _varables[varableName]; cv.Value = VarableArguments; _varables[varableName] = cv; } else if (_functions.Contains(varableName)) { var result = ExecuteFunc(varableName, ArgSplit(VarableArguments, true)); if (result.State == ConsoleCommandState.Failure) { WriteLine("Failed to parse line {0}: {1}", linenumber.ToString(), result.Value); } if (result.State == ConsoleCommandState.Sucess && result.Value != "") { WriteLine(result.Value); } } } } }
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); } }