コード例 #1
0
        public void deleteIoTHub(string IoTHubAlias)
        {
            DBHelper._IoTHub dbhelp         = new DBHelper._IoTHub();
            IoTHub           existingIoTHub = dbhelp.GetByid(IoTHubAlias);

            dbhelp.Delete(existingIoTHub);
        }
コード例 #2
0
        public void deleteIoTHub(int Id)
        {
            DBHelper._IoTHub dbhelp         = new DBHelper._IoTHub();
            IoTHub           existingIoTHub = dbhelp.GetByid(Id);

            if (existingIoTHub == null)
            {
                throw new CDSException(10901);
            }

            dbhelp.Delete(existingIoTHub);
        }
コード例 #3
0
        public void addIoTHub(Edit iotHub)
        {
            DBHelper._IoTHub dbhelp = new DBHelper._IoTHub();
            var newIoTHub           = new IoTHub()
            {
                IoTHubName                      = iotHub.IoTHubName,
                Description                     = iotHub.Description,
                CompanyID                       = iotHub.CompanyId,
                IoTHubEndPoint                  = iotHub.IoTHubEndPoint,
                IoTHubConnectionString          = iotHub.IoTHubConnectionString,
                EventConsumerGroup              = iotHub.EventConsumerGroup,
                EventHubStorageConnectionString = iotHub.EventHubStorageConnectionString,
                UploadContainer                 = iotHub.UploadContainer
            };

            dbhelp.Add(newIoTHub);
        }
コード例 #4
0
        private void loadConfigurationFromDB(string iotHubAliasName, MessageProcessorFactoryModel msgProcessorFactoryModel)
        {
            DBHelper._IoTHub iotHubHelper = new DBHelper._IoTHub();

            IoTHub iotHub = iotHubHelper.GetByid(_IoTHubAliasName);

            if (iotHub == null)
            {
                ConsoleLog.WriteToConsole("IoTHubAlias Not Found. Alias:{0}", iotHubAliasName);
                ConsoleLog.WriteBlobLogError("IoTHubAlias Not Found. Alias:{0}", iotHubAliasName);
                throw new Exception("IoTHubAlias Not Found");
            }

            _companyId = iotHub.CompanyID;

            msgProcessorFactoryModel.SimpleIoTDeviceMessageCatalogList = findAllMessageSchema(iotHub);
            msgProcessorFactoryModel.MessageIdAlarmRules = findAllMessageAlarmRules(iotHub.IoTHubAlias);
            findAllCompatibleEventHubs(iotHub);
            findDocDBConnectionString(iotHub);
        }
コード例 #5
0
        public void updateIoTHub(int Id, Edit iotHub)
        {
            DBHelper._IoTHub dbhelp         = new DBHelper._IoTHub();
            IoTHub           existingIoTHub = dbhelp.GetByid(Id);

            if (existingIoTHub == null)
            {
                throw new CDSException(10901);
            }

            existingIoTHub.IoTHubName                      = iotHub.IoTHubName;
            existingIoTHub.Description                     = iotHub.Description;
            existingIoTHub.CompanyID                       = iotHub.CompanyId;
            existingIoTHub.IoTHubEndPoint                  = iotHub.IoTHubEndPoint;
            existingIoTHub.IoTHubConnectionString          = iotHub.IoTHubConnectionString;
            existingIoTHub.EventConsumerGroup              = iotHub.EventConsumerGroup;
            existingIoTHub.EventHubStorageConnectionString = iotHub.EventHubStorageConnectionString;
            existingIoTHub.UploadContainer                 = iotHub.UploadContainer;

            dbhelp.Update(existingIoTHub);
        }
コード例 #6
0
        public void updateIoTHub(string IoTHubAlias, Edit iotHub)
        {
            DBHelper._IoTHub dbhelp         = new DBHelper._IoTHub();
            IoTHub           existingIoTHub = dbhelp.GetByid(IoTHubAlias);

            existingIoTHub.IoTHubAlias                       = iotHub.IoTHubAlias;
            existingIoTHub.Description                       = iotHub.Description;
            existingIoTHub.CompanyID                         = iotHub.CompanyId;
            existingIoTHub.P_IoTHubEndPoint                  = iotHub.P_IoTHubEndPoint;
            existingIoTHub.P_IoTHubConnectionString          = iotHub.P_IoTHubConnectionString;
            existingIoTHub.P_EventConsumerGroup              = iotHub.P_EventConsumerGroup;
            existingIoTHub.P_EventHubStorageConnectionString = iotHub.P_EventHubStorageConnectionString;
            existingIoTHub.P_UploadContainer                 = iotHub.P_UploadContainer;
            existingIoTHub.S_IoTHubEndPoint                  = iotHub.S_IoTHubEndPoint;
            existingIoTHub.S_IoTHubConnectionString          = iotHub.S_IoTHubConnectionString;
            existingIoTHub.S_EventConsumerGroup              = iotHub.S_EventConsumerGroup;
            existingIoTHub.S_EventHubStorageConnectionString = iotHub.S_EventHubStorageConnectionString;
            existingIoTHub.S_UploadContainer                 = iotHub.S_UploadContainer;

            dbhelp.Update(existingIoTHub);
        }
