public List <Detail> GetAllIoTDeviceByCompanyId(int companyId) { DBHelper._IoTDevice dbhelp_iotDevice = new DBHelper._IoTDevice(); DBHelper._Factory dbhelp_factory = new DBHelper._Factory(); List <int> factoryIdList = dbhelp_factory.GetAllByCompanyId(companyId).Select(s => s.Id).ToList <int>(); List <IoTDevice> iotDeviceList = new List <IoTDevice>(); foreach (int factoryId in factoryIdList) { iotDeviceList.AddRange(dbhelp_iotDevice.GetAllByFactory(factoryId)); } return(iotDeviceList.Select(s => new Detail() { IoTHubDeviceId = s.IoTHubDeviceID, IoTHubAlias = s.IoTHubAlias, IoTHubProtocol = s.IoTHubProtocol, FactoryId = s.FactoryID.ToString(), FactoryName = (s.Factory == null ? "" : s.Factory.Name), AuthenticationType = s.AuthenticationType, DeviceCertificateId = s.DeviceCertificateID.ToString(), DeviceCertificateName = (s.DeviceCertificate == null ? "" : s.DeviceCertificate.Name), DeviceTypeId = s.DeviceTypeId.ToString(), DeviceTypeName = (s.DeviceType == null ? "" : s.DeviceType.Name), DeviceVendor = s.DeviceVendor, DeviceModel = s.DeviceModel, DeviceConfigurationStatus = s.DeviceConfigurationStatus.ToString() }).ToList <Detail>()); }
public List <Detail_WithMetaData> GetAllEquipmentWithMetaDataByCompanyIdReadonly(int companyId) { DBHelper._Equipment dbhelp_equipment = new DBHelper._Equipment(); DBHelper._Factory dbhelp_factory = new DBHelper._Factory(); List <Equipment> equipmentList = new List <Equipment>(); List <int> factoryIdList = dbhelp_factory.GetAllByCompanyId(companyId).Select(s => s.Id).ToList <int>(); foreach (int factoryId in factoryIdList) { equipmentList.AddRange(dbhelp_equipment.GetAllByFactoryId(factoryId)); } return(equipmentList.Select(s => new Detail_WithMetaData() { EquipmentId = s.EquipmentId, Name = s.Name, EquipmentClassName = s.EquipmentClass.Name, FactoryName = s.Factory.Name, IoTHubDeviceId = s.IoTHubDeviceID, IoTDeviceTypeName = s.IoTDevice.DeviceType.Name, Latitude = (s.Latitude == null) ? "" : s.Latitude.ToString(), Longitude = (s.Longitude == null) ? "" : s.Longitude.ToString(), PhotoUrl = s.PhotoURL, MetaDatas = GetMetaDataById(s.Id) }).ToList <Detail_WithMetaData>()); }
public List <Detail> GetAllEquipmentByCompanyId(int companyId) { DBHelper._Equipment dbhelp_equipment = new DBHelper._Equipment(); DBHelper._Factory dbhelp_factory = new DBHelper._Factory(); List <Equipment> equipmentList = new List <Equipment>(); List <int> factoryIdList = dbhelp_factory.GetAllByCompanyId(companyId).Select(s => s.Id).ToList <int>(); foreach (int factoryId in factoryIdList) { equipmentList.AddRange(dbhelp_equipment.GetAllByFactoryId(factoryId)); } return(equipmentList.Select(s => new Detail() { Id = s.Id, EquipmentId = s.EquipmentId, Name = s.Name, EquipmentClassId = s.EquipmentClassId, EquipmentClassName = s.EquipmentClass.Name, FactoryId = s.FactoryId, FactoryName = s.Factory.Name, IoTHubDeviceId = s.IoTHubDeviceID, IoTDeviceTypeName = s.IoTDevice.DeviceType.Name, Latitude = (s.Latitude == null) ? "" : s.Latitude.ToString(), Longitude = (s.Longitude == null) ? "" : s.Longitude.ToString(), MaxIdleInSec = s.MaxIdleInSec, PhotoUrl = s.PhotoURL }).ToList <Detail>()); }
public List <Detail_readonly> GetAllFactoryByCompanyIdReadonly(int companyId) { DBHelper._Factory dbhelp = new DBHelper._Factory(); return(dbhelp.GetAllByCompanyId(companyId).Select(s => new Detail_readonly() { Id = s.Id, Name = s.Name, Description = s.Description, Latitude = (s.Latitude == null) ? "" : s.Latitude.ToString(), Longitude = (s.Longitude == null) ? "" : s.Longitude.ToString(), PhotoURL = s.PhotoURL, TimeZone = s.TimeZone, CultureInfoName = s.RefCultureInfo.Name }).ToList <Detail_readonly>()); }
public List <Detail_readonly> GetAllIoTDeviceByCompanyIdReadonly(int companyId) { DBHelper._IoTDevice dbhelp_iotdevice = new DBHelper._IoTDevice(); DBHelper._Factory dbhelp_factory = new DBHelper._Factory(); List <IoTDevice> iotDeviceList = new List <IoTDevice>(); List <int> factoryIdList = dbhelp_factory.GetAllByCompanyId(companyId).Select(s => s.Id).ToList <int>(); foreach (int factoryId in factoryIdList) { iotDeviceList.AddRange(dbhelp_iotdevice.GetAllByFactory(factoryId)); } return(iotDeviceList.Select(s => new Detail_readonly() { IoTHubDeviceId = s.IoTHubDeviceID, IoTHubProtocol = s.IoTHubProtocol, FactoryId = s.FactoryID.ToString(), FactoryName = s.Factory.Name, DeviceTypeId = s.DeviceTypeId.ToString(), DeviceTypeName = s.DeviceType.Name, DeviceVendor = s.DeviceVendor, DeviceModel = s.DeviceModel }).ToList <Detail_readonly>()); }
public List <Detail> GetAllFactoryByCompanyId(int companyId) { DBHelper._Factory dbhelp = new DBHelper._Factory(); var factoryList = dbhelp.GetAllByCompanyId(companyId); if (factoryList == null) { throw new CDSException(10701); } return(factoryList.Select(s => new Detail() { Id = s.Id, Name = s.Name, Description = s.Description, CompanyId = s.CompanyId, Latitude = (s.Latitude == null) ? "" : s.Latitude.ToString(), Longitude = (s.Longitude == null) ? "" : s.Longitude.ToString(), PhotoURL = s.PhotoURL, TimeZone = s.TimeZone, CultureInfoId = s.CultureInfo, CultureInfoName = s.RefCultureInfo.Name }).ToList <Detail>()); }
public override void Exec() { RecordStartLog(); DBHelper._Company dbhelp_Company = new DBHelper._Company(); DBHelper._Factory dbhelp_Facotry = new DBHelper._Factory(); DBHelper._Equipment dbhelp_Equipment = new DBHelper._Equipment(); DBHelper._UsageLog dbhelp_UsageLog = new DBHelper._UsageLog(); List <UsageLog> usageLogList = new List <UsageLog>(); foreach (var company in dbhelp_Company.GetAll()) { int companyId = company.Id; int factoryQty = 0; int equipmentQty = 0; long deviceMsgQty = 0; long alarmMsgQty = 0; int DocDbSizeInGB = 0; int DocDBPercentage = 0; try { foreach (var factory in dbhelp_Facotry.GetAllByCompanyId(companyId)) { factoryQty++; equipmentQty += dbhelp_Equipment.GetAllByFactoryId(factory.Id).Count; } DocumentDBHelper docDBHelpler = new DocumentDBHelper(companyId, company.DocDBConnectionString); docDBHelpler.Init(); deviceMsgQty = docDBHelpler.GetCompanyDeviceMsgQty(); alarmMsgQty = docDBHelpler.GetCompanyAlarmMessageQty(); DocDbSizeInGB = Convert.ToInt32(docDBHelpler._SizeQuotaInKB / (1024 * 1024)); DocDBPercentage = Convert.ToInt32(docDBHelpler._SizeUsageInKB * 100 / docDBHelpler._SizeQuotaInKB); } catch (Exception ex) { StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("Routine TaskActor : " + _TaskName); logMessage.AppendLine("\tCompayId " + companyId + " is failed"); logMessage.AppendLine("\tException: " + ex.Message); if (ex.InnerException != null) { logMessage.AppendLine("\tInnerException: " + ex.InnerException.Message); } _sfAppLogger.Error(logMessage); } usageLogList.Add(new UsageLog() { CompanyId = companyId, FactoryQty = factoryQty, EquipmentQty = equipmentQty, DeviceMessage = deviceMsgQty, AlarmMessage = alarmMsgQty, DocSizeInGB = DocDbSizeInGB, DocDBPercentage = DocDBPercentage, UpdatedAt = DateTime.Now }); } try { dbhelp_UsageLog.Add(usageLogList); } catch (Exception ex) { StringBuilder logMessage = new StringBuilder(); logMessage.AppendLine("Routine TaskActor : " + _TaskName); logMessage.AppendLine("\tException: " + ex.Message); logMessage.AppendLine("\tInnerException: " + ex.InnerException.Message); _sfAppLogger.Error(logMessage); } RecordEndLog(); }