public async Task <bool> WriteAsync(CancellationToken ct, MessageData data, bool result) { const string funcName = nameof(WriteAsync); // Format the message. var message = new Message { Header = { MessageType = "RESPONSE", MessageContent = "DATA", Result = result, ResultSpecified = true }, Item = data, }; if (!data.RespondToOperatorUI) // Respond to front end. { try { var serializer = new XmlSerializer(typeof(Message)); var writer = new StringWriter(); serializer.Serialize(writer, message); var responseString = writer.ToString(); return(await FrontEndConnection.WriteResponse(responseString, ct)); // } catch (Exception ex) { Log.ErrorEx(funcName, $"Exception occurred while writing data response to front-end: {ex}"); // TODO: Throw? } } else // Respond to operator ui. { var opMessage = new OperatorMessage { Header = new OperatorMessageHeader { // TODO: Set Header infos. }, Item = message // Append front end message as the item field. }; try { var serializer = new XmlSerializer(typeof(OperatorMessage)); var writer = new StringWriter(); serializer.Serialize(writer, opMessage); var responseString = writer.ToString(); return(await OperatorConnection.WriteResponse(responseString, ct)); } catch (Exception ex) { Log.ErrorEx(funcName, $"Exception occurred while writing data response to operator: {ex}"); // TODO: Throw? } } throw new NotImplementedException(); }
public void Run(CancellationToken ct) { // Start the servers. _frontEndTask = FrontEndConnection.Run(ct); _opUiTask = OperatorConnection.Run(ct); }