public string Generate(Topic topic)
        {
            if (topic.IsSplashPage())
            {
                return _transformer.Transform(topic, new FileSystem().ReadStringFromFile(topic.File));
            }

            try
            {
                return generate(topic);
            }
            catch (Exception e)
            {
                ConsoleWriter.Write(ConsoleColor.Yellow, "Failed to transform topic at " + topic.File);
                ConsoleWriter.Write(ConsoleColor.Red, e.ToString());

                var document = new HtmlDocument
                {
                    Title = "Error!"
                };

                document.Add("h1").Text("Error!");

                document.Add("pre").Text(e.ToString());


                return document.ToString();
            }
        }
Example #2
0
        private void write500(IDictionary<string, object> environment, Exception exception)
        {
            using (var writer = new OwinHttpResponse(environment))
            {
                writer.WriteResponseCode(HttpStatusCode.InternalServerError);
                var document = new HtmlDocument
                {
                    Title = "Exception!"
                };

                document.Add("h1").Text("FubuMVC has detected an exception");
                document.Add("hr");
                document.Add("pre").Id("error").Text(exception.ToString());

                writer.WriteContentType(MimeType.Html.Value);
                writer.Write(document.ToString());
            }
        }
Example #3
0
        public static void ExportToHtmFile(string fileName, params IValidator[] validators)
        {
            bool all = false;

            while (true)
            {
                Console.Write("Please enter the type of validations to run (All/Populars)[a/p]:p");
                Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                var k = Console.ReadKey();

                if (k.Key == ConsoleKey.A)
                {
                    all = true;
                    break;
                }

                if (k.Key == ConsoleKey.P || k.Key == ConsoleKey.Enter)
                {
                    all = false;
                    break;
                }
            }


            var doc = new HtmlTags.HtmlDocument();


            doc.Head
            .Add("description").Attr("content", "Some validations of BriefFiniteEelement.NET library")
            .Parent.Add("keywords").Attr("content",
                                         "finite element, C#, FEA, FEM, BriefFiniteEelement.NET, BriefFiniteEelementDOTNET")
            .Parent.Add("viewport").Attr("content", "width=device-width, initial-scale=1")

            .Parent.Add("link").Attr("rel", "stylesheet").Attr("crossorigin", "anonymous").Attr("href", "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css").Attr("integrity", "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm").Text(" ")
            .Parent.Add("script").Attr("crossorigin", "anonymous").Attr("src", "https://code.jquery.com/jquery-3.2.1.slim.min.js").Attr("integrity", "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN").Text(" ")
            .Parent.Add("script").Attr("crossorigin", "anonymous").Attr("src", "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js").Attr("integrity", "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q").Text(" ")
            .Parent.Add("script").Attr("crossorigin", "anonymous").Attr("src", "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js").Attr("integrity", "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl").Text(" ")
            ;

            //doc.ReferenceJavaScriptFile("https://code.jquery.com/jquery-3.2.1.slim.min.js");
            ;

            /*
             * doc.AddScript("javascript","https://code.jquery.com/jquery-3.2.1.slim.min.js");
             * doc.AddJavaScript("https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js");
             * doc.AddJavaScript("https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js");
             *
             * doc.AddStyle("https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css");
             *
             */
            doc.Title = "BriefFiniteElement Validtion Cases";

            var body = doc.Body;

            body.Add("noscript")
            .Text(
                "This page needs javascript to be enabled in your webbrowser, otherwise page will be a little illegible");

            body.Style("padding", "60px");

            body.Add("script").Attr("type", "text/javascript")
            .Text(
                @"$(document).ready(function(){jQuery?void(0):alert('jquery not loaded')});");



            var ctx = body.Add("div").Id("ctxtbl").AddClass("jumbotron");

            ctx.Add("div").Add("p").Text("Table of contents:");

            body = body.Add("div").AddClass("container");

            foreach (var validator in validators)
            {
                var valReses = all ?
                               validator.DoAllValidation() :
                               validator.DoPopularValidation();

                foreach (var valRese in valReses)
                {
                    var id = Guid.NewGuid().ToString("N").Substring(0, 5);

                    var validationSpan = body.Add("div").Id(id).AddClasses("card");


                    validationSpan.Add("div").AddClasses("card-header").Text("Validation");//title


                    var blc = validationSpan.Add("div").AddClasses("card-block");

                    blc.Add("h4").AddClasses("card-title").Text(valRese.Title);
                    var panelBody = blc.Add("div").AddClasses("card-text");


                    panelBody.Children.Add(valRese.Span);

                    if (valRese.ValidationFailed.HasValue)
                    {
                        var fail = valRese.ValidationFailed.Value;

                        var sp2 = validationSpan.Add("div").AddClass("alert").AddClass(fail? "alert-danger" : "alert-success").Attr("role", "alert");

                        sp2.Text(fail ? "Validation Failed!!" : "Validation Success!!");
                        //body.Children.Add(sp2);
                    }



                    ctx.Add("a").Attr("href", "#" + id).Text(valRese.Title);
                    ctx.Add("br");
                }
            }

            var fl = "c:\\temp\\val-res.html";

            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(doc.ToString());

            xmlDoc.Save(fl);


            Process.Start(fl);
        }
Example #4
0
        internal TestResult Execute()
        {
            _listener.StartTest(_request.Test, _result.Counts);

            Stopwatch timer = Stopwatch.StartNew();

            try
            {
                _execution = _system.CreateContext();
            }
            catch (Exception e)
            {
                var document = new HtmlDocument();
                document.Title = "Catastrophic Failure!";
                document.Add("pre").Text(e.ToString());

                var result = new TestResult
                {
                    Counts = new Counts(0, 0, 1, 0),
                    ExceptionText = e.ToString(),
                    Html = document.ToString(),
                    Locator = _request.Test.LocatorPath(),
                    ExecutionTime = 0,
                    FullExceptionText = e.ToString(),
                    WasCancelled = false,
                    RetryAttemptNumber = _request.Test.RetryAttemptNumber
                };

                _request.Test.LastResult = result;

                return result;
            }

            _context = new TestContext(_execution, _request.Test, _listener);

            if (_context.RetryAttemptNumber > 0)
            {
                _system.Recycle();
            }

            _reset = new ManualResetEvent(false);

            try
            {
                startThread();

                recordTimeout();
            }
            catch (Exception e)
            {
                captureException(e);
                _listener.Exception(e.ToString());
            }

            _testThread = null;

            timer.Stop();

            recordResults(timer);

            _listener.FinishTest(_request.Test);

            return _result;
        }