Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                showUsage();
            }
            else
            {
                ScriptConfig config = null;
                try
                {
                    config = ScriptConfig.Parse(args);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("invalid parameter");
                    Console.WriteLine(ex.Message);
                    showUsage();
                    Console.WriteLine("Press any key to exit");
                    Console.Read();
                    return;
                }
                JavaScriptHostingConfig hostingConfig = new JavaScriptHostingConfig();
                hostingConfig
                .AddPlugin <SysInfoPluginInstaller>()
                .AddModuleFolder(config.RootFolder)
                .AddPlugin(new EchoProvider(new Echo()))
                .AddModuleFolderFromCurrentAssembly()
                .EnableHosting((moduleName) => { return(hostingConfig); })
                ;

                string script = File.ReadAllText(config.File);
                Console.WriteLine("---Script Start---");
                if (config.IsModule)
                {
                    var app = JavaScriptHosting.Default.GetModuleClass <JSApp>(config.FileName, config.ModuleClass, hostingConfig);
                    app.EntryPoint = config.ModuleEntryPoint;
                    app.Run();
                }
                else
                {
                    JavaScriptHosting.Default.RunScript(script, hostingConfig);
                }
            }

            Console.WriteLine("Press Enter to exit");
            Console.Read();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            CancellationTokenSource debugCTS = null;
            ScriptConfig            config   = null;
            JSApp app = null;

            if (args.Length == 0)
            {
                showUsage();
                return;
            }
            else
            {
                try
                {
                    config = ScriptConfig.Parse(args);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("invalid parameter");
                    Console.WriteLine(ex.Message);
                    showUsage();
                    Console.WriteLine("Press any key to exit");
                    Console.Read();
                    return;
                }
                JavaScriptHostingConfig hostingConfig = new JavaScriptHostingConfig();

                hostingConfig
                .AddPlugin <SysInfoPluginInstaller>()
                .AddModuleFolder(config.RootFolder)
                .AddPlugin(new EchoProvider(new Echo()))
                .AddModuleFolderFromCurrentAssembly()
                .EnableHosting((moduleName) => { return(hostingConfig); })
                ;
                if (config.DebugMode)
                {
                    debugCTS = new CancellationTokenSource();
                    var adapter = new VSCodeDebugAdapter(true);//wait for launch command from VSCode, user can reconnect with attach command after launch debug is done
                    //var adapter = new VSCodeDebugAdapter(false);//start program, wait for attach command from VSCode
                    adapter.OnLaunch         += (sender, arguments) => { Console.WriteLine($"Launch requested,arguments={arguments}"); };
                    adapter.OnAttach         += (sender, arguments) => { Console.WriteLine($"Attach requested,arguments={arguments}"); };
                    adapter.OnAdapterMessage += (sender, msg) => { Console.WriteLine(msg); };
                    adapter.OnStatusChang    += (sender, e) => { Console.WriteLine(e); };
                    adapter.RunServer(3515, debugCTS.Token);
                    //adapter.RunClient(3515, debugCTS.Token);
                    hostingConfig.DebugAdapter = adapter;
                }

                if (config.IsModule)
                {
                    app            = JavaScriptHosting.Default.GetModuleClass <JSApp>(config.FileName, config.ModuleClass, hostingConfig);
                    app.EntryPoint = config.ModuleEntryPoint;
                    app.Run();
                }
                else
                {
                    string script = File.ReadAllText(config.File);
                    Console.WriteLine("---Script Start---");
                    JavaScriptHosting.Default.RunScript(script, hostingConfig);
                }
            }
            if (config.IsModule)
            {
                while (true)
                {
                    Console.WriteLine("input \"exit\" to exit, anything else to run the module again");
                    string command = Console.ReadLine();
                    if (command.ToLower() == "exit")
                    {
                        break;
                    }
                    app.Run();
                }
            }
            else
            {
                Console.WriteLine("Press Enter to exit");
                Console.Read();
            }



            debugCTS?.Cancel();
        }