private Timer _t; //timer for doing period cleaning out of the object cache

        #endregion Fields

        #region Constructors

        public aaAttributeManager()
        {
            Singleton = this;
            ListenPort = 8123;
            //If we can't do the following, then we can't continue anyway so let the caller handle the error
            _lmxServer = new ArchestrA.MxAccess.LMXProxyServerClass();
            _hLmx = _lmxServer.Register("aaAttributeBrowser");
            _lmxServer.OnDataChange += new _ILMXProxyServerEvents_OnDataChangeEventHandler(LMX_OnDataChange);
            _t = new Timer(CleanStaleObjects, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(-1));
        }
예제 #2
0
        static void ConnectMXAccess()
        {
            int hitem;

            try
            {
                if (_LMX_Server == null)
                {
                    // instantiate an ArchestrA.MxAccess.LMXProxyServer
                    try
                    {
                        _LMX_Server = new ArchestrA.MxAccess.LMXProxyServerClass();
                    }
                    catch
                    {
                        throw;
                    }
                }

                if ((_LMX_Server != null) && (_hLMX == 0))
                {
                    // Register with LMX and get the Registration handle
                    _hLMX = _LMX_Server.Register("aaDataForwarderApp");

                    // connect the event handlers
                    _LMX_Server.OnDataChange    += new _ILMXProxyServerEvents_OnDataChangeEventHandler(LMX_OnDataChange);
                    _LMX_Server.OnWriteComplete += new _ILMXProxyServerEvents_OnWriteCompleteEventHandler(LMX_OnWriteComplete);
                }

                // Read in the MX Access Settings from the configuration file
                _MXAccessSettings = JsonConvert.DeserializeObject <localMXAccessSettings>(System.IO.File.ReadAllText("mxaccess.json"));

                // Loop through all of the tags and add
                foreach (publish publishtag in _MXAccessSettings.publishtags)
                {
                    log.Info("Adding Publish for " + publishtag.tag);
                    hitem = _LMX_Server.AddItem(_hLMX, publishtag.tag);

                    if (hitem > 0)
                    {
                        _MXAccessTagDictionary.Add(hitem, publishtag.tag);
                        _LMX_Server.Advise(_hLMX, hitem);
                    }
                }

                // Loop through all of the tags we are subscribing to and get those on supervisory advise so we can perform writes
                if (MQTTOK())
                {
                    // Now add the subscriptions
                    List <string> topics    = new List <string>();
                    List <byte>   qoslevels = new List <byte>();

                    // First get on advise
                    foreach (subscription sub in _MXAccessSettings.subscribetags)
                    {
                        log.Info("Adding Subscribe for " + sub.writetag);
                        hitem = _LMX_Server.AddItem(_hLMX, sub.writetag);

                        if (hitem > 0)
                        {
                            sub.hitem = hitem;
                            _MXAccessTagDictionary.Add(hitem, sub.writetag);
                            _LMX_Server.AdviseSupervisory(_hLMX, hitem);
                            topics.Add(sub.topic.ToLower());
                            qoslevels.Add(sub.qoslevel);
                        }
                    }

                    // Now add all the subscritpions and QOS in one statement
                    _mqttClient.Subscribe(topics.ToArray <string>(), qoslevels.ToArray <byte>());
                }
            }
            catch
            {
                throw;
            }
        }