Exemple #1
0
        //RFIDGestureEnum RFIDgesture;

        public override void StartReceiveMessage()
        {
            NetworkStream ns = GetStream();

            Task.Run(() => {
                while (true)
                {
                    try
                    {
                        if (IsConnected())
                        {
                            byte[] messageByte = new byte[ReceiveBufferSize];
                            ns.Read(messageByte, 0, ReceiveBufferSize);
                            string message = Encoding.ASCII.GetString(messageByte);
                            MessageReceiveEventArgs receiveEventArgs = new MessageReceiveEventArgs();
                            receiveEventArgs.Parameter = "RFID";
                            receiveEventArgs.Message   = message;
                            //Process();
                            base.OnMessageReceived(receiveEventArgs);
                        }
                        else
                        {
                            System.Windows.Forms.MessageBox.Show("Connection terminated");
                            base.OnConnectionTerminated();
                        }
                    }
                    catch (IOException ex)
                    {
                        System.Windows.Forms.MessageBox.Show(ex.Message.Contains("existing connection was forcibly closed") ? "Connection terminated" : ex.GetBaseException().ToString());
                        base.OnConnectionTerminated();
                    }
                }
            });
        }
 protected virtual void OnMessageReceived(MessageReceiveEventArgs e)
 {
     if (MessageReceived != null)
     {
         MessageReceived(this, e);
     }
 }
Exemple #3
0
        private void HandleMessage(string message)
        {
            //fhget : thumbPos , indexPos , middlePos , ringPos , pinkyPos ,
            //         """ Cur ,  """ Cur ,  """ Cur  , """ Cur ,  """ Cur ,
            //         """ Fsr ,  """ Fsr ,  """ Fsr  , """ Fsr ,  """ Temp,
            //        RFID

            if (message.StartsWith("fhget:"))
            {
                string[] values = message.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                try
                {
                    for (int i = 0; i < (values.Length); i++)
                    {
                        string data = values[i].Split(':')[1];
                        MessageReceiveEventArgs receiveEventArgs = new MessageReceiveEventArgs();
                        receiveEventArgs.Parameter = null;
                        receiveEventArgs.Message   = data;
                        base.OnMessageReceived(receiveEventArgs);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.GetBaseException().ToString() + "\n\nfrom Hand Handle message");
                }
            }
        }
Exemple #4
0
        private void ReceiveMessageAction()
        {
            uint packetSize = ReadUint();
            MessageReceiveEventArgs messageArgs = new MessageReceiveEventArgs();

            messageArgs.Number = (int)ReadUint();
            int seq      = (int)ReadUint();
            int time     = (int)ReadUint();
            int msgClass = (int)ReadUint();

            if ((msgClass == MESSAGE_CLASS_NEWMSG) && (packetSize == 26))
            {
                RequestImageAction((uint)messageArgs.Number);
                return;
            }

            messageArgs.Time = utcStartTime.AddSeconds(time);

            byte[] msg = new byte[packetSize - 16];

            for (int i = 0; i < packetSize - 16; i++)
            {
                msg[i] = (byte)NetStream.ReadByte();
            }

            messageArgs.Message = Encoding.GetEncoding(DEFAULT_ENCODING).GetString(msg);
            PostCallback <MessageReceiveEventArgs>(GGMessageReceive, messageArgs);
        }
