Exemplo n.º 1
0
        private void readCallback(IAsyncResult ar)
        {
            try
            {
                netStream.EndRead(ar);
                NetworkMessage netMesasge = new NetworkMessageFormatter <NetworkMessage>().Deserialize(ar.AsyncState as byte[]);
                if (netMesasge != null)
                {
                    ReadCompleted?.Invoke(this, new NetworkMessageReaderReadCompletedEventArgs(netMesasge, TcpClient));
                }
                else
                {
                    ReadError?.Invoke(this, new NetworkMessageReaderReadErrorEventArgs(TcpClient, new ArgumentNullException("NetworkMessage is null")));
                }


                if (readLoop)
                {
                    ReadAsync(readLoop);
                }
            }
            catch (Exception ex)
            {
                ReadError?.Invoke(this, new NetworkMessageReaderReadErrorEventArgs(TcpClient, ex));
            }
        }
Exemplo n.º 2
0
 private void SocketEventArgs_Completed(object sender, SocketAsyncEventArgs e)
 {
     if (e.LastOperation == SocketAsyncOperation.Receive)
     {
         ReadCompleted?.Invoke(sender as Socket, e);
     }
     //e.LastOperation
 }
        private void TryRead(IAsyncResult ar)
        {
            try
            {
                ReadCompleted?.Invoke(this, new TcpCompletedEventArgs(Socket.EndReceive(ar)));
            }
            catch (Exception ex) {
                var eventArgs = new TcpCompletedEventArgs(ex);
                eventArgs.Error = true;

                ReadCompleted?.Invoke(this, eventArgs);
            }
        }
        void IOPCDataCallback.OnReadComplete(int p_TransID, int p_Group, int p_MasterQuality,
                                             int p_MasterError, int p_Count, IntPtr p_ClientItems, IntPtr p_Values,
                                             IntPtr p_Qualities, IntPtr p_TimeStamps, IntPtr p_Errors)
        {
            Trace.WriteLine("OPCGroup.OnReadComplete");
            if ((p_Count == 0) || (p_Group != m_State.HandleClient))
            {
                return;
            }

            int l_Count = (int)p_Count;
            int l_RunH  = (int)p_ClientItems;
            int l_RunV  = (int)p_Values;
            int l_RunQ  = (int)p_Qualities;
            int l_RunT  = (int)p_TimeStamps;
            int l_RunE  = (int)p_Errors;

            OpcItemState[] l_Sts = new OpcItemState[l_Count];

            for (int i = 0; i < l_Count; ++i)
            {
                l_Sts[i]       = new OpcItemState();
                l_Sts[i].Error = Marshal.ReadInt32((IntPtr)l_RunE);
                l_RunE        += 4;

                l_Sts[i].HandleClient = Marshal.ReadInt32((IntPtr)l_RunH);
                l_RunH += 4;

                if (HResults.Succeeded(l_Sts[i].Error))
                {
                    short l_VT = Marshal.ReadInt16((IntPtr)l_RunV);
                    if (l_VT == (short)VarEnum.VT_ERROR)
                    {
                        l_Sts[i].Error = Marshal.ReadInt32((IntPtr)(l_RunV + 8));
                    }

                    l_Sts[i].DataValue = Marshal.GetObjectForNativeVariant((IntPtr)l_RunV);
                    l_Sts[i].Quality   = Marshal.ReadInt16((IntPtr)l_RunQ);
                    l_Sts[i].Timestamp = Marshal.ReadInt64((IntPtr)l_RunT);
                }

                l_RunV += DummyVariant.CONST_SIZE;
                l_RunQ += 2;
                l_RunT += 8;
            }

            var args = new ReadCompleteEventArgs(p_TransID, p_Group, p_MasterQuality, p_MasterError, l_Sts);

            ReadCompleted?.Invoke(this, args);
        }
Exemplo n.º 5
0
            public void DoRead()
            {
                var buffer = new byte[1024];

                try
                {
                    var fs = new FileStream(_fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    var r  = new BinaryReader(fs);
                    buffer = r.ReadBytes(buffer.Length);
                    _completed?.Invoke(_fileName, buffer);
                }
                catch (IOException ex)
                {
                    _failed?.Invoke(_fileName, ex);
                }
            }
Exemplo n.º 6
0
 protected virtual void RaiseReadCompleted() => ReadCompleted?.Invoke(this, new EventArgs());
Exemplo n.º 7
0
 protected virtual void OnReadCompleted(EventArgs e)
 {
     ReadCompleted?.Invoke(this, e);
 }
Exemplo n.º 8
0
 private void Socket_ReadCompleted(object sender, TcpCompletedEventArgs e)
 {
     ReadCompleted?.Invoke(sender, e);
 }