Esempio n. 1
0
        public void ExecuteCommand(Extension.IEnsoService service, Command command)
        {
            Logging.AddActionLog(string.Format("CommandsManager: Executing command '{0}' ...", command.Name));

            if (command.Name == "repeat")
            {
                Logging.AddActionLog(string.Format("CommandsManager: Repeating last command: {0}", CommandsHistory.GetLast().caption));
                CommandsHistory.GetLast().Execute(service);
            }
            else
            if (command.Name == "remove" || command.Name == "forget")
            {
                command.parametersOnExecute[0].GetProvider().Remove(command.parametersOnExecute[0]);
                Logging.AddActionLog(string.Format("CommandsManager: Command '{0}' removed.", command.parametersOnExecute[0].GetCaption()));
                MessagesHandler.Display(string.Format("{0} removed.", command.parametersOnExecute[0].GetCaption()));
            }
            else
            if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]")
            {
                MessagesHandler.Display(string.Format("Executing {0} ...", command.Name));
            }
            else
            {
                throw new ApplicationException(string.Format("HistoryManager: Command not found. Command: {0} {1}", command.Name, command.Postfix));
            }
        }
Esempio n. 2
0
        public void PopTest()
        {
            var c1 = new TestCommand("1");
            var c2 = new TestCommand("2");
            var c3 = new TestCommand("3");
            var ch = new CommandsHistory();

            ch.Push(c1);
            ch.Push(c2);
            ch.Push(c3);

            Assert.Equal(c3, ch.Pop());
            Assert.Equal(c2, ch.Pop());
            Assert.Equal(c1, ch.Pop());
        }
Esempio n. 3
0
        public void CantMoveForward()
        {
            var c1 = new TestCommand("1");
            var c2 = new TestCommand("2");
            var c3 = new TestCommand("3");
            var ch = new CommandsHistory();

            ch.Push(c1);
            ch.Push(c2);
            ch.Push(c3);

            var moved = ch.TryMoveForward(out var actual);

            Assert.False(moved);
            Assert.Equal(null, actual);
        }
Esempio n. 4
0
        private void UpdateHistory()
        {
            try
            {
                HistoryListBox.Items.Clear();

                var history = new CommandsHistory(CompanyName).Load();
                foreach (var command in history)
                {
                    HistoryListBox.Items.Add(command);
                }
            }
            catch (Exception exception)
            {
                OnExceptionOccurred(exception);
            }
        }
Esempio n. 5
0
        public static void Run()
        {
            var history  = new CommandsHistory();
            var document = new HtmlDocument();

            document.Content = "Hello World!";

            var boldCommand = new BoldCommand(document, history);

            boldCommand.Execute();

            Console.WriteLine(document.Content);

            var undoCommand = new UndoCommand(history);

            undoCommand.Execute();

            Console.WriteLine(document.Content);
        }
Esempio n. 6
0
        public void ClearingUnusedItems()
        {
            var c1 = new TestCommand("1");
            var c2 = new TestCommand("2");
            var c3 = new TestCommand("3");
            var c4 = new TestCommand("4");
            var ch = new CommandsHistory();

            ch.Push(c1);
            ch.Push(c2);
            ch.Push(c3);
            ch.Push(c4);

            ch.Pop();
            ch.Pop();
            ch.Pop();
            ch.Push(c4);

            Assert.Equal(c4, ch.Pop());
        }
Esempio n. 7
0
        private Hashtable GetCommands(GameSession gameSession)
        {
            // TODO: Split for two functions 1. - Get commands from API 2. Get unfinished commands
            Hashtable result;

            _logger.Debug($"Turn {gameSession.Turn}. Commands count is {gameSession.Commands.Count}");


            lock (Commands)
            {
                result = Commands.DeepClone();

                foreach (Command command in Commands.Values)
                {
                    CommandsHistory.Add(command.DeepClone());
                }

                Commands = new Hashtable();

                foreach (Command command in gameSession.Commands.Values)
                {
                    if (command.UntilTurnId <= gameSession.Turn)
                    {
                        continue;
                    }

                    var commandKey = gameSession.Id + "_" + command.CelestialObjectId + "_" + command.Type;

                    _logger.Info($"Turn {gameSession.Turn} resume command execution. {command.Type}");

                    result.Add(commandKey, command);
                }

                _logger.Debug($"Finished clear turn commands. Count is {result.Count}");
            }

            return(result);
        }
