Exemple #1
0
        private void fSave_Click(object sender, EventArgs e)
        {
            int fInd = Convert.ToInt32(this.fInd.Text);
            int iCl  = MainProgram.fs.files[fInd].First_clust;

            char[] allText = new char[fileText.Text.Length];
            allText = fileText.Text.ToCharArray();
            byte[] txt    = System.Text.Encoding.UTF8.GetBytes(allText);
            int    length = txt.Length; // fileText.Text.Length;

            // check if FS has enough clusters for text...
            int needCl = length / FSEmul.CLUST_SIZE;

            if (FSEmul.getFreeClustCount() < needCl)
            {
                MessageBox.Show("Файл слишком велик, не хватает кластеров. Сократите файл перед сохранением");
                return;
            }

            fileText.Text += "  ";
            clearFile(fInd); // clear blocks of this file in fs

            BinaryWriter bw = new BinaryWriter(File.Open("MyFS.dat", FileMode.Open), Encoding.UTF8);

            MainProgram.fs.files[fInd].Size = length + 1;  // text.Length;

            int cl_count = length / FSEmul.CLUST_SIZE + 1; // number of clusters for file

            for (int i = 0; i < cl_count; i++)
            {
                bw.BaseStream.Seek((iCl - 1) * FSEmul.CLUST_SIZE, SeekOrigin.Begin);

                int j          = 0;
                int countBytes = 0;
                int countChars = 0;
                while (j < FSEmul.CLUST_SIZE && countBytes + 1 < FSEmul.CLUST_SIZE)
                {
                    if (j < allText.Length)
                    {
                        bw.Write(allText[j]);
                    }
                    else
                    {
                        break;
                    }
                    countBytes += System.Text.Encoding.UTF8.GetBytes(allText[j].ToString()).Length;
                    countChars++;
                    j++;
                }

                // cut byte-array
                if (System.Text.Encoding.UTF8.GetBytes(allText).Length > FSEmul.CLUST_SIZE)
                {
                    int    num         = allText.Length - countChars;
                    char[] TempallText = new char[num];
                    int    k           = 0;
                    while (k < num)
                    {
                        TempallText[k] = allText[k + countChars];
                        k++;
                    }
                    allText = new char[num];
                    allText = TempallText;
                }

                if (i + 1 < cl_count) // not enough clusters for changeed file
                {
                    // get another free cluster
                    ushort newiCl = FSEmul.getFreeClust(false);
                    MainProgram.fs.listCl[iCl]    = newiCl;
                    MainProgram.fs.listCl[newiCl] = 500;
                    iCl = newiCl;
                }
            }
            bw.Close();
        }
Exemple #2
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); // не корректная команда
        }
Exemple #3
0
 private void back_Click_1(object sender, EventArgs e)
 {
     FSEmul.FS_Save();
     this.Close();
 }