static void Main(string[] args)
        {
            Console.WriteLine("NEO Developer Shell - " + DebuggerUtils.DebuggerVersion);
            var settings = new DebuggerSettings(Directory.GetCurrentDirectory());
            var shell    = new DebuggerShell(settings);

            shell.AddCommand(new ExitCommand());

            if (args.Length > 0)
            {
                shell.Execute("load " + args[0], OutputMessage);
            }

            while (true)
            {
                Console.Write(">");
                var input = Console.ReadLine();

                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                if (!shell.Execute(input, OutputMessage))
                {
                    Console.WriteLine("Unknown command. Type HELP for list of commands.");
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("NEO Developer Shell - " + DebuggerUtils.DebuggerVersion);
            var settings = new DebuggerSettings(Directory.GetCurrentDirectory());
            var debugger = new DebugManager(settings);
            var shell    = new DebuggerShell(debugger);

            shell.AddCommand(new ExitCommand());

            if (args.Length > 0)
            {
                var input = args[0].Replace("'", "\"");
                if (input.StartsWith("\"") && input.EndsWith("\""))
                {
                    input = input.Substring(1, input.Length - 2);
                }

                var lines = input.Split(';');
                foreach (var line in lines)
                {
                    if (!string.IsNullOrEmpty(line))
                    {
                        Console.WriteLine(line);
                        shell.Execute(line, OutputMessage);
                    }
                }
            }

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write(">");
                var input = Console.ReadLine();

                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }

                if (!shell.Execute(input, OutputMessage))
                {
                    Console.WriteLine("Unknown command. Type HELP for list of commands.");
                }
            }
        }
Exemple #3
0
        public Backend(ServerSettings serverSettings)
        {
            var settings = new DebuggerSettings(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

            var curPath = Directory.GetCurrentDirectory();

            if (!settings.compilerPaths.ContainsKey(SourceLanguage.CSharp))
            {
                settings.compilerPaths[SourceLanguage.CSharp] = curPath + "/compilers";
            }

            if (!settings.compilerPaths.ContainsKey(SourceLanguage.Python))
            {
                settings.compilerPaths[SourceLanguage.Python] = curPath + "/compilers";
            }

            _debugger = new DebugManager(settings);
            _shell    = new DebuggerShell(_debugger);

            // initialize a logger
            //var log = new SynkServer.Core.Logger();

            var server = new HTTPServer(serverSettings);

            // instantiate a new site, the second argument is the file path where the public site contents will be found
            //var site = new Site("../public");

            var templateEngine = new TemplateEngine(server, "../views");

            LoadContract(curPath + "/contracts/DefaultContract.cs");

            server.Get("/", (request) =>
            {
                var context = GetContext();

                return(templateEngine.Render(context, new string[] { "index" }));
            });

            server.Post("/switch", (request) =>
            {
                var code = request.args["code"];
                projectFiles[this.activeDocumentID].content = code;

                this.activeDocumentID = request.args["id"];

                var context = GetContext();

                return("ok");
            });

            server.Get("/content", (request) =>
            {
                var content = projectFiles[activeDocumentID].content;
                return(content);
            });

            server.Get("/breakpoint/list", (request) =>
            {
                var breakpoints = projectFiles[activeDocumentID].breakpoints;
                var node        = DataNode.CreateArray();
                foreach (var line in breakpoints)
                {
                    var item = DataNode.CreateValue(line);
                    node.AddNode(item);
                }
                return(node);
            });

            server.Post("/breakpoint/add", (request) =>
            {
                int line = int.Parse(request.args["line"]);

                var file = projectFiles[activeDocumentID];
                if (_debugger.AddBreakpoint(line, file.path))
                {
                    var breakpoints = file.breakpoints;
                    breakpoints.Add(line);

                    return("ok");
                }

                return("fail");
            });

            server.Post("/breakpoint/remove", (request) =>
            {
                int line = int.Parse(request.args["line"]);

                var file        = projectFiles[activeDocumentID];
                var breakpoints = file.breakpoints;

                breakpoints.Remove(line);

                _debugger.RemoveBreakpoint(line, file.path);

                return("ok");
            });

            server.Post("/compile", (request) =>
            {
                var code = request.args["code"];
                request.session.SetString("code", code);

                if (Compile(serverSettings, code))
                {
                    return("OK");
                }

                return("FAIL");
            });

            server.Post("/shell", (request) =>
            {
                var input  = request.args["input"];
                var output = DataNode.CreateObject();

                var lines = DataNode.CreateArray("lines");
                output.AddNode(lines);

                if (!_shell.Execute(input, (type, text) =>
                {
                    lines.AddValue(text);
                }))
                {
                    output.AddValue("Invalid command");
                }

                string filePath;
                var curLine = _shell.Debugger.ResolveLine(_shell.Debugger.Info.offset, true, out filePath);

                output.AddField("state", _shell.Debugger.Info.state);
                output.AddField("offset", _shell.Debugger.Info.offset);
                output.AddField("line", curLine);
                output.AddField("path", filePath);

                if (_shell.Debugger.Info.state == Emulation.DebuggerState.State.Finished)
                {
                    var val = _debugger.Emulator.GetOutput();

                    _debugger.Blockchain.Save();

                    var methodName = _debugger.Emulator.currentMethod;
                    var hintType   = !string.IsNullOrEmpty(methodName) && _debugger.ABI != null && _debugger.ABI.functions.ContainsKey(methodName) ? _debugger.ABI.functions[methodName].returnType : Emulator.Type.Unknown;

                    var temp = FormattingUtils.StackItemAsString(val, false, hintType);
                    output.AddField("result", temp);
                    output.AddField("gas", _debugger.Emulator.usedGas);
                }

                var json = JSONWriter.WriteToString(output);
                return(json);
            });

            server.Run();
        }
Exemple #4
0
        public Backend(ServerSettings serverSettings)
        {
            var settings = new DebuggerSettings(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

            var curPath = Directory.GetCurrentDirectory();

            if (!settings.compilerPaths.ContainsKey(SourceLanguage.CSharp))
            {
                settings.compilerPaths[SourceLanguage.CSharp] = curPath + "/compilers";
            }

            if (!settings.compilerPaths.ContainsKey(SourceLanguage.Python))
            {
                settings.compilerPaths[SourceLanguage.Python] = curPath + "/compilers";
            }

            _shell = new DebuggerShell(settings);

            // initialize a logger
            var log = new SynkServer.Core.Logger();

            var server = new HTTPServer(log, serverSettings);

            var templateEngine = new TemplateEngine(server, "../views");

            // instantiate a new site, the second argument is the file path where the public site contents will be found
            var site = new Site(server, "../public");

            LoadContract(curPath + "/contracts/DefaultContract.cs");

            site.Get("/", (request) =>
            {
                var context = GetContext();

                return(templateEngine.Render(site, context, new string[] { "index" }));
            });

            site.Post("/switch", (request) =>
            {
                var code = request.args["code"];
                projectFiles[this.activeDocumentID].content = code;

                this.activeDocumentID = request.args["id"];

                var context = GetContext();

                return("ok");
            });

            site.Get("/content", (request) =>
            {
                var content = projectFiles[activeDocumentID].content;
                return(content);
            });

            site.Get("/breakpoint/list", (request) =>
            {
                var breakpoints = projectFiles[activeDocumentID].breakpoints;
                var node        = DataNode.CreateArray();
                foreach (var line in breakpoints)
                {
                    var item = DataNode.CreateValue(line);
                    node.AddNode(item);
                }
                return(node);
            });

            site.Post("/breakpoint/add", (request) =>
            {
                int line = int.Parse(request.args["line"]);

                var breakpoints = projectFiles[activeDocumentID].breakpoints;
                breakpoints.Add(line);

                return("ok");
            });

            site.Post("/breakpoint/remove", (request) =>
            {
                int line = int.Parse(request.args["line"]);

                var breakpoints = projectFiles[activeDocumentID].breakpoints;
                breakpoints.Remove(line);

                return("ok");
            });

            site.Post("/compile", (request) =>
            {
                var code = request.args["code"];
                request.session.Set("code", code);

                if (Compile(serverSettings, code))
                {
                    return("OK");
                }

                return("FAIL");
            });

            site.Post("/shell", (request) =>
            {
                var input  = request.args["input"];
                var output = new StringBuilder();

                _shell.Execute(input, (type, text) =>
                {
                    output.AppendLine(text);
                });

                return(output.ToString());
            });

            server.Run();
        }