public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            if (args.IsNull("lst"))
            {
                return(ValueNull.NULL);
            }
            var value = args.GetList("lst").GetValue();
            var start = (int)args.GetInt("startidx").GetValue();

            if (start < 0)
            {
                start = value.Count + start;
            }
            if (start > value.Count)
            {
                return(new ValueList());
            }
            var end = (int)args.GetInt("endidx", value.Count).GetValue();

            if (end < 0)
            {
                end = value.Count + end;
            }
            if (end > value.Count)
            {
                end = value.Count;
            }
            var result = new ValueList();

            for (var i = start; i < end; i++)
            {
                result.AddItem(value[i]);
            }
            return(result);
        }
        public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            var    program   = args.GetString("program").GetValue();
            var    arguments = args.GetList("args").GetValue();
            string work_dir  = null;

            if (args.HasArg("work_dir"))
            {
                work_dir = args.GetString("work_dir").GetValue();
            }
            var echo = false;

            if (args.HasArg("echo"))
            {
                echo = args.GetBoolean("echo").GetValue();
            }
            try
            {
                var list = new StringBuilder();
                list.Append(program).Append(" ");
                foreach (var argument in arguments)
                {
                    list.Append(argument.AsString().GetValue()).Append(" ");
                }
                list.Remove(list.Length - 1, 1);
                var process = new Process();
                var info    = process.StartInfo;
                info.FileName  = program;
                info.Arguments = list.ToString();
                if (work_dir != null)
                {
                    info.WorkingDirectory = work_dir;
                }
                info.CreateNoWindow         = true;
                info.RedirectStandardOutput = true;
                info.RedirectStandardError  = true;
                info.RedirectStandardInput  = true;
                if (echo)
                {
                    System.Console.WriteLine(program + " " + list);
                }
                process.Start();
                process.WaitForExit();
                return(new ValueInt(process.ExitCode));
            } catch (Exception e) {
                throw new ControlErrorException(new ValueString("ERROR"), "Cannot execute " + program + ": " + e.Message, pos);
            }
        }
Beispiel #3
0
        public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            if (args.IsNull("lst"))
            {
                return(ValueNull.NULL);
            }
            var lst    = args.GetList("lst").GetValue();
            var result = new ValueList();

            for (var i = 0; i < lst.Count - 1; i++)
            {
                var pair = new ValueList();
                pair.AddItem(lst[i]);
                pair.AddItem(lst[i + 1]);
                result.AddItem(pair);
            }
            return(result);
        }
Beispiel #4
0
        public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            if (args.IsNull("str"))
            {
                return(ValueNull.NULL);
            }
            var str  = args.GetString("str").GetValue();
            var fmts = new List <string>();

            if (args.HasArg("fmt"))
            {
                if (args.Get("fmt").IsList())
                {
                    foreach (var fmt_ in args.GetList("fmt").GetValue())
                    {
                        fmts.Add(fmt_.AsString().GetValue());
                    }
                }
                else
                {
                    fmts.Add(args.GetString("fmt").GetValue());
                }
            }
            else
            {
                fmts.Add("yyyyMMdd");
            }

            foreach (var fmt in fmts)
            {
                try
                {
                    return(new ValueDate(DateTime.ParseExact(str, fmt, DateTimeFormatInfo.InvariantInfo)));
                }
                catch
                {
                    // continue;
                }
            }

            return(ValueNull.NULL);
        }
Beispiel #5
0
        public override Value Execute(Args args, Environment environment, SourcePos pos)
        {
            if (args.IsNull("list"))
            {
                return(ValueNull.NULL);
            }

            var list   = args.GetList("list").GetValue();
            var ignore = new List <Value>();

            if (args.HasArg("ignore"))
            {
                ignore.AddRange(args.GetList("ignore").GetValue());
            }

            var resultdecimal   = (decimal)0;
            var resultint       = 0L;
            var decimalrequired = false;

            foreach (var value in list)
            {
                var skipvalue = false;
                foreach (var ignoreval in ignore)
                {
                    if (ignoreval.IsEquals(value))
                    {
                        skipvalue = true;
                        break;
                    }
                }
                if (skipvalue)
                {
                    continue;
                }

                if (decimalrequired)
                {
                    resultdecimal += value.AsDecimal().GetValue();
                }
                else if (value.IsInt())
                {
                    resultint += value.AsInt().GetValue();
                }
                else if (value.IsDecimal())
                {
                    if (!decimalrequired)
                    {
                        decimalrequired = true;
                        resultdecimal   = resultint;
                    }

                    resultdecimal += value.AsDecimal().GetValue();
                }
                else
                {
                    throw new ControlErrorException(new ValueString("ERROR"), "Cannot sum " + value, pos);
                }
            }

            if (decimalrequired)
            {
                return(new ValueDecimal(resultdecimal));
            }
            return(new ValueInt(resultint));
        }