Beispiel #1
0
        public override bool DoWork()
        {
            string meterType = CloudConfigurationManager.GetSetting("DISCOVERY_ELETRIC_METER");

            string[] supportedDemandTypes = CloudConfigurationManager.GetSetting("DISCOVERY_SUPPORTED_DEMAND_TYPE").Split(',');
            var      enabledCustomer      = _dataRep.Customers.Where(c => c.Guid == _customerGuid).SingleOrDefault();
            var      addedMeters          = new List <WattApp.data.Models.Equipment>();

            if (enabledCustomer != null)
            {
                var company = new BuildingApi.Company()
                {
                    Id = _customerGuid
                };
                var eletricMeters = _apiClient.EquipmentClient.GetEquipmentAndPointRoles(meterType, company);
                foreach (var item in eletricMeters)
                {
                    if (item.PointRoles.Items.Where(p => p.Type.Id.Contains(CloudConfigurationManager.GetSetting("DISCOVERY_SUPPORTED_DEMAND"))).Count() > 0)
                    {
                        // Check if the equipment has been discovered
                        if (enabledCustomer.EquipmentList.Where(e => e.PxGuid == item.Id).Count() == 0)
                        {
                            var equip = new WattApp.data.Models.Equipment()
                            {
                                Name = item.Name, Type = item.Type.Id, PxGuid = item.Id, Location = "TBD", CustomerId = enabledCustomer.Id
                            };
                            // Retrieve Point info
                            var ptInfo = item.PointRoles.Items.FirstOrDefault(p => p.Type.Id == supportedDemandTypes[0]);
                            if (ptInfo == null)
                            {
                                ptInfo = item.PointRoles.Items.FirstOrDefault(p => p.Type.Id == supportedDemandTypes[1]);
                            }
                            var point = new WattApp.data.Models.Point()
                            {
                                Name = ptInfo.Point.Name, Type = ptInfo.Type.Id, PxGuid = ptInfo.Point.Id, Enabled = true
                            };
                            equip.PointsList.Add(point);

                            // Retrive Building / location info
                            var building = _apiClient.GetContainerBuilding(item.Location, company);
                            if (building != null)
                            {
                                equip.Location = building.Name;
                            }
                            addedMeters.Add(equip);
                        }
                    }
                }

                // Add new meters
                if (addedMeters.Count() > 0)
                {
                    _dataRep.Insert(addedMeters);
                }
                _logger.Info(string.Format("Added {0} new meters to customer={1}", addedMeters.Count(), _customerGuid));
            }

            return(true);
        }
Beispiel #2
0
        public void DiscoveryAndUpdateMetersTask()
        {
            _logger.Info("****DiscoveryAndUpdateMetersTask****");
            _stopWatch.Restart();
            var addedMeters = new List <WattApp.data.Models.Equipment>();

            try
            {
                string   meterType            = CloudConfigurationManager.GetSetting("DISCOVERY_ELETRIC_METER");
                string[] supportedDemandTypes = CloudConfigurationManager.GetSetting("DISCOVERY_SUPPORTED_DEMAND_TYPE").Split(',');
                var      enabledCustomer      = _dataRep.Customers.Where(c => c.Enabled == true);
                Console.WriteLine("Enabled Customers " + enabledCustomer.Count());

                // Dev Only one Customer enabled
                if (enabledCustomer.Count() > 0)
                {
                    var customer = enabledCustomer.SingleOrDefault();
                    var company  = new BuildingApi.Company()
                    {
                        Id = customer.Guid
                    };
                    var eletricMeters = _equipmentClient.GetEquipmentAndPointRoles(meterType, company);
                    Console.WriteLine("Found Meters " + eletricMeters.Count());
                    foreach (var item in eletricMeters)
                    {
                        if (item.PointRoles.Items.Where(p => p.Type.Id.Contains(CloudConfigurationManager.GetSetting("DISCOVERY_SUPPORTED_DEMAND"))).Count() > 0)
                        {
                            if (_temporaryJCIMeterName.Contains(item.Name))
                            {
                                // Check if the equipment has been discovered
                                if (customer.EquipmentList.Where(e => e.PxGuid == item.Id).Count() == 0)
                                {
                                    var equip = new WattApp.data.Models.Equipment()
                                    {
                                        Name = item.Name, Type = item.Type.Id, PxGuid = item.Id, Location = "TBD", CustomerId = customer.Id
                                    };
                                    var ptInfo = item.PointRoles.Items.FirstOrDefault(p => p.Type.Id == supportedDemandTypes[0]);
                                    if (ptInfo == null)
                                    {
                                        ptInfo = item.PointRoles.Items.FirstOrDefault(p => p.Type.Id == supportedDemandTypes[1]);
                                    }
                                    var point = new WattApp.data.Models.Point()
                                    {
                                        Name = ptInfo.Point.Name, Type = ptInfo.Type.Id, PxGuid = ptInfo.Point.Id, Enabled = true
                                    };
                                    equip.PointsList.Add(point);
                                    addedMeters.Add(equip);
                                }
                            }
                        }
                    }
                }

                // Add new meters
                if (addedMeters.Count() > 0)
                {
                    _dataRep.Insert(addedMeters);
                }
            }
            catch (Exception e)
            {
                _logger.Error("DiscoveryAndUpdateMetersTask->Unhandle Exception ", e);
                Trace.WriteLine("DiscoveryAndUpdateMetersTask -> Unhandle Exception " + e.Message);
            }
            _logger.Info(string.Format("Added {0} new meters ", addedMeters.Count()));
            _logger.Info(string.Format("DiscoveryAndUpdateMetersTask executed in (ms) {0}", _stopWatch.ElapsedMilliseconds));
        }