private FieldGuid sendTelegramWithGuidPayloadResponse(NodeTelegram telegram) { var response = sendReceiveTelegram <NodeTelegram>(telegram); if (response != null) { string payload = response.Payload.Decode(); if (FieldGuid.CheckSyntax(payload)) { return(new FieldGuid(payload)); } else { return(null); } } else { return(null); } }
/// <summary> /// Generic way to send a telegram to the engine, and get a response of a given type /// If the receive type if NodeTelegram, it checks the MessageId to make sure the /// response matches the outgoing MessageId. /// </summary> /// <returns>null if no response</returns> public T sendReceiveTelegram <T>(NodeTelegram outgoingTelegram) where T : NodeBase { responseNode = null; m_sendReceiveTelegram_ARE.Reset(); var msgId = new FieldGuid(); // generates a unique message ID m_communicationService.Value.SendToPeer(this, Peer, outgoingTelegram.SetMessageId(msgId)); if (m_sendReceiveTelegram_ARE.WaitOne(COMM_TIMEOUT, false)) { var telegramRead = responseNode as NodeTelegram; if (telegramRead != null && telegramRead.MessageId != msgId) { return(null); } return(responseNode as T); } else { // timeout return(null); } }
private NodeTelegram readSignals(NodeTelegram request) { // incoming request should just be a bunch of Guids that represent signalIds var inPayload = request.Payload.Decode(); var outPayload = new StringBuilder(); if (runtimeApplication != null) { for (int index = 0; index < inPayload.Length; index += m_guidLength) { string oneGuidString = inPayload.Substring(index, m_guidLength); if (FieldGuid.CheckSyntax(oneGuidString)) { var signalId = new FieldGuid(oneGuidString); var signal = runtimeApplication.FindSignal(signalId); if (signal != null) { outPayload.Append(EncodedSignalValue.EncodeSignalValue(signal)); } } } } return(request.SetPayload(FieldBase64.Encode(outPayload.ToString()))); }