Example #1
0
        public override void Initialize(Dictionary <string, object> settings)
        {
            string pluginNamespace = GetContainerNamespace();
            //load types specific to this host into TypeContainer
            TagConfigDatabase tagConfigDatabase = TagConfigDatabase.Instance;

            tagConfigDatabase.Load(ConfigUtility.ReadFile(settings.GetValueOrNull("OpcTagConfigFile") as string));
            TagStateManager tagStateManager = new TagStateManager(tagConfigDatabase);

            settings["TagStateManager"]   = tagStateManager;
            settings["TagConfigDatabase"] = tagConfigDatabase;

            //configure receiver
            TypeContainer            tc           = TypeContainer.Instance;
            IProcessor               opcReceiver  = tc.GetInstance <IReceiver>(pluginNamespace) as IProcessor;
            IConverter <object, Tag> opcConverter = tc.GetInstance <IConverter <object, Tag> >(pluginNamespace);

            settings["Logger"]          = tc.GetInstance <ILogger>();
            settings["OpcTagConverter"] = opcConverter;
            if (opcReceiver != null)
            {
                this.AddReceiver("OpcReceiver", opcReceiver);
            }

            //configure IotHub Sender: need "IotHubConfigFile", "TagStateManager", "TagToIotHubMessageConverter" in settings
            settings["TagToIotHubMessageConverter"] = tc.GetInstance <IConverter <Tag, object> >(pluginNamespace);
            IProcessor iotHubSender = tc.GetInstance <ISender>(pluginNamespace) as IProcessor;

            if (iotHubSender != null)
            {
                this.AddSender("IotHubSender", iotHubSender);
            }

            base.Initialize(settings);
        }
Example #2
0
        public void ConstructorTest()
        {
            TagConfigDatabase db = TagConfigDatabase.Instance;

            db.Load(_tagRecords);
            TagStateManager tsm = new TagStateManager(db);

            Assert.AreEqual("AirConditioner1.Temperature", tsm.GetTag("AirConditioner1.Temperature").Name);
        }
Example #3
0
        public void UpdateTagTest()
        {
            TagConfigDatabase db = TagConfigDatabase.Instance;

            db.Load(_tagRecords);
            TagStateManager             tsm    = new TagStateManager(db);
            Dictionary <string, object> fields = new Dictionary <string, object> {
                { "Quality", "1" }
            };

            tsm.UpdateTag <double>("AirConditioner1.Temperature", DateTime.UtcNow, 77.5D, fields);
            tsm.UpdateTag <double>("AirConditioner1.Temperature", DateTime.UtcNow, 79.4D, fields);

            var tag = tsm.GetTag("AirConditioner1.Temperature");
            DataPoint <double> dp = (DataPoint <double>)tag.DataPoints["AirConditioner1.Temperature"];

            Assert.AreEqual(79.4D, dp.Val);
        }
Example #4
0
        private void LoadTags(TagConfigDatabase tagConfigDatabase)
        {
            var tagGroups = tagConfigDatabase.GetDisctinctTagGroupNames();

            foreach (var groupName in tagGroups)
            {
                TagGroup currentTagGroup;
                if (!_tagGroups.TryGetValue(groupName, out currentTagGroup))
                {
                    currentTagGroup = new TagGroup(groupName);
                    _tagGroups.TryAdd(groupName, currentTagGroup);
                }

                var tagRecords = tagConfigDatabase.GetTags(groupName);
                foreach (var tr in tagRecords)
                {
                    Tag tag = new Tag(tr.TagName);
                    currentTagGroup.Config.SendIntervalSeconds = tr.SendingInterval;
                    currentTagGroup.Tags.TryAdd(tag.Name, tag);
                }
            }
        }
Example #5
0
        public void QueryTest1()
        {
            List <TagConfigRecord> tagRecords = new List <TagConfigRecord>();

            tagRecords.Add(new TagConfigRecord {
                TagGroupName = "Group1", TagName = "Boiler1.Temperature", SendingInterval = 5, TagNamespaceIndex = 2
            });
            tagRecords.Add(new TagConfigRecord {
                TagGroupName = "Group1", TagName = "AirConditioner1.Temperature", SendingInterval = 5, TagNamespaceIndex = 2
            });
            tagRecords.Add(new TagConfigRecord {
                TagGroupName = "Group2", TagName = "Boiler2.Temperature", SendingInterval = 2, TagNamespaceIndex = 2
            });
            tagRecords.Add(new TagConfigRecord {
                TagGroupName = "Group2", TagName = "AirConditioner2.Temperature", SendingInterval = 2, TagNamespaceIndex = 2
            });

            TagConfigDatabase db = TagConfigDatabase.Instance;

            db.Load(tagRecords);

            var groups = db.GetDisctinctTagGroupNames();
            int count  = 0;

            foreach (string str in groups)
            {
                count++;
            }
            Assert.AreEqual(2, count);

            var t1 = db.GetTagGroupName("Boiler1.Temperature");

            Assert.AreEqual("Group1", t1);

            var tagName = db.GetTagGroupName("Boiler1.Temperature1");

            Assert.IsNull(tagName);
        }
Example #6
0
 public TagStateManager(TagConfigDatabase tagConfigDatabase)
 {
     LoadTags(tagConfigDatabase);
 }