protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.NEXT_ARG_ARRAY); Utils.CheckNotEmpty(script, varName, m_name); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName, script); Variable currentValue = func.GetValue(script); // 3. Get the value to be added or appended. Variable newValue = Utils.GetItem(script); // 4. Take either the string part if it is defined, // or the numerical part converted to a string otherwise. string arg1 = currentValue.AsString(); string arg2 = newValue.AsString(); // 5. The variable becomes a string after adding a string to it. newValue.Reset(); newValue.String = arg1 + arg2; ParserFunction.AddGlobalOrLocalVariable(varName, new GetVarFunction(newValue)); return(newValue); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); double timestamp = Utils.GetSafeDouble(args, 0); string strFormat = Utils.GetSafeString(args, 1, "yyyy/MM/dd HH:mm:ss.fff"); Utils.CheckNotEmpty(strFormat, m_name); var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0); if (m_millis) { dt = dt.AddMilliseconds(timestamp); } else { dt = dt.AddSeconds(timestamp); } DateTime runtimeKnowsThisIsUtc = DateTime.SpecifyKind(dt, DateTimeKind.Utc); DateTime localVersion = runtimeKnowsThisIsUtc.ToLocalTime(); string when = localVersion.ToString(strFormat); return(new Variable(when)); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); string strFormat = m_stringVersion ? Utils.GetSafeString(args, 0, "HH:mm:ss.fff") : Utils.GetSafeString(args, 1, "yyyy/MM/dd HH:mm:ss"); Utils.CheckNotEmpty(strFormat, m_name); if (m_stringVersion) { return(new Variable(DateTime.Now.ToString(strFormat))); } var date = DateTime.Now; string when = Utils.GetSafeString(args, 0); if (!string.IsNullOrWhiteSpace(when) && !DateTime.TryParseExact(when, strFormat, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out date)) { throw new ArgumentException("Couldn't parse [" + when + "] using format [" + strFormat + "]."); } return(new Variable(date)); }
protected override Variable Evaluate(ParsingScript script) { string varName = Utils.GetToken(script, Constants.NEXT_ARG_ARRAY); Utils.CheckNotEmpty(script, varName, m_name); Variable varValue = Utils.GetItem(script); string strValue = varValue.AsString(); Environment.SetEnvironmentVariable(varName, strValue); return new Variable(varName); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); string strFormat = Utils.GetSafeString(args, 0, "HH:mm:ss.fff"); Utils.CheckNotEmpty(strFormat, m_name); string when = DateTime.Now.ToString(strFormat); return(new Variable(when)); }
protected override Variable Evaluate(ParsingScript script) { bool isList = false; List <Variable> args = Utils.GetArgs(script, Constants.START_ARG, Constants.END_ARG, out isList); string strFormat = Utils.GetSafeString(args, 0, "hh:mm:ss.fff"); Utils.CheckNotEmpty(strFormat, m_name); string when = DateTime.Now.ToString(strFormat); return(new Variable(when)); }
protected override Variable Evaluate(ParsingScript script) { string processName = Utils.GetItem(script).String; Utils.CheckNotEmpty(processName, "processName"); List <string> args = Utils.GetFunctionArgs(script); int processId = -1; try { Process pr = Process.Start(processName, string.Join("", args.ToArray())); processId = pr.Id; } catch (Exception exc) { throw new ArgumentException("Couldn't start [" + processName + "]: " + exc.Message); } Interpreter.Instance.AppendOutput("Process " + processName + " started, id: " + processId, true); return(new Variable(processId)); }
protected override Variable Evaluate(ParsingScript script) { string substring; // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.NEXT_ARG_ARRAY); Utils.CheckNotEmpty(script, varName, m_name); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Variable currentValue = func.GetValue(script); // 3. Take either the string part if it is defined, // or the numerical part converted to a string otherwise. string arg = currentValue.AsString(); // 4. Get the initial index of the substring. Variable init = Utils.GetItem(script); Utils.CheckNonNegativeInt(init); // 5. Get the length of the substring if available. bool lengthAvailable = Utils.SeparatorExists(script); if (lengthAvailable) { Variable length = Utils.GetItem(script); Utils.CheckPosInt(length); if (init.Value + length.Value > arg.Length) { throw new ArgumentException("The total substring length is larger than [" + arg + "]"); } substring = arg.Substring((int)init.Value, (int)length.Value); } else { substring = arg.Substring((int)init.Value); } Variable newValue = new Variable(substring); return(newValue); }
protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.END_ARG_ARRAY); Utils.CheckNotEmpty(script, varName, m_name); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Variable currentValue = func.GetValue(script); // 3. Take either the string part if it is defined, // or the numerical part converted to a string otherwise. string arg = currentValue.AsString(); Variable newValue = new Variable(arg.ToLower()); return(newValue); }
protected override Variable Evaluate(ParsingScript script) { string methodName = Utils.GetItem(script).AsString(); Utils.CheckNotEmpty(script, methodName, m_name); script.MoveForwardIf(Constants.NEXT_ARG); string paramName = Utils.GetToken(script, Constants.NEXT_ARG_ARRAY); Utils.CheckNotEmpty(script, paramName, m_name); script.MoveForwardIf(Constants.NEXT_ARG); Variable paramValueVar = Utils.GetItem(script); string paramValue = paramValueVar.AsString(); var result = Statics.InvokeCall(typeof(Statics), methodName, paramName, paramValue); return(result); }
protected override Variable Evaluate(ParsingScript script) { // 1. Get the name of the variable. string varName = Utils.GetToken(script, Constants.NEXT_ARG_ARRAY); Utils.CheckNotEmpty(script, varName, m_name); // 2. Get the current value of the variable. ParserFunction func = ParserFunction.GetFunction(varName); Variable currentValue = func.GetValue(script); // 3. Get the value to be looked for. Variable searchValue = Utils.GetItem(script); // 4. Apply the corresponding C# function. string basePart = currentValue.AsString(); string search = searchValue.AsString(); int result = basePart.IndexOf(search); return(new Variable(result)); }