Ejemplo n.º 1
0
        /// <summary>
        /// Begins the process of receiving a message from the client.
        /// This method must manually be called to Begin receiving data
        /// </summary>
        public void BeginReceive()
        {
            try
            {
                if (Connection != null)
                {
                    // Reset Buffer offset back to the original allocated offset
                    BufferDataToken token = ReadEventArgs.UserToken as BufferDataToken;
                    ReadEventArgs.SetBuffer(token.BufferOffset, token.BufferBlockSize);

                    // Begin Receiving
                    if (!Connection.ReceiveAsync(ReadEventArgs))
                    {
                        ProcessReceive();
                    }
                }
            }
            catch (ObjectDisposedException)
            {
                if (!DisconnectEventCalled)
                {
                    // Disconnect user
                    DisconnectEventCalled = true;
                    OnDisconnect?.Invoke(this);
                }
            }
            catch (SocketException e)
            {
                HandleSocketError(e.SocketErrorCode);
            }
        }
Ejemplo n.º 2
0
        private void readIDCrad_OnReadedInfo(object sender, ReadEventArgs e)
        {
            if (isShowFrom == false)
            {
                idinfo      = new IDCardInfo();
                idinfo.Name = e.NewHuman.Name;

                idinfo.Address   = e.NewHuman.Address;
                idinfo.Sex       = e.NewHuman.Gender;
                idinfo.Birthday  = e.NewHuman.BirthDay.ToString("yyyy-MM-dd");
                idinfo.Signdate  = e.NewHuman.InceptDate;
                idinfo.Number    = e.NewHuman.IDCardNo;
                idinfo.Name      = e.NewHuman.Name;
                idinfo.People    = e.NewHuman.Nation;
                idinfo.ValidDate = e.NewHuman.ExpireDate;
                idinfo.ImagePath = e.NewHuman.PhotoLocation;
                if (idinfo != null && !string.IsNullOrEmpty(idinfo.Name))
                {
                    rc.Over();
                    isShowFrom = true;
                    if (ShowForm() == true)
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        if (!rc.IsRun)
                        {
                            rc.Start(ReadType.读基本信息);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private async Task ReadHandlerAsync(ReadEventArgs arg)
        {
            if (arg.Result)
            {
                StringBuilder sbSendValue = new StringBuilder();
                foreach (var data in arg.Data)
                {
                    if (!Data.ContainsKey(data.Key))
                    {
                        Data.Add(data.Key, data.Value);
                    }
                    else
                    {
                        Data[data.Key] = data.Value;
                    }
                    sbSendValue.AppendFormat("{0}={1};", data.Key, data.Value);
                    await RedisHelper.SetAsync(data.Key, data.Value);
                }

                if (sbSendValue.Length > 0)
                {
                    await RedisHelper.PublishAsync("Collector_Value", sbSendValue.ToString());
                }

                sbSendValue.Clear();
                sbSendValue = null;
            }
            else
            {
                LogError(string.Format("读取超时:{0}。", arg.ErrorMsg));
            }

            arg.Dispose();
            arg = null;
        }
Ejemplo n.º 4
0
        object Readadv(string prompt, int DataType, string userinputext, string btncanceltext, string btnoktext)
        {
            ReadEventArgs tmpArgs = new ReadEventArgs {
                Prompt = prompt, DataType = DataType, userinputext = userinputext, btncanceltext = btncanceltext, btnoktext = btnoktext
            };

            OnReadAdv?.Invoke(this, tmpArgs);
            return(tmpArgs.Result);
        }
Ejemplo n.º 5
0
        object Read(string prompt, int DataType)
        {
            ReadEventArgs tmpArgs = new ReadEventArgs {
                Prompt = prompt, DataType = DataType
            };

            OnRead?.Invoke(this, tmpArgs);
            return(tmpArgs.Result);
        }
Ejemplo n.º 6
0
        private void RecieveSocket(IAsyncResult ar)
        {
            var socket  = (System.Net.Sockets.Socket)ar.AsyncState;
            var localEp = socket.LocalEndPoint;
            var count   = socket.EndReceive(ar);

            var readEventArgs = new ReadEventArgs(_buffer, count, localEp);

            ReadEvent?.Invoke(this, readEventArgs);
            BeginRead();
        }
Ejemplo n.º 7
0
        private static void Reader_ReadHandler(object sender, ReadEventArgs e)
        {
            Task.Run(() =>
            {
                if (e.Result == 0 || e.Result == 5)
                {
                    var CXNCKD = S7.GetIntAt(e.Data, 42);
                    Console.WriteLine(string.Format("一号线-车辆车厢内侧宽度:{0}", CXNCKD));

                    var CXNCCD = S7.GetIntAt(e.Data, 40);
                    Console.WriteLine(string.Format("一号线-车辆车厢内侧长度:{0}", CXNCCD));

                    var CKGD = S7.GetIntAt(e.Data, 6);
                    Console.WriteLine(string.Format("一号线-车框高度:{0}", CKGD));

                    var SDZCBS = S7.GetIntAt(e.Data, 36);
                    Console.WriteLine(string.Format("一号线-设定装车包数:{0}", SDZCBS));

                    var JHZQCS = S7.GetIntAt(e.Data, 34);
                    Console.WriteLine(string.Format("一号线-计划抓取次数:{0}", JHZQCS));

                    var DQZCSKZL = S7.GetIntAt(e.Data, 176);
                    Console.WriteLine(string.Format("一号线-当前装车刷卡重量:{0}", DQZCSKZL));

                    var ZZCS = S7.GetDIntAt(e.Data, 138);
                    Console.WriteLine(string.Format("一号线-总装车数:{0}", ZZCS));

                    var DTZCS = S7.GetIntAt(e.Data, 142);
                    Console.WriteLine(string.Format("一号线-当天装车数:{0}", DTZCS));

                    var ZZCZL = S7.GetRealAt(e.Data, 158);
                    Console.WriteLine(string.Format("一号线-总装车重量:{0}", ZZCZL));

                    var DTZCZL = S7.GetRealAt(e.Data, 162);
                    Console.WriteLine(string.Format("一号线-当天装车重量:{0}", DTZCZL));

                    var JCSJHG = S7.GetBitAt(e.Data, 70, 2);
                    Console.WriteLine(string.Format("一号线-检测数据合格:{0}", JCSJHG));

                    var WMBXZHG = S7.GetBitAt(e.Data, 70, 3);
                    Console.WriteLine(string.Format("一号线-尾门板X值合格:{0}", WMBXZHG));

                    var DQZCZL = S7.GetDIntAt(e.Data, 0);
                    Console.WriteLine(string.Format("一号线-当前装车重量:{0}", DQZCZL));

                    var CPH = S7.GetStringAt(e.Data, 180, Encoding.GetEncoding("GB2312"));
                    Console.WriteLine(string.Format("一号线-车牌号:{0}", CPH));
                }
                e.Dispose();
                e = null;
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Closes the underlying socket
        /// </summary>
        /// <param name="disposing">
        /// If true, the EventArg objects will be disposed instead of being re-added to
        /// the IO pool. This should NEVER be set to true unless we are shutting down the server!
        /// </param>
        private void Dispose(bool disposeEventArgs = false)
        {
            // Set that the socket is being closed once, and properly
            if (SocketClosed)
            {
                return;
            }
            SocketClosed = true;


            ReadEventArgs.Dispose();
            WriteEventArgs.Dispose();
            DisposedEventArgs = true;
            //// Do a shutdown before you close the socket
            //try
            //{
            //    Connection.Shutdown(SocketShutdown.Both);
            //}
            //catch (Exception) { }
            //finally
            //{
            //    // Unregister for vents
            //    ReadEventArgs.Completed -= IOComplete;
            //    WriteEventArgs.Completed -= IOComplete;

            //    // Close the connection
            //    Connection.Close();
            //    Connection = null;
            //}

            //// Call Disconnect Event
            //if (!DisconnectEventCalled && OnDisconnected != null)
            //{
            //    DisconnectEventCalled = true;
            //    OnDisconnected();
            //}

            //// If we need to dispose out EventArgs
            //if (disposeEventArgs)
            //{
            //    ReadEventArgs.Dispose();
            //    WriteEventArgs.Dispose();
            //    DisposedEventArgs = true;
            //}
            //else
            //{
            //    // Finally, release this stream so we can allow a new connection
            //    SocketManager.Release(this);
            //    Released = true;
            //}
        }
Ejemplo n.º 9
0
        private void readIDCrad_OnReadedInfo(object sender, ReadEventArgs e)
        {
            idinfo      = new IDCardInfo();
            idinfo.Name = e.NewHuman.Name;

            idinfo.Address   = e.NewHuman.Address;
            idinfo.Sex       = e.NewHuman.Gender;
            idinfo.Birthday  = e.NewHuman.BirthDay.ToString("yyyy-MM-dd");
            idinfo.Signdate  = e.NewHuman.InceptDate;
            idinfo.Number    = e.NewHuman.IDCardNo;
            idinfo.Name      = e.NewHuman.Name;
            idinfo.People    = e.NewHuman.Nation;
            idinfo.ValidDate = e.NewHuman.ExpireDate;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Closes the underlying socket
        /// </summary>
        /// <param name="DisposeEventArgs">
        /// If true, the EventArg objects will be disposed instead of being re-added to
        /// the IO pool. This should NEVER be set to true unless we are shutting down the server!
        /// </param>
        public void Close(bool DisposeEventArgs = false)
        {
            // Set that the socket is being closed once, and properly
            if (SocketClosed)
            {
                return;
            }
            SocketClosed = true;

            // Do a shutdown before you close the socket
            try
            {
                Connection.Shutdown(SocketShutdown.Both);
            }
            catch (Exception) { }
            finally
            {
                // Unregister for vents
                ReadEventArgs.Completed  -= IOComplete;
                WriteEventArgs.Completed -= IOComplete;

                // Close the connection
                Connection.Close();
                Connection = null;
            }

            // If we need to dispose out EventArgs
            if (DisposeEventArgs)
            {
                ReadEventArgs.Dispose();
                WriteEventArgs.Dispose();
                DisposedEventArgs = true;
            }
            else
            {
                // Finally, release this stream so we can allow a new connection
                SocketManager.Release(this);
                Released = true;
            }

            // Call Disconnect Event
            if (!DisconnectEventCalled && OnDisconnect != null)
            {
                DisconnectEventCalled = true;
                OnDisconnect(this);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Stream 'On Read Event'. Called as downstream components or the BizTalk Messaging Agent itself
        /// reads the message. This method spools the portion of the stream read to disk. An 'optimized' copy.
        /// </summary>
        /// <param name="src"></param>
        /// <param name="args"></param>
        private void StreamOnReadEvent(object src, EventArgs args)
        {
            try
            {
                ReadEventArgs rargs = args as ReadEventArgs;

                if (rargs != null)
                {
                    using (FileStream fileArchiveStream = new FileStream(this.auditFileFullPath, FileMode.Append, FileAccess.Write))
                    {
                        fileArchiveStream.Write(rargs.buffer, rargs.offset, rargs.bytesRead);
                    }
                }
            }
            catch (Exception ex)
            {
                // log a warning but do not rethrow to avoid stopping main message processing
                TraceProvider.Logger.TraceWarning(Resources.ArchiverExceptionMessage, this.auditFileFullPath, ex.Message);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Begins the process of receiving a message from the client.
        /// This method must manually be called to Begin receiving data
        /// </summary>
        public void BeginReceive()
        {
            try
            {
                if (Connection != null)
                {
                    // Reset Buffer offset back to the original allocated offset
                    BufferDataToken token = ReadEventArgs.UserToken as BufferDataToken;
                    ReadEventArgs.SetBuffer(token.BufferOffset, token.BufferBlockSize);

                    // Begin Receiving
                    if (!Connection.ReceiveAsync(ReadEventArgs))
                    {
                        ProcessReceive();
                    }
                }
            }
            catch (ObjectDisposedException e)
            {
                if (!DisconnectEventCalled)
                {
                    // Uh-Oh. idk how we got here
                    L.LogError("WARNING: [GamespyStream.BeginReceive] ObjectDisposedException was thrown: " + e.Message);

                    // Disconnect user
                    DisconnectEventCalled = true;
                    if (OnDisconnect != null)
                    {
                        OnDisconnect();
                    }
                }
            }
            catch (SocketException e)
            {
                HandleSocketError(e.SocketErrorCode);
            }
        }
        private void readIDCrad_OnReadedInfo(object sender, ReadEventArgs e)
        {
            idinfo = new IDCardInfo();

            strCardNO = e.NewHuman.IDCardNo;
        }
Ejemplo n.º 14
0
 private void OnReadEvent(object sender, ReadEventArgs e)
 {
     //Console.WriteLine($"Bytes read: {e.Count}");
     ParsePacket(e.BytesReceived);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// This method is called when data is received from our socket.
        /// </summary>
        /// <param name="sender">The socket which sent the data</param>
        /// <param name="args">Socket data</param>
        protected virtual void OnReceiveData(object sender, SocketEventArgs args)
        {
            SocketClient  socket       = (SocketClient)sender;
            ReadEventArgs re           = (ReadEventArgs)args;
            int           packetLength = SmppPdu.REQUIRED_SIZE;

            if (re.Length >= packetLength)
            {
                // Get the first DWORD from the buffer; this is the total size of the packet.
                packetLength = BitConverter.ToInt32(new byte[] { re.Buffer[3], re.Buffer[2], re.Buffer[1], re.Buffer[0] }, 0);
                if (re.Length >= packetLength)
                {
                    try
                    {
                        // Have the entire buffer; parse it out.
                        SmppPdu pdu = SmppPdu.Create(new SmppByteStream(re.Buffer));
                        SmppPduReceivedEventArgs ea = new SmppPduReceivedEventArgs(this, pdu);
                        FireEvent(EventType.PreProcessPdu, ea);

                        PduSyncronizer sync = null;
                        if (pdu is SmppResponse)
                        {
                            if ((sync = FindAndRemoveWaitingPdu(pdu.SequenceNumber)) != null)
                            {
                                ((SmppResponse)pdu).OriginalRequest = (SmppRequest)sync.PduRequest;
                            }
                            else
                            {
                                throw new SmppException("Invalid pdu response received with no pending request: " + pdu.ToString());
                            }
                        }

                        if (!ea.Handled)
                        {
                            try
                            {
                                ProcessPdu(pdu);
                            }
                            catch (InvalidSmppStateException)
                            {
                                if (pdu.RequiresResponse)
                                {
                                    SendPdu(new generic_nack(StatusCodes.ESME_RINVCMDID, pdu.SequenceNumber));
                                }
                            }
                        }

                        if (sync != null)
                        {
                            sync.PduResponse = pdu;
                        }
                    }
                    catch (PduException pduex)
                    {
                        SmppPdu pdu = (pduex.HasPDU) ? pduex.PDU : null;
                        if (pdu != null && pdu.RequiresResponse)
                        {
                            SendPdu(new generic_nack(StatusCodes.ESME_RINVCMDID, pdu.SequenceNumber));
                        }
                        FireEvent(EventType.Error, new SmppErrorEventArgs(this, pduex, pdu));
                    }
                    catch (Exception ex)
                    {
                        socket.Close(true);
                        FireEvent(EventType.SessionDisconnected, new SmppDisconnectEventArgs(this, ex));
                    }

                    // Reset the buffer
                    re.AppendToBuffer = false;
                    re.NextReadSize   = SmppPdu.REQUIRED_SIZE;
                    return;
                }
            }

            // Wait for more data to show up on the socket.
            re.AppendToBuffer = true;
            re.NextReadSize   = packetLength - re.Length;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// 批次采数完成(Reader Read Event)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Reader_ReadHandler(object sender, ReadEventArgs e)
 {
     ReadHandlerAsync(e);
 }