コード例 #1
0
ファイル: ClientObj.cs プロジェクト: guilee1/omc-ni-simulator
        /// <summary>
        /// 处理接收到的OMC消息
        /// </summary>
        /// <param name="buffer"></param>
        void receiveMsg(byte[] buffer)
        {
            Message omcMsg = Message.parse(buffer);

            if (omcMsg.MsgType == 0)
            {
                //realTimeAlarm
                AlarmVo almObj = AlarmVo.ParseFromJson(omcMsg);
                almObj.LogTime = DateTime.Now.ToLongTimeString();
                //如果告警时间与当前时间相差超过5s,则认为延迟问题
                TimeSpan time = DateTime.Now - Util.getTime(almObj.EventTime);
                if (time.TotalSeconds >= 5)
                {
                    log.Info("exceed 5 sec:" + "time is :" + time.TotalMilliseconds + " user:"******" msg:" + almObj.toString());
                }
                else
                {
                    log.Info("time is :" + time.TotalSeconds + " user:"******" msg:" + almObj.toString());
                }
                if (!isLogModel)
                {
                    this.rtAlmList.Add(almObj);
                    mainFrame.RefrashRtAlmGrid(this.Id, this.rtAlmList);
                }
            }
            else
            {
                OperInfo operObj = OperInfo.Parse(omcMsg);
                this.operInfoList.Add(operObj);
                log.Info("user:"******" msg:" + operObj.toString());
                mainFrame.RefrashOperInfoGrid(this.Id, this.operInfoList);
            }
        }
コード例 #2
0
        /// <summary>
        /// 读取告警文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReadAlarm_Click(object sender, EventArgs e)
        {
            if (this.txtAlarmFilePath.Text == "")
            {
                MessageBox.Show("pls choose a file to read first!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            ArrayList    alarmList = new ArrayList();
            string       path      = this.txtAlarmFilePath.Text;
            StreamReader sr        = new StreamReader(path, Encoding.UTF8);
            String       line;

            try
            {
                while ((line = sr.ReadLine()) != null)
                {
                    AlarmVo vo = Util.DeserializeJsonToObject <AlarmVo>(line);
                    alarmList.Add(vo);
                }
                MessageBox.Show("parse over!");
                this.dgAlarmFile.DataSource = alarmList;
            }
            catch
            {
                MessageBox.Show("bad alarm file format!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally{
                sr.Close();
            }
        }