Beispiel #1
0
        public List <SecsLog> RetrieveMessageList(List <string> messages)
        {
            string         message;
            List <SecsLog> secsLogs = new List <SecsLog>();

            string[] headerSplits;
            string   messageID;
            string   timeStamp;
            string   msgTypeString;
            string   msgStatus;

            string positionInfo;
            long   filePosition;
            int    lineNum;
            string readMessage;
            string nextMessage;
            int    nextIndex = -1;


            eMessageType msgType = eMessageType.UNKNOWN;

            for (int msgIndex = 0; msgIndex < messages.Count; msgIndex++)
            {
                message      = messages[msgIndex];
                positionInfo = message.Substring(0, message.IndexOf(':'));
                filePosition = long.Parse(positionInfo.Substring(0, positionInfo.IndexOf(',')));
                lineNum      = int.Parse(positionInfo.Substring(positionInfo.IndexOf(',') + 1));
                readMessage  = message.Substring(message.IndexOf(':') + 2);

                if (readMessage.Length > 20)
                {
                    if (IsIncludeTimeStamp(readMessage) == true) // Is the header of each message containing timestamp??
                    {
                        timeStamp     = readMessage.Substring(0, 8);
                        msgTypeString = readMessage.Substring(10, (readMessage.IndexOf("]") - 10));
                        msgStatus     = readMessage.Substring(readMessage.IndexOf("]") + 1).Trim();

                        switch (msgTypeString)
                        {
                        case "SECS-II:Rcv":
                            msgType = eMessageType.SECS_RCV;
                            break;

                        case "SECS-II:Send":
                            msgType = eMessageType.SECS_SEND;
                            break;

                        case "I/F:Alarm":
                            msgType = eMessageType.IF_ALARM;
                            break;

                        case "Proc:Event":
                            msgType = eMessageType.PROC_ALARM;
                            break;

                        case "Proc:Alarm":
                            msgType = eMessageType.PROC_ALARM;
                            break;

                        case "HSMS:State":
                            msgType = eMessageType.HSMS_STATE;
                            break;

                        case "HSMS:Send":
                            msgType = eMessageType.HSMS_SEND;
                            break;

                        case "HSMS:Rcv":
                            msgType = eMessageType.HSMS_RCV;
                            break;

                        default:
                            msgType = eMessageType.UNKNOWN;
                            break;
                        }

                        SecsLog       secsLog     = new SecsLog(timeStamp, msgType, msgStatus);
                        StringBuilder messageBody = new StringBuilder();

                        secsLog.FilePosition = filePosition;

                        messageID         = "N/A";
                        secsLog.MessageID = messageID;



                        // *----1. MSG Header 가져오기.
                        if (msgType == eMessageType.SECS_RCV || msgType == eMessageType.SECS_SEND)
                        {
                            if ((nextIndex = this.GetNextMessageIndex(messages, msgIndex)) != -1)  // 다음 메시지가 있다면
                            {
                                nextMessage = messages[nextIndex];
                                nextMessage = messages[nextIndex].Substring(message.IndexOf(':') + 2);

                                // 다음 메시지가 시간을 포함하는 다른 시작 메세지가 아니라면 (정상 메시지가 아닌지 확인)
                                if (this.IsHeaderMessage(nextMessage) == true)
                                {
                                    message     = messages[nextIndex];
                                    readMessage = message.Substring(message.IndexOf(':') + 2);

                                    readMessage = readMessage.Replace("\t", string.Empty);

                                    headerSplits      = readMessage.Split(',');
                                    messageID         = headerSplits[0].Trim() + ", " + headerSplits[1].Trim();
                                    secsLog.MessageID = messageID;

                                    secsLog.SystemByte = headerSplits[4].Remove(0, " SystemByte = ".Length);

                                    msgIndex = nextIndex;   // msgIndex를 nextIndex로 확정.
                                }
                            }

                            // *----2. MSG Body 가져오기.


                            while (true)
                            {
                                if ((nextIndex = this.GetNextMessageIndex(messages, msgIndex)) != -1)  // 다음 메시지가 있다면
                                {
                                    nextMessage = messages[nextIndex];
                                    nextMessage = messages[nextIndex].Substring(message.IndexOf(':') + 2);

                                    // 다음 메시지가 시간을 포함하는 다른 시작 메세지가 아니라면 (정상 메시지가 아닌지 확인)
                                    if (IsIncludeTimeStamp(nextMessage) == false)
                                    {
                                        message     = messages[nextIndex];
                                        readMessage = message.Substring(message.IndexOf(':') + 2);

                                        readMessage = readMessage.Replace("\t", string.Empty);

                                        messageBody.Append(readMessage);

                                        msgIndex = nextIndex;   // msgIndex를 nextIndex로 확정.
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }

                        // 여기서 Message를 각각 Parsing할 일이 있다면 구현해줘어야 함.
                        switch (secsLog.MessageID)
                        {
                        case "S6, F11":
                            S6F11Parser s6f11Parser = new S6F11Parser();
                            secsLog.SecsMessage = s6f11Parser.GetParsedMessage(messageBody.ToString());
                            break;

                        case "S10, F5":
                            S10F5Parser s10f5Parser = new S10F5Parser();
                            secsLog.SecsMessage = s10f5Parser.GetParsedMessage(messageBody.ToString());
                            break;

                        case "N/A":
                            secsLog.SecsMessage = new NAMessage(secsLog.MsgStatus);
                            break;
                        }


                        secsLogs.Add(secsLog);
                    }
                }

                if (EV_updateProgress != null)
                {
                    EV_updateProgress(messages.Count, msgIndex, "Retrieving SECS Messages");
                }
            }

            EV_updateProgress(100, 0, "Complete");

            return(secsLogs);
        }
Beispiel #2
0
        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;
            }
        }