/// <summary> /// Writes message to log /// </summary> /// <param name="m"> Message to write </param> public void WriteLog(Message m) { String logDirectory = ConfigurationManager.AppSettings.Get("LogsDirectory"); CreateDirectory(logDirectory); String currentYear = DateTime.Now.ToString("yyyy"); logDirectory = Path.Combine(logDirectory, currentYear); CreateDirectory(logDirectory); String currentMonth = DateTime.Now.ToString("MMMM"); logDirectory = Path.Combine(logDirectory, currentMonth); CreateDirectory( logDirectory ); String fileName = Path.Combine(logDirectory, (m.Type == MessageType.Common ? "Common" : m.ConferenceNumber) + ".log"); CreateFile( fileName ); using (FileStream fs = File.OpenWrite(fileName)) { using (StreamWriter writer = new StreamWriter(fs)) { writer.WriteLine(m.GetMessageString()); writer.Close(); } } }
/// <summary> /// Serialize Message objcet to byte array /// </summary> /// <param name="m"> Message object </param> /// <returns> Byte array. </returns> public static Byte[] Serialize(Message m) { IFormatter formatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); formatter.Serialize(stream, m); Byte[] buffer = stream.ToArray(); stream.Close(); return buffer; }
public MsgReceiveEventArgs( Byte[] serializedMessage) { message = Message.Deserialize(serializedMessage); }
public MsgReceiveEventArgs(Message message) { this.message = message; }
/// <summary> /// Creates a new tab /// </summary> /// <param name="message"> Received message </param> private void CreateTab(Message message) { Grid grid = new Grid { Margin = new Thickness(0, -1, 0, 26) }; RichTextBox rtb = new RichTextBox { HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0, 0, 0, -24), Width = 417, AllowDrop = false, IsReadOnly = true, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, AcceptsReturn = false, IsUndoEnabled = false, Resources = ChatArea0.Resources }; ListBox lb = new ListBox { HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(424, 0, 0, -24), Width = 204 }; foreach (CheckBox cb in ConnectList0.Items) { lb.Items.Add(new CheckBox { Content = cb.Content, Foreground = cb.Foreground, IsChecked = true, IsEnabled = false }); } grid.Children.Add(lb); grid.Children.Add(rtb); String tag = message == null ? DateTime.Now.ToString("ddHHmmss") : message.ConferenceNumber; TabItem tabItem = new TabItem { Background = ((TabItem)Tabs.Items[0]).Background, Foreground = ((TabItem)Tabs.Items[0]).Foreground, Name = "TabItem" + (Tabs.Items.Count - 1), Tag = "Conference#" + tag, Content = grid }; SetHeader(tabItem); Tabs.Items.Insert(Tabs.Items.Count - 1, tabItem); }
/// <summary> /// Prints message text in message area. /// </summary> /// <param name="message"> Message object to print </param> public void ShowMessage(Message message) { Dispatcher.Invoke((ThreadStart)delegate { switch (message.Type) { case MessageType.Common: { ShowAt(0, new Run(message.GetMessageString())); break; } case MessageType.Conference: { for (int i = 1; i < Tabs.Items.Count - 1; i++) { if (((TabItem)Tabs.Items[i]).Tag.ToString() == message.ConferenceNumber) { ShowAt(i, RunBuilder.DefaultRun(message)); return; } } CreateTab(message); ShowAt(Tabs.Items.Count - 2, RunBuilder.DefaultRun(message)); break; } default: { for (int i = 0; i < Tabs.Items.Count - 1; i++) { ListBox lb = (ListBox)((Grid)((TabItem)Tabs.Items[i]).Content).Children[0]; foreach (CheckBox item in lb.Items) { if (item.Content.ToString() == message.SenderName && item.IsChecked == true) { ShowAt(i, RunBuilder.SystemRun(message)); } } } break; } } }); }