Exemplo n.º 1
0
        private void FreezeButtonClick(object sender, EventArgs e)
        {
            if (CheckId())
            {
                string id = this.processIdBox.Text;

                PuppetMaster.FreezeProcess(id);
                SetStatus("FREEZE " + id);
            }
        }
Exemplo n.º 2
0
        // returns true if break point
        private bool ReadCommand(string lineToRun, int lineNumber)
        {
            if (string.IsNullOrEmpty(lineToRun))
            {
                return(false);
            }

            // PARSER
            string[] steps = lineToRun.Split(new char[] { '\n', ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (string.IsNullOrEmpty(steps[0]))
            {
                return(false);
            }

            if (steps[0].First() == '#')
            {
                // #! is a BREAKPOINT 'laica boss'
                if (steps[0].Length == 2 && steps[0].Substring(0, 2) == "#!")
                {
                    return(true);
                }

                return(false);
            }

            switch (steps[0])
            {
            // CREATE ID FILENAME NBDATASERVERS READQ WRITEQ
            case "CREATE":
            {
                if (steps.Length != 6)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id            = steps[1];
                string filename      = steps[2];
                int    nbDataServers = Convert.ToInt32(steps[3]);
                int    readq         = Convert.ToInt32(steps[4]);
                int    writeq        = Convert.ToInt32(steps[5]);

                PuppetMaster.CreateFile(id, filename, nbDataServers, readq, writeq);
                SetStatus("CREATE " + id + " => " + filename + ":" + nbDataServers + ":" + readq + ":" + writeq);

                break;
            }

            // DELETE ID FILENAME
            case "DELETE":
            {
                if (steps.Length != 3)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id       = steps[1];
                string filename = steps[2];
                PuppetMaster.DeleteFile(id, filename);
                SetStatus("DELETE " + id + " => " + filename);
                break;
            }

            // OPEN ID FILENAME
            case "OPEN":
            {
                if (steps.Length != 3)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id       = steps[1];
                string filename = steps[2];
                PuppetMaster.OpenFile(id, filename);
                SetStatus("OPEN " + id + " => " + filename);
                break;
            }

            // OPEN ID FILENAME
            case "CLOSE":
            {
                if (steps.Length != 3)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id       = steps[1];
                string filename = steps[2];
                PuppetMaster.CloseFile(id, filename);
                SetStatus("CLOSE " + id + " => " + filename);
                break;
            }

            // FAIL ID
            case "FAIL":
            {
                if (steps.Length != 2)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id = steps[1];
                PuppetMaster.FailProcess(id);
                SetStatus("FAIL " + id);
                break;
            }

            // RECOVER ID
            case "RECOVER":
            {
                if (steps.Length != 2)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id = steps[1];
                PuppetMaster.RecoverProcess(id);
                SetStatus("RECOVER " + id);
                break;
            }

            // FREEZE ID
            case "FREEZE":
            {
                if (steps.Length != 2)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id = steps[1];
                PuppetMaster.FreezeProcess(id);
                SetStatus("FREEZE " + id);
                break;
            }

            // UNFREEZE ID
            case "UNFREEZE":
            {
                if (steps.Length != 2)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id = steps[1];
                PuppetMaster.UnfreezeProcess(id);
                SetStatus("UNFREEZE " + id);

                break;
            }

            // READ ID FILE REGISTER SEMANTICS STRING-REGISTER
            case "READ":
            {
                if (steps.Length != 5)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id           = steps[1];
                int    fileRegister = Convert.ToInt32(steps[2]);
                string semantic     = steps[3];
                int    byteRegister = Convert.ToInt32(steps[4]);

                PuppetMaster.ReadFile(id, fileRegister, semantic, byteRegister);
                SetStatus("READ " + id + " => " + fileRegister + ":" + semantic + ":" + byteRegister);

                break;
            }

            // WRITE ID FILE-REGISTER BYTE-ARRAY-REGISTER
            // WRITE ID FILE-REGISTER CONTENTS
            case "WRITE":
            {
                string[] writeSteps = lineToRun.Split(new char[] { ' ', ',' }, 4, StringSplitOptions.RemoveEmptyEntries);
                if (writeSteps.Length != 4)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id           = writeSteps[1];
                int    fileRegister = Convert.ToInt32(writeSteps[2]);
                string contents     = writeSteps[3];

                if (contents.First() != '"')
                {
                    int byteArrayRegister = Convert.ToInt32(contents);
                    PuppetMaster.WriteFile(id, fileRegister, byteArrayRegister);
                    SetStatus("WRITE " + id + " => " + fileRegister + ":" + byteArrayRegister);
                    return(false);
                }

                string actualContents = contents.Substring(1, contents.Length - 2);
                PuppetMaster.WriteFile(id, fileRegister, actualContents);
                SetStatus("WRITE " + id + " => " + fileRegister + ":" + actualContents);
                break;
            }

            // COPY ID FILE-REGISTER-1 SEMANTICS FILE-REGISTER-2 SALT
            case "COPY":
            {
                string[] copySteps = lineToRun.Split(new char[] { ' ', ',' }, 6, StringSplitOptions.RemoveEmptyEntries);

                if (copySteps.Length != 6)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id            = copySteps[1];
                int    fileRegister1 = Convert.ToInt32(copySteps[2]);
                int    fileRegister2 = Convert.ToInt32(copySteps[4]);
                string semantics     = copySteps[3];
                string salt          = copySteps[5].Substring(1, copySteps[5].Length - 2);

                PuppetMaster.CopyFile(id, fileRegister1, semantics, fileRegister2, salt);
                SetStatus("COPY " + id + " => " + fileRegister1 + ":" + semantics + ":" + fileRegister2 + ":" + salt);

                break;
            }

            // DUMP ID
            case "DUMP":
            {
                if (steps.Length != 2)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id = steps[1];
                PuppetMaster.DumpProcess(id);
                SetStatus("DUMP " + id);

                break;
            }

            // EXESCRIPT ID FILENAME
            case "EXESCRIPT":
            {
                if (steps.Length != 3)
                {
                    SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                    return(false);
                }

                string id       = steps[1];
                string filename = steps[2];

                SetStatus("EXESCRIPT " + id + ":" + filename);

                ExeScript(id, filename);

                break;
            }

            default:
            {
                SetStatus("[ERROR] Invalid Script at line " + lineNumber);
                return(false);
            }
            }

            return(false);
        }