} // End sub /// <summary> /// Initializes a connection to the control command message broker /// </summary> private bool InitializeMessageConnection() { // initialize the connection parameter fields string msgBrokerURL = m_MgrSettings.GetParam("ControlQueueURI"); string msgTopicName = m_MgrSettings.GetParam("ControlQueueTopic"); // get a unique name for the message client DateTime tn = DateTime.Now; // Alternative: System.Guid.NewGuid().ToString(); string strClientID = System.Net.Dns.GetHostEntry("localhost").HostName + '_' + tn.Ticks.ToString(); if (this.m_TopSubscribe != null) { this.m_TopSubscribe.Dispose(); } try { this.m_TopSubscribe = new SimpleTopicSubscriber(msgTopicName, msgBrokerURL, ref strClientID); this.m_TopSubscribe.OnMessageReceived += new MessageReceivedDelegate(subscriber_OnMessageReceived); this.m_TopSubscribe.OnConnectionException += new ConnectionExceptionDelegate(connection_OnConnectionException); clsLogTools.WriteLog(clsLogTools.LoggerTypes.LogFile, clsLogTools.LogLevels.INFO, "Control broker connected"); // Everything worked! return(true); } catch (Exception Ex) { string ErrMsg = "Exception initializing connection to control broker"; clsLogTools.WriteLog(clsLogTools.LoggerTypes.LogFile, clsLogTools.LogLevels.ERROR, ErrMsg, Ex); return(false); } } // End sub
public bool start() { bool success = false; communication com = new communication(); string uri = "tcp://" + device.Component.Address + ":61616"; string clientID = com.generateID(10); try { topic = new SimpleTopicSubscriber(device.DeviceQueue, uri, clientID, clientID); } catch (Exception e) { } return(success); }