コード例 #1
0
        public int analyseCommand(string command)
        {
            int j;

            string[] str = command.Split(' ');
            if (str[2].ToLower() == "mt" && str.Length == 3)
            {
                MainProgram.memt = new MemoryTest(); //форма
                MainProgram.memt.Show();
                return(0);
            }
            #region start
            if (str[2].ToLower() == "start" && str.Length == 5 && str[3].Length > 0 && Int32.TryParse(str[4], out j))
            {
                if (ProcessControll.findProcess(str[3]) == -1) // процесс еще не запущен
                {
                    this.AllPr.Rows.Add(1);
                    Random  rand     = new Random();
                    int     time     = rand.Next(1000, 2000);
                    Process tempProc = new Process(str[3], j, time, MainProgram.currentuser.getLogin()); //j = Convert.ToInt32(str[4])

                    lock (ProcessControll.listProc)
                        ProcessControll.listProc.Add(tempProc);
                    lock (MainProgram.qPr)
                        MainProgram.qPr.Enqueue(tempProc);
                    return(0);
                }
                else
                {
                    return(1); // MessageBox.Show("Процесс с таким именем уже запущен");
                }
            }
            #endregion
            #region stop
            if (str[2].ToLower() == "stop" && str[3].ToLower() != "all" && str.Length == 4 && str[3].Length > 0)
            {
                Queue <Process> tempQu;
                Process         tempPr  = new Process();
                bool            isFound = false;
                int             i       = 0;
                lock (MainProgram.qPr)
                    tempQu = new Queue <Process>(MainProgram.qPr);

                while (!isFound && i++ < MainProgram.qPr.Count)
                {
                    tempPr = tempQu.Peek();
                    if (tempPr.getName() == str[3])
                    {
                        isFound = true;
                        if (MainProgram.currentuser.getLogin() == tempPr.getUserID() ||
                            MainProgram.currentuser.getLogin() == "admin" ||
                            tempPr.getUserID() == "UnknownUser")
                        {
                            tempQu.Peek().setTime(0);
                            tempQu.Peek().pause = false;
                            return(0);
                        }
                        else
                        {
                            return(2);  // MessageBox.Show("У вас не достаточно прав");
                        }
                    }
                    else
                    {
                        tempQu.Dequeue();
                        tempQu.Enqueue(tempPr);
                    }
                }
                if (!isFound)
                {
                    return(3); // MessageBox.Show("Процесс с таким именем не запущен");
                }
            }
            #endregion
            #region stopAll
            if (str[2].ToLower() == "stop" && str[3].ToLower() == "all" && str.Length == 4)
            {
                if (MainProgram.currentuser.getLogin() == "admin")
                {
                    MainProgram.planir.Abort();
                    while (MainProgram.qPr.Count > 0)
                    {
                        MainProgram.qPr.Dequeue();
                    }
                    ProcessControll.listProc.Clear();
                    MainProgram.addPr.Invoke(MainProgram.addPr.delegClear); // очистка таблицы
                    MainProgram.planir = new Thread((new ProcessControll()).run);
                    MainProgram.planir.Start();
                    return(0);
                }
                return(2);
            }
            #endregion
            #region pause
            if (str[2].ToLower() == "pause" && str[3].Length > 0 && str.Length == 4)
            {
                Queue <Process> tempQu;
                Process         tempPr  = new Process();
                bool            isFound = false;
                int             i       = 0;
                lock (MainProgram.qPr)
                    tempQu = new Queue <Process>(MainProgram.qPr);

                while (!isFound && i++ < MainProgram.qPr.Count)
                {
                    tempPr = tempQu.Peek();
                    if (tempPr.getName() == str[3])
                    {
                        isFound = true;
                        if (MainProgram.currentuser.getLogin() == tempPr.getUserID() ||
                            MainProgram.currentuser.getLogin() == "admin" ||
                            tempPr.getUserID() == "UnknownUser")
                        {
                            tempQu.Peek().pause = true;
                            return(0);//
                        }
                        else
                        {
                            return(2); // MessageBox.Show("У вас не достаточно прав");
                        }
                    }
                    else
                    {
                        tempQu.Dequeue();
                        tempQu.Enqueue(tempPr);
                    }
                }
                if (!isFound)
                {
                    return(3); // MessageBox.Show("Процесс с таким именем не запущен");
                }
            }
            #endregion
            #region go
            if (str[2].ToLower() == "go" && str[3].Length > 0 && str.Length == 4)
            {
                Queue <Process> tempQu;
                Process         tempPr  = new Process();
                bool            isFound = false;
                int             i       = 0;
                lock (MainProgram.qPr)
                    tempQu = new Queue <Process>(MainProgram.qPr);

                while (!isFound && i++ < MainProgram.qPr.Count)
                {
                    tempPr = tempQu.Peek();
                    if (tempPr.getName() == str[3])
                    {
                        isFound = true;
                        if (MainProgram.currentuser.getLogin() == tempPr.getUserID() ||
                            MainProgram.currentuser.getLogin() == "admin" ||
                            tempPr.getUserID() == "UnknownUser")
                        {
                            tempQu.Peek().pause = false;
                            return(0);
                        }
                        else
                        {
                            return(2); // MessageBox.Show("У вас не достаточно прав");
                        }
                    }
                    else
                    {
                        tempQu.Dequeue();
                        tempQu.Enqueue(tempPr);
                    }
                }
                if (!isFound)
                {
                    return(3); // MessageBox.Show("Процесс с таким именем не запущен");
                }
            }
            #endregion
            #region registrate
            if (str[2].ToLower() == "register" && str.Length == 3)
            {
                (new Registrate()).Show();
                return(0);
            }
            #endregion
            #region login
            if (str[2].ToLower() == "login" && str.Length == 3)
            {
                (new SignIn()).Show();
                return(0);
            }
            #endregion
            #region logout
            if (str[2].ToLower() == "logout" && str.Length == 3)
            {
                MainProgram.resetCurrentuser();
                return(0);
            }
            #endregion
            #region delete
            if (str[2].ToLower() == "delete" && str.Length == 4 && str[3].Length > 0)
            {
                if (MainProgram.currentuser.getLogin() != "UknownUser")
                {
                    MyOS.User.deleteUser(str[3]); return(0);
                }
                else
                {
                    return(2); // MessageBox.Show("У вас недостаточно прав");
                }
            }
            #endregion
            #region packet
            if (str[2].ToLower() == "packet" && str.Length == 3)
            {
                Packet packet = new Packet();
                packet.Show();
                return(0);
            }
            #endregion
            #region fs
            if (str[2].ToLower() == "fs" && str.Length == 3)
            {
                //    if (MainProgram.currentuser.getLogin()!="UnknownUser")
                //   {
                (new FSEmul()).Show();
                FSEmul.FS_Start();
                return(0);
                //     }
                //     else
                //     {
                //         return 2;
                //     }
            }
            #endregion
            return(4); // не корректная команда
        }
コード例 #2
0
 private void AddProcess_FormClosing(object sender, FormClosingEventArgs e)
 {
     MainProgram.Save();
 }