Ejemplo n.º 1
0
        /// <summary>
        /// runs in current thread
        /// </summary>
        /// <param name="args"></param>
        public static void Run(string[] args)
        {
            //if (args.Length == 0) args = new string[] { /*"--httpd", "--aiml",*/ "Nephrael", "Rae" };
            //if (args.Length == 0) args = new string[] { "--httpd", "--aiml", "Zeno", "Aironaut" };
            //if (args.Length == 0) args = new string[] { "--httpd", "--aiml", "test", "suite" };
            //if (args.Length == 0) args = new string[] { "--aiml", "kotoko", "irata", "--servitor" };
            //if (args.Length == 0) args = new string[] { "--httpd", "--aiml", "BinaBot", "Daxeline" };

            //if (args.Length == 0) args = new string[] { "--swipl" };


            var orig = args;

            args = ProgramUtil.SetAllCommandLineOptions(args);

            string[] oArgs;
            if (ClientManagerConfig.arguments.GetAfter("--aiml", out oArgs))
            {
                string[] newArgs = oArgs;
                ProgramUtil.AllocConsole();
                RunType("AltAIMLbot:AltAIMLbot.AltBot", args);
                return;
            }
            if (ClientManagerConfig.arguments.GetAfter("--plwin", out oArgs))
            {
                ProgramUtil.DoAndExit(() =>
                {
                    var firstProc = new System.Diagnostics.Process();
                    firstProc.StartInfo.FileName  = @"c:\Program Files\pl\bin\swipl-win.exe";
                    firstProc.StartInfo.Arguments = "-f prolog/cogbot.pl";// "-f StartCogbot.pl";

                    firstProc.EnableRaisingEvents = true;
                    ProgramUtil.AllocConsole();
                    firstProc.Start();
                    firstProc.WaitForExit();
                });
                return;
            }
            if (ClientManagerConfig.arguments.GetAfter("--swipl", out oArgs))
            {
                string[] newArgs = oArgs;
                if (newArgs.Length == 0)
                {
                    newArgs = new string[] { "-f", "cynd/cogbot.pl" }
                }
                ;
                RunType("PrologBotModule:PrologScriptEngine.PrologScriptInterpreter", newArgs);
                return;
            }
            string newDir;

            if (ClientManagerConfig.arguments.TryGetValueWithout("--main", out newDir, true, out oArgs))
            {
                string[] newArgs = oArgs;
                RunType(newDir, newArgs);
                return;
            }

            DoAndExit(() => ConsoleApp.Main(args));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Non Blocking
        /// </summary>
        /// <param name="args"></param>
        public static void Start(string[] args)
        {
            string[] args0;
            var      state = GetApartmentState(args, out args0);

            args = args0;
            ProgramUtil.RunInThread(state, () => Run(args), false);
        }
Ejemplo n.º 3
0
        private static void RunType(Type t, string[] newArgs)
        {
            if (ProgramUtil.ChangeLCD)
            {
                ProgramUtil.SetCurrentDirectory(t);
            }
            MethodInfo mi = t.GetMethod("Main", new Type[] { typeof(string[]) });

            if (mi != null)
            {
                DoAndExit(() => mi.Invoke(null, new object[] { newArgs }));
                return;
            }
            mi = t.GetMethod("Main", new Type[] { });
            if (mi != null)
            {
                DoAndExit(() => mi.Invoke(null, new object[] { }));
                return;
            }
            var mainOrRun = new List <string>(new[] { "main", "run", "start", "exec" });

            foreach (var s in t.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public))
            {
                if (mainOrRun.Contains(s.Name.ToLower()))
                {
                    var ps = s.GetParameters();
                    if (ps.Length == 0)
                    {
                        DoAndExit(() => s.Invoke(null, new object[] {}));
                        return;
                    }
                    if (ps.Length == 1)
                    {
                        DoAndExit(() => s.Invoke(null, new object[] { newArgs }));
                        return;
                    }
                }
            }
            throw new MethodAccessException("No main for " + t);
        }
Ejemplo n.º 4
0
 public static void DoAndExit(ThreadStart o)
 {
     ProgramUtil.DoAndExit(o);
 }