Exemple #1
0
        private void AssignVariable(string line, int lineCount)
        {
            try
            {
                var split = line.Split(new char[] { ' ' }, 3);
                //if (split[1] != "|")
                //    throw new InvalidDataException("Script error at line " + lineCount + ": Expected equals sign, didn't get.");
                string possibleNewValue = "";
                bool   foundVar         = false;
                if (IsCommand(split[2]))
                {
                    //showQuestionMessage("message","Yes","No","Unsure");
                    if (split[2].StartsWith("showQuestionDialog"))
                    {
                        possibleNewValue = QuestionDialog.ShowQuestionDialog(line, lineCount);
                    }
                    else
                    {
                        throw new InvalidDataException("Script error at line " + lineCount + ": Command is not allowed to be run here as it does not return a value.");
                    }
                }
                else
                {
                    possibleNewValue = split[2];
                }

                for (int i = 0; i < DeclaredValues.Count; i++)
                {
                    if (DeclaredValues[i].Key == split[0])
                    {
                        DeclaredValues.RemoveAt(i);
                        DeclaredValues.Add(new KeyValuePair <string, string>(split[0], possibleNewValue));
                        foundVar = true;
                    }
                }

                if (foundVar == false)
                {
                    throw new InvalidDataException("Script error at line " + lineCount + ": Value not previously assigned to.");
                }
            }
            catch (InvalidDataException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("\nERROR: ");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(ex.Message);
            }
        }
Exemple #2
0
        private void InterpretLine(string line, int lineCount)
        {
            if (lineCount == 0)
            {
                if (line != "#BasicScriptFile")
                {
                    throw new InvalidDataException("First line is not '#BasicScriptFile' or is not a BasicScriptFile!");
                }
                lineCount++;
                return;
            }

            if (line == "\n")
            {
                lineCount++;
                return;
            }

            if (line.StartsWith("#"))
            {
                if (line.StartsWith("#metadata"))
                {
                    ParseMetadata(line, lineCount);
                    lineCount++;
                    return;
                }
                else
                { /*Comment, ignore*/
                }
            }

            if (line.StartsWith("declare"))
            {
                ParseDeclareVariable(line, lineCount);
                lineCount++;
                return;
            }

            if (StartsWithVariable(line)) //useful for checking for variable assining/updating variables
            {
                if (!line.StartsWith("if"))
                {
                    if (IsAssigningVariable(line))
                    {
                        AssignVariable(line, lineCount);
                        lineCount++;
                        return;
                    }
                }
            }

            if (line.StartsWith("endif"))
            {
                ifStatementIsFalse = false; lineCount++; return;
            }

            if (line.StartsWith("if"))
            {
                bool ifStatementEvaluate = ParseIfStatement(line, lineCount);

                if (ifStatementEvaluate)
                {
                    lineCount++;
                    return;
                }
                else
                {
                    ifStatementIsFalse = true;
                    lineCount++;
                    return;
                }
            }

            if (ifStatementIsFalse == false)
            {
                if (IsCommand(line))
                {
                    if (line.StartsWith("echo"))
                    {
                        BasicOutput.Echo(line, lineCount);
                    }
                    else if (line.StartsWith("showQuestionDialog"))
                    {
                        QuestionDialog.ShowQuestionDialog(line, lineCount);
                    }
                    else if (line.StartsWith("runProcess"))
                    {
                        ProcessExecutor.StartProcess(line, lineCount);
                    }
                    else if (line.StartsWith("wait"))
                    {
                        BasicOutput.Wait(line, lineCount);
                    }

                    lineCount++;
                    return;
                }
            }
            lineCount++;
        }