Beispiel #1
0
        public void deleteFactory(int id)
        {
            DBHelper._Factory dbhelp          = new DBHelper._Factory();
            Factory           existingFactory = dbhelp.GetByid(id);

            dbhelp.Delete(existingFactory);
        }
Beispiel #2
0
        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>());
        }
Beispiel #3
0
        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>());
        }
Beispiel #4
0
        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>());
        }
Beispiel #5
0
        public void deleteFactory(int id)
        {
            DBHelper._Factory dbhelp          = new DBHelper._Factory();
            Factory           existingFactory = dbhelp.GetByid(id);

            if (existingFactory == null)
            {
                throw new CDSException(10701);
            }

            dbhelp.Delete(existingFactory);
        }
Beispiel #6
0
        public void updateFactory(int id, Edit factory)
        {
            DBHelper._Factory dbhelp          = new DBHelper._Factory();
            Factory           existingFactory = dbhelp.GetByid(id);

            existingFactory.Name        = factory.Name;
            existingFactory.Description = factory.Description;
            existingFactory.Latitude    = factory.Latitude;
            existingFactory.Longitude   = factory.Longitude;
            existingFactory.TimeZone    = factory.TimeZone;
            existingFactory.CultureInfo = factory.CultureInfoId;

            dbhelp.Update(existingFactory);
        }
Beispiel #7
0
        public static bool IsFactoryUnderCompany(int factoryId, int companyId)
        {
            DBHelper._Factory dbhelp_factory = new DBHelper._Factory();
            var factory = dbhelp_factory.GetByid(factoryId, companyId);

            if (factory == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #8
0
        public void addFactory(Edit factory)
        {
            DBHelper._Factory dbhelp = new DBHelper._Factory();
            var newFactory           = new Factory()
            {
                Name        = factory.Name,
                Description = factory.Description,
                CompanyId   = factory.CompanyId,
                Latitude    = factory.Latitude,
                Longitude   = factory.Longitude,
                TimeZone    = factory.TimeZone,
                CultureInfo = factory.CultureInfoId
            };

            dbhelp.Add(newFactory);
        }
Beispiel #9
0
        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>());
        }
Beispiel #10
0
        public Detail_readonly getFactoryByIdReadonly(int id, int companyId)
        {
            DBHelper._Factory dbhelp  = new DBHelper._Factory();
            Factory           factory = dbhelp.GetByid(id, companyId);

            return(new Detail_readonly()
            {
                Id = factory.Id,
                Name = factory.Name,
                Description = factory.Description,
                Latitude = (factory.Latitude == null) ? "" : factory.Latitude.ToString(),
                Longitude = (factory.Longitude == null) ? "" : factory.Longitude.ToString(),
                PhotoURL = factory.PhotoURL,
                TimeZone = factory.TimeZone,
                CultureInfoName = factory.RefCultureInfo.Name
            });
        }
Beispiel #11
0
        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>());
        }
Beispiel #12
0
        public Detail getFactoryById(int id)
        {
            DBHelper._Factory dbhelp  = new DBHelper._Factory();
            Factory           factory = dbhelp.GetByid(id);

            if (factory == null)
            {
                throw new CDSException(10701);
            }

            return(new Detail()
            {
                Id = factory.Id,
                Name = factory.Name,
                Description = factory.Description,
                CompanyId = factory.CompanyId,
                Latitude = (factory.Latitude == null) ? "" : factory.Latitude.ToString(),
                Longitude = (factory.Longitude == null) ? "" : factory.Longitude.ToString(),
                PhotoURL = factory.PhotoURL,
                TimeZone = factory.TimeZone,
                CultureInfoId = factory.CultureInfo,
                CultureInfoName = factory.RefCultureInfo.Name
            });
        }
Beispiel #13
0
        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>());
        }
Beispiel #14
0
        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();
        }