Esempio n. 8
0
        public static String ReadLine()
        {
            var xConsole = GetConsole();

            if (xConsole == null)
            {
                // for now:
                return(null);
            }
            List <char> chars = new List <char>(32);
            KeyEvent    current;

            int currentCount = 0;

            bool firstdown = false;

            string CMDToComplete = "";

            xConsole.CursorVisible = true;

            while ((current = KeyboardManager.ReadKey()).Key != ConsoleKeyEx.Enter)
            {
                if (current.Key == ConsoleKeyEx.NumEnter)
                {
                    break;
                }
                //Check for "special" keys
                if (current.Key == ConsoleKeyEx.Backspace) // Backspace
                {
                    CMDToComplete = "";
                    if (currentCount > 0)
                    {
                        int curCharTemp = GetConsole().X;
                        chars.RemoveAt(currentCount - 1);
                        GetConsole().X = GetConsole().X - 1;

                        //Move characters to the left
                        for (int x = currentCount - 1; x < chars.Count; x++)
                        {
                            Write(chars[x]);
                        }

                        Write(' ');

                        GetConsole().X = curCharTemp - 1;

                        currentCount--;
                    }
                    else
                    {
                        Aura_OS.Kernel.speaker.beep();
                    }
                    continue;
                }
                else if (current.Key == ConsoleKeyEx.LeftArrow)
                {
                    if (currentCount > 0)
                    {
                        GetConsole().X = GetConsole().X - 1;
                        currentCount--;
                    }
                    continue;
                }
                else if (current.Key == ConsoleKeyEx.RightArrow)
                {
                    if (currentCount < chars.Count)
                    {
                        GetConsole().X = GetConsole().X + 1;
                        currentCount++;
                    }
                    continue;
                }
                else if (current.Key == ConsoleKeyEx.Tab)
                {
                    if (currentCount >= 1)
                    {
                        int index = -1;

                        foreach (char ch in chars)
                        {
                            CMDToComplete = CMDToComplete + ch.ToString();
                        }

                        foreach (string c in CommandManager.CMDs)
                        {
                            index++;
                            if (c.StartsWith(CMDToComplete))
                            {
                                CommandsHistory.ClearCurrentConsoleLine();
                                currentCount = 0;
                                chars.Clear();

                                Aura_OS.Kernel.BeforeCommand();

                                foreach (char chr in c)
                                {
                                    chars.Add(chr);
                                    Write(chr);
                                    currentCount++;
                                }
                            }
                        }
                        continue;
                    }
                }
                else if (current.Key == ConsoleKeyEx.C && KeyboardManager.ControlPressed)
                {
                    CMDToComplete = "";
                    if (Aura_OS.Kernel.AConsole.writecommand)
                    {
                        CommandsHistory.ClearCurrentConsoleLine();
                        currentCount = 0;
                        chars.Clear();

                        Aura_OS.Kernel.BeforeCommand();
                    }
                }
                else if (current.Key == ConsoleKeyEx.UpArrow) //COMMAND HISTORY UP
                {
                    if (Aura_OS.Kernel.AConsole.writecommand) //IF SHELL
                    {
                        CMDToComplete = "";
                        if (CommandsHistory.CHIndex >= 0)
                        {
                            CommandsHistory.ClearCurrentConsoleLine();
                            currentCount = 0;
                            chars.Clear();

                            Aura_OS.Kernel.BeforeCommand();

                            string Command = Aura_OS.Kernel.AConsole.commands[CommandsHistory.CHIndex];
                            CommandsHistory.CHIndex = CommandsHistory.CHIndex - 1;

                            foreach (char chr in Command)
                            {
                                if (currentCount == chars.Count)
                                {
                                    chars.Add(chr);
                                    Write(chr);
                                    currentCount++;
                                }
                                else
                                {
                                    //Insert the new character in the correct location
                                    //For some reason, List.Insert() doesn't work properly
                                    //so the character has to be inserted manually
                                    List <char> temp = new List <char>();

                                    for (int x = 0; x < chars.Count; x++)
                                    {
                                        if (x == currentCount)
                                        {
                                            temp.Add(chr);
                                        }

                                        temp.Add(chars[x]);
                                    }

                                    chars = temp;

                                    //Shift the characters to the right
                                    for (int x = currentCount; x < chars.Count; x++)
                                    {
                                        Write(chars[x]);
                                    }

                                    Aura_OS.Kernel.AConsole.X -= (chars.Count - currentCount) - 1;
                                    currentCount++;
                                }
                            }
                        }
                    }
                    continue;
                }
                else if (current.Key == ConsoleKeyEx.DownArrow) //COMMAND HISTORY UP
                {
                    if (Aura_OS.Kernel.AConsole.writecommand)   //IF SHELL
                    {
                        CMDToComplete = "";
                        if (CommandsHistory.CHIndex < Aura_OS.Kernel.AConsole.commands.Count - 1)
                        {
                            CommandsHistory.ClearCurrentConsoleLine();
                            currentCount = 0;
                            chars.Clear();

                            Aura_OS.Kernel.BeforeCommand();

                            CommandsHistory.CHIndex = CommandsHistory.CHIndex + 1;

                            if (!firstdown)
                            {
                                CommandsHistory.CHIndex = CommandsHistory.CHIndex + 1;
                                firstdown = true;
                            }

                            string Command = Aura_OS.Kernel.AConsole.commands[CommandsHistory.CHIndex];

                            foreach (char chr in Command)
                            {
                                if (currentCount == chars.Count)
                                {
                                    chars.Add(chr);
                                    Write(chr);
                                    currentCount++;
                                }
                                else
                                {
                                    //Insert the new character in the correct location
                                    //For some reason, List.Insert() doesn't work properly
                                    //so the character has to be inserted manually
                                    List <char> temp = new List <char>();

                                    for (int x = 0; x < chars.Count; x++)
                                    {
                                        if (x == currentCount)
                                        {
                                            temp.Add(chr);
                                        }

                                        temp.Add(chars[x]);
                                    }

                                    chars = temp;

                                    //Shift the characters to the right
                                    for (int x = currentCount; x < chars.Count; x++)
                                    {
                                        Write(chars[x]);
                                    }

                                    Aura_OS.Kernel.AConsole.X -= (chars.Count - currentCount) - 1;
                                    currentCount++;
                                }
                            }
                        }
                    }
                    continue;
                }

                if (current.KeyChar == '\0')
                {
                    continue;
                }

                //Write the character to the screen
                if (currentCount == chars.Count)
                {
                    chars.Add(current.KeyChar);
                    Write(current.KeyChar);
                    currentCount++;
                }
                else
                {
                    //Insert the new character in the correct location
                    //For some reason, List.Insert() doesn't work properly
                    //so the character has to be inserted manually
                    List <char> temp = new List <char>();

                    for (int x = 0; x < chars.Count; x++)
                    {
                        if (x == currentCount)
                        {
                            temp.Add(current.KeyChar);
                        }

                        temp.Add(chars[x]);
                    }

                    chars = temp;

                    //Shift the characters to the right
                    for (int x = currentCount; x < chars.Count; x++)
                    {
                        Write(chars[x]);
                    }

                    GetConsole().X -= (chars.Count - currentCount) - 1;
                    currentCount++;
                }
            }
            WriteLine();

            xConsole.CursorVisible = false;

            char[] final = chars.ToArray();
            return(new string(final));
        }
