/// <summary>
        /// Renders feedback messages.
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="messageRenderer"></param>
        /// <param name="showValidationErrors"></param>
        /// <returns></returns>
        public static IHtmlContent FeedbackMessagePanel(this IHtmlHelper helper, FeedbackMessageRenderer messageRenderer, bool showValidationErrors = false)
        {
            if (showValidationErrors)
            {
                FeedbackMessageUtil.AppendValidationErrorsToStore(helper.ViewContext);
            }

            return(new HtmlString(messageRenderer.RenderMessages().ToString()));
        }
        public FeedbackMessageSettings InitializeSettings()
        {
            var renderer      = new FeedbackMessageRenderer();
            var scriptBuilder = new FeedbackMessageScriptBuilder(msg => $"alert('{msg.ToString()}')");
            var config        = new FeedbackMessageSettings.FeedbackMessageConfig();

            FeedbackMessageSettings.CreateInitializer()
            .SetMessageRendererInstance(renderer)
            .SetScriptBuilderInstance(scriptBuilder)
            .SetConfigInstance(config)
            .Initialize();

            return(FeedbackMessageSettings.Instance);
        }
示例#3
0
        public void TestDefaultProperties()
        {
            var renderer = new FeedbackMessageRenderer();

            Assert.IsNotNull(renderer.OuterTagName);
            Assert.IsNotNull(renderer.InnerTagName);

            Assert.AreEqual("ul", renderer.OuterTagName);
            Assert.AreEqual("li", renderer.InnerTagName);

            Assert.IsFalse(renderer.EscapeMessage);

            Assert.IsNotNull(renderer.StringConverter);
        }
示例#4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseSession();
            app.UseFeedackMessages();

            FeedbackMessageSettings.CreateInitializer()
            .SetMessageRendererFactory(() =>
            {
                var messageRenderer          = new FeedbackMessageRenderer();
                messageRenderer.OuterTagName = "div";
                messageRenderer.InnerTagName = "span";

                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.INFO, "class", "ui info message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.SUCCESS, "class", "ui success message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.WARN, "class", "ui warning message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.ERROR, "class", "ui error message");

                return(messageRenderer);
            })
            .SetScriptBuilderInstance(new FeedbackMessageScriptBuilder(msg => $"alert('{msg.ToString()}');"))
            .Initialize();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "Second",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
示例#5
0
        public void TestAppendAttributeValue()
        {
            InitializeHttpContext();

            InfoMessage("TestMessage");


            var renderer = new FeedbackMessageRenderer();

            renderer.OuterTagName = "div";
            renderer.InnerTagName = "div";

            renderer.AppendOuterAttributeValue("id", "outer");
            renderer.AppendInnerAttributeValue("id", "inner");

            {
                var htmlString = renderer.RenderMessages().ToString();
                var htmlParser = new HtmlParser();

                var htmlDoc = htmlParser.ParseDocument(htmlString);
                var outer   = htmlDoc.GetElementById("outer");
                Assert.IsNotNull(outer);
                var inner = htmlDoc.GetElementById("inner");
                Assert.IsNotNull(inner);
            }



            renderer.AppendOuterAttributeValue("class", "outer");
            renderer.AppendInnerAttributeValue("class", "inner");

            {
                var htmlString = renderer.RenderMessages().ToString();
                var htmlParser = new HtmlParser();

                var htmlDoc = htmlParser.ParseDocument(htmlString);
                var outer   = htmlDoc.GetElementById("outer");
                Assert.IsNotNull(outer);
                Assert.IsTrue(outer.Attributes["class"].Value.Contains("outer"));
                var inner = htmlDoc.GetElementById("inner");
                Assert.IsNotNull(inner);
                Assert.IsTrue(inner.Attributes["class"].Value.Contains("inner"));
            }
        }
示例#6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseSession();
            app.UseFeedackMessages();

            FeedbackMessageSettings.CreateInitializer()
            .SetMessageRendererFactory(() =>
            {
                var messageRenderer          = new FeedbackMessageRenderer();
                messageRenderer.OuterTagName = "div";
                messageRenderer.InnerTagName = "p";

                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.INFO, "class", "ui info message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.SUCCESS, "class", "ui success message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.WARN, "class", "ui warning message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.ERROR, "class", "ui error message");

                return(messageRenderer);
            })
            .SetScriptBuilderInstance(new FeedbackMessageScriptBuilder(msg => $"alert('{msg.ToString()}');"))
            .Initialize();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });
        }