コード例 #7
0
        public void addIoTHub(Edit iotHub)
        {
            DBHelper._IoTHub dbhelp = new DBHelper._IoTHub();
            var newIoTHub           = new IoTHub()
            {
                IoTHubAlias                       = iotHub.IoTHubAlias,
                Description                       = iotHub.Description,
                CompanyID                         = iotHub.CompanyId,
                P_IoTHubEndPoint                  = iotHub.P_IoTHubEndPoint,
                P_IoTHubConnectionString          = iotHub.P_IoTHubConnectionString,
                P_EventConsumerGroup              = iotHub.P_EventConsumerGroup,
                P_EventHubStorageConnectionString = iotHub.P_EventHubStorageConnectionString,
                P_UploadContainer                 = iotHub.P_UploadContainer,
                S_IoTHubEndPoint                  = iotHub.S_IoTHubEndPoint,
                S_IoTHubConnectionString          = iotHub.S_IoTHubConnectionString,
                S_EventConsumerGroup              = iotHub.S_EventConsumerGroup,
                S_EventHubStorageConnectionString = iotHub.S_EventHubStorageConnectionString,
                S_UploadContainer                 = iotHub.S_UploadContainer
            };

            dbhelp.Add(newIoTHub);
        }
コード例 #8
0
        public List <Detail> GetAllIoTHubByCompanyId(int companyId)
        {
            DBHelper._IoTHub dbhelp = new DBHelper._IoTHub();

            return(dbhelp.GetAllByCompanyId(companyId).Select(s => new Detail()
            {
                IoTHubAlias = s.IoTHubAlias,
                Description = s.Description,
                CompanyId = s.Company == null ? "" : s.Company.Id.ToString(),
                CompanyName = s.Company == null ? "" : s.Company.Name,
                P_IoTHubEndPoint = s.P_IoTHubEndPoint,
                P_IoTHubConnectionString = s.P_IoTHubConnectionString,
                P_EventConsumerGroup = s.P_EventConsumerGroup,
                P_EventHubStorageConnectionString = s.P_EventHubStorageConnectionString,
                P_UploadContainer = s.P_UploadContainer,
                S_IoTHubEndPoint = s.S_IoTHubEndPoint,
                S_IoTHubConnectionString = s.S_IoTHubConnectionString,
                S_EventConsumerGroup = s.S_EventConsumerGroup,
                S_EventHubStorageConnectionString = s.S_EventHubStorageConnectionString,
                S_UploadContainer = s.S_UploadContainer
            }).ToList <Detail>());
        }
コード例 #9
0
        public Detail getIoTHubById(string IoTHubAlias)
        {
            DBHelper._IoTHub dbhelp = new DBHelper._IoTHub();
            IoTHub           iotHub = dbhelp.GetByid(IoTHubAlias);

            return(new Detail()
            {
                IoTHubAlias = iotHub.IoTHubAlias,
                Description = iotHub.Description,
                CompanyId = iotHub.Company == null ? "" : iotHub.Company.Id.ToString(),
                CompanyName = iotHub.Company == null ? "" : iotHub.Company.Name,
                P_IoTHubEndPoint = iotHub.P_IoTHubEndPoint,
                P_IoTHubConnectionString = iotHub.P_IoTHubConnectionString,
                P_EventConsumerGroup = iotHub.P_EventConsumerGroup,
                P_EventHubStorageConnectionString = iotHub.P_EventHubStorageConnectionString,
                P_UploadContainer = iotHub.P_UploadContainer,
                S_IoTHubEndPoint = iotHub.S_IoTHubEndPoint,
                S_IoTHubConnectionString = iotHub.S_IoTHubConnectionString,
                S_EventConsumerGroup = iotHub.S_EventConsumerGroup,
                S_EventHubStorageConnectionString = iotHub.S_EventHubStorageConnectionString,
                S_UploadContainer = iotHub.S_UploadContainer
            });
        }
コード例 #10
0
        public List <Detail> GetAllIoTHub()
        {
            DBHelper._IoTHub dbhelp = new DBHelper._IoTHub();
            var iotHubList          = dbhelp.GetAll();

            if (iotHubList == null)
            {
                throw new CDSException(10901);
            }

            return(dbhelp.GetAll().Select(s => new Detail()
            {
                Id = s.Id,
                IoTHubName = s.IoTHubName,
                Description = s.Description,
                CompanyId = s.Company == null ? "" : s.Company.Id.ToString(),
                CompanyName = s.Company == null ? "" : s.Company.Name,
                IoTHubEndPoint = s.IoTHubEndPoint,
                IoTHubConnectionString = s.IoTHubConnectionString,
                EventConsumerGroup = s.EventConsumerGroup,
                EventHubStorageConnectionString = s.EventHubStorageConnectionString,
                UploadContainer = s.UploadContainer
            }).ToList <Detail>());
        }
コード例 #11
0
        public Detail getIoTHubById(int Id)
        {
            DBHelper._IoTHub dbhelp = new DBHelper._IoTHub();
            IoTHub           iotHub = dbhelp.GetByid(Id);

            if (iotHub == null)
            {
                throw new CDSException(10901);
            }

            return(new Detail()
            {
                Id = iotHub.Id,
                IoTHubName = iotHub.IoTHubName,
                Description = iotHub.Description,
                CompanyId = iotHub.Company == null ? "" : iotHub.Company.Id.ToString(),
                CompanyName = iotHub.Company == null ? "" : iotHub.Company.Name,
                IoTHubEndPoint = iotHub.IoTHubEndPoint,
                IoTHubConnectionString = iotHub.IoTHubConnectionString,
                EventConsumerGroup = iotHub.EventConsumerGroup,
                EventHubStorageConnectionString = iotHub.EventHubStorageConnectionString,
                UploadContainer = iotHub.UploadContainer
            });
        }
コード例 #12
0
        public async void ThreadProc()
        {
            try
            {
                string exceptionString              = "";
                DBHelper._IoTDevice dbhelper        = new DBHelper._IoTDevice();
                DBHelper._IoTHub    dbhelper_iotHub = new DBHelper._IoTHub();
                IoTDevice           iotDevice       = dbhelper.GetByid(_IoTHubDeviceId);
                int deviceConfigurationStatus       = iotDevice.DeviceConfigurationStatus;
                switch (_Action)
                {
                case "update deired":
                    exceptionString += await UpdateDeviceConfigurationToTwins(_PrimaryIothubConnectionString, "primary");

                    //exceptionString += await UpdateDeviceConfigurationToTwins(_SecondaryIothubConnectionString, "secondary");
                    if (_Status != TaskStatus.FAILED)
                    {
                        dbhelper.UpdateDeviceConfigurationStatusAndProperty(_IoTHubDeviceId, IoTDeviceConfigurationStatus.WAITING_DEVICE_ACK);
                    }
                    break;

                case "update db device reported":
                {
                    Thread.Sleep(30000);
                    string iotHubConnectionString = "";

                    //Get IoT Hub Device Twins Reported Value
                    IoTHub iotHub = dbhelper_iotHub.GetByid(_IoTHubAlias);
                    if (_IoTHubIsPrimary)
                    {
                        iotHubConnectionString = iotHub.P_IoTHubConnectionString;
                    }
                    else
                    {
                        iotHubConnectionString = iotHub.S_IoTHubConnectionString;
                    }

                    string reportedObjJsonString = await GetDeviceTwinsReportedValue(iotHubConnectionString, _IoTHubDeviceId);

                    Console.WriteLine(reportedObjJsonString);

                    //update db
                    dbhelper.UpdateDeviceConfigurationStatusAndProperty(_IoTHubDeviceId, IoTDeviceConfigurationStatus.RECEIVE_DEVICE_ACK, null, reportedObjJsonString);

                    return;
                    //recode to operationTask
                }
                break;
                }

                if (exceptionString == "")
                {
                    Program.UpdateTaskBySuccess(_TaskId);
                    Console.WriteLine("[DeviceManagement] Apply device configuration to IoTHub desired property success: IoTHubDeviceId-" + _IoTHubDeviceId);
                }
                else
                {
                    throw new Exception(exceptionString);
                }
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = new StringBuilder();
                logMessage.AppendLine("[DeviceManagement] Apply device configuration to IoTHub desired property faild: IoTHubDeviceId-" + _IoTHubDeviceId);
                logMessage.AppendLine("\tMessage:" + JsonConvert.SerializeObject(this));
                logMessage.AppendLine("\tException:" + ex.Message);
                Program._sfAppLogger.Error(logMessage);
                Program.UpdateTaskByFail(_TaskId, Program.FilterErrorMessage(ex.Message), _Status);
                Console.WriteLine(logMessage);
                _Status = 0;
            }
        }