public void SetMessage(SessionMessage message) { if (message == null) return; List<SessionMessage> messages = GetMessage(); if (messages == null) messages = new List<SessionMessage>(); if (!string.IsNullOrEmpty(message.Key) && messages.Exists(x => x.Key == message.Key && x.Behavior == message.Behavior)) return; messages.Add(message); HttpContext.Current.Session[SessionMessageKey] = messages; }
public void SetMessage(SessionMessage message) { if (message == null) return; string json = null; List<SessionMessage> messages = GetMessage(); if (messages == null) messages = new List<SessionMessage>(); if (!string.IsNullOrEmpty(message.Key) && messages.Exists(x => x.Key == message.Key && x.Behavior==message.Behavior)) return; messages.Add(message); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<SessionMessage>)); using (MemoryStream ms = new MemoryStream()) { ser.WriteObject(ms, messages); json = Encoding.Default.GetString(ms.ToArray()); ms.Close(); } HttpContext.Current.Response.Cookies[SessionMessageKey].Value=json; }
public static void SetMessage(MessageType messageType, MessageBehaviors behavior, string message, string key,string caption, MessageButton? messageButtons, MessageIcon? messageIcon) { if (caption == null || caption.Trim() == string.Empty) caption = messageType.ToString(); if (!messageButtons.HasValue) messageButtons = MessageButton.Ok; if (!messageIcon.HasValue) { switch (messageType) { case MessageType.Error: messageIcon = MessageIcon.Error; break; case MessageType.Warning: messageIcon = MessageIcon.Warning; break; case MessageType.Info: messageIcon = MessageIcon.Information; break; } } SessionMessage sessionMessage = new SessionMessage(messageType, behavior, message, key,caption, messageButtons, messageIcon); ISessionMessageProvider provider = IoC.GetService<ISessionMessageProvider>(); provider.SetMessage(sessionMessage); }