/// <summary> /// Button_Click_Ok /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_Ok(object sender, RoutedEventArgs e) { try { DialogResult = true; FocusMessage = new byte[HexEdit.Stream.Length]; HexEdit.SubmitChanges(); FocusMessage = HexEdit.Stream.ToArray(); } catch (Exception ex) { _logger.Error(String.Format("Exception in {0} {1}", LST.GetCurrentMethod(), ex.Message)); } Close(); }
/******************************/ /* Menu Events */ /******************************/ #region Menu Events #endregion /******************************/ /* Other Events */ /******************************/ #region Other Events #endregion /******************************/ /* Other Functions */ /******************************/ #region Other Functions /// <summary> /// ApplyMessageTabsContent /// </summary> /// <param name="i"></param> /// <returns></returns> private void ApplyMessagesFromTabsContent() { int i = 0; try { foreach (var t in TabItems) { t.HexEditor.SubmitChanges(); MessagesToEdit[i].MessageName = t.Header; MessagesToEdit[i].Content = t.HexEditor.Stream.ToArray(); i++; } FocusMessage = MessagesToEdit[tabHexaEditors.SelectedIndex].Content; } catch (Exception ex) { _logger.Error(String.Format("Exception in {0} {1}", LST.GetCurrentMethod(), ex.Message)); } }
/// <summary> /// AddTabItem /// </summary> /// <param name="v"></param> private TabItem AddTabItem(Message m) { int count = TabItems.Count; TabItem tab = new TabItem(); if (String.IsNullOrEmpty(m.MessageName)) { m.MessageName = String.Format("Message {0}", count + 1); } tab.Header = m.MessageName; tab.HexEditor = new HexaEditor(); tab.HexEditor.Width = Double.NaN; tab.HexEditor.Height = Double.NaN; tab.HexEditor.Stream = new System.IO.MemoryStream(m.Content); TabItems.Add(tab); _logger.Trace(String.Format("AddTabItem in {0}", LST.GetCurrentMethod())); return(tab); }
/// <summary> /// mDIWindow_Unloaded /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mDIWindow_Unloaded(object sender, System.Windows.RoutedEventArgs e) { switch (MyConnection.ConnectionType) { case EConnectionType.TCPSocketServer: _minaTCPServer.Close(); _minaTCPServer.ConnectionStateChaneged -= ConStateChaneged; break; case EConnectionType.TCPSocketCient: _minaTCPClient.Close(); _minaTCPClient.ConnectionStateChaneged -= ConStateChaneged; break; } _logger.Debug(String.Format("{0} ------------------------------- IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), IsConnected, System.Threading.Thread.CurrentThread.ManagedThreadId, GetHashCode())); }
/******************************/ /* Button Events */ /******************************/ #region Button Events #endregion /******************************/ /* Menu Events */ /******************************/ #region Menu Events #endregion /******************************/ /* Other Events */ /******************************/ #region Other Events /// <summary> /// ConStateChaneged /// </summary> /// <param name="conState"></param> private void ConStateChaneged(bool conState) { // Unlink the threads between TCP thread and UI thread: // http://stackoverflow.com/questions/2403972/c-sharp-events-between-threads-executed-in-their-own-thread-how-to DispatcherObjectForTaskDispatcher.BeginInvoke(new Action( () => { IsConnected = conState; if (IsConnected) { TheMdiChild.Title = String.Format("{0} (!)", MyConnection.ConnectionName); } else { TheMdiChild.Title = String.Format("{0} ( )", MyConnection.ConnectionName); } _mainWindow.UpdateWindow(); _logger.Debug(String.Format("#2 {0} IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), IsConnected, System.Threading.Thread.CurrentThread.ManagedThreadId, GetHashCode())); })); }
/// <summary> /// CanAddNewMessageCommand /// </summary> /// <returns></returns> private bool CanAddNewMessageCommand() { MdiChild tw = GetTopMDIWindow(); if (tw == null) { return(false); } UserControlTCPMDIChild uctmc = GetTopMDIWindow().Content as UserControlTCPMDIChild; _logger.Debug(String.Format("#3 {0} IsConnected={1} ThreadId={2} hashcode={3}", LST.GetCurrentMethod(), uctmc.IsConnected, System.Threading.Thread.CurrentThread.ManagedThreadId, uctmc.GetHashCode())); return(uctmc.IsConnected); }