示例#1
0
        public void CheckComunication()
        {

            MaskEventItem ci = new MaskEventItem();

            ci.CancelTime = DateTime.Now.ToString("YYYY:MM:DD HH:MM:SS");
            ci.DBHostIdx = 0;
            ci.EnableCancel = "1";
            ci.CancelTime = "1";
            ci.Idx = 1;
            ci.MaskDesk = "1";
            ci.MaskInfo = "1";
            ci.MaskState = 1;
            ci.MaskTime = "1";
            ci.MaskUser = "******";
            ci.TagID = 1;
            ci.TagName = "1";

            Byte[] buffer = GetRequestMaskBytes(ci);
            SendData(buffer);


        }
示例#2
0
        //protected byte[] GetData(byte[] buffer)
        //{
        //    ConnectServer();
        //    try
        //    {
        //        SocketClient.Send(buffer);
        //        int length = 0;
        //        List<byte[]> list = new List<byte[]>();
        //        while (true)
        //        {
        //            Byte[] part = new Byte[2000];
        //            int n = 0;
        //            n = SocketClient.Receive(part);
        //            if (n > 12)
        //                length += n;
        //            if (n <= 12)
        //            {
        //                byte[] result = new byte[length];
        //                int index = 0;
        //                list.ForEach(item =>
        //                {
        //                    Array.Copy(item, 0, result, index, item.Length);
        //                    index += item.Length;
        //                });
        //                //Array.Copy(part, 0, result, index, n);
        //                return result;
        //            }
        //            Byte[] aBytes = new Byte[n];
        //            Array.Copy(part, 0, aBytes, 0, n);
        //            list.Add(aBytes);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        DisconnectServer();
        //        ConnectServer();
        //        throw ex;
        //    }
        //}

        //请求屏蔽测点报文格式		
        //ProcID	char[39]	请求的标识
        //TagID	int	测点TagID
        //DBHostIdx	int	测点所在的数据中心
        //EnableCancel	char	启用屏蔽期限,'1'-启用,'0'-不启用
        //CancelTime	char[25]	屏蔽期限,时间格式:2011:03:11 10:12:30

        //2、	请求屏蔽响应报文
        //如果超时或者响应失败则需要重发请求屏蔽测点的报文,重发3次都失败则放弃,并打印失败日志到日志文件。

        //表:请求屏蔽测点响应报文格式		
        //ProcID	char[39]	请求的标识
        //Result	char	'1'-成功,'0'-失败

        /// <summary>
        /// 得到请求包
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Byte[] GetRequestMaskBytes(MaskEventItem item)
        {
            Byte[] buffer = GetRequestMaskContent(item);
            buffer = AppendRequestMaskHeader(buffer);
            return buffer;
        }
示例#3
0
        /// <summary>
        /// 得到请求的内容
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Byte[] GetRequestMaskContent(MaskEventItem item)
        {
            //ProcID	char[39]	请求的标识
            //Idx	int	活动告警的Idx
            //TagID	int	测点TagID
            //TagName	char[32]	测点TagName
            //DBHostIdx	int	测点所在的数据中心
            //MaskState	int	屏蔽状态
            //MaskUser	char[32]	屏蔽人
            //MaskDesk	char[32]	屏蔽的操作站,通常是电脑名称或者手机名称
            //MaskInfo	char[160]	屏蔽信息,用户在确认时可能会输出一些屏蔽信息
            //MaskTime	char[25]	屏蔽时间,格式2011-03-11 10:12:30
            //EnableCancel	char	启用屏蔽期限,'1'-启用,'0'-不启用
            //CancelTime	char[25]	屏蔽期限,时间格式:2011-03-11 10:12:30

            int contentLen = 39 + 4 + 4 + +32 + 4 + 4 + 32 + 32 + 160 + 25 + 1 + 25;
            Byte[] buffer = new Byte[contentLen];

            guid = Guid.NewGuid();
            Encoding.ASCII.GetBytes("{" + guid.ToString() + "}").CopyTo(buffer, 0);
            BitConverter.GetBytes(item.Idx).CopyTo(buffer, 39);
            BitConverter.GetBytes(item.TagID).CopyTo(buffer, 39 + 4);
            Encoding.ASCII.GetBytes(item.TagName).CopyTo(buffer, 39 + 4 + 4);
            BitConverter.GetBytes(item.DBHostIdx).CopyTo(buffer, 39 + 4 + 4 + 32);
            BitConverter.GetBytes(item.MaskState).CopyTo(buffer, 39 + 4 + 4 + 32 + 4);
            Encoding.ASCII.GetBytes(item.MaskUser).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 4);
            Encoding.ASCII.GetBytes(item.MaskDesk).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 4 + 32);
            Encoding.ASCII.GetBytes(item.MaskInfo).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 4 + 32 + 32);
            Encoding.ASCII.GetBytes(item.MaskTime).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 4 + 32 + 32 + 160);
            Encoding.ASCII.GetBytes(item.EnableCancel).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 4 + 32 + 32 + 160 + 25);
            Encoding.ASCII.GetBytes(item.CancelTime).CopyTo(buffer, 39 + 4 + 4 + 32 + 4 + 4 + 32 + 32 + 160 + 25 + 1);

            return buffer;
        }