Ejemplo n.º 1
0
        static public void AddTestCaseStateToReport(RichTextBox richTextBoxResult, OnWebParserUpdateEventArgs e)
        {
            // Only past the webparser result if the parsing failed
            if (e.WebParserInfoState.Exception == null)
            {
                if (e.WebParserInfoState.LastErrorCode < 0)
                {
                    richTextBoxResult.AppendText("Error:\t");
                }
                else
                {
                    richTextBoxResult.AppendText("Status:\t");
                }

                richTextBoxResult.AppendText(
                    String.Format("{0} ({1} %){2}",
                                  e.WebParserInfoState.LastErrorCode.ToString(), e.WebParserInfoState.Percent.ToString(), Environment.NewLine, Environment.NewLine)
                    );
            }
            else
            {
                if (e.WebParserInfoState.LastErrorCode < 0)
                {
                    richTextBoxResult.AppendText("Error:\t");
                }
                else
                {
                    richTextBoxResult.AppendText("Status:\t");
                }

                richTextBoxResult.AppendText(
                    String.Format("{0} ({1} %){2}{3}{4}",
                                  e.WebParserInfoState.LastErrorCode.ToString(), e.WebParserInfoState.Percent.ToString(), Environment.NewLine, e.WebParserInfoState.Exception.Message, Environment.NewLine)
                    );
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This function updates the test report
        /// </summary>
        /// <param name="sender">Webparser</param>
        /// <param name="e">OnWebSiteLoadFinishedEventArgs</param>
        public void OnUpdate(object sender, OnWebParserUpdateEventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action(() => OnUpdate(sender, e)));
            }
            else
            {
                // Write state to the richedit box
                HelperFunctions.AddTestCaseStateToReport(richTextBoxResult, e);

                Console.WriteLine("CaseCounter: " + _threadFunctions.TestCaseCounter + " / LastErrorCode: " + e.WebParserInfoState.LastErrorCode + " / GUI: " + _threadFunctions.GuiUpdateCounter);
                switch (_threadFunctions.TestCaseCounter)
                {
                case 1:
                {
                    int guiUpdateCounterReached = 2;
                    if (e.WebParserInfoState.LastErrorCode == WebParserErrorCodes.Started)
                    {
                        _threadFunctions.WebParser.StartParsing();
                    }

                    if (_threadFunctions.GuiUpdateCounter == guiUpdateCounterReached)
                    {
                        _threadFunctions.WebParser.OnWebParserUpdate -= OnUpdate;
                        if (e.WebParserInfoState.LastErrorCode == WebParserErrorCodes.BusyFailed)
                        {
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, true);
                        }
                        else
                        {
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, false);
                            _resultFlag = false;
                        }
                        _threadFunctions.NextTestCaseFlag = true;
                    }
                    else
                    {
                        if (e.WebParserInfoState.LastErrorCode < 0 && _threadFunctions.GuiUpdateCounter < guiUpdateCounterReached)
                        {
                            CancelWebParserStartNextTestCase();
                        }
                    }

                    _threadFunctions.GuiUpdateCounter++;
                    break;
                }

                case 2:
                {
                    int guiUpdateCounterReached = 1;
                    if (_threadFunctions.GuiUpdateCounter == guiUpdateCounterReached)
                    {
                        _threadFunctions.WebParser.OnWebParserUpdate -= OnUpdate;

                        Console.WriteLine(" LastErrorCode: " + e.WebParserInfoState.LastErrorCode + " / GUI: " + _threadFunctions.GuiUpdateCounter);
                        if (e.WebParserInfoState.LastErrorCode == WebParserErrorCodes.InvalidWebSiteGiven)
                        {
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, true);
                        }
                        else
                        {
                            _threadFunctions.WebParser.CancelThread = true;
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, false);
                            _resultFlag = false;
                        }
                        _threadFunctions.NextTestCaseFlag = true;
                    }
                    else
                    {
                        if (e.WebParserInfoState.LastErrorCode < 0 && _threadFunctions.GuiUpdateCounter < guiUpdateCounterReached)
                        {
                            CancelWebParserStartNextTestCase();
                        }
                    }

                    _threadFunctions.GuiUpdateCounter++;
                    break;
                }

                case 3:
                {
                    int guiUpdateCounterReached = 1;
                    if (_threadFunctions.GuiUpdateCounter == guiUpdateCounterReached)
                    {
                        _threadFunctions.WebParser.OnWebParserUpdate -= OnUpdate;

                        if (e.WebParserInfoState.LastErrorCode == WebParserErrorCodes.NoRegexListGiven)
                        {
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, true);
                        }
                        else
                        {
                            _threadFunctions.WebParser.CancelThread = true;
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, false);
                            _resultFlag = false;
                        }
                        _threadFunctions.NextTestCaseFlag = true;
                    }
                    else
                    {
                        if (e.WebParserInfoState.LastErrorCode < 0 && _threadFunctions.GuiUpdateCounter < guiUpdateCounterReached)
                        {
                            CancelWebParserStartNextTestCase();
                        }
                    }

                    _threadFunctions.GuiUpdateCounter++;
                    break;
                }

                case 4:
                {
                    int guiUpdateCounterReached = 1;
                    if (_threadFunctions.GuiUpdateCounter == guiUpdateCounterReached)
                    {
                        _threadFunctions.WebParser.OnWebParserUpdate -= OnUpdate;

                        if (e.WebParserInfoState.LastErrorCode == WebParserErrorCodes.InvalidWebSiteGiven)
                        {
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, true);
                        }
                        else
                        {
                            _threadFunctions.WebParser.CancelThread = true;
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, false);
                            _resultFlag = false;
                        }
                        _threadFunctions.NextTestCaseFlag = true;
                    }
                    else
                    {
                        if (e.WebParserInfoState.LastErrorCode < 0 && _threadFunctions.GuiUpdateCounter < guiUpdateCounterReached)
                        {
                            CancelWebParserStartNextTestCase();
                        }
                    }

                    _threadFunctions.GuiUpdateCounter++;
                    break;
                }

                case 5:
                {
                    int guiUpdateCounterReached = 5;
                    if (_threadFunctions.GuiUpdateCounter == guiUpdateCounterReached)
                    {
                        _threadFunctions.WebParser.OnWebParserUpdate -= OnUpdate;

                        if (e.WebParserInfoState.LastErrorCode == WebParserErrorCodes.ParsingFailed)
                        {
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, true);
                        }
                        else
                        {
                            _threadFunctions.WebParser.CancelThread = true;
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, false);
                            _resultFlag = false;
                        }
                        _threadFunctions.NextTestCaseFlag = true;
                    }
                    else
                    {
                        if (e.WebParserInfoState.LastErrorCode < 0 && _threadFunctions.GuiUpdateCounter < guiUpdateCounterReached)
                        {
                            CancelWebParserStartNextTestCase();
                        }
                    }
                    _threadFunctions.GuiUpdateCounter++;
                    break;
                }

                case 6:
                {
                    int guiUpdateCounterReached = 6;
                    if (_threadFunctions.GuiUpdateCounter == guiUpdateCounterReached)
                    {
                        _threadFunctions.WebParser.OnWebParserUpdate -= OnUpdate;

                        if (e.WebParserInfoState.LastErrorCode == WebParserErrorCodes.Finished &&
                            _threadFunctions.WebParser.SearchResult.Count == 1 &&
                            e.WebParserInfoState.SearchResult["Gesamt"][0] == "Anlage")
                        {
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, true);
                        }
                        else
                        {
                            _threadFunctions.WebParser.CancelThread = true;
                            HelperFunctions.AddTestCaseResultToReport(richTextBoxResult, false);
                            _resultFlag = false;
                        }
                        _threadFunctions.NextTestCaseFlag = true;
                    }
                    else
                    {
                        if (e.WebParserInfoState.LastErrorCode < 0 && _threadFunctions.GuiUpdateCounter < guiUpdateCounterReached)
                        {
                            CancelWebParserStartNextTestCase();
                        }
                    }
                    _threadFunctions.GuiUpdateCounter++;
                    break;
                }
                }
            }
        }