private void AddCustomVariable(string cmd) { GroupCollection groups = Regex.Match(cmd, @"#set\s(?<name>@[a-z,A-z,0-9]+)=?(?<value>.+)?", RegexOptions.Compiled).Groups; string value = groups["value"].Value; if (value.StartsWith("@")) { value = CustomVariable.GetVariable(value); } CustomVariable.AddVariable(groups["name"].Value, value); }
private string ProcessCustomVariable(string cmd) { if (cmd.Contains('@')) { MatchCollection matches = Regex.Matches(cmd, @"@[a-z,A-z,0-9]+", RegexOptions.Compiled); foreach (Match match in matches) { string name = match.Value; cmd = cmd.Replace(name, CustomVariable.GetVariable(name)); } } return(cmd); }
private void ProcessCalcuate(string cmd) { try { GroupCollection groups = Regex.Match(cmd, @"#calc\s(?<name>@[a-z,A-z,0-9]+)=(?<value>.+)?", RegexOptions.Compiled).Groups; string value = groups["value"].Value; value = Regex.Replace(value, @"@[a-z,A-z,0-9]+", new MatchEvaluator(new Func <Match, string>(m => { return(CustomVariable.GetVariable(m.Value)); })), RegexOptions.Compiled); double result = Util.ParseArithmeticalExpression(value); CustomVariable.AddVariable(groups["name"].Value, result.ToString()); } catch (Exception e) { SendText("#test Error:" + e.Message); } }