Exemple #5
0
        internal static void ExcuteSql(MessageReceiveEventArgs args)
        {
            bool queryStoreProcedure = false;

            if (args.InMessage is string)
            {
                string sql = args.InMessage as string;

                if (sql.StartsWith("exec", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (sql.IndexOf("select", 0, StringComparison.CurrentCultureIgnoreCase) < 0)
                    {
                        queryStoreProcedure = true;
                    }
                }
            }

            args.QueryStoreProcedure = queryStoreProcedure;

            if (queryStoreProcedure)
            {
                _SPPool.ExecuteSql(args);
            }
            else
            {
                if ((args.MsgHead.Flag & MessageFlag.Prior) == 0)
                {
                    _PrimaryPool.ExecuteSql(args);
                }
                else
                {
                    _PriorPool.ExecuteSql(args);
                }
            }
        }
            /// <summary>
            /// BPEからのセンサーデータ要求を受けてセンサーデータを送信する。
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void sensorServer_MessageReceived(object sender, MessageReceiveEventArgs e)
            {
                string msg = e.ReceivedMessage;

                byte[] data = e.ReceivedData;

                if (msg.StartsWith("REQDATA"))
                {
                    byte[] sendmsg = getSensorValueForBPE();
                    //byte[] sendmsg = getAllSensorValueForBPE();
                    sensorServer.sendBytes(sendmsg);
                }
            }
Exemple #7
0
 internal void ExecuteFinished(QueryThread qThread)
 {
     lock (_LockObj)
     {
         if (_Queue.Count > 0)
         {
             MessageReceiveEventArgs args = _Queue.Dequeue();
             qThread.ASendMessage((int)SQLClient.ConnectEvent.ExcuteSql, args);
         }
         else
         {
             _Pool.Push(qThread);
         }
     }
 }
Exemple #8
0
 internal void ExecuteSql(MessageReceiveEventArgs args)
 {
     lock (_LockObj)
     {
         if (_Pool.Count > 0)
         {
             QueryThread qThread = _Pool.Pop();
             qThread.ASendMessage((int)SQLClient.ConnectEvent.ExcuteSql, args);
         }
         else
         {
             _Queue.Enqueue(args);
         }
     }
 }
Exemple #9
0
        private void PrintReceivedMessageToConsole(object sender, MessageReceiveEventArgs messageReceiveEventArgs)
        {
            Messages.Add(messageReceiveEventArgs.Message);

            System.Console.Clear();

            foreach (var m in Messages)
            {
                System.Console.WriteLine($"{m.CreatedDate.ToShortTimeString()} {m.Username}: {m.Text}");
            }

            if (!string.IsNullOrEmpty(_userInput))
            {
                System.Console.Write(_userInput);
            }
        }
Exemple #10
0
        object ReceiveMessage(int evt, MessageQueue.MessageFlag flag, object data)
        {
            if (evt == (int)SQLClient.ConnectEvent.ExcuteSql)
            {
                try
                {
                    _Args = data as MessageReceiveEventArgs;
                    CurrentConnection currentConnection = new CurrentConnection(
                        _Args.ConnectionInfo as ConnectionInformation);

                    CurrentConnection.ConnectionInfo.QueryThread = this;
                    _ManagedThreadId = this.ManagedThreadId;

                    if (!_Args.QueryStoreProcedure)
                    {
                        int queryQueueWaitingTimeout = Global.Setting.Config.QueryQueueWaitingTimeout;

                        if (queryQueueWaitingTimeout > 0)
                        {
                            TimeSpan timeSpan = DateTime.Now - _Args.StartTime;
                            if (timeSpan.TotalSeconds > queryQueueWaitingTimeout)
                            {
                                throw new Hubble.Core.Query.QueryException("Timeout during sql was waiting in Query Queue.");
                            }
                        }
                    }

                    HubbleTask.ExcuteSqlMessageProcess(_Args);

                    _Args = null;
                }
                catch (Exception e)
                {
                    _Args.ReturnMsg = e;
                    TcpServer.ReturnMessage(_Args);
                }
                finally
                {
                    _Pool.ExecuteFinished(this);
                    CurrentConnection.Disconnect();
                }
            }

            return(null);
        }
            /// <summary>
            /// クライアントからの接続要求を待つ
            /// </summary>
            private void startWaiting()
            {
                Byte[] msg = new Byte[256];
                // 接続要求が送信されるまでブロック
                client = server.AcceptTcpClient();
                Debug.WriteLine("Client connected!");

                if (client.Connected)
                {
                    server.Stop();
                    NetworkStream stream = client.GetStream();

                    int    i;
                    string data;
                    // BPEからのデータを受信(バイトデータ)
                    try
                    {
                        while ((i = stream.Read(msg, 0, msg.Length)) != 0)
                        {
                            byte[] rcv = new byte[i];
                            Array.Copy(msg, rcv, i);
                            // バイトデータをASCII文字に変換
                            data = System.Text.Encoding.ASCII.GetString(msg, 0, i);
                            //Debug.WriteLine("Received: {0}", data);
                            // 受信データから改行(\r\n)を削除
                            data = data.Replace("\r", "").Replace("\n", "");

                            if (data == "BREAK")
                            {
                                break;
                            }

                            MessageReceiveEventArgs e = new MessageReceiveEventArgs();
                            e.ReceivedData    = rcv;
                            e.ReceivedMessage = data;
                            OnMessageReceived(e);
                        }
                    }
                    catch (IOException)
                    {
                    }
                }
            }
            /// <summary>
            /// BPEからのコマンド受信時イベント発生時の処理。基板にコマンドを送信する。
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void commandServer_MessageReceived(object sender, MessageReceiveEventArgs e)
            {
                string msg = e.ReceivedMessage;

                byte[] data = e.ReceivedData;
                int    size = data.Length - 7 - 2;

                Debug.WriteLine(string.Format("Data size: {0:d}", size));

                if (msg.StartsWith("REQSEND"))
                {
                    if (size < 10)
                    {
                        byte[] senddata = new byte[size];
                        Array.Copy(data, 7, senddata, 0, size);
                        sendCommand(senddata);
                        commandServer.sendMessage("ACK");
                    }
                }
            }
Exemple #13
0
        internal static void ExcuteSqlMessageProcess(MessageReceiveEventArgs args)
        {
            CurrentConnection.ConnectionInfo.StartCommand();

            System.Diagnostics.Stopwatch sw = null;
            TimeSpan ts    = default(TimeSpan);
            long     sqlid = 0;

            string sql = (args.InMessage as string);

            if (Global.Setting.Config.SqlTrace)
            {
                int len = Math.Min(4096, sql.Length);
                sql = sql.Substring(0, len);

                ts = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;

                sw    = new System.Diagnostics.Stopwatch();
                sqlid = _SqlId++;

                Global.Report.WriteAppLog(string.Format("Excute sqlid={0} sql={1}",
                                                        sqlid, sql));

                _ThreadMonitor.Register(new ThreadMonitor.MonitorParameter(
                                            System.Threading.Thread.CurrentThread, string.Format("sqlid={0} sql={1}",
                                                                                                 sqlid, sql), 30000, 20000,
                                            ThreadMonitor.MonitorFlag.MonitorHang));

                sw.Start();
            }
            else
            {
                int len = Math.Min(255, sql.Length);

                sql = sql.Substring(0, len);

                _ThreadMonitor.Register(new ThreadMonitor.MonitorParameter(
                                            System.Threading.Thread.CurrentThread, string.Format("time={0} sql={1}",
                                                                                                 DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), sql), 60000, 20000,
                                            ThreadMonitor.MonitorFlag.MonitorHang));
            }

            if ((args.MsgHead.Flag & MessageFlag.ASyncMessage) != 0)
            {
                try
                {
                    args.ReturnMsg = Excute(args.InMessage as string);
                }
                catch (System.Threading.ThreadAbortException)
                {
                    Global.Report.WriteAppLog("Thread abort");
                }
                catch (Exception e)
                {
                    args.ReturnMsg = e;
                }
                finally
                {
                    if (Global.Setting.Config.SqlTrace && sw != null)
                    {
                        sw.Stop();
                    }

                    _ThreadMonitor.UnRegister(System.Threading.Thread.CurrentThread);
                }
            }
            else
            {
                try
                {
                    args.ReturnMsg = Excute(args.InMessage as string);
                }
                finally
                {
                    if (Global.Setting.Config.SqlTrace && sw != null)
                    {
                        sw.Stop();
                    }

                    _ThreadMonitor.UnRegister(System.Threading.Thread.CurrentThread);
                }
            }

            if (args.ReturnMsg is QueryResult)
            {
                args.CustomSerializtion = new Hubble.SQLClient.QueryResultSerialization(
                    args.ReturnMsg as QueryResult);

                if (Global.Setting.Config.SqlTrace && sw != null)
                {
                    sw.Stop();

                    TimeSpan ts1 = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime;

                    Global.Report.WriteAppLog(string.Format("Excute esplase:{0}ms, total processortime={1}ms, sqlid={2}",
                                                            sw.ElapsedMilliseconds, (int)(ts1.TotalMilliseconds - ts.TotalMilliseconds), sqlid));
                }
            }
            else
            {
                if (Global.Setting.Config.SqlTrace && sw != null)
                {
                    sw.Stop();
                }
            }

            if ((args.MsgHead.Flag & MessageFlag.ASyncMessage) != 0)
            {
                TcpServer.ReturnMessage(args);
            }
        }
 public void OnMessageReceived(object sender, MessageReceiveEventArgs messageReceiveEventArgs)
 {
     System.Windows.Application.Current.Dispatcher
     .Invoke(() => Messages.Add(messageReceiveEventArgs.Message));
 }
