Example #1
0
 private void KillProcess()
 {
     if (dictionaryOfProcesses == null)
     {
         return;
     }
     CommandState.Command command = CommandState.Instance.GetCommand();
     if (command.length == 2)
     {
         if (dictionaryOfProcesses.Contains(command.values[1]))
         {
             Process[] process = Process.GetProcessesByName(command.values[1]);
             if (process.Length > 0)
             {
                 process[0].Kill();
                 dictionaryOfProcesses.Remove(command.values[1]);
             }
         }
         else
         {
             Console.WriteLine("Process does not exist");
         }
     }
     else
     {
         Console.WriteLine("Wrong Command");
     }
 }
Example #2
0
 private void ExecuteTask()
 {
     mainThread = new Thread(() =>
     {
         do
         {
             if (ReadyTasks.Count <= MAX_VALUE)
             {
                 for (int i = ReadyTasks.Count; i < MAX_VALUE; i++)
                 {
                     if (StoreTasks.Count != 0)
                     {
                         ReadyTasks.Enqueue(StoreTasks.Peek());
                         StoreTasks.Dequeue();
                     }
                 }
             }
             if (ReadyTasks.Count > 0)
             {
                 Taskandler executeHandler = ReadyTasks.Peek();
                 UserTask u = executeHandler.UserTask;
                 thread     = new Thread(new ThreadStart(u));
                 thread.Start();
                 ReadyTasks.Dequeue();
                 thread.Join();
                 EventDataBase.TriggerEvent("PRINT_LABEL");
                 CommandState.Command commamd = CommandState.Instance.GetCommand();
             }
         } while (true);
     });
     mainThread.Start();
 }
Example #3
0
 private void RunProcess()
 {
     CommandState.Command command = CommandState.Instance.GetCommand();
     if (command.length == 2)
     {
         try
         {
             if (dictionaryOfProcesses == null)
             {
                 dictionaryOfProcesses = new List <string>();
             }
             if (dictionaryOfProcesses.Contains(command.values[1]))
             {
                 Console.WriteLine("Proccess Already Exist");
                 return;
             }
             using var proccess = Process.Start(command.values[1]);
             dictionaryOfProcesses.Add(command.values[1]);
         }
         catch (Exception e)
         {
             Console.WriteLine("Wrong Process Name");
         }
     }
     else
     {
         Console.WriteLine("Wrong Command");
     }
 }
Example #4
0
    private void Zip_File()
    {
        CommandState.Command command = CommandState.Instance.GetCommand();
        string path = command.values[1];

        if (command.length < 2 || command.length > 3)
        {
            Console.WriteLine("Wrong Command");
            return;
        }
        if (!File.Exists(path))
        {
            Console.WriteLine("File is not exist");
            return;
        }
        string[] splitedPath = path.Split(".");
        if (File.Exists(splitedPath[0] + ".zip"))
        {
            Console.WriteLine("Zip File Exists");
            return;
        }
        using (var archive = ZipFile.Open(Environment.CurrentDirectory + "\\" + splitedPath[0] + ".zip", ZipArchiveMode.Create))
        {
            archive.CreateEntryFromFile(path, Path.GetFileName(path));
            if (command.length == 3)
            {
                if (command.values[2] == "-d")
                {
                    File.Delete(path);
                }
            }
        }
    }
Example #5
0
    private void CreateFolder()
    {
        CommandState.Command command = CommandState.Instance.GetCommand();
        string path = Environment.CurrentDirectory;

        if (Directory.Exists(path + "/" + command.values[1]))
        {
            return;
        }
        Directory.CreateDirectory(path + "/" + command.values[1]);
    }
Example #6
0
 private void Zip_Folder()
 {
     CommandState.Command command = CommandState.Instance.GetCommand();
     using (var archive = ZipFile.Open(Environment.CurrentDirectory + "\\" + command.values[1] + ".zip", ZipArchiveMode.Create))
     {
         string[] filePath = Directory.GetFiles(command.values[1]);
         for (int i = 0; i < filePath.Length; i++)
         {
             archive.CreateEntry(filePath[i]);
         }
     }
 }
Example #7
0
    private void RemoveFolder()
    {
        CommandState.Command command = CommandState.Instance.GetCommand();
        string path = Environment.CurrentDirectory + "\\" + command.values[1];

        if (!Directory.Exists(path))
        {
            Console.WriteLine("Folder is not Exist");
            return;
        }
        Directory.Delete(path);
    }
