示例#1
0
        //获取告警字符串
        public CommandMsg ConvertToMsg()
        {
            try
            {
                SyncRoot.AcquireReaderLock(-1);

                CommandMsg msg = new CommandMsg();
                msg.TK_CommandType = Constants.TK_CommandType.ADAPTER_ALARM_REPORT;

                msg.Content["集中告警流水号"] = TKSn;
                msg.Content["厂商告警流水号"] = ManuSn;
                msg.Content["告警城市"]    = City;
                msg.Content["设备厂商"]    = Manufacturer;
                msg.Content["业务类型"]    = BusinessType;
                msg.Content["网元名称"]    = NeName;
                msg.Content["网元类型"]    = NeType;
                msg.Content["对象名称"]    = ObjName;
                msg.Content["对象类型"]    = ObjType;
                msg.Content["告警名称"]    = AlarmName;
                msg.Content["重定义告警名称"] = Redefinition;
                //msg.Content["告警种类"] = Category;
                msg.Content["告警级别"]      = Severity;
                msg.Content["告警发生时间"]    = OccurTime;
                msg.Content["告警确认时间LV1"] = AckTimeLV1;
                msg.Content["再次确认时间LV1"] = AckAgainTimeLV1;
                msg.Content["告警确认时间LV2"] = AckTimeLV2;
                msg.Content["再次确认时间LV2"] = AckAgainTimeLV2;
                msg.Content["告警恢复时间"]    = ClearTime;
                msg.Content["告警定位信息"]    = Location;
                msg.Content["操作员信息LV11"] = OperatorLV11;
                msg.Content["操作员信息LV12"] = OperatorLV12;
                msg.Content["操作员信息LV21"] = OperatorLV21;
                msg.Content["操作员信息LV22"] = OperatorLV22;
                msg.Content["工程上报信息"]    = ProjectInfo;
                msg.Content["工程超时"]      = ProjectBool;
                msg.Content["派单人LV1"]    = OrderOperatorLV1;
                msg.Content["派单号LV1"]    = OrderIDLV1;
                msg.Content["派单时间LV1"]   = OrderTimeLV1;
                msg.Content["派单人LV2"]    = OrderOperatorLV2;
                msg.Content["派单号LV2"]    = OrderIDLV2;
                msg.Content["派单时间LV2"]   = OrderTimeLV2;
                msg.Content["OMCName"]   = OMCName;
                msg.Content["Reserved2"] = Reserved2;
                msg.Content["Reserved3"] = Reserved3;
                msg.Content["接收时间"]      = ReceiveTime;

                return(msg);
            }
            finally
            {
                SyncRoot.ReleaseReaderLock();
            }
        }