Exemple #15
0
        private static void PrintReceivedMessageToConsole(object sender, MessageReceiveEventArgs messageReceiveEventArgs)
        {
            var message = messageReceiveEventArgs.Message;

            System.Console.WriteLine($"{message.CreatedDate.ToShortTimeString()} {message.Username}: {message.Text}");
        }
Exemple #16
0
        private void MessageReceiveEventHandler(object sender, MessageReceiveEventArgs args)
        {
            lock (_LockObj)
            {
                if (_Closing)
                {
                    throw new Exception("Hubble task closing!");
                }
            }

            switch ((SQLClient.ConnectEvent)args.MsgHead.Event)
            {
            case SQLClient.ConnectEvent.Connect:      //Connecting
                CurrentConnection currentConnection = new CurrentConnection(
                    new ConnectionInformation(args.InMessage as string));

                if (Global.Setting.Config.SqlTrace)
                {
                    Global.Report.WriteAppLog(string.Format("Connected, remain:{0}",
                                                            _Server.ConnectionRemain));
                }

                break;

            case ConnectEvent.ExcuteSql:     //excute sql
                if ((args.MsgHead.Flag & MessageFlag.ASyncMessage) != 0)
                {
                    args.ConnectionInfo = CurrentConnection.ConnectionInfo.Clone();
                    QueryThreadManager.ExcuteSql(args);
                }
                else
                {
                    ExcuteSqlMessageProcess(args);
                }
                break;

            case ConnectEvent.Exit:     //quit

                string startTimeStr = (string)args.InMessage;

                if (startTimeStr == null)
                {
                    throw new Exception("StartTime is null!");
                }

                DateTime startTime = DateTime.ParseExact(startTimeStr, "yyyy-MM-dd HH:mm:ss", null);

                if (!startTimeStr.Equals(_StartTime.ToString("yyyy-MM-dd HH:mm:ss"),
                                         StringComparison.CurrentCultureIgnoreCase))
                {
                    throw new Exception("Invalid startTime!");
                }

                lock (_LockObj)
                {
                    if (_Closing)
                    {
                        throw new Exception("Hubble task closing!");
                    }

                    _Closing = true;
                }

                System.Threading.ThreadPool.QueueUserWorkItem(Close);

                break;
            }
        }
Exemple #17
0
 private static void OnMessageReceivedEventHandler(object sender, MessageReceiveEventArgs e)
 {
     Console.WriteLine("Message fire reached: {0} on {1}", e.Message, DateTime.Now.ToString("hh.mm.ss.ffffff"));
 }