Example #8
0
 private void MoveUp()
 {
     CommandState.Command command = CommandState.Instance.GetCommand();
     if (command.length == 1)
     {
         var path = Directory.GetParent(Environment.CurrentDirectory);
         Environment.CurrentDirectory = path.ToString();
     }
     else
     {
         Console.WriteLine("Wrong Command");
         return;
     }
 }
Example #9
0
 private void UnpackZip()
 {
     CommandState.Command command = CommandState.Instance.GetCommand();
     if (command.length != 2)
     {
         Console.WriteLine("Wrong Command");
         return;
     }
     if (!File.Exists(command.values[1]))
     {
         Console.WriteLine("Zip File is not Exists");
         return;
     }
     using (var archive = ZipFile.OpenRead(Environment.CurrentDirectory + "\\" + command.values[1]))
     {
         archive.ExtractToDirectory(Environment.CurrentDirectory);
     }
     // ZipFile.ExtractToDirectory(Environment.CurrentDirectory, command.values[1]);
 }
Example #10
0
 private void OpenFolder()
 {
     CommandState.Command command = CommandState.Instance.GetCommand();
     if (/*string.IsNullOrWhiteSpace(command.values[1]) ||*/ command.length == 1)
     {
         Environment.CurrentDirectory = @"c:\";
         return;
     }
     else
     {
         string path = Environment.CurrentDirectory + "\\" + command.values[1];
         if (!Directory.Exists(path))
         {
             Console.WriteLine("Folder is not Exist");
             return;
         }
         Environment.CurrentDirectory = path;
     }
 }
Example #11
0
 private void DayTimeMainFunc()
 {
     CommandState.Command command = CommandState.Instance.GetCommand();
     if (command.length == 1)
     {
         Console.WriteLine(DateTime.Now);
         return;
     }
     else
     {
         string finalPrint = "";
         for (int i = 1; i < command.length; i++)
         {
             finalPrint += GetFormatingData(command.values[i]) + " ";
         }
         if (foundError)
         {
             Console.WriteLine("Wrong Command");
             return;
         }
         Console.WriteLine(finalPrint);
     }
 }
Example #12
0
        static void Main(string[] args)
        {
            EventDataBase.RegisterEvent("PRINT_LABEL", PrintLabel);
            Execute execute      = new Execute();
            string  userInput    = null;
            bool    shellStatus  = true;
            int     currentIndex = 0;

            CommandState.Command c = CommandState.Instance.GetCommand();
            PrintLabel();
            while (shellStatus)
            {
                if (ThreadPool.Instance.EmptyThreadList())
                {/*
                  * if (accum == 0)
                  * {
                  *     PrintLabel();
                  *     accum += 1;
                  * }*/
                    ConsoleKeyInfo readKey = Console.ReadKey(true);
                    if (readKey.Key == ConsoleKey.Enter)
                    {
                        if (userInput != null)
                        {
                            Console.WriteLine();
                            execute.Input(userInput);
                            currentIndex = 0;
                            accum        = 0;
                        }
                        //Thread.Sleep(10);
                        userInput = null;
                    }
                    else if (readKey.Key == ConsoleKey.Backspace)
                    {
                        if (currentIndex > 0)
                        {
                            userInput = userInput.Remove(userInput.Length - 1);
                            Console.Write(readKey.KeyChar);
                            Console.Write(' ');
                            Console.Write(readKey.KeyChar);
                            currentIndex--;
                        }
                    }
                    else if (readKey.Key == ConsoleKey.UpArrow)
                    {
                        ClearCurrentConsoleLine();
                        var swapString = CommandState.Instance.GetHistoryItem(false);
                        if (swapString != null)
                        {
                            userInput    = swapString;
                            currentIndex = userInput.Length;
                            Console.Write("> " + swapString);
                        }
                    }
                    else if (readKey.Key == ConsoleKey.DownArrow)
                    {
                        ClearCurrentConsoleLine();
                        var swapString = CommandState.Instance.GetHistoryItem(true);
                        if (swapString != null)
                        {
                            userInput    = swapString;
                            currentIndex = userInput.Length;
                            Console.Write("> " + swapString);
                        }
                    }
                    else
                    {
                        userInput += readKey.KeyChar;
                        Console.Write(readKey.KeyChar);
                        currentIndex++;
                    }
                }
            }
        }