コード例 #1
0
 public B2Data(RecieveMessage message)
 {
     Id         = new ObjectId();
     ClientCode = message.ClientCodeStr;
     Content    = message.Content;
     SendTime   = message.SendTime;
     IsChecked  = message.IsChecked;
     Data       = (List <B2Element>)message.Data;
 }
コード例 #2
0
ファイル: MongoData.cs プロジェクト: tom6886/DQGJK
 internal B3Data(RecieveMessage message)
 {
     Id         = new ObjectId();
     ClientCode = message.ClentCodeStr;
     Content    = message.Content;
     SendTime   = message.SendTime;
     IsChecked  = message.IsChecked;
     Data       = (B3Element)message.Data;
 }
コード例 #3
0
ファイル: MongoData.cs プロジェクト: tom6886/DQGJK
 internal B0C0Data(RecieveMessage message)
 {
     Id         = new ObjectId();
     ClientCode = message.ClentCodeStr;
     Content    = message.Content;
     SendTime   = message.SendTime;
     DataTime   = message.DataTime;
     IsChecked  = message.IsChecked;
     Data       = (List <B0C0Element>)message.Data;
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: tom6886/DQGJK
        private static void Listener_OnMsgReceived(AsyncUserToken token, byte[] data)
        {
            Console.WriteLine("接收到数据:");
            Console.WriteLine(" 来源IP:" + token.Remote.Address.ToString());
            Console.WriteLine(" 连接时间:" + token.ConnectTime.ToString());
            Console.WriteLine(" 最近通讯时间:" + token.FreshTime.ToString());

            RecieveMessageDecode reader  = new RecieveMessageDecode(data);
            RecieveMessage       message = reader.Read();

            //string str = BytesUtil.ToHexString(message.ToByte());

            //Console.WriteLine(" 发送内容:" + str);
        }
コード例 #5
0
        private void Listener_OnMsgReceived(AsyncUserToken token, byte[] info)
        {
            string str = BytesUtil.ToHexString(info);

            try
            {
                RecieveMessageDecode reader  = new RecieveMessageDecode(info);
                RecieveMessage       message = reader.Read();

                StringBuilder sb = new StringBuilder();
                sb.Append("接收到数据:");
                sb.Append("\r\n");
                sb.Append(" 来源IP:" + token.Remote.Address.ToString());
                sb.Append("\r\n");
                sb.Append(" 接收时间:" + DateTime.Now);
                sb.Append("\r\n");
                sb.Append(" 数据类型:" + message.FunctionCode);
                sb.Append("\r\n");
                sb.Append(" 接收内容:" + str);
                sb.Append("\r\n");
                AppendLog(sb.ToString());

                //更新设备缓存
                UpdateCache(message.ClientCodeStr, token.UID);
                if (message.FunctionCode.Equals("F2"))
                {
                    return;
                }
                IMessageHandler handler = HandlerFactory.Create(message.FunctionCode, token.UID, message);
                handler.Handle();

                //如果是设备自报数据,向设备发送接收成功的报文
                if (message.FunctionCode.Equals("C0"))
                {
                    SendMessage res = new SendMessage();
                    res.ClientCode   = message.ClientCode;
                    res.CenterCode   = message.CenterCode;
                    res.SendTime     = DateTime.Now;
                    res.Serial       = 0;
                    res.FunctionCode = "C0";

                    listener.Send(token.UID, res.ToByte());
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("接收消息时出错", "接收到的消息:" + str + "\r\n" + ex.Message, ex.StackTrace);
            }
        }
コード例 #6
0
ファイル: BaseHandler.cs プロジェクト: tom6886/DQGJK
        public void UpdateOperate(RecieveMessage _Message, string FunctionCode)
        {
            using (DBContext db = new DBContext())
            {
                List <Operate> operate = db.Operate.Where(q => q.ClientCode.Equals(_Message.ClientCodeStr) &&
                                                          q.State == OperateState.Sended && q.FunctionCode.Equals(FunctionCode)).ToList();

                foreach (var item in operate)
                {
                    item.State           = OperateState.Done;
                    db.Entry(item).State = EntityState.Modified;
                }

                db.SaveChanges();
            }
        }
コード例 #7
0
        /// <summary>
        /// Subscribe a delegate to a specific message type
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="messageHandler"></param>
        /// <param name="responseInstanceId"></param>
        /// <param name="limit">Maximum number of times to invoke delegate before unsubscribing</param>
        public Subscription Subscribe <T>(
            RecieveMessage messageHandler,
            Guid?responseInstanceId = null,
            int?limit = null)
        {
            var subscription = new Subscription()
            {
                MessageService     = this,
                Subscriber         = messageHandler,
                Type               = typeof(T),
                ResponseInstanceId = responseInstanceId,
                Limit              = limit
            };

            OnMessageHandlers.Add(subscription);
            return(subscription);
        }
コード例 #8
0
ファイル: Service1.cs プロジェクト: tom6886/DQGJK
        private void Listener_OnMsgReceived(AsyncUserToken token, byte[] info)
        {
            string str = BytesUtil.ToHexString(info);

            try
            {
                RecieveMessageDecode reader     = new RecieveMessageDecode(info);
                RecieveMessage       message    = reader.Read();
                MessageHandler       msgHandler = new MessageHandler(token.UID, message);
                msgHandler.OnIPChanged += MsgHandler_OnIPChanged;
                msgHandler.OnMsgSend   += MsgHandler_OnMsgSend;
                msgHandler.Set();
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("接收消息时出错", "接收到的消息:" + str + "\r\n" + ex.Message, ex.StackTrace);
            }
        }
コード例 #9
0
        private void ChatClient_FileRecieved(object sender, EventArgs e)
        {
            if (!Dispatcher.CheckAccess())
            {
                RecieveMessage r = ChatClient_FileRecieved;
                Dispatcher.Invoke(r, sender, e);
            }
            else
            {
                var args = (FileEventArgs)e;

                var page = FindTabPage(args.From) ?? AddTabPage(args.From);
                var time = DateTime.Now.ToString("HH:mm:ss");

                var    window = new CallForm(args.From, FormType.File);
                var    result = window.ShowDialog();
                string strResult;

                if (result == true)
                {
                    strResult = string.Format(ChatHelper.TRANSFERED, args.FileName);

                    var saveDialog = new SaveFileDialog
                    {
                        FileName     = args.FileName,
                        AddExtension = true,
                        DefaultExt   = args.Extenstion,
                        Filter       = ChatHelper.FILE_FILTER_ALL
                    };

                    if (saveDialog.ShowDialog(this) == true)
                    {
                        File.WriteAllBytes(saveDialog.FileName, args.File);
                    }
                }
                else
                {
                    strResult = ChatHelper.TRANSFER_CANCELED;
                }
                page.DialogBox.AppendText(string.Format("[{0}] {1}", time, strResult));
                page.DialogBox.AppendText(Environment.NewLine);
            }
        }
コード例 #10
0
        private void chatClient_MessageReceived(object sender, EventArgs e)
        {
            if (!Dispatcher.CheckAccess())
            {
                RecieveMessage r = chatClient_MessageReceived;
                Dispatcher.Invoke(r, sender, e);
            }
            else
            {
                var args = e as ServerEventArgs;
                if (args == null)
                {
                    return;
                }

                var page = FindTabPage((string)sender) ?? AddTabPage((string)sender);
                var time = DateTime.Now.ToString("HH:mm:ss");

                page.DialogBox.AppendText(string.Format("[{0}] {1}", time, args.Message));
                page.DialogBox.AppendText(Environment.NewLine);
            }
        }
コード例 #11
0
 public IMessageHandler CreateHandler(string UID, RecieveMessage Message)
 {
     return(new C0Handler(UID, Message));
 }
コード例 #12
0
ファイル: BaseHandler.cs プロジェクト: tom6886/DQGJK
        public void UpdateCabinet(RecieveMessage _Message)
        {
            using (DBContext db = new DBContext())
            {
                Station _station = db.Station.Where(q => q.Code.Equals(_Message.ClientCodeStr)).FirstOrDefault();

                if (_station == null)
                {
                    return;
                }

                DateTime now = DateTime.Now;

                _station.ModifyTime = now;

                db.Entry(_station).State = EntityState.Modified;

                if (_Message.Data == null)
                {
                    db.SaveChanges(); return;
                }

                List <Cabinet> _cabinets = db.Cabinet.Where(q => q.StationCode.Equals(_Message.ClientCodeStr)).ToList();

                List <T> data = (List <T>)_Message.Data;

                foreach (var item in data)
                {
                    Cabinet cabinet = _cabinets.Where(q => q.Code.Equals(item.Code)).FirstOrDefault();

                    bool isNull = cabinet == null;

                    if (isNull)
                    {
                        cabinet      = new Cabinet();
                        cabinet.Name = item.Code;
                        cabinet.Code = item.Code;
                        if (!item.Code.Equals("FF"))
                        {
                            cabinet.Sort = Convert.ToInt32(item.Code, 16);
                        }
                        cabinet.StationCode = _Message.ClientCodeStr;
                        cabinet.Status      = Status.enable;
                    }

                    if (!SetCabinet(db, item, ref cabinet))
                    {
                        continue;
                    }
                    ;

                    if (isNull)
                    {
                        db.Cabinet.Add(cabinet);
                    }
                    else
                    {
                        db.Entry(cabinet).State = EntityState.Modified;
                    }
                }

                db.SaveChanges();
            }
        }
コード例 #13
0
 protected virtual void OnRecieveMessage(string e)
 {
     RecieveMessage?.Invoke(this, e);
 }
コード例 #14
0
 /// <summary>
 /// Unsubscribe a delegate from a specific message type
 /// </summary>
 /// <param name="recieveMessage"></param>
 /// <param name="type"></param>
 public void Unsubscribe(RecieveMessage recieveMessage, Type type)
 {
     OnMessageHandlers.RemoveAll(x => x.Subscriber == recieveMessage && x.Type == type);
 }
コード例 #15
0
 /// <summary>
 /// Unsubscribe a delegate from a specific message type
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="recieveMessage"></param>
 public void Unsubscribe <T>(RecieveMessage recieveMessage)
 {
     OnMessageHandlers.RemoveAll(x => x.Subscriber == recieveMessage && x.Type == typeof(T));
 }
コード例 #16
0
        public static IMessageHandler Create(string FunctionCode, string UID, RecieveMessage Message)
        {
            IHandlerFactory factory = (IHandlerFactory)Assembly.Load("DQGJK.Winform.Handlers").CreateInstance("DQGJK.Winform.Handlers." + FunctionCode + "Factory");

            return(factory.CreateHandler(UID, Message));
        }
コード例 #17
0
 public C0Handler(string UID, RecieveMessage Message)
 {
     _UID     = UID;
     _Message = Message;
 }
コード例 #18
0
ファイル: MessageHandler.cs プロジェクト: tom6886/DQGJK
 internal MessageHandler(string UID, RecieveMessage Message)
 {
     _UID     = UID;
     _Message = Message;
 }