/// <summary> /// Sending thread loop. /// </summary> private void SendingMethod() { while (IsConnected) { if (_commandQueue.Count > 0) { WatchoutCommand command = null; if (_commandQueue.TryDequeue(out command)) { String commandText = CommandFormatter.Serialize(command); Debug.WriteLine("Sending: " + commandText); try { var stream = _tcpClient.GetStream(); byte[] commandBytes = Encoding.UTF8.GetBytes(commandText); stream.Write(commandBytes, 0, commandBytes.Length); } catch { } } } Thread.Sleep(30); } }
/// <summary> /// Called when a feedback has been received. /// </summary> /// <param name="response">The response string.</param> protected virtual void OnFeedbackReceived(String response) { var feedback = CommandFormatter.Deserialize(response); if (feedback != null) { if (feedback.ID != null) { _availableFeedbacks.Add(feedback); } if (feedback.GetType() == typeof(ErrorFeedback)) { if (ErrorReceived != null) { ErrorReceived(this, feedback as ErrorFeedback); } } else { if (FeedbackReceived != null) { FeedbackReceived(this, feedback); } } } }
/// <summary> /// Serializes this command. /// </summary> /// <returns>A string representation of this command.</returns> public String Serialize() { return(CommandFormatter.Serialize(this)); }