private static IServicesConfig GetServicesConfig(IConfigData configData) { var connstring = configData.GetString(IOTHUB_CONNSTRING_KEY); if (connstring.ToLowerInvariant().Contains("connection string")) { // In order to connect to Azure IoT Hub, the service requires a connection // string. The value can be found in the Azure Portal. For more information see // https://docs.microsoft.com/azure/iot-hub/iot-hub-csharp-csharp-getstarted // to find the connection string value. // The connection string can be stored in the 'appsettings.ini' configuration // file, or in the PCS_IOTHUB_CONNSTRING environment variable. When // working with VisualStudio, the environment variable can be set in the // WebService project settings, under the "Debug" tab. ShowIoTHubConnStringInstructions(); throw new Exception("The service configuration is incomplete. " + "Please provide your Azure IoT Hub connection string. " + "For more information, see the environment variables " + "used in project properties and the 'iothub_connstring' " + "value in the 'appsettings.ini' configuration file."); } var hubImportStorageAccount = configData.GetString(IOTHUB_IMPORT_STORAGE_CONNSTRING_KEY); if (hubImportStorageAccount.ToLowerInvariant().Contains("connection string")) { throw new Exception("The service configuration is incomplete. " + "Please provide your Azure Storage Account connection string. " + "For more information, see the environment variables " + "used in project properties and the 'iothub_connstring' " + "value in the 'appsettings.ini' configuration file."); } return(new ServicesConfig { DeviceModelsFolder = MapRelativePath(configData.GetString(DEVICE_MODELS_FOLDER_KEY)), DeviceModelsScriptsFolder = MapRelativePath(configData.GetString(DEVICE_MODELS_SCRIPTS_FOLDER_KEY)), IoTHubDataFolder = MapRelativePath(configData.GetString(IOTHUB_DATA_FOLDER_KEY)), IoTHubConnString = connstring, IoTHubImportStorageAccount = hubImportStorageAccount, IoTHubSdkDeviceClientTimeout = configData.GetOptionalUInt(IOTHUB_SDK_DEVICE_CLIENT_TIMEOUT_KEY), StorageAdapterApiUrl = configData.GetString(STORAGE_ADAPTER_API_URL_KEY), StorageAdapterApiTimeout = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY), AzureManagementAdapterApiUrl = configData.GetString(AZURE_MANAGEMENT_ADAPTER_API_URL_KEY), AzureManagementAdapterApiTimeout = configData.GetInt(AZURE_MANAGEMENT_ADAPTER_API_TIMEOUT_KEY), AzureManagementAdapterApiVersion = configData.GetString(AZURE_MANAGEMENT_ADAPTER_API_VERSION), TwinReadWriteEnabled = configData.GetBool(TWIN_READ_WRITE_ENABLED_KEY, true), MainStorage = GetStorageConfig(configData, MAIN_STORAGE_KEY), NodesStorage = GetStorageConfig(configData, NODES_STORAGE_KEY), SimulationsStorage = GetStorageConfig(configData, SIMULATIONS_STORAGE_KEY), DevicesStorage = GetStorageConfig(configData, DEVICES_STORAGE_KEY), PartitionsStorage = GetStorageConfig(configData, PARTITIONS_STORAGE_KEY), DiagnosticsEndpointUrl = configData.GetString(LOGGING_DIAGNOSTICS_URL_KEY) }); }
private static IServicesConfig GetServicesConfig(IConfigData configData) { var connstring = configData.GetString(IOTHUB_CONNSTRING_KEY); if (connstring.ToLowerInvariant().Contains("connection string")) { // In order to connect to Azure IoT Hub, the service requires a connection // string. The value can be found in the Azure Portal. For more information see // https://docs.microsoft.com/azure/iot-hub/iot-hub-csharp-csharp-getstarted // to find the connection string value. // The connection string can be stored in the 'appsettings.ini' configuration // file, or in the PCS_IOTHUB_CONNSTRING environment variable. When // working with VisualStudio, the environment variable can be set in the // WebService project settings, under the "Debug" tab. ShowIoTHubConnStringInstructions(); throw new Exception("The service configuration is incomplete. " + "Please provide your Azure IoT Hub connection string. " + "For more information, see the environment variables " + "used in project properties and the 'iothub_connstring' " + "value in the 'appsettings.ini' configuration file."); } var hubImportStorageAccount = configData.GetString(IOTHUB_IMPORT_STORAGE_CONNSTRING_KEY); if (hubImportStorageAccount.ToLowerInvariant().Contains("connection string")) { throw new Exception("The service configuration is incomplete. " + "Please provide your Azure Storage Account connection string. " + "For more information, see the environment variables " + "used in project properties and the 'iothub_connstring' " + "value in the 'appsettings.ini' configuration file."); } var azureManagementAdapterApiUrl = configData.GetString(AZURE_MANAGEMENT_ADAPTER_API_URL_KEY); if (!azureManagementAdapterApiUrl.ToLowerInvariant().StartsWith("https:")) { throw new Exception("The service configuration is incomplete. " + "Azure Management API url must start with https. " + "For more information, see the environment variables " + "used in project properties and the 'webservice_url' " + "value in the 'appsettings.ini' configuration file."); } return(new ServicesConfig { SeedTemplate = configData.GetString(SEED_TEMPLATE_KEY), SeedTemplateFolder = MapRelativePath(configData.GetString(SEED_TEMPLATE_FOLDER_KEY)), DeviceModelsFolder = MapRelativePath(configData.GetString(DEVICE_MODELS_FOLDER_KEY)), DeviceModelsScriptsFolder = MapRelativePath(configData.GetString(DEVICE_MODELS_SCRIPTS_FOLDER_KEY)), IoTHubConnString = connstring, IoTHubImportStorageAccount = hubImportStorageAccount, IoTHubSdkDeviceClientTimeout = configData.GetOptionalUInt(IOTHUB_SDK_DEVICE_CLIENT_TIMEOUT_KEY), StorageAdapterApiUrl = configData.GetString(STORAGE_ADAPTER_API_URL_KEY), StorageAdapterApiTimeout = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY), AzureManagementAdapterApiUrl = azureManagementAdapterApiUrl, AzureManagementAdapterApiTimeout = configData.GetInt(AZURE_MANAGEMENT_ADAPTER_API_TIMEOUT_KEY), AzureManagementAdapterApiVersion = configData.GetString(AZURE_MANAGEMENT_ADAPTER_API_VERSION), DeviceTwinEnabled = configData.GetBool(DEVICE_TWIN_ENABLED_KEY, true), C2DMethodsEnabled = configData.GetBool(C_2_D_METHODS_ENABLED_KEY, true), MainStorage = GetStorageConfig(configData, MAIN_STORAGE_KEY), NodesStorage = GetStorageConfig(configData, NODES_STORAGE_KEY), SimulationsStorage = GetStorageConfig(configData, SIMULATIONS_STORAGE_KEY), DevicesStorage = GetStorageConfig(configData, DEVICES_STORAGE_KEY), PartitionsStorage = GetStorageConfig(configData, PARTITIONS_STORAGE_KEY), UserAgent = configData.GetString(USER_AGENT_KEY, DEFAULT_USER_AGENT_STRING), StatisticsStorage = GetStorageConfig(configData, STATISTICS_STORAGE_KEY), DiagnosticsEndpointUrl = configData.GetString(LOGGING_DIAGNOSTICS_URL_KEY), DevelopmentMode = configData.GetBool(DEBUGGING_DEVELOPMENT_MODE_KEY, false), DisableSimulationAgent = configData.GetBool(DEBUGGING_DISABLE_SIMULATION_AGENT_KEY, false), DisablePartitioningAgent = configData.GetBool(DEBUGGING_DISABLE_PARTITIONING_AGENT_KEY, false), DisableSeedByTemplate = configData.GetBool(DEBUGGING_DISABLE_SEED_BY_TEMPLATE_KEY, false) }); }