Esempio n. 1
0
        private void findAllCompatibleEventHubs(IoTHub iotHub)
        {
            _Primary_CompatibleEventHub = new CompatibleEventHub(
                iotHub.P_IoTHubEndPoint,                   // messages/events
                iotHub.P_IoTHubConnectionString,           // IoT Hub Connection String
                iotHub.P_EventConsumerGroup,               // Consumer Group
                iotHub.P_EventHubStorageConnectionString); // Storage Connection String

            _Secondary_CompatibleEventHub = new CompatibleEventHub(
                iotHub.S_IoTHubEndPoint,                   // messages/events
                iotHub.S_IoTHubConnectionString,           // IoT Hub Connection String
                iotHub.S_EventConsumerGroup,               // Consumer Group
                iotHub.S_EventHubStorageConnectionString); // Storage Connection String
        }
Esempio n. 2
0
        private async Task loadConfigurationFromDB(EventProcessorFactoryModel epfm)
        {
            CdsInfo cdsInfo = epfm.CdsInfo;
            IoTHub  iotHub;
            CompanyInSubscriptionPlan cisp;
            string telemetryStorageContainer;
            string eventStorageContainer;

            if (_ignoreCDS20DB)
            {
                /* For Test */
                TestSampleHelper tsHelper = new TestSampleHelper();
                iotHub = tsHelper.generateIoTHubForTest(cdsInfo.IoTHubId);

                cisp                  = new CompanyInSubscriptionPlan();
                cisp.ExpiredDate      = DateTime.UtcNow.AddMonths(1);// Test
                cisp.StoreColdMessage = true;
                cisp.StoreHotMessage  = true;
                /* Walker's Cosmos DB */
                cisp.CosmosDBConnectionString = "https://sfdev.documents.azure.com:443/;AccountKey=PHsydcvXyVdELDtWTgLvlbrP5ohuaJbMKQNNCxZKR1UPwS45qVkYiTuXR6wTm9PhnqIDe5IwUoQ0fqmk28CJww==;";// "https://sfdocumentdb.documents.azure.com:443/;AccountKey=uscYe8taxXEtIIzQjCM47T3y3F53wMn2QOPUOnZu55oBClFnzOzfd5UDSlMixgCR6aqBNbHebJmIgoSmdk2MxQ==;";
                cisp.CosmosDBName             = "db69";
                cisp.CosmosDBCollectionID     = "69";

                telemetryStorageContainer = "telemetry";
                eventStorageContainer     = "event";
            }
            else
            {
                /* For CDS 2.0 DB */
                AzureSQLHelper.IoTHubModel ioTHubModel = new AzureSQLHelper.IoTHubModel();
                iotHub = ioTHubModel.GetById(Int32.Parse(cdsInfo.IoTHubId));

                AzureSQLHelper.CompanyModel companyModel = new AzureSQLHelper.CompanyModel();
                cisp = companyModel.GetActiveSubscriptionPlanByCompanyId(Int32.Parse(cdsInfo.CompanyId));

                telemetryStorageContainer = AzureSQLHelper.SystemConfigurationModel.GetCDSConfigValueByKey("TelemetryStorageContainer");
                telemetryStorageContainer = telemetryStorageContainer == null ? "telemetry" : telemetryStorageContainer;
                eventStorageContainer     = AzureSQLHelper.SystemConfigurationModel.GetCDSConfigValueByKey("EventStorageContainer");
                eventStorageContainer     = eventStorageContainer == null ? "event" : eventStorageContainer;
            }

            if (iotHub == null)
            {
                _consoleLog.Info("IoTHub Not Found. IoTHubId:{0}", cdsInfo.IoTHubId);
                _consoleLog.BlobLogError("IoTHub Not Found. IoTHubId:{0}", cdsInfo.IoTHubId);
                throw new Exception("IoTHub Not Found");
            }
            if (cisp == null)
            {
                _consoleLog.Info("NO Actived CompanyInSubscriptionPlan. CompanyId:{0}", cdsInfo.CompanyId);
                _consoleLog.BlobLogError("NO Actived CompanyInSubscriptionPlan. CompanyId:{0}", cdsInfo.CompanyId);
                throw new Exception("NO Actived CompanyInSubscriptionPlan");
            }

            /* IoTHubAlias */
            cdsInfo.IoTHubAlias = iotHub.IoTHubName;

            /* CompanyInSubscriptionPlan */
            cdsInfo.CompanyInSubscriptionPlan = cisp;

            /* Load the message schema from IoT Hub devices */
            epfm.SimpleIoTDeviceMessageCatalogList = findAllMessageCatalogIdInIoTDevices(iotHub.IoTDevice);

            /* Load the message JSON transformer from IoT Hub devices */
            epfm.MessageTransformerInDeviceId = findAllMessageTransformers(iotHub.IoTDevice);

            /* Load Alarm Rules */
            epfm.EventRulesInMessageId = findAllEventRules(iotHub);

            /* Load Monitor Frequence In MinSec By MessageId */
            epfm.MonitorFrequenceInMinSecByMessageId = findMonitorFrequenceInMinSecByMessageId(iotHub.IoTDevice);

            /* Load IoT Hub configuration */
            _CompatibleEventHub = findCompatibleEventHub(iotHub);

            /* Cosmos DB Helper */
            epfm.docDBHelper = await createDocDBHelper(cdsInfo.CompanyInSubscriptionPlan);

            /* Blob Helper */
            epfm.TelemetryBlobStorageHelper = new BlobStorageHelper(_CompatibleEventHub.StorageConnectionString, telemetryStorageContainer);
            epfm.EventBlobStorageHelper     = new BlobStorageHelper(_CompatibleEventHub.StorageConnectionString, eventStorageContainer);

            /* Service Bus Helper */
            CdsBackendSetting cdsBackendSetting = cdsInfo.cdsBackendSetting;

            epfm.EventQueueClient = QueueClient.CreateFromConnectionString(cdsBackendSetting.ServiceBusConnectionString, cdsBackendSetting.ServiceBusEventActionQueue);
            epfm.InfraQueueClient = QueueClient.CreateFromConnectionString(cdsBackendSetting.ServiceBusConnectionString, cdsBackendSetting.ServiceBusProvisionQueue);
        }