Exemple #1
0
 public void FastForwardAllSteps()
 {
     while ((currentStep = DequeueStep()) != null)
     {
         currentStep.StartStep();
     }
 }
Exemple #2
0
 public void NextStep()
 {
     currentStep = DequeueStep();
     if (currentStep != null)
     {
         currentStep.StartStep();
     }
 }
Exemple #3
0
 private Step.IStep DequeueStep()
 {
     if (allSteps.Count == 0)
     {
         return(null);
     }
     Step.IStep step = allSteps[0];
     allSteps.RemoveAt(0);
     return(step);
 }
Exemple #4
0
        private static Manus BuildFromString(string filename, string manusString)
        {
            List <string> splitManus = new List <string>(manusString.Split(linebreaks, StringSplitOptions.None));
            Manus         manus      = new Manus();

            Step.IStep step          = null;
            string     contentHeader = null;
            string     contentBody   = null;
            string     row;
            int        rowNumber = 0;

            while ((row = DequeueRow(splitManus)) != null)
            {
                rowNumber++;
                row = row.Trim();

                if (step != null)
                {
                    // Try continue content reading
                    if (row.Length > 0 && row[0] == '>')
                    {
                        if (step is Step.IStepNoBody)
                        {
                            throw new ManusBuildingException(step.GetType().Name + " doesn't support body parameters!", rowNumber, filename);
                        }

                        if (contentBody == null)
                        {
                            contentBody = row.Substring(1);
                        }
                        else
                        {
                            contentBody += "\n" + row.Substring(1);
                        }
                    }
                    else
                    {
                        // Reading complete
                        if (contentBody == null && !(step is Step.IStepNoBody))
                        {
                            throw new ManusBuildingException(step.GetType().Name + " requires a body parameter!", rowNumber, filename);
                        }

                        try {
                            step.ParseContent(manus, contentHeader, contentBody);
                        } catch (ManusBuildingException inner) {
                            throw new ManusBuildingException(rowNumber, filename, inner);
                        }
                        manus.allSteps.Add(step);
                        step = null;
                    }
                }

                // Comments
                if (row.StartsWith("//") || row.StartsWith("#"))
                {
                    continue;
                }

                // Empty rows
                if (row.Length == 0)
                {
                    continue;
                }

                if (step == null)
                {
                    if (row[0] == '>')
                    {
                        throw new ManusBuildingException("Unexpected body parameter.", rowNumber, filename);
                    }

                    // Listen for step start
                    Match match = Regex.Match(row, @"^([_\-\wåäöÅÄÖ.,]+):(?:\s*(.+)\s*)?$");

                    if (!match.Success)
                    {
                        match = Regex.Match(row, @"^([_\-\wåäöÅÄÖ.,]+)\s*$");
                        if (!match.Success)
                        {
                            throw new ManusBuildingException("Expected step, got \"" + row + "\"", rowNumber, filename);
                        }
                    }

                    string g1 = match.Groups[1].Value;
                    string g2 = (match.Groups.Count > 2 && match.Groups[2].Success) ? match.Groups[2].Value : null;

                    try {
                        step = GetAppropietStep(g1);
                    } catch (ManusBuildingException inner) {
                        throw new ManusBuildingException(rowNumber, filename, inner);
                    }

                    if (g2 != null && step is Step.IStepNoHeader)
                    {
                        throw new ManusBuildingException(step.GetType().Name + " doesn't support header parameters!", rowNumber, filename);
                    }
                    if (g2 == null && !(step is Step.IStepNoHeader))
                    {
                        throw new ManusBuildingException(step.GetType().Name + " requires a header parameter!", rowNumber, filename);
                    }
                    if (match.Groups.Count != 3 && !(step is Step.IStepNoParameters))
                    {
                        throw new ManusBuildingException(step.GetType().Name + " requires a body parameter!", rowNumber, filename);
                    }

                    contentHeader = g2;
                    contentBody   = null;

                    if (step is Step.IStepNoBody)
                    {
                        // Reading complete
                        try {
                            step.ParseContent(manus, contentHeader, contentBody);
                        } catch (ManusBuildingException inner) {
                            throw new ManusBuildingException(rowNumber, filename, inner);
                        }
                        manus.allSteps.Add(step);
                        step = null;
                    }
                }
            }

            if (step != null)
            {
                // Reading complete
                if (contentBody == null && !(step is Step.IStepNoBody))
                {
                    throw new ManusBuildingException(step.GetType().Name + " requires a body parameter!", rowNumber, filename);
                }

                try {
                    step.ParseContent(manus, contentHeader, contentBody);
                } catch (ManusBuildingException inner) {
                    throw new ManusBuildingException(rowNumber, filename, inner);
                }
                manus.allSteps.Add(step);
                step = null;
            }

            return(manus);
        }