예제 #1
0
        public bool SendMessage(string msg)
        {
            if (string.IsNullOrEmpty(msg))
            {
                return(false);
            }
            if (!_tcpClient.Connected)
            {
                return(false);
            }

            var strm   = _tcpClient.GetStream();
            var writer = new StreamWriter(strm)
            {
                AutoFlush = true
            };

            try
            {
                if (_tcpClient.Connected)
                {
                    writer.WriteLine(msg);
                }

                return(true);
            }
            catch (Exception ex)
            {
                SendFailed?.Invoke(this, ex);
                Log?.Error("SendMessage failed", ex);
                return(false);
            }
        }
예제 #2
0
 public bool SendMessage(string msg)
 {
     try
     {
         if (string.IsNullOrEmpty(msg))
         {
             return(false);
         }
         if (_client == null)
         {
             return(false);
         }
         if (!_client.Connected)
         {
             return(false);
         }
         Log("<Send> {0}", msg.Trim());
         var strm   = _client.GetStream();
         var writer = new StreamWriter(strm)
         {
             AutoFlush = true
         };
         writer.WriteLine(msg);
         return(true);
     }
     catch (Exception ex)
     {
         SendFailed?.Invoke(this, ex);
         return(false);
     }
 }
예제 #3
0
 private void OnSendFailed()
 {
     if (SendFailed != null)
     {
         SendFailed.Invoke(this, new EventArgs());
     }
 }
예제 #4
0
 public void Send(byte[] content)
 {
     try
     {
         _client.Send(content);
         SendSuccessed?.Invoke(new DownloadSenderSendEventArgs
         {
             SendContent = content
         });
     }
     catch (Exception ex)
     {
         SendFailed?.Invoke(new DownloadSenderSendEventArgs
         {
             SendContent = content,
             Exception   = ex
         });
     }
 }
 public void Send(byte[] content)
 {
     try
     {
         Thread.Sleep(5);
         _portHelper.SendBytes(content);
         SendSuccessed?.Invoke(new DownloadSenderSendEventArgs
         {
             SendContent = content
         });
     }
     catch (Exception ex)
     {
         SendFailed?.Invoke(new DownloadSenderSendEventArgs
         {
             SendContent = content,
             Exception   = ex
         });
     }
 }
        private void SendData(List <IStreamData> sendList)
        {
            int attempts   = 0;
            var writeQueue = sendList.ToList();

            do
            {
                attempts++;

                // Connect to TCP Client
                if (ConnectToClient())
                {
                    // Write the data to the client's stream
                    writeQueue = WriteList(writeQueue);
                }
                else
                {
                    log.Debug("StreamClient : Connection Error : " + sendList.Count + " Items");
                }

                // Some items weren't sent successfully so try reconnecting to client
                if (writeQueue.Count > 0)
                {
                    DisconnectClient();
                }
            } while (writeQueue.Count > 0 && attempts < 2);

            // Send Count of Successful Items
            int successfullySent = sendList.Count - writeQueue.Count;

            if (successfullySent > 0)
            {
                SendSuccessful?.Invoke(successfullySent);
            }

            // Check if items were left in queue (failed to send)
            if (writeQueue.Count > 0)
            {
                SendFailed?.Invoke(writeQueue);
            }
        }
예제 #7
0
        public bool SendMessage(string msg)
        {
            if (string.IsNullOrEmpty(msg))
            {
                return(false);
            }
            if (!IsConnected)
            {
                return(false);
            }

            try
            {
                NativeSession.Send(msg);
                return(true);
            }
            catch (Exception ex)
            {
                SendFailed?.Invoke(this, ex);
                Logger?.Log?.Error("Send message failed", ex);
                return(false);
            }
        }
예제 #8
0
 private void ConnectionInfoOnFailed(object sender, EventArgs eventArgs)
 {
     SendFailed?.Invoke(this, EventArgs.Empty);
 }