Example #1
1
 /// <summary>
 /// Queues a flash message for display with the specified message.
 /// </summary>
 /// <param name="message"></param>
 /// <param name="title"></param>
 /// <param name="messageType"></param>
 /// <param name="isHtml"></param>
 public static void Queue(string message, string title, FlashMessageType messageType, bool isHtml)
 {
     // Append the new message.
     var flashMessage = new FlashMessageModel { IsHtml = isHtml, Message = message, Title = title, Type = messageType };
     Queue(flashMessage);
 }
Example #2
0
        /// <summary>
        /// Deserializes a serialized collection of flash messages.
        /// </summary>
        /// <param name="serializedMessages"></param>
        /// <returns></returns>
        public static List <FlashMessageModel> Deserialize(byte[] data)
        {
            var messages = new List <FlashMessageModel>();
            int messageCount;

            // Check if there is any data to read, if not we are done quickly.
            if (data.Length == 0)
            {
                return(messages);
            }

            using (MemoryStream stream = new MemoryStream(data))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    // Read the number of message in the stream and deserialize each message.
                    messageCount = reader.ReadInt32();
                    while (messageCount > 0)
                    {
                        var model = new FlashMessageModel();
                        model.IsHtml  = reader.ReadBoolean();
                        model.Message = reader.ReadString();
                        model.Title   = reader.ReadString();
                        model.Type    = (FlashMessageType)reader.ReadByte();

                        // Store message and decrement message counter.
                        messages.Add(model);
                        messageCount--;
                    }

                    return(messages);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Queues a flash message for display with the specified message.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="title"></param>
        /// <param name="messageType"></param>
        public static void Queue(string message, string title, FlashMessageType messageType)
        {
            // Append the new message.
            var flashMessage = new FlashMessageModel {
                IsHtml = false, Message = message, Title = title, Type = messageType
            };

            Queue(flashMessage);
        }
Example #4
0
        /// <summary>
        /// Queues the passed flash message for display.
        /// </summary>
        /// <param name="message"></param>
        public static void Queue(FlashMessageModel message)
        {
            List <FlashMessageModel> messages;

            // Retrieve the currently queued cookies.
            messages = GetQueued();

            // Append the new message.
            messages.Add(message);

            // Store the messages.
            Transport.Queue(messages);
        }
Example #5
0
        /// <summary>
        /// Queues the passed flash message for display.
        /// </summary>
        /// <param name="message"></param>
        public void Queue(FlashMessageModel message)
        {
            List <FlashMessageModel> messages;

            // Retrieve the currently queued cookies.
            messages = Queued(TempData);

            // Append the new message.
            messages.Add(message);

            // Store the messages.
            Store(messages);
        }
        /// <summary>
        /// Renders the passed flash message as a Twitter Bootstrap alert component.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static string RenderFlashMessage(FlashMessageModel message)
        {
            string result = "<div class=\"" + message.Type.GetCssStyle() + " alert-dismissible\" role=\"alert\">\r\n";

            result += "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>\r\n";
            if (!string.IsNullOrWhiteSpace(message.Title))
                result += "<strong>" + HttpUtility.HtmlEncode(message.Title) + "</strong> ";

            if (message.IsHtml)
                result += message.Message;
            else
                result += HttpUtility.HtmlEncode(message.Message);

            result += "</div>";
            return result;
        }
        public void SerializeSingleTest()
        {
            FlashMessageModel message = new FlashMessageModel
            {
                IsHtml  = true,
                Message = "<p>test content</p> üñï€ode",
                Title   = "Title",
                Type    = FlashMessageType.Custom
            };

            // Serialize and deserialize.
            FlashMessage.Queue(message);
            var messages     = FlashMessage.GetQueued();
            var deserialized = messages[0];

            // Compare the results.
            Assert.Equal(message.Type, deserialized.Type);
            Assert.Equal(message.Title, deserialized.Title);
            Assert.Equal(message.Message, deserialized.Message);
            Assert.Equal(message.IsHtml, message.IsHtml);
        }
        public void SerializeSingleTest()
        {
            FlashMessageModel message = new FlashMessageModel
            {
                IsHtml = true,
                Message = "<p>test content</p> üñï€ode",
                Title = "Title",
                Type = FlashMessageType.Custom
            };

            // Serialize and deserialize.
            FlashMessage.Queue(message);
            var messages = FlashMessage.GetQueued();
            var deserialized = messages[0];

            // Compare the results.
            Assert.Equal(message.Type, deserialized.Type);
            Assert.Equal(message.Title, deserialized.Title);
            Assert.Equal(message.Message, deserialized.Message);
            Assert.Equal(message.IsHtml, message.IsHtml);
        }
        /// <summary>
        /// Renders the passed flash message as a Twitter Bootstrap alert component.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static HtmlString RenderFlashMessage(FlashMessageModel message)
        {
            string result = "<div class=\"" + message.Type.GetCssStyle() + " alert-dismissible\" role=\"alert\">\r\n";

            result += "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"><span aria-hidden=\"true\">&times;</span></button>\r\n";
            if (!string.IsNullOrWhiteSpace(message.Title))
            {
                result += "<strong>" + WebUtility.HtmlEncode(message.Title) + "</strong> ";
            }

            if (message.IsHtml)
            {
                result += message.Message;
            }
            else
            {
                result += WebUtility.HtmlEncode(message.Message);
            }

            result += "</div>";
            return(new HtmlString(result));
        }
        /// <summary>
        /// Renders the passed flash message as a Twitter Bootstrap alert component.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="dismissable">Indicates if this message should be dismissable</param>
        /// <returns></returns>
        public static string RenderFlashMessage(FlashMessageModel message, bool dismissable = true)
        {
            var    cssClasses = message.Type.GetCssStyle();
            var    icon       = message.Type.GetIconBody();
            string result     = $"<div class=\"alert alert-custom alert-notice alert-light-{cssClasses} fade show\" role=\"alert\">";

            result += icon;
            result += "<div class=\"alert-text font-weight-bold\">";

            if (!string.IsNullOrWhiteSpace(message.Title))
            {
                result += "<strong>" + HttpUtility.HtmlEncode(message.Title) + "</strong> ";
            }

            if (message.IsHtml)
            {
                result += message.Message;
            }
            else
            {
                result += HttpUtility.HtmlEncode(message.Message);
            }

            result += "</div>";

            if (dismissable)
            {
                result += "<div class=\"alert-close\">";
                result += "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">";
                result += "<span aria-hidden=\"true\"><i class=\"ki ki-close\"></i></span>";
                result += "</button>";
                result += "</div>";
            }

            result += "</div>";

            return(result);
        }
        public void SerializeSingleTest()
        {
            List<FlashMessageModel> messages = new List<FlashMessageModel>();
            FlashMessageModel message = new FlashMessageModel
            {
                IsHtml = true,
                Message = "<p>test content</p> üñï€ode",
                Title = "Title",
                Type = FlashMessageType.Custom
            };

            // Serialize and deserialize.
            messages.Add(message);
            var data = FlashMessage.Serialize(messages);
            messages = FlashMessage.Deserialize(data);
            var deserialized = messages[0];

            // Compare the results.
            Assert.Equal(message.Type, deserialized.Type);
            Assert.Equal(message.Title, deserialized.Title);
            Assert.Equal(message.Message, deserialized.Message);
            Assert.Equal(message.IsHtml, message.IsHtml);
        }
Example #12
0
        public void SerializeSingleTest()
        {
            List <FlashMessageModel> messages = new List <FlashMessageModel>();
            FlashMessageModel        message  = new FlashMessageModel
            {
                IsHtml  = true,
                Message = "<p>test content</p> üñï€ode",
                Title   = "Title",
                Type    = FlashMessageType.Custom
            };

            // Serialize and deserialize.
            messages.Add(message);
            var data = FlashMessage.Serialize(messages);

            messages = FlashMessage.Deserialize(data);
            var deserialized = messages[0];

            // Compare the results.
            Assert.Equal(message.Type, deserialized.Type);
            Assert.Equal(message.Title, deserialized.Title);
            Assert.Equal(message.Message, deserialized.Message);
            Assert.Equal(message.IsHtml, message.IsHtml);
        }
Example #13
0
        /// <summary>
        /// Deserializes a serialized collection of flash messages.
        /// </summary>
        /// <param name="serializedMessages"></param>
        /// <returns></returns>
        public static List<FlashMessageModel> Deserialize(byte[] data)
        {
            var messages = new List<FlashMessageModel>();
            int messageCount;

            // Check if there is any data to read, if not we are done quickly.
            if (data.Length == 0)
                return messages;

            using (MemoryStream stream = new MemoryStream(data))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {

                    // Read the number of message in the stream and deserialize each message.
                    messageCount = reader.ReadInt32();
                    while (messageCount > 0)
                    {

                        var model = new FlashMessageModel();
                        model.IsHtml = reader.ReadBoolean();
                        model.Message = reader.ReadString();
                        model.Title = reader.ReadString();
                        model.Type = (FlashMessageType)reader.ReadByte();

                        // Store message and decrement message counter.
                        messages.Add(model);
                        messageCount--;
                    }

                    return messages;
                }
            }
        }
Example #14
0
        /// <summary>
        /// Queues the passed flash message for display.
        /// </summary>
        /// <param name="message"></param>
        public static void Queue(FlashMessageModel message)
        {
            List<FlashMessageModel> messages;

            // Retrieve the currently queued cookies.
            messages = GetQueued();

            // Append the new message.
            messages.Add(message);

            // Store the messages.
            Transport.Queue(messages);
        }