Example #1
0
        private bool ProcessInternalCommand(string command)
        {
            if (command == "cls")
            {
                Shell.Clear();
            }
            else if (command == "history")
            {
                string[]      commands      = Shell.GetCommandHistory();
                StringBuilder stringBuilder = new StringBuilder(commands.Length);
                foreach (string s in commands)
                {
                    stringBuilder.Append(s);
                    stringBuilder.Append(System.Environment.NewLine);
                }
                Shell.WriteText(stringBuilder.ToString());
            }
            else if (command == "help")
            {
                Shell.WriteText(GetHelpText());
            }
            //else if (command.StartsWith("prompt"))
            //{
            //    string[] parts = command.Split(new char[] { '=' });
            //    if (parts.Length == 2 && parts[0].Trim() == "prompt")
            //        Shell.Prompt = parts[1].Trim();
            //}
            else if (command.Equals("switch", StringComparison.CurrentCultureIgnoreCase))
            {
            }
            else
            {
                //command += "Application.";
                MethodInfo minfo = typeof(Netron.Cobalt.Application).GetMethod(command);
                if (minfo != null)
                {
                    minfo.Invoke(null, new object[] { "There you go" });
                }
                else
                {
                    PropertyInfo pinfo = typeof(Netron.Cobalt.Application).GetProperty(command);
                    if (pinfo != null)
                    {
                        Shell.WriteText(pinfo.GetValue(null, new object[] { }).ToString());
                    }
                }

                return(false);
            }

            return(true);
        }
Example #2
0
        public void HandleConsole(ShellControl shell, Command cmd)
        {
            switch (cmd.Name)
            {
            case "help":
                Shell.WriteLine("Here are some Commands");
                foreach (var c in ConsolePage.Tools)
                {
                    var spl = c.HelpText.Split('|');
                    foreach (var ht in spl)
                    {
                        Shell.WriteLine(ht);
                    }
                }

                break;

            case "save":
                var sg = ServiceLocator.Get <SavedGame>("SavedGame");
                sg.Save();

                Shell.WriteLine("Successfully saved");

                break;

            case "load":
                var sg2 = ServiceLocator.Add("SavedGame", SavedGame.Load());
                ServiceLocator.CallEvent("Loaded", sg2);

                Shell.WriteLine("Successfully loaded");

                break;

            case "echo":
                Shell.WriteLine(cmd.Args[0]);

                break;

            case "cls":
                Shell.Clear();

                break;

            case "shutdown":
                Application.Exit();

                break;

            case "info":
                Shell.WriteLine(ServiceLocator._("Name:") + " " + ServiceLocator.Get <SavedGame>("SavedGame").Computer.Name);
                Shell.WriteLine(ServiceLocator._("Language:") + " " + ServiceLocator.Get <SavedGame>("SavedGame").Locale);
                break;

            case "settings":
                switch (cmd.Args[0])
                {
                case "language":
                    var sg3 = ServiceLocator.Get <SavedGame>("SavedGame");

                    sg3.Locale = cmd.Args[1];
                    CultureInfo.CurrentUICulture = new CultureInfo(sg3.Locale);

                    ServiceLocator.LoadLocale();


                    break;

                default:
                    break;
                }

                break;
            }
        }