public StompSource(PacketConverter <T> packetConverter, string serverPortTopic) : base(packetConverter) { string server = "localhost"; int port = StompConnection.DEFAULT_PORT; string topic = packetConverter.GetDefaultTopic(true); PacketSource <T> .ParseServerPortTopic(serverPortTopic, ref server, ref port, ref topic); // Create STOMP connection stompConnection = null; try { stompConnection = new StompConnection(server, port); } catch (Exception) {; } if (stompConnection != null) { // Subscribe to a topic stompConnection.Subscribe(topic); // Create threaded listener and add a message handler stompListener = new StompListener(stompConnection); stompListener.ReceivedMessage += stompListener_ReceivedMessage; } }
public void UpdateHypothesis(string name, bool value, string label = null) { //Console.WriteLine("HYPOTHESIS: " + name + "=" + value + " (" + label + ")."); if (label == null) { label = name; } if (!value && activeHypothesis.ContainsKey(name)) { activeHypothesis.Remove(name); } else if (value) { activeHypothesis[name] = label; } string currentLabel = null; foreach (KeyValuePair <string, string> kvp in activeHypothesis) { currentLabel = kvp.Value; } //Console.WriteLine("HYPOTHESIS: " + currentLabel); CurrentHypothesis = currentLabel; ManagerEventArgs mea = new ManagerEventArgs(name, value, label); OnHypothesisChanged(mea); if (outStompConnection == null && !outStompAttempted) { try { outStompConnection = new StompConnection(outStompHost, outStompPort); } catch (Exception) { ; } outStompAttempted = true; } if (outStompConnection != null) { // Create JSON-encoded data Hashtable sourceData = new Hashtable(); sourceData.Add("name", name); sourceData.Add("value", value); string jsonData = Json.JsonEncode(sourceData); outStompConnection.Send(outStompTopic, jsonData); Console.WriteLine("Sent " + jsonData + " to " + outStompTopic); } else { //Console.WriteLine("FAILED to send to " + outStompTopic); } }
public StompDest(PacketConverter <T> packetConverter, string serverPortTopic) : base(packetConverter) { string server = "localhost"; int port = StompConnection.DEFAULT_PORT; string topic = packetConverter.GetDefaultTopic(false); PacketSource <T> .ParseServerPortTopic(serverPortTopic, ref server, ref port, ref topic); this.topic = topic; // Create STOMP connection stompConnection = null; try { stompConnection = new StompConnection(server, port); } catch (Exception) {; } }
public void UpdateHypothesis(string name, bool value, string label = null) { //Console.WriteLine("HYPOTHESIS: " + name + "=" + value + " (" + label + ")."); if (label == null) { label = name; } if (!value && activeHypothesis.ContainsKey(name)) { activeHypothesis.Remove(name); } else if (value) { activeHypothesis[name] = label; } string currentLabel = null; foreach (KeyValuePair<string, string> kvp in activeHypothesis) { currentLabel = kvp.Value; } //Console.WriteLine("HYPOTHESIS: " + currentLabel); CurrentHypothesis = currentLabel; ManagerEventArgs mea = new ManagerEventArgs(name, value, label); OnHypothesisChanged(mea); if (outStompConnection == null && !outStompAttempted) { try { outStompConnection = new StompConnection(outStompHost, outStompPort); } catch (Exception) { ; } outStompAttempted = true; } if (outStompConnection != null) { // Create JSON-encoded data Hashtable sourceData = new Hashtable(); sourceData.Add("name", name); sourceData.Add("value", value); string jsonData = Json.JsonEncode(sourceData); outStompConnection.Send(outStompTopic, jsonData); Console.WriteLine("Sent " + jsonData + " to " + outStompTopic); } else { //Console.WriteLine("FAILED to send to " + outStompTopic); } }
public StompListener(StompConnection stompConnection) { this.stompConnection = stompConnection; Start(); }
public StompListener(StompConnection stompConnection) { this.stompConnection = stompConnection; Start(); }