Beispiel #1
0
        public void It_Should_Be_Able_To_Take_Partials_And_Render_Settings()
        {
            var output = StaticStubbleRenderer.Render(
                "{{FooValue}} {{#Foo}}{{> FooBar}}{{/Foo}}",
                new
            {
                FooValue = "Foo",
                Foo      = new
                {
                    BarValue = "Bar"
                }
            },
                new Dictionary <string, string>
            {
                {
                    "FooBar",
                    "{{FooValue}}{{BarValue}}"
                }
            },
                new RenderSettings {
                SkipRecursiveLookup = true
            });

            Assert.Equal("Foo Bar", output);
        }
Beispiel #2
0
        public void It_Can_Render_WithPartials()
        {
            var output = StaticStubbleRenderer.Render("{{> inner}}", new { Foo = "Bar" }, new Dictionary <string, string> {
                { "inner", "{{Foo}}" }
            });

            Assert.Equal("Bar", output);
        }
Beispiel #3
0
        public void It_Can_Render_With_LambdaSection_Dynamic()
        {
            var output = StaticStubbleRenderer.Render("{{#Foo}}Foo{{/Foo}}", new
            {
                BarValue = "Bar",
                Foo      = new Func <dynamic, string, object>((context, str) => str + " " + context.BarValue)
            });

            Assert.Equal("Foo Bar", output);
        }
Beispiel #4
0
        public void It_Should_Be_Able_To_Skip_Recursive_Lookups()
        {
            var output = StaticStubbleRenderer.Render(
                "{{FooValue}} {{#Foo}}{{FooValue}}{{BarValue}}{{/Foo}}",
                new
            {
                FooValue = "Foo",
                Foo      = new
                {
                    BarValue = "Bar"
                }
            },
                new RenderSettings
            {
                SkipRecursiveLookup = true
            });

            Assert.Equal("Foo Bar", output);
        }
Beispiel #5
0
        public async Task <IActionResult> Generate([FromBody] NewBlogPostNotification blogPostNotification,
                                                   CancellationToken cancellationToken)
        {
            List <BlogPostNotification> result = new List <BlogPostNotification>();

            //Reads the Mustache template and the data to render
            string template = await GetTemplateAsync();

            object view = await GetTemplateDataAsync(blogPostNotification.BlogName);

            //Creates the message using Stubble
            string message = StaticStubbleRenderer.Render(template, view);

            //Adds the results
            result.AddRange(blogPostNotification.EmailAddresses
                            .Select(x => new BlogPostNotification
            {
                EmailAddress = x,
                Text         = message
            }));

            return(Ok(result));
        }
 public string Render(ShaderInfo info) => StaticStubbleRenderer.Render(Template, info);
        public bool UpdateLabelSwitchedPath(Topology.MPLS.LabelSwitchedPath.LabelSwitchedPath LabelSwitchedPath)
        {
            // Fill PCC property if empty
            if (string.IsNullOrWhiteSpace(LabelSwitchedPath.PCC))
            {
                LabelSwitchedPath.PCC = LabelSwitchedPath.IPv4TunnelSenderAddress;
            }

            // Parse the template:
            var contents = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                         "Controller", "OpenDayLight", "Nitrogen", "Templates", "pcep-update-lsp-objects.odlt"));

            // Combine the model with the template to get content:
            var content = StaticStubbleRenderer.Render(contents, LabelSwitchedPath);


            var client = new RestClient();

            client.BaseUrl       = this.ControllerURI;
            client.Authenticator = new HttpBasicAuthenticator(this.ControllerUsername, this.ControllerPassword);

            var request = new RestRequest(Method.POST);

            request.AddParameter("application/xml", content, ParameterType.RequestBody);
            request.Resource = "restconf/operations/network-topology-pcep:update-lsp";

            IRestResponse response = client.Execute(request);



            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var result = JObject.Parse(response.Content);

                JToken output;
                if (result.TryGetValue("output", out output))
                {
                    if (!output.HasValues)
                    {
                        Console.WriteLine("SUCCESS: PCC {0} --> Updated LSP {1}/{2}", LabelSwitchedPath.PCC, LabelSwitchedPath.ParentId, LabelSwitchedPath.SymbolicPathName);

                        return(true);
                    }
                    else
                    {
                        if (output["failure"] != null)
                        {
                            Console.WriteLine("FAILURE: PCC {0} --> {1}", LabelSwitchedPath.PCC, output["failure"].ToString());

                            if (output["error"] != null)
                            {
                                Console.WriteLine("ERROR: PCC {0} --> {1}", LabelSwitchedPath.PCC, output["error"].ToString());
                            }

                            return(false);
                        }
                        else
                        {
                            Console.WriteLine("FAILURE: PCC {0} --> UNKNOWN FAILURE", LabelSwitchedPath.PCC);

                            return(false);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("FAILURE: PCC {0} --> UNKNOWN FAILURE", LabelSwitchedPath.PCC);

                    return(false);
                }
            }
            else
            {
                Console.WriteLine("FAILURE: PCC {0} --> ODL: REST FAILURE", LabelSwitchedPath.PCC);

                return(false);
            }
        }
Beispiel #8
0
        public void It_Can_Render_With_LambdaSection_NoDynamic()
        {
            var output = StaticStubbleRenderer.Render("{{#Foo}}Foo{{/Foo}}", new { Foo = new Func <string, object>((str) => str + " Bar") });

            Assert.Equal("Foo Bar", output);
        }
Beispiel #9
0
        public void It_Can_Render_With_LambdaToken_Dynamic()
        {
            var output = StaticStubbleRenderer.Render("{{Foo}}", new { BarValue = "Bar", Foo = new Func <dynamic, object>((context) => context.BarValue) });

            Assert.Equal("Bar", output);
        }
Beispiel #10
0
        public void It_Can_Render_With_LambdaToken_NoDynamic()
        {
            var output = StaticStubbleRenderer.Render("{{Foo}}", new { Foo = new Func <object>(() => "Bar") });

            Assert.Equal("Bar", output);
        }
Beispiel #11
0
        public void It_Can_Render_WithoutData()
        {
            var output = StaticStubbleRenderer.Render("I Have No Data :(", null);

            Assert.Equal("I Have No Data :(", output);
        }
Beispiel #12
0
        public void It_Doesnt_Error_When_Partial_Is_Used_But_None_Are_Given()
        {
            var output = StaticStubbleRenderer.Render("{{> inner}}", new { Foo = "Bar" });

            Assert.Equal("", output);
        }
Beispiel #13
0
        public void It_Can_Render_WithoutPartials()
        {
            var output = StaticStubbleRenderer.Render("{{Foo}}", new { Foo = "Bar" });

            Assert.Equal("Bar", output);
        }