Exemple #1
0
        public static void ListExec(RCRunner runner, RCClosure closure)
        {
            RCArray <Exec> modules = new RCArray <Exec> ();
            RCArray <long> keys    = new RCArray <long> ();

            lock (runner._botLock)
            {
                foreach (KeyValuePair <long, RCBot> kv in runner._bots)
                {
                    keys.Write(kv.Key);
                    modules.Write((Exec)runner._bots[kv.Key].GetModule(typeof(Exec)));
                }
            }
            RCCube result = new RCCube("S");

            for (int i = 0; i < modules.Count; ++i)
            {
                lock (modules[i]._lock)
                {
                    foreach (KeyValuePair <long, Exec.ChildProcess> kv in modules[i]._process)
                    {
                        RCSymbolScalar sym = RCSymbolScalar.From("exec", keys[i], kv.Key);
                        result.WriteCell("bot", sym, keys[i]);
                        result.WriteCell("handle", sym, (long)kv.Key);
                        result.WriteCell("pid", sym, (long)kv.Value._pid);
                        result.WriteCell("program", sym, kv.Value._program);
                        result.WriteCell("arguments", sym, kv.Value._arguments);
                        result.WriteCell("exit", sym, kv.Value._exitCode);
                        result.Write(sym);
                    }
                }
            }
            runner.Yield(closure, result);
        }
Exemple #2
0
        /*
         * public static void ListFibers (RCRunner runner, RCClosure closure)
         * {
         * RCArray<Fiber> modules = new RCArray<Fiber> ();
         * RCArray<long> keys = new RCArray<long> ();
         * lock (runner._botLock)
         * {
         *  foreach (KeyValuePair<long, RCBot> kv in runner._bots)
         *  {
         *    keys.Write (kv.Key);
         *    modules.Write ((Fiber) runner._bots[kv.Key].GetModule (typeof (Fiber)));
         *  }
         * }
         * RCArray<long> bots = new RCArray<long> ();
         * RCArray<long> fibers = new RCArray<long> ();
         * RCArray<string> states = new RCArray<string> ();
         * for (int i = 0; i < modules.Count; ++i)
         * {
         *  lock (modules[i]._fiberLock)
         *  {
         *    foreach (KeyValuePair<long, Fiber.FiberState> kv in modules[i]._fibers)
         *    {
         *      bots.Write (keys[i]);
         *      fibers.Write (kv.Key);
         *      states.Write (kv.Value.State);
         *    }
         *  }
         * }
         * RCBlock result = RCBlock.Empty;
         * if (states.Count > 0)
         * {
         *  result = new RCBlock (result, "bot", ":", new RCLong (bots));
         *  result = new RCBlock (result, "fiber", ":", new RCLong (fibers));
         *  result = new RCBlock (result, "state", ":", new RCString (states));
         * }
         *
         * runner.Yield (closure, result);
         * }
         */

        public static void ListFibers(RCRunner runner, RCClosure closure)
        {
            RCArray <Fiber> modules = new RCArray <Fiber> ();
            RCArray <long>  keys    = new RCArray <long> ();

            lock (runner._botLock)
            {
                foreach (KeyValuePair <long, RCBot> kv in runner._bots)
                {
                    keys.Write(kv.Key);
                    modules.Write((Fiber)runner._bots[kv.Key].GetModule(typeof(Fiber)));
                }
            }
            RCCube result = new RCCube("S");

            for (int i = 0; i < modules.Count; ++i)
            {
                lock (modules[i]._fiberLock)
                {
                    foreach (KeyValuePair <long, Fiber.FiberState> kv in modules[i]._fibers)
                    {
                        RCSymbolScalar sym = RCSymbolScalar.From("fiber", keys[i], kv.Key);
                        result.WriteCell("bot", sym, keys[i]);
                        result.WriteCell("fiber", sym, kv.Key);
                        result.WriteCell("state", sym, kv.Value.State);
                        result.Write(sym);
                    }
                }
            }
            runner.Yield(closure, result);
        }
Exemple #3
0
        public static void ListRequest(RCRunner runner, RCClosure closure)
        {
            RCArray <HttpServer> modules = new RCArray <HttpServer> ();
            RCArray <long>       keys    = new RCArray <long> ();

            lock (runner._botLock)
            {
                foreach (KeyValuePair <long, RCBot> kv in runner._bots)
                {
                    keys.Write(kv.Key);
                    modules.Write((HttpServer)runner._bots[kv.Key].GetModule(typeof(HttpServer)));
                }
            }
            RCCube result = new RCCube("S");

            for (int i = 0; i < modules.Count; ++i)
            {
                lock (modules[i]._lock)
                {
                    foreach (KeyValuePair <int, HttpServer.RequestInfo> kv in modules[i]._contexts)
                    {
                        RCSymbolScalar urlsym = RCSymbolScalar.From("request", keys[i], (long)kv.Key);
                        result.WriteCell("bot", urlsym, keys[i]);
                        result.WriteCell("handle", urlsym, (long)kv.Key);
                        result.WriteCell("url", urlsym, kv.Value.Context.Request.RawUrl);
                        result.Write(urlsym);
                    }
                }
            }
            runner.Yield(closure, result);
        }
Exemple #4
0
        public void EvalTuple(RCRunner runner, RCClosure closure, RCString left, RCString right)
        {
            RCArray <RCSymbolScalar> result = new RCArray <RCSymbolScalar> ();

            for (int i = 0; i < right.Count; ++i)
            {
                string[]       parts = right[i].Split(left[0].ToCharArray());
                RCSymbolScalar sym   = RCSymbolScalar.From(parts);
                result.Write(sym);
            }
            runner.Yield(closure, new RCSymbol(result));
        }
Exemple #5
0
        public void EvalSymbolString(RCRunner runner, RCClosure closure, RCString right)
        {
            RCLexer lexer = new RCLexer(new RCArray <RCTokenType> (
                                            RCTokenType.Number,
                                            RCTokenType.Boolean,
                                            RCTokenType.Symbol,
                                            RCTokenType.Name));
            RCArray <RCSymbolScalar> result = new RCArray <RCSymbolScalar> (right.Count);

            for (int i = 0; i < right.Count; ++i)
            {
                RCSymbolScalar symbol = RCSymbolScalar.From(lexer, right[i]);
                result.Write(symbol);
            }
            runner.Yield(closure, new RCSymbol(result));
        }
Exemple #6
0
        public void Timezones(RCRunner runner, RCClosure closure, RCBlock right)
        {
            RCCube   result = new RCCube("S");
            DateTime now    = DateTime.UtcNow;
            ReadOnlyCollection <TimeZoneInfo> timezones = TimeZoneInfo.GetSystemTimeZones();

            foreach (TimeZoneInfo timezone in timezones)
            {
                RCSymbolScalar sym = RCSymbolScalar.From("timezones", timezone.Id);
                result.WriteCell("displayName", sym, timezone.DisplayName);
                result.WriteCell("standardName", sym, timezone.StandardName);
                result.WriteCell("daylightName", sym, timezone.DaylightName);
                result.WriteCell("utcOffset", sym, new RCTimeScalar(timezone.GetUtcOffset(now)));
                result.WriteCell("isDaylightSavingTime", sym, timezone.IsDaylightSavingTime(now));
                result.WriteCell("supportsDaylightSavingTime", sym, timezone.SupportsDaylightSavingTime);
                result.Axis.Write(sym);
            }
            runner.Yield(closure, result);
        }
Exemple #7
0
 protected void DoChart <T> (RCCube result,
                             RCSymbolScalar name,
                             long row,
                             long col,
                             RCVector <T> right)
 {
     for (int i = 0; i < right.Count; ++i)
     {
         string         val = right[i].ToString();
         RCSymbolScalar s   = RCSymbolScalar.From(row, (long)col + i, 0L);
         RCSymbolScalar k   = new RCSymbolScalar(name, (long)i);
         result.WriteCell("r", s, row);
         result.WriteCell("c", s, (long)col + i);
         result.WriteCell("l", s, 0L);
         result.WriteCell("k", s, k);
         result.WriteCell("v", s, val);
         result.Write(s);
     }
 }
Exemple #8
0
        public static void ListVars(RCRunner runner, RCClosure closure)
        {
            RCArray <Variable> modules = new RCArray <Variable> ();
            RCArray <long>     keys    = new RCArray <long> ();

            lock (runner._botLock)
            {
                foreach (KeyValuePair <long, RCBot> kv in runner._bots)
                {
                    keys.Write(kv.Key);
                    modules.Write((Variable)runner._bots[kv.Key].GetModule(typeof(Variable)));
                }
            }
            RCCube result = new RCCube("S");

            for (int i = 0; i < modules.Count; ++i)
            {
                lock (modules[i]._lock)
                {
                    foreach (KeyValuePair <object, Dictionary <RCSymbolScalar,
                                                               RCValue> > section in modules[i]._sections)
                    {
                        RCSymbolScalar botsym = RCSymbolScalar.From("var", keys[i]);
                        foreach (KeyValuePair <RCSymbolScalar, RCValue> kv in section.Value)
                        {
                            RCSymbolScalar varsym = RCSymbolScalar.From(botsym, kv.Key);
                            result.WriteCell("bot", varsym, keys[i]);
                            result.WriteCell("section", varsym, section.Key);
                            result.WriteCell("name", varsym, kv.Key);
                            result.WriteCell("value", varsym, kv.Value.ToString());
                            result.Write(varsym);
                        }
                    }
                }
            }
            runner.Yield(closure, result);
        }
Exemple #9
0
 public void EvalSort(RCRunner runner, RCClosure closure, RCCube right)
 {
     runner.Yield(closure,
                  SortCubeByDirectionAndColumn(new RCSymbol(RCSymbolScalar.From("asc", "S")),
                                               right));
 }
Exemple #10
0
        protected static void ListFilesCube(object obj)
        {
            RCAsyncState state = (RCAsyncState)obj;
            ListArgs     args  = (ListArgs)state.Other;

            try
            {
                RCCube         result   = new RCCube(new RCArray <string> ("S"));
                Queue <string> todo     = new Queue <string> ();
                string         top      = args.Path;
                string[]       topParts = top.Split(Path.DirectorySeparatorChar);
                int            startPart;
                RCSymbolScalar prefix;
                if (args.Spec != null)
                {
                    startPart = (int)(topParts.Length - args.Spec.Length) + 1;
                    prefix    = RCSymbolScalar.From(args.Spec.Part(0));
                }
                else
                {
                    startPart = 1;
                    prefix    = RCSymbolScalar.From(topParts[0]);
                }
                todo.Enqueue(top);
                while (todo.Count > 0)
                {
                    string   path  = todo.Dequeue();
                    string[] files = Directory.GetFiles(path);
                    for (int i = 0; i < files.Length; ++i)
                    {
                        FileInfo file = new FileInfo(files[i]);
                        if (args.All || file.Name[0] != '.')
                        {
                            string []      parts  = files[i].Split(Path.DirectorySeparatorChar);
                            RCSymbolScalar symbol = RCSymbolScalar.From(startPart, prefix, parts);
                            result.WriteCell("name", symbol, file.Name);
                            result.WriteCell("size", symbol, file.Length);
                            result.WriteCell("type", symbol, "f");
                            result.WriteCell("ext", symbol, file.Extension);
                            result.WriteCell("access",
                                             symbol,
                                             new RCTimeScalar(file.LastAccessTime,
                                                              RCTimeType.Datetime));
                            result.WriteCell("write",
                                             symbol,
                                             new RCTimeScalar(file.LastWriteTime,
                                                              RCTimeType.Datetime));
                            result.Axis.Write(symbol);
                        }
                    }
                    RCArray <string> dirs = new RCArray <string> (Directory.GetDirectories(path));
                    for (int i = 0; i < dirs.Count; ++i)
                    {
                        DirectoryInfo dir = new DirectoryInfo(dirs[i]);
                        if (args.All || dir.Name[0] != '.')
                        {
                            string []      parts  = dirs[i].Split(Path.DirectorySeparatorChar);
                            RCSymbolScalar symbol = RCSymbolScalar.From(startPart, prefix, parts);
                            result.WriteCell("name", symbol, dir.Name);
                            result.WriteCell("type", symbol, "d");
                            result.WriteCell("access",
                                             symbol,
                                             new RCTimeScalar(dir.LastAccessTime,
                                                              RCTimeType.Datetime));
                            result.WriteCell("write",
                                             symbol,
                                             new RCTimeScalar(dir.LastWriteTime,
                                                              RCTimeType.Datetime));
                            result.Axis.Write(symbol);
                            if (args.Deep)
                            {
                                todo.Enqueue(dirs[i]);
                            }
                        }
                    }
                }
                state.Runner.Yield(state.Closure, result);
            }
            catch (DirectoryNotFoundException ex)
            {
                state.Runner.Finish(state.Closure,
                                    new RCException(state.Closure, RCErrors.File, ex.Message),
                                    1);
            }
            catch (Exception ex)
            {
                state.Runner.Report(state.Closure, ex);
            }
        }
Exemple #11
0
        protected void DoChart(RCCube result,
                               RCSymbolScalar name,
                               ref long row,
                               long col,
                               RCCube cube)
        {
            for (int i = 0; i < cube.Cols; ++i)
            {
                string         colname = cube.NameAt(i);
                ColumnBase     data    = cube.GetColumn(i);
                RCSymbolScalar cell    = RCSymbolScalar.From(row, (long)col, 0L);
                RCSymbolScalar parent  = new RCSymbolScalar(name, colname);
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, colname);
                result.Write(cell);

                for (int j = 0; j < data.Count; ++j)
                {
                    string val = data.BoxCell(j).ToString();
                    cell = RCSymbolScalar.From(row, (long)col + data.Index[j] + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)j);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + data.Index[j] + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
            if (cube.Axis.Global != null)
            {
                RCSymbolScalar cell   = RCSymbolScalar.From(row, col, 0L);
                RCSymbolScalar parent = new RCSymbolScalar(name, "G");
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, "G");
                result.Write(cell);
                for (int i = 0; i < cube.Axis.Global.Count; ++i)
                {
                    string val = cube.Axis.Global[i].ToString();
                    cell = RCSymbolScalar.From(row, col + i + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)i);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + i + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
            if (cube.Axis.Event != null)
            {
                RCSymbolScalar cell   = RCSymbolScalar.From(row, col, 0L);
                RCSymbolScalar parent = new RCSymbolScalar(name, "E");
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, "E");
                result.Write(cell);
                for (int i = 0; i < cube.Axis.Event.Count; ++i)
                {
                    string val = cube.Axis.Event[i].ToString();
                    cell = RCSymbolScalar.From(row, col + i + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)i);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + i + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
            if (cube.Axis.Time != null)
            {
                RCSymbolScalar cell   = RCSymbolScalar.From(row, col, 0L);
                RCSymbolScalar parent = new RCSymbolScalar(name, "T");
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, "T");
                result.Write(cell);
                for (int i = 0; i < cube.Axis.Time.Count; ++i)
                {
                    string val = cube.Axis.Time[i].ToString();
                    cell = RCSymbolScalar.From(row, col + i + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)i);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + i + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
            if (cube.Axis.Symbol != null)
            {
                RCSymbolScalar cell   = RCSymbolScalar.From(row, col, 0L);
                RCSymbolScalar parent = new RCSymbolScalar(name, "S");
                result.WriteCell("r", cell, (long)row);
                result.WriteCell("c", cell, (long)col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, parent);
                result.WriteCell("v", cell, "S");
                result.Write(cell);
                for (int i = 0; i < cube.Axis.Symbol.Count; ++i)
                {
                    string val = cube.Axis.Symbol[i].ToString();
                    cell = RCSymbolScalar.From(row, col + i + 1, 0L);
                    RCSymbolScalar child = new RCSymbolScalar(parent, (long)i);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col + i + 1);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, child);
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                }
                ++row;
            }
        }
Exemple #12
0
        protected void DoChart(RCCube result,
                               RCSymbolScalar parent,
                               ref long row,
                               long col,
                               RCBlock
                               right)
        {
            for (int i = 0; i < right.Count; ++i)
            {
                RCBlock current   = right.GetName(i);
                object  shortName = current.Name;
                if (shortName.Equals(""))
                {
                    shortName = (long)i;
                }
                RCSymbolScalar name = new RCSymbolScalar(parent, shortName);
                RCSymbolScalar cell = RCSymbolScalar.From(row, col, 0L);
                result.WriteCell("r", cell, row);
                result.WriteCell("c", cell, col);
                result.WriteCell("l", cell, 0L);
                result.WriteCell("k", cell, name);
                result.WriteCell("v", cell, shortName is long?shortName.ToString() : shortName);
                result.Axis.Write(cell);
                RCVectorBase vector = current.Value as RCVectorBase;
                if (vector != null)
                {
                    ++col;
                    switch (vector.TypeCode)
                    {
                    case 'l': DoChart <long> (result, name, row, col, (RCVector <long>)vector); break;

                    case 'd': DoChart <double> (result, name, row, col, (RCVector <double>)vector); break;

                    case 'm': DoChart <decimal> (result, name, row, col, (RCVector <decimal>)vector); break;

                    case 's': DoChart <string> (result, name, row, col, (RCVector <string>)vector); break;

                    case 'x': DoChart <byte> (result, name, row, col, (RCVector <byte>)vector); break;

                    case 'y': DoChart <RCSymbolScalar> (result,
                                                        name,
                                                        row,
                                                        col,
                                                        (RCVector <RCSymbolScalar>)vector); break;

                    case 'b': DoChart <bool> (result, name, row, col, (RCVector <bool>)vector); break;

                    default: throw new Exception("Unknown typecode: " + vector.TypeCode);
                    }
                    --col;
                    ++row;
                    continue;
                }
                RCBlock block = current.Value as RCBlock;
                if (block != null)
                {
                    ++col;
                    ++row;
                    DoChart(result, name, ref row, col, block);
                    --col;
                    continue;
                }
                RCOperator oper = current.Value as RCOperator;
                if (oper != null)
                {
                    ++col;
                    string val = oper.ToString();
                    cell = RCSymbolScalar.From(row, col, 0L);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, new RCSymbolScalar(name, 0L));
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                    ++row;
                    --col;
                    continue;
                }
                RCReference reference = current.Value as RCReference;
                if (reference != null)
                {
                    ++col;
                    string val = reference.ToString();
                    cell = RCSymbolScalar.From(row, col, 0L);
                    result.WriteCell("r", cell, (long)row);
                    result.WriteCell("c", cell, (long)col);
                    result.WriteCell("l", cell, 0L);
                    result.WriteCell("k", cell, new RCSymbolScalar(name, 0L));
                    result.WriteCell("v", cell, val);
                    result.Write(cell);
                    ++row;
                    --col;
                    continue;
                }
                RCCube cube = current.Value as RCCube;
                if (cube != null)
                {
                    ++col;
                    ++row;
                    DoChart(result, name, ref row, col, cube);
                    ++row;
                    --col;
                    continue;
                }
            }
        }