Esempio n. 9
0
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            #region Power

            if (cmd.Equals("shutdown"))
            {//NOTE: Why isn't it just the constructor? This leaves more room for <package>.<class>.HelpInfo;
                Power.Shutdown.c_Shutdown();
            }
            else if (cmd.Equals("reboot"))
            {
                Power.Reboot.c_Reboot();
            }

            #endregion Power

            #region Console

            else if ((cmd.Equals("clear")) || (cmd.Equals("cls")))
            {
                c_Console.Clear.c_Clear();
            }
            else if (cmd.StartsWith("echo "))
            {
                c_Console.Echo.c_Echo(cmd);
            }
            else if (cmd.Equals("help"))
            {
                System.Translation.List_Translation._Help();
            }

            #endregion Console

            #region FileSystem

            else if (cmd.StartsWith("cd "))
            {
                FileSystem.CD.c_CD(cmd);
            }
            else if (cmd.Equals("cp"))
            {
                FileSystem.CP.c_CP_only();
            }
            else if (cmd.StartsWith("cp "))
            {
                FileSystem.CP.c_CP(cmd);
            }
            else if ((cmd.Equals("dir")) || (cmd.Equals("ls")))
            {
                FileSystem.Dir.c_Dir();
            }
            else if ((cmd.StartsWith("dir ")) || (cmd.StartsWith("ls ")))
            {
                FileSystem.Dir.c_Dir(cmd);
            }
            else if (cmd.Equals("mkdir"))
            {
                FileSystem.Mkdir.c_Mkdir();
            }
            else if (cmd.StartsWith("mkdir "))
            {
                FileSystem.Mkdir.c_Mkdir(cmd);
            }
            else if (cmd.StartsWith("rmdir "))
            {
                FileSystem.Rmdir.c_Rmdir(cmd);
            }//TODO: orgainize
            else if (cmd.StartsWith("rmfil "))
            {
                FileSystem.Rmfil.c_Rmfil(cmd);
            }
            else if (cmd.Equals("mkfil"))
            {
                FileSystem.Mkfil.c_mkfil();
            }
            else if (cmd.StartsWith("mkfil "))
            {
                FileSystem.Mkfil.c_mkfil(cmd);
            }
            else if (cmd.StartsWith("edit "))
            {
                FileSystem.Edit.c_Edit(cmd);
            }
            else if (cmd.Equals("vol"))
            {
                FileSystem.Vol.c_Vol();
            }
            else if (cmd.StartsWith("run "))
            {
                FileSystem.Run.c_Run(cmd);
            }

            #endregion FileSystem

            #region Settings

            else if (cmd.Equals("logout"))
            {
                Settings.Logout.c_Logout();
            }
            else if (cmd.Equals("settings"))
            {
                Settings.Settings.c_Settings();
            }
            else if (cmd.StartsWith("settings "))
            {
                Settings.Settings.c_Settings(cmd);
            }
            else if (cmd.StartsWith("passwd "))
            {
                Settings.Passwd.c_Passwd(cmd);
            }
            else if (cmd.Equals("passwd"))
            {
                Settings.Passwd.c_Passwd(Kernel.userLogged);
            }

            #endregion Settings

            #region System Infomation

            else if (cmd.Equals("systeminfo"))
            {
                SystemInfomation.SystemInfomation.c_SystemInfomation();
            }
            else if ((cmd.Equals("ver")) || (cmd.Equals("version")))
            {
                SystemInfomation.Version.c_Version();
            }
            else if ((cmd.Equals("ipconfig")) || (cmd.Equals("ifconfig")) || (cmd.Equals("netconf")))
            {
                SystemInfomation.IPConfig.c_IPConfig();
            }
            else if ((cmd.Equals("time")) || (cmd.Equals("date")))
            {
                SystemInfomation.Time.c_Time();
            }

            #endregion System Infomation

            #region Tests

            else if (cmd.Equals("crash"))
            {
                Tests.Crash.c_Crash();
            }

            else if (cmd.Equals("cmd"))
            {
                CMDs.Add("ipconfig");
                CMDs.Add("netconf");
                CMDs.Add("help");
            }

            else if (cmd.Equals("crashcpu"))
            {
                int value = 1;
                value = value - 1;
                int result = 1 / value; //Division by 0
            }

            else if (cmd.Equals("beep"))
            {
                Kernel.speaker.beep();
            }

            else if (cmd.Equals("play"))
            {
                Kernel.speaker.playmusic();
            }

            //else if (cmd.StartsWith("xml "))
            //{
            //    Util.xml.CmdXmlParser.c_CmdXmlParser(cmd, 0, 4);
            //}

            #endregion Tests

            #region Tools

            else if (cmd.Equals("snake"))
            {
                Tools.Snake.c_Snake();
            }
            else if (cmd.StartsWith("md5"))
            {
                Tools.MD5.c_MD5(cmd);
            }
            else if (cmd.StartsWith("sha256"))
            {
                Tools.SHA256.c_SHA256(cmd);
            }

            #endregion

            #region Util

            else if (cmd.StartsWith("export"))
            {
                Util.EnvVar.c_Export(cmd);
            }

            else if (cmd.Equals("lspci"))
            {
                Util.Lspci.c_Lspci();
            }

            else if (cmd.Equals("about"))
            {
                Util.About.c_About();
            }

            else
            {
                if (cmd.Length <= 0)
                {
                    Console.WriteLine();
                    return;
                }
                else
                {
                    Util.CmdNotFound.c_CmdNotFound();
                }
            }

            CommandsHistory.Add(cmd); //adding last command to the commands history

            Console.WriteLine();

            #endregion Util
        }
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            CommandsHistory.Add(cmd); //adding last command to the commands history

            if (cmd.Length <= 0)
            {
                Console.WriteLine();
                return;
            }

            #region Parse command

            List <string> arguments = Misc.ParseCommandLine(cmd);

            string firstarg = arguments[0]; //command name

            if (arguments.Count > 0)
            {
                arguments.RemoveAt(0); //get only arguments
            }

            #endregion

            foreach (var command in CMDs)
            {
                if (command.ContainsCommand(firstarg))
                {
                    ReturnInfo result;

                    if (arguments.Count > 0 && (arguments[0] == "/help" || arguments[0] == "/h"))
                    {
                        ShowHelp(command);
                        result = new ReturnInfo(command, ReturnCode.OK);
                    }
                    else
                    {
                        result = CheckCommand(command);

                        if (result.Code == ReturnCode.OK)
                        {
                            if (arguments.Count == 0)
                            {
                                result = command.Execute();
                            }
                            else
                            {
                                result = command.Execute(arguments);
                            }
                        }
                    }

                    ProcessCommandResult(result);

                    return;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkRed;
            L.Text.Display("UnknownCommand");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine();
        }
Esempio n. 11
0
 public List <Command> GetHistoryCommands(int sessionId, long Id)
 {
     return(CommandsHistory.Where(_ => _.CelestialObjectId == Id).ToList());
 }
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            if (Kernel.debugger != null)
            {
                if (Kernel.debugger.enabled)
                {
                    Kernel.debugger.Send("[Command] > " + cmd);
                }
            }

            #region Power

            if (cmd.Equals("shutdown") || cmd.Equals("sd"))
            {//NOTE: Why isn't it just the constructor? This leaves more room for <package>.<class>.HelpInfo;
                Power.Shutdown.c_Shutdown();
            }
            else if (cmd.Equals("reboot") || cmd.Equals("rb"))
            {
                Power.Reboot.c_Reboot();
            }

            #endregion Power

            #region Console

            else if ((cmd.Equals("clear")) || (cmd.Equals("cls")))
            {
                c_Console.Clear.c_Clear();
            }
            else if (cmd.StartsWith("echo "))
            {
                c_Console.Echo.c_Echo(cmd);
            }
            else if (cmd.Equals("help"))
            {
                System.Translation.List_Translation._Help();
            }

            #endregion Console

            #region FileSystem

            else if (cmd.StartsWith("cd "))
            {
                FileSystem.CD.c_CD(cmd);
            }
            else if (cmd.Equals("cp"))
            {
                FileSystem.CP.c_CP_only();
            }
            else if (cmd.StartsWith("cp "))
            {
                FileSystem.CP.c_CP(cmd);
            }
            else if ((cmd.Equals("dir")) || (cmd.Equals("ls")))
            {
                FileSystem.Dir.c_Dir();
            }
            else if ((cmd.StartsWith("dir ")) || (cmd.StartsWith("ls ")))
            {
                FileSystem.Dir.c_Dir(cmd);
            }
            else if (cmd.Equals("mkdir"))
            {
                FileSystem.Mkdir.c_Mkdir();
            }
            else if (cmd.StartsWith("mkdir "))
            {
                FileSystem.Mkdir.c_Mkdir(cmd);
            }
            else if (cmd.StartsWith("rmdir "))
            {
                FileSystem.Rmdir.c_Rmdir(cmd);
            }//TODO: orgainize
            else if (cmd.StartsWith("rmfil "))
            {
                FileSystem.Rmfil.c_Rmfil(cmd);
            }
            else if (cmd.Equals("mkfil"))
            {
                FileSystem.Mkfil.c_mkfil();
            }
            else if (cmd.StartsWith("mkfil "))
            {
                FileSystem.Mkfil.c_mkfil(cmd);
            }
            else if (cmd.StartsWith("edit "))
            {
                FileSystem.Edit.c_Edit(cmd);
            }
            else if (cmd.Equals("vol"))
            {
                FileSystem.Vol.c_Vol();
            }
            else if (cmd.StartsWith("run "))
            {
                FileSystem.Run.c_Run(cmd);
            }
            else if (cmd.StartsWith("cat"))
            {
                FileSystem.Cat.c_Cat(cmd);
            }

            #endregion FileSystem

            #region Settings

            else if (cmd.Equals("logout"))
            {
                Settings.Logout.c_Logout();
            }
            else if (cmd.Equals("settings"))
            {
                Settings.Settings.c_Settings();
            }
            else if (cmd.StartsWith("settings "))
            {
                Settings.Settings.c_Settings(cmd);
            }
            else if (cmd.StartsWith("passwd "))
            {
                Settings.Passwd.c_Passwd(cmd);
            }
            else if (cmd.Equals("passwd"))
            {
                Settings.Passwd.c_Passwd(Kernel.userLogged);
            }

            #endregion Settings

            #region System Infomation

            else if (cmd.Equals("systeminfo"))
            {
                SystemInfomation.SystemInfomation.c_SystemInfomation();
            }
            else if ((cmd.Equals("ver")) || (cmd.Equals("version")))
            {
                SystemInfomation.Version.c_Version();
            }
            else if ((cmd.StartsWith("ipconfig")) || (cmd.StartsWith("ifconfig")) || (cmd.StartsWith("netconf")))
            {
                SystemInfomation.IPConfig.c_IPConfig(cmd);
            }
            else if ((cmd.Equals("time")) || (cmd.Equals("date")))
            {
                SystemInfomation.Time.c_Time();
            }

            #endregion System Infomation

            #region Tests

            else if (cmd.Equals("crash"))
            {
                Tests.Crash.c_Crash();
            }

            else if (cmd.Equals("crashcpu"))
            {
                int value = 1;
                value = value - 1;
                int result = 1 / value; //Division by 0
            }

            else if (cmd.Equals("beep"))
            {
                Kernel.speaker.beep();
            }

            else if (cmd.Equals("play"))
            {
                Kernel.speaker.playmusic();
            }

            else if (cmd.Equals("udp"))
            {
                var xClient = new System.Network.IPV4.UDP.UdpClient(4242);
                xClient.Connect(new System.Network.IPV4.Address(192, 168, 1, 12), 4242);
                xClient.Send(Encoding.ASCII.GetBytes("Hello from Aura Operating System!"));
            }

            else if (cmd.Equals("tcp"))
            {
                var xClient = new System.Network.IPV4.TCP.TCPClient(4343);
                xClient.Connect(new System.Network.IPV4.Address(192, 168, 1, 12), 4224);
                xClient.Send(Encoding.ASCII.GetBytes("1"));
                xClient.Send(Encoding.ASCII.GetBytes("2"));
                xClient.Send(Encoding.ASCII.GetBytes("3"));
                xClient.Send(Encoding.ASCII.GetBytes("4"));
                xClient.Send(Encoding.ASCII.GetBytes("5"));
            }

            else if (cmd.Equals("haship"))
            {
                Console.WriteLine(new HAL.MACAddress(new byte[] { 00, 01, 02, 03, 04, 05 }).Hash);
                Console.WriteLine(new System.Network.IPV4.Address(192, 168, 1, 12).Hash);
            }

            else if (cmd.Equals("dns"))
            {
                System.Network.IPV4.UDP.DNS.DNSClient DNSRequest = new System.Network.IPV4.UDP.DNS.DNSClient(53);
                DNSRequest.Ask("perdu.com");
            }

            else if (cmd.Equals("net /refresh"))
            {
                foreach (HAL.Drivers.Network.NetworkDevice networkDevice in HAL.Drivers.Network.NetworkDevice.Devices)
                {
                    File.Create(@"0:\System\" + networkDevice.Name + ".conf");
                    Utils.Settings settings = new Utils.Settings(@"0:\System\" + networkDevice.Name + ".conf");
                    settings.Edit("ipaddress", "0.0.0.0");
                    settings.Edit("subnet", "0.0.0.0");
                    settings.Edit("gateway", "0.0.0.0");
                    settings.Edit("dns01", "0.0.0.0");
                    settings.Push();
                }
            }

            //else if (cmd.StartsWith("xml "))
            //{
            //    Util.xml.CmdXmlParser.c_CmdXmlParser(cmd, 0, 4);
            //}

            #endregion Tests

            #region Tools

            else if (cmd.Equals("snake"))
            {
                Tools.Snake.c_Snake();
            }
            else if (cmd.StartsWith("md5"))
            {
                Tools.MD5.c_MD5(cmd);
            }
            else if (cmd.StartsWith("sha256"))
            {
                Tools.SHA256.c_SHA256(cmd);
            }
            else if (cmd.StartsWith("ping"))
            {
                Network.Ping.c_Ping(cmd);
            }
            else if (cmd.Equals("debug"))
            {
                Tools.Debug.c_Debug();
            }
            else if (cmd.StartsWith("debug "))
            {
                Tools.Debug.c_Debug(cmd);
            }

            #endregion

            #region Util

            else if (cmd.StartsWith("export"))
            {
                Util.EnvVar.c_Export(cmd);
            }

            else if (cmd.Equals("lspci"))
            {
                Util.Lspci.c_Lspci();
            }

            else if (cmd.Equals("about"))
            {
                Util.About.c_About();
            }

            else
            {
                if (cmd.Length <= 0)
                {
                    Console.WriteLine();
                    return;
                }
                else if (cmd.Length == 2)
                {
                    FileSystem.ChangeVol.c_ChangeVol(cmd);
                }
                else
                {
                    Util.CmdNotFound.c_CmdNotFound();
                }
            }

            CommandsHistory.Add(cmd); //adding last command to the commands history

            Console.WriteLine();

            #endregion Util
        }
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            CommandsHistory.Add(cmd); //adding last command to the commands history

            if (cmd.Length <= 0)
            {
                Console.WriteLine();
                return;
            }

            List <string> arguments = Misc.ParseCommandLine(cmd);

            string firstarg = arguments[0]; //command name

            if (arguments.Count > 0)
            {
                arguments.RemoveAt(0); //get only arguments
            }

            foreach (var command in CMDs)
            {
                if (command.ContainsCommand(firstarg))
                {
                    ReturnInfo result;

                    if (arguments.Count == 0)
                    {
                        result = command.Execute();
                    }
                    else
                    {
                        result = command.Execute(arguments);
                    }

                    if (result.Code == ReturnCode.ERROR_ARG)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        L.Text.Display("invalidargcommand");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (result.Code == ReturnCode.ERROR)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("Error: " + result.Info);
                        Console.ForegroundColor = ConsoleColor.White;
                    }

                    Console.WriteLine();

                    return;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkRed;
            L.Text.Display("UnknownCommand");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine();

            /*
             *
             #region FileSystem
             *
             * else if (cmd.StartsWith("cd "))
             * {
             *  FileSystem.CD.c_CD(cmd);
             * }
             * else if (cmd.Equals("cp"))
             * {
             *  FileSystem.CP.c_CP_only();
             * }
             * else if (cmd.StartsWith("cp "))
             * {
             *  FileSystem.CP.c_CP(cmd);
             * }
             * else if ((cmd.Equals("dir")) || (cmd.Equals("ls")))
             * {
             *  FileSystem.Dir.c_Dir();
             * }
             * else if ((cmd.StartsWith("dir ")) || (cmd.StartsWith("ls ")))
             * {
             *  FileSystem.Dir.c_Dir(cmd);
             * }
             * else if (cmd.Equals("mkdir"))
             * {
             *  FileSystem.Mkdir.c_Mkdir();
             * }
             * else if (cmd.StartsWith("mkdir "))
             * {
             *  FileSystem.Mkdir.c_Mkdir(cmd);
             * }
             * else if (cmd.StartsWith("rmdir "))
             * {
             *  FileSystem.Rmdir.c_Rmdir(cmd);
             * }//TODO: orgainize
             * else if (cmd.StartsWith("rmfil "))
             * {
             *  FileSystem.Rmfil.c_Rmfil(cmd);
             * }
             * else if (cmd.Equals("mkfil"))
             * {
             *  FileSystem.Mkfil.c_mkfil();
             * }
             * else if (cmd.StartsWith("mkfil "))
             * {
             *  FileSystem.Mkfil.c_mkfil(cmd);
             * }
             * else if (cmd.StartsWith("edit "))
             * {
             *  FileSystem.Edit.c_Edit(cmd);
             * }
             * else if (cmd.Equals("vol"))
             * {
             *  FileSystem.Vol.c_Vol();
             * }
             * else if (cmd.StartsWith("run "))
             * {
             *  FileSystem.Run.c_Run(cmd);
             * }
             * else if (cmd.StartsWith("cat"))
             * {
             *  FileSystem.Cat.c_Cat(cmd);
             * }
             *
             #endregion FileSystem
             *
             #region Settings
             *
             * else if (cmd.Equals("logout"))
             * {
             *  Settings.Logout.c_Logout();
             * }
             * else if (cmd.Equals("settings"))
             * {
             *  Settings.Settings.c_Settings();
             * }
             * else if (cmd.StartsWith("settings "))
             * {
             *  Settings.Settings.c_Settings(cmd);
             * }
             * else if (cmd.StartsWith("passwd "))
             * {
             *  Settings.Passwd.c_Passwd(cmd);
             * }
             * else if (cmd.Equals("passwd"))
             * {
             *  Settings.Passwd.c_Passwd(Kernel.userLogged);
             * }
             *
             #endregion Settings
             *
             #region Tools
             *
             * else if (cmd.Equals("snake"))
             * {
             *  Tools.Snake.c_Snake();
             * }
             * else if (cmd.StartsWith("md5"))
             * {
             *  Tools.MD5.c_MD5(cmd);
             * }
             * else if (cmd.StartsWith("sha256"))
             * {
             *  Tools.SHA256.c_SHA256(cmd);
             * }
             * else if (cmd.Equals("debug"))
             * {
             *  Tools.Debug.c_Debug();
             * }
             * else if (cmd.StartsWith("debug "))
             * {
             *  Tools.Debug.c_Debug(cmd);
             * }
             *
             #endregion
             */
        }
        void InitializeCommandProcessor(string[] args, bool printInfo = true, CommandEvaluationContext commandEvaluationContext = null)
        {
            SetArgs(args);

            cons.ForegroundColor = DefaultForeground;
            cons.BackgroundColor = DefaultBackground;

            commandEvaluationContext = commandEvaluationContext ??
                                       new CommandEvaluationContext(
                this,
                Out,
                cons.In,
                Err,
                null
                );
            CommandEvaluationContext = commandEvaluationContext;

            if (printInfo)
            {
                PrintInfo(CommandEvaluationContext);
            }

            // assume the application folder ($env.APPDATA/OrbitalShell) exists and is initialized

            var lbr = false;

            // creates user app data folders
            if (!Directory.Exists(AppDataFolderPath))
            {
                LogAppendAllLinesErrorIsEnabled = false;
                Info(ColorSettings.Log + $"creating user shell folder: '{AppDataFolderPath}' ... ", false);
                try
                {
                    Directory.CreateDirectory(AppDataFolderPath);
                    Success();
                } catch (Exception createAppDataFolderPathException)
                {
                    Fail(createAppDataFolderPathException);
                }
                lbr = true;
            }

            // initialize log file
            if (!File.Exists(LogFilePath))
            {
                Info(ColorSettings.Log + $"creating log file: '{LogFilePath}' ... ", false);
                try
                {
                    var logError = Log($"file created on {System.DateTime.Now}");
                    if (logError == null)
                    {
                        Success();
                    }
                    else
                    {
                        throw logError;
                    }
                }
                catch (Exception createLogFileException)
                {
                    LogAppendAllLinesErrorIsEnabled = false;
                    Fail(createLogFileException);
                }
                lbr = true;
            }

            // initialize user profile
            if (!File.Exists(UserProfileFilePath))
            {
                Info(ColorSettings.Log + $"creating user profile file: '{UserProfileFilePath}' ... ", false);
                try
                {
                    var defaultProfileFilePath = Path.Combine(DefaultsFolderPath, UserProfileFileName);
                    File.Copy(defaultProfileFilePath, UserProfileFilePath);
                    Success();
                }
                catch (Exception createUserProfileFileException)
                {
                    Fail(createUserProfileFileException);
                }
                lbr = true;
            }

            // create/restore commands history
            CmdsHistory = new CommandsHistory();
            var createNewHistoryFile = !File.Exists(HistoryFilePath);

            if (createNewHistoryFile)
            {
                Info(ColorSettings.Log + $"creating user commands history file: '{HistoryFilePath}' ... ", false);
            }
            try
            {
                if (createNewHistoryFile)
#pragma warning disable CS0642 // Possibilité d'instruction vide erronée
                {
                    using (var fs = File.Create(HistoryFilePath));
                }
#pragma warning restore CS0642 // Possibilité d'instruction vide erronée
                CmdsHistory.Init(AppDataFolderPath, HistoryFileName);
                if (createNewHistoryFile)
                {
                    Success();
                }
            }
            catch (Exception createUserProfileFileException)
            {
                Fail(createUserProfileFileException);
            }
            lbr |= createNewHistoryFile;

            // create/restore user aliases
            CommandsAlias = new CommandsAlias();
            var createNewCommandsAliasFile = !File.Exists(CommandsAliasFilePath);
            if (createNewCommandsAliasFile)
            {
                Info(ColorSettings.Log + $"creating user commands aliases file: '{CommandsAliasFilePath}' ... ", false);
            }
            try
            {
                if (createNewCommandsAliasFile)
                {
                    var defaultAliasFilePath = Path.Combine(DefaultsFolderPath, CommandsAliasFileName);
                    File.Copy(defaultAliasFilePath, CommandsAliasFilePath);
                }
                if (createNewCommandsAliasFile)
                {
                    Success();
                }
            }
            catch (Exception createUserProfileFileException)
            {
                Fail(createUserProfileFileException);
            }
            lbr |= createNewHistoryFile;

            // end inits
            if (lbr)
            {
                Out.Echoln();
            }

            // load kernel commands
            RegisterCommandsAssembly(CommandEvaluationContext, Assembly.GetExecutingAssembly());
#if enable_test_commands
            RegisterCommandsClass <TestCommands>();
#endif
        }
Esempio n. 15
0
 public ShortcutsReader(Code code, CommandsHistory history)
 {
     this.code    = code;
     this.history = history;
 }
Esempio n. 16
0
        /// <summary>
        /// Shell Interpreter
        /// </summary>
        /// <param name="cmd">Command</param>
        public static void _CommandManger(string cmd)
        {
            CommandsHistory.Add(cmd); //adding last command to the commands history

            if (cmd.Length <= 0)
            {
                Console.WriteLine();
                return;
            }

            List <string> arguments = Misc.ParseCommandLine(cmd);

            string firstarg = arguments[0]; //command name

            if (arguments.Count > 0)
            {
                arguments.RemoveAt(0); //get only arguments
            }

            foreach (var command in CMDs)
            {
                if (command.ContainsCommand(firstarg))
                {
                    ReturnInfo result = DoCheck(command);

                    if (result.Code == ReturnCode.OK)
                    {
                        if (arguments.Count == 0)
                        {
                            result = command.Execute();
                        }
                        else
                        {
                            result = command.Execute(arguments);
                        }
                    }

                    if (result.Code == ReturnCode.ERROR_ARG)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        L.Text.Display("invalidargcommand");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (result.Code == ReturnCode.ERROR)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("Error: " + result.Info);
                        Console.ForegroundColor = ConsoleColor.White;
                    }

                    Console.WriteLine();

                    return;
                }
            }

            Console.ForegroundColor = ConsoleColor.DarkRed;
            L.Text.Display("UnknownCommand");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine();
        }