private void ShowSecsMessagesToList(BackgroundWorker worker, DoWorkEventArgs e) { this.EnableControls(false); if (secsLogs == null) { return; } lvMsgMain.Items.Clear(); lvMsgMain.BeginUpdate(); int imgType; bool isIgnore = false; int msgIndex = 0; int listViewIndex = 0; string msgInfo; int colorIndex; msgIndexDic.Clear(); string msgDesc = string.Empty; foreach (SecsLog secsLog in secsLogs) { if (worker.CancellationPending) { e.Cancel = true; break; } if (this.messageFilter.IsExcludeEnable == true) { foreach (string excludeMessage in this.messageFilter.ExcludeMessages) { if (secsLog.MessageID.Equals(excludeMessage)) { isIgnore = true; break; } else { isIgnore = false; } } } else if (this.messageFilter.IsIncludeEnable == true) { foreach (string includeMessage in this.messageFilter.IncludeMessages) { if (secsLog.MessageID.Equals(includeMessage)) { isIgnore = false; break; } else { isIgnore = true; } } } else { isIgnore = false; } switch (secsLog.MessageType) { case eMessageType.SECS_SEND: imgType = (int)eMsgTypeImg.ARROW_LEFT; break; case eMessageType.SECS_RCV: imgType = (int)eMsgTypeImg.ARROW_RIGHT; break; default: imgType = (int)eMsgTypeImg.INFORMATION; break; } if (secsLog.SecsMessage != null) { msgInfo = secsLog.SecsMessage.GetInfo(); } else { msgInfo = string.Empty; } MessageHelpInfo messageHelpInfo = messageHelpInfoList.GetMessageHelp(secsLog.MessageID); if (messageHelpInfo != null) { msgDesc = messageHelpInfo.Description; colorIndex = messageHelpInfo.ColorIndex; } else { msgDesc = string.Empty; colorIndex = Color.White.ToArgb(); } if (isIgnore == false) { // *--- Column-00 MsgType ICon ListViewItem item = new ListViewItem(string.Empty, imgType); // *--- Column-01 ColorIndex item.SubItems.Add(string.Empty); item.SubItems[1].BackColor = Color.FromArgb(colorIndex); item.UseItemStyleForSubItems = false; //*---- Column-02 Msg ID item.SubItems.Add(secsLog.MessageID); // *---- Column-03 TimeStamp item.SubItems.Add(secsLog.TimeStamp); // *--- Column-04 Message Information item.SubItems.Add(msgInfo); // *--- Column-05 Message Description item.SubItems.Add(msgDesc); // *--- Column-06 System Byte item.SubItems.Add(secsLog.SystemByte); lvMsgMain.Items.Add(item); msgIndexDic.Add(listViewIndex, msgIndex); listViewIndex++; } msgIndex++; this.UpdateProgress(secsLogs.Count, msgIndex, "Showing Messages"); } this.UpdateProgress(100, 0, "Complete"); lvMsgMain.EndUpdate(); }
private void lvMsgMain_SelectedIndexChanged(object sender, EventArgs e) { if (lvMsgMain.SelectedItems.Count > 0) { int index = lvMsgMain.SelectedIndices[0]; int msgIndex = this.msgIndexDic[index]; SecsLog secsLog = this.GetSecsLog(msgIndex); long endFilePosition = secsLog.FilePosition + LogFileParsing.maxReadBuffer; SecsLog nextSecsLog = this.GetSecsLog(msgIndex + 1); if (nextSecsLog != null) { endFilePosition = nextSecsLog.FilePosition; } List <string> messages = this.logFileControl.LoadLogFileByPosition(secsLog.FilePosition, endFilePosition); // *--- Message Type txtMessageType.Text = secsLog.MessageType.ToString(); // *--- Message ID txtMessageID.Text = secsLog.MessageID; // *--- Message Body rtbWholeMsg.Text = string.Empty; StringBuilder sbMsgBody = new StringBuilder(); int i = 1; foreach (string message in messages) { sbMsgBody.Append(message.Substring(message.IndexOf(':') + 2)); this.UpdateProgress(messages.Count, i++, "Showing Message Body"); } rtbWholeMsg.AppendText(sbMsgBody.ToString()); this.UpdateProgress(100, 0, "Complete"); // *--- Information string information; if (secsLog.SecsMessage != null) { information = secsLog.SecsMessage.GetInfo(); } else { information = string.Empty; } txtInformation.Text = information; // *--- Message Help MessageHelpInfo messageHelpInfo = messageHelpInfoList.GetMessageHelp(secsLog.MessageID); string messageHelp; string description = string.Empty; if (messageHelpInfo != null) { messageHelp = messageHelpInfo.MessageHelp; description = messageHelpInfo.Description; } else { messageHelp = string.Empty; } rtbMessageHelper.Text = messageHelp; // *--- Description this.txtDescription.Text = description; } }
private void btnAdd_Click(object sender, EventArgs e) { if (txtStream.Text != string.Empty && txtFunction.Text != string.Empty) { int inputStream; int inputFunction; if (int.TryParse(txtStream.Text, out inputStream) == false) { MessageBox.Show("Stream is not number."); return; } if (int.TryParse(txtFunction.Text, out inputFunction) == false) { MessageBox.Show("Function is not number."); return; } bool isModify = false; foreach (MessageHelpInfo messageHelp in this.messageHelpList.Items) { // 같으면 수정만 한다. if (messageHelp.Stream == inputStream && messageHelp.Function == inputFunction) { messageHelp.Stream = Convert.ToInt32(txtStream.Text); messageHelp.Function = Convert.ToInt32(txtFunction.Text); messageHelp.Description = this.txtDescription.Text; messageHelp.MessageHelp = this.txtMessageHelp.Text; messageHelp.ColorIndex = this.btnColorIndex.BackColor.ToArgb(); isModify = true; } } if (isModify == false) { MessageHelpInfo newMessageHelp = new MessageHelpInfo(); newMessageHelp.Stream = inputStream; newMessageHelp.Function = inputFunction; newMessageHelp.Description = this.txtDescription.Text; newMessageHelp.MessageHelp = this.txtMessageHelp.Text; newMessageHelp.ColorIndex = this.btnColorIndex.BackColor.ToArgb(); this.messageHelpList.Items.Add(newMessageHelp); } this.messageHelpList.Items.Sort(new MessageHelperComparer()); this.ShowList(); try { XmlWriterSettings settings = new XmlWriterSettings(); settings.IndentChars = "\t"; settings.Indent = true; using (StreamWriter sw = new StreamWriter(Application.StartupPath + "\\" + messageHelpXmlFilePath)) using (XmlWriter xw = XmlWriter.Create(sw, settings)) { XmlSerializer xs = new XmlSerializer(typeof(MessageHelpInfoList)); xs.Serialize(xw, this.messageHelpList); } } catch (IOException) { MessageBox.Show("Fail to save files"); } } this.txtStream.Text = string.Empty; this.txtFunction.Text = string.Empty; this.txtDescription.Text = string.Empty; this.txtMessageHelp.Text = string.Empty; this.btnColorIndex.BackColor = Color.White; this.isTextChanged = false; this.messageHelpList.IsChangeSaved = true; }