示例#7
0
        public void TestRenderMessagesMultiMessage()
        {
            InitializeHttpContext();

            InfoMessage("TestMessage1");
            InfoMessage("TestMessage2");

            var renderer = new FeedbackMessageRenderer();

            renderer.OuterTagName = "div";
            renderer.InnerTagName = "div";

            renderer.AppendOuterAttributeValue("id", "outer");



            var htmlString = renderer.RenderMessages().ToString();

            var htmlParser = new HtmlParser();
            var htmlDoc    = htmlParser.ParseDocument(htmlString);


            var outer = htmlDoc.GetElementById("outer");

            Assert.IsNotNull(outer);
            Assert.AreEqual("div", outer.NodeName.ToLower());
            Assert.IsTrue(outer.Attributes["class"].Value.Contains("feedback-info"));


            Assert.AreEqual(2, outer.ChildElementCount);

            var mes1 = outer.FirstChild;

            Assert.IsNotNull(mes1);
            Assert.AreEqual("div", mes1.NodeName.ToLower());
            Assert.AreEqual("TestMessage1", mes1.TextContent);

            var mes2 = mes1.NextSibling;

            Assert.IsNotNull(mes2);
            Assert.AreEqual("div", mes2.NodeName.ToLower());
            Assert.AreEqual("TestMessage2", mes2.TextContent);
        }
        public void TestInitializeSettings()
        {
            var renderer        = new FeedbackMessageRenderer();
            var scriptBuilder   = new FeedbackMessageScriptBuilder(msg => msg.ToString());
            var config          = new FeedbackMessageSettings.FeedbackMessageConfig();
            var storeSerializer = new FeedbackMessageStoreSerializer();

            FeedbackMessageSettings.CreateInitializer()
            .SetMessageRendererInstance(renderer)
            .SetScriptBuilderInstance(scriptBuilder)
            .SetConfigInstance(config)
            .SetStoreSerializerInstance(storeSerializer)
            .Initialize();


            Assert.IsTrue(Object.ReferenceEquals(FeedbackMessageSettings.Instance.MessageRenderer, renderer));
            Assert.IsTrue(Object.ReferenceEquals(FeedbackMessageSettings.Instance.ScriptBuilder, scriptBuilder));
            Assert.IsTrue(Object.ReferenceEquals(FeedbackMessageSettings.Instance.Config, config));
            Assert.IsTrue(Object.ReferenceEquals(FeedbackMessageSettings.Instance.StoreSerializer, storeSerializer));
        }
        public void TestRenderPanelWithCustomRenderer()
        {
            InitializeHttpContext();

            InfoMessage("Test message");

            var panel = new FeedbackMessagePanel();

            panel.ID   = "fm";
            panel.Page = new Page();

            var renderer = new FeedbackMessageRenderer();

            renderer.OuterTagName = "div";
            renderer.InnerTagName = "p";
            panel.MessageRenderer = renderer;


            var writer = new StringWriter();
            var output = new HtmlTextWriter(writer);

            panel.RenderControl(output);

            var htmlString = writer.GetStringBuilder().ToString();

            var parser  = new HtmlParser();
            var htmlDoc = parser.ParseDocument(htmlString);

            var panelElement = htmlDoc.GetElementById(panel.ClientID);

            Assert.AreEqual("div", panelElement.TagName.ToLower());

            var infoArea = panelElement.GetElementsByClassName("feedback-info")[0];
            var mes1     = infoArea.FirstChild;

            Assert.AreEqual("p", mes1.NodeName.ToLower());
            Assert.AreEqual("Test message", mes1.TextContent);
        }
示例#10
0
        void Application_Start(object sender, EventArgs e)
        {
            // アプリケーションのスタートアップで実行するコードです
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            FeedbackMessageSettings.CreateInitializer()
            .SetMessageRendererFactory(() =>
            {
                var messageRenderer          = new FeedbackMessageRenderer();
                messageRenderer.OuterTagName = "div";
                messageRenderer.InnerTagName = "span";

                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.INFO, "class", "ui info message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.SUCCESS, "class", "ui success message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.WARN, "class", "ui warning message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.ERROR, "class", "ui error message");

                return(messageRenderer);
            })
            .SetScriptBuilderInstance(new FeedbackMessageScriptBuilder(msg => $"alert('{msg.ToString()}');"))
            .Initialize();
        }
示例#11
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            FeedbackMessageSettings.CreateInitializer()
            .SetMessageRendererFactory(() =>
            {
                var messageRenderer          = new FeedbackMessageRenderer();
                messageRenderer.OuterTagName = "div";
                messageRenderer.InnerTagName = "span";

                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.INFO, "class", "ui info message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.SUCCESS, "class", "ui success message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.WARN, "class", "ui warning message");
                messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.ERROR, "class", "ui error message");

                return(messageRenderer);
            })
            .SetScriptBuilderInstance(new FeedbackMessageScriptBuilder(msg => $"alert('{msg.ToString()}');"))
            .Initialize();
        }