Пример #1
0
        public int Run(string[] args)
        {
            var app = new CommandLineApplication(false)
            {
                Name        = "Prospect code generator",
                Description = "Runs different methods as dnx commands to help you to create some of picies of code",
            };

            var help       = app.HelpOption("-?|--help");
            var csharp     = app.Option("-c|--csharp", "C# code generarion", CommandOptionType.NoValue);
            var typeScript = app.Option("-t|--typescript", "TypeScript code generarion", CommandOptionType.NoValue);

            CustomRunners.ForEach(item =>
            {
                item.Command = app.Option($"-{item.TemplateShort}|--{item.TemplateLong}", item.Description, CommandOptionType.NoValue);
            });

            app.OnExecute(() =>
            {
                if (csharp.HasValue())
                {
                    Runner = new CSharpRunner();
                    return(Runner.Run());
                }

                if (typeScript.HasValue())
                {
                    Runner = new TypeScriptRunner();
                    return(Runner.Run());
                }

                foreach (var item in CustomRunners)
                {
                    if (item.Command.HasValue())
                    {
                        Runner = (BaseRunner)Activator.CreateInstance(item.RunnerType);
                        return(Runner.Run());
                    }
                }

                app.ShowHelp();
                return(0);
            });

            return(app.Execute(args));
        }
Пример #2
0
        public int Run(string[] args)
        {
            var app = new CommandLineApplication(false)
            {
                Name        = "Prospect code generator",
                Description = "Runs different methods as dnx commands to help you to create some of picies of code",
            };

            var help       = app.HelpOption("-?|--help");
            var angular    = app.Option("-a|--angular", "Angular code generation", CommandOptionType.NoValue);
            var csharp     = app.Option("-c|--csharp", "C# code generarion", CommandOptionType.NoValue);
            var typeScript = app.Option("-t|--typescript", "TypeScript code generarion", CommandOptionType.NoValue);

            app.OnExecute(() => {
                //if (csharp.HasValue())
                //{
                var runner = new CSharpRunner();
                return(runner.Run());
                //}

                //if (angular.HasValue())
                //{
                //	var runner = new AngularRunner();
                //	return runner.Run(args);
                //}

                //if (typeScript.HasValue())
                //{
                //	var runner = new TypeScriptRunner();
                //	return runner.Run();
                //}

                //app.ShowHelp();
                //return 0;
            });

            return(app.Execute(args));
        }
Пример #3
0
        public override void Update()
        {
            if (csharp) //C# compiled script
            {
                //Initialize thread on first update
                if (thread == null)
                {
                    tpause = new ManualResetEvent(false);
                    thread = new Thread(() =>
                    {
                        try
                        {
                            CSharpRunner.Run(this, tpause, lines, args, localVars);
                        }
                        catch (CSharpException e)
                        {
                            string errorMessage = "Script '" + file + "' failed to run (" + e.ExceptionType + ").";
                            LogToConsole(errorMessage);
                            if (owner != null)
                            {
                                SendPrivateMessage(owner, errorMessage);
                            }
                            LogToConsole(e.InnerException);
                        }
                    });
                    thread.Start();
                }

                //Let the thread run for a short span of time
                if (thread != null)
                {
                    tpause.Set();
                    tpause.Reset();
                    if (!thread.IsAlive)
                    {
                        UnloadBot();
                    }
                }
            }
            else //Classic MCC script interpreter
            {
                if (sleepticks > 0)
                {
                    sleepticks--;
                }
                else
                {
                    if (nextline < lines.Length)                          //Is there an instruction left to interpret?
                    {
                        string instruction_line = lines[nextline].Trim(); // Removes all whitespaces at start and end of current line
                        nextline++;                                       //Move the cursor so that the next time the following line will be interpreted

                        if (instruction_line.Length > 1)
                        {
                            if (instruction_line[0] != '#' && instruction_line[0] != '/' && instruction_line[1] != '/')
                            {
                                instruction_line = Settings.ExpandVars(instruction_line, localVars);
                                string instruction_name = instruction_line.Split(' ')[0];
                                switch (instruction_name.ToLower())
                                {
                                case "wait":
                                    int ticks = 10;
                                    try
                                    {
                                        ticks = Convert.ToInt32(instruction_line.Substring(5, instruction_line.Length - 5));
                                    }
                                    catch { }
                                    sleepticks = ticks;
                                    break;

                                default:
                                    if (!PerformInternalCommand(instruction_line))
                                    {
                                        Update();     //Unknown command : process next line immediately
                                    }
                                    else if (instruction_name.ToLower() != "log")
                                    {
                                        LogToConsole(instruction_line);
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                Update();
                            }                  //Comment: process next line immediately
                        }
                    }
                    else
                    {
                        //No more instructions to interpret
                        UnloadBot();
                    }
                }
            }
        }