示例#2
0
        virtual public ICommunicationMessage clone()
        {
            CommandMsg cm = new CommandMsg();

            cm.m_EncodeMode = EncodeMode;
            cm.m_SeqID      = SeqID;
            cm.m_Type       = TK_CommandType;

            lock (m_SyncRoot)
            {
                foreach (C5.KeyValuePair <string, object> de in m_Content)
                {
                    cm.SetValue(de.Key, de.Value);
                }
            }

            return(cm);
        }
        public List <ICommunicationMessage> extractMessages(byte[] package, ref byte[] rest)
        {
            List <ICommunicationMessage> ar = new List <ICommunicationMessage>();

            rest = new byte[0];
            int packagePos = 0;

            while (true)
            {
                if (packagePos == package.Length)
                {
                    return(ar);
                }

                int content_len;
                if (package.Length - packagePos < sizeof(int))
                {
                    rest = new byte[package.Length - packagePos];
                    for (int i = packagePos; i < package.Length; ++i)
                    {
                        rest[i - packagePos] = package[i];
                    }
                    return(ar);
                }
                else
                {
                    content_len = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(package, packagePos));
                }

                if (content_len > 100000000)
                {
                    throw new Exception("报文过长.");
                }

                if (package.Length < packagePos + content_len + sizeof(int))
                { // 包不完整, 等待下次读取
                  //if (package.Length > packagePos + sizeof(int))
                  //{
                  //    // 检查报文的有效性
                  //    string s = Encoding.Default.GetString(package, packagePos + sizeof(int), package.Length - packagePos - sizeof(int));
                  //    for (int i = 0; i < s.Length && i < Constants.MSG_START_ID.Length; ++i)
                  //        if (s[i] != Constants.MSG_START_ID[i])
                  //            throw new Exception("无效报文头.");
                  //}

                    rest = new byte[package.Length - packagePos];
                    for (int i = packagePos; i < package.Length; ++i)
                    {
                        rest[i - packagePos] = package[i];
                    }
                    return(ar);
                }

                string sTemp;
                if (m_bCompressed)
                {
                    using (MemoryStream ms = new MemoryStream(package, packagePos + sizeof(int), content_len))
                    {
                        using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress))
                        {
                            using (MemoryStream outstream = new MemoryStream())
                            {
                                byte[] tempbuf = new byte[2048];
                                while (true)
                                {
                                    int read = gs.Read(tempbuf, 0, 2048);
                                    if (read == 0)
                                    {
                                        break;
                                    }

                                    outstream.Write(tempbuf, 0, read);
                                }

                                sTemp = Encoding.Default.GetString(outstream.GetBuffer(), 0, Convert.ToInt32(outstream.Length));
                            }
                        }
                    }
                }
                else
                {
                    sTemp = System.Text.Encoding.Default.GetString(package, packagePos + sizeof(int), content_len);
                }

                packagePos += sizeof(int) + content_len;

                if (!sTemp.StartsWith(Constants.MSG_START_ID) || !sTemp.EndsWith(Constants.MSG_END_ID))
                {
                    throw new Exception("无效报文标识.");
                }

                int indexBegin, indexEnd;

                int startPos = 0;
                while (true)
                {
                    if (sTemp.Length == startPos)
                    {
                        break;
                    }

                    while (true)
                    { // 如果内容含有标识头,服务器侧会用双标识头替换
                        indexBegin = sTemp.IndexOf(Constants.MSG_START_ID, startPos);
                        if (indexBegin == -1)
                        {
                            throw new Exception("无效报文.");
                        }

                        if (sTemp.Length - indexBegin < Constants.MSG_DOUBLE_START_ID.Length)
                        {
                            break; // 长度不足容纳双标识头
                        }
                        if (sTemp.Substring(indexBegin + Constants.MSG_START_ID.Length, Constants.MSG_START_ID.Length) == Constants.MSG_START_ID)
                        {
                            startPos = indexBegin + 2 * Constants.MSG_START_ID.Length;
                        }
                        else
                        {
                            break;
                        }
                    }

                    while (true)
                    {
                        indexEnd = sTemp.IndexOf(Constants.MSG_END_ID, startPos);
                        if (indexEnd == -1)
                        {
                            break;
                        }

                        if (sTemp.Length - indexEnd < Constants.MSG_DOUBLE_END_ID.Length)
                        {
                            break; // 长度不足容纳双标识尾
                        }
                        if (sTemp.Substring(indexEnd + Constants.MSG_END_ID.Length, Constants.MSG_END_ID.Length) == Constants.MSG_END_ID)
                        {
                            startPos = indexEnd + 2 * Constants.MSG_END_ID.Length;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (-1 != indexBegin && -1 != indexEnd && indexBegin > indexEnd)
                    {
                        startPos = indexEnd + Constants.MSG_END_ID.Length;
                        continue;
                    }

                    if (-1 != indexBegin && -1 != indexEnd && indexBegin < indexEnd)
                    {
                        CommandMsg msg = new CommandMsg();

                        // 仅把内容传如包解码
                        msg.decode(sTemp.Substring(indexBegin, indexEnd - indexBegin + Constants.MSG_END_ID.Length));
                        ar.Add(msg);

                        startPos = indexEnd + Constants.MSG_END_ID.Length;
                    }
                    else
                    {
                        int peeked = System.Text.Encoding.Default.GetByteCount(sTemp.Substring(0, startPos));

                        if (peeked < package.Length)
                        {
                            throw new Exception("报文含有无效内容.");
                        }
                    }
                }
            } // end while
        }