public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            var storageType          = configData.GetString(STORAGE_TYPE_KEY).ToLowerInvariant();
            var documentDbConnString = configData.GetString(DOCUMENT_DB_CONNECTION_STRING_KEY);

            if (storageType == "documentdb" &&
                (string.IsNullOrEmpty(documentDbConnString) ||
                 documentDbConnString.StartsWith("${") ||
                 documentDbConnString.Contains("...")))
            {
                // In order to connect to the storage, the service requires a connection
                // string for Document Db. The value can be found in the Azure Portal.
                // The connection string can be stored in the 'appsettings.ini' configuration
                // file, or in the PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING environment variable.
                // When working with VisualStudio, the environment variable can be set in the
                // WebService project settings, under the "Debug" tab.
                throw new Exception("The service configuration is incomplete. " +
                                    "Please provide your DocumentDb connection string. " +
                                    "For more information, see the environment variables " +
                                    "used in project properties and the 'documentdb_connstring' " +
                                    "value in the 'appsettings.ini' configuration file.");
            }

            this.ServicesConfig = new ServicesConfig
            {
                StorageType          = storageType,
                DocumentDbConnString = documentDbConnString,
                DocumentDbDatabase   = configData.GetString(DOCUMENT_DB_DATABASE_KEY),
                DocumentDbCollection = configData.GetString(DOCUMENT_DB_COLLECTION_KEY),
                DocumentDbRUs        = configData.GetInt(DOCUMENT_DB_RUS_KEY),
            };
        }
Esempio n. 2
0
        private static Services.Storage.Config GetStorageConfig(IConfigData configData, string prefix)
        {
            var defaults    = new Services.Storage.Config();
            var storageType = configData.GetEnum(prefix + STORAGE_TYPE_KEY, Services.Storage.Type.Unknown);

            switch (storageType)
            {
            case Services.Storage.Type.CosmosDbSql:
                return(new Services.Storage.Config
                {
                    StorageType = storageType,
                    MaxPendingOperations = configData.GetInt(prefix + STORAGE_MAX_PENDING_OPERATIONS, defaults.MaxPendingOperations),
                    CosmosDbSqlConnString = configData.GetString(prefix + COSMOSDBSQL_CONNECTION_STRING_KEY, ""),
                    CosmosDbSqlDatabase = configData.GetString(prefix + COSMOSDBSQL_DATABASE_KEY, ""),
                    CosmosDbSqlCollection = configData.GetString(prefix + COSMOSDBSQL_COLLECTION_KEY, ""),
                    CosmosDbSqlThroughput = configData.GetInt(prefix + COSMOSDBSQL_THROUGHPUT_KEY, defaults.CosmosDbSqlThroughput),
                });

            case Services.Storage.Type.TableStorage:
                return(new Services.Storage.Config
                {
                    StorageType = storageType,
                    MaxPendingOperations = configData.GetInt(prefix + STORAGE_MAX_PENDING_OPERATIONS, defaults.MaxPendingOperations),
                    TableStorageConnString = configData.GetString(prefix + TABLESTORAGE_CONNECTION_STRING_KEY, ""),
                    TableStorageTableName = configData.GetString(prefix + TABLESTORAGE_TABLE_KEY, "")
                });
            }

            throw new ArgumentOutOfRangeException("Unknown storage type: " + storageType);
        }
Esempio n. 3
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            this.ServicesConfig = new ServicesConfig
            {
                JwtUserIdFrom = configData.GetString(JWT_USER_ID_FROM_KEY, "email").Split(','),
                JwtNameFrom   = configData.GetString(JWT_NAME_FROM_KEY, "email").Split(','),
                JwtEmailFrom  = configData.GetString(JWT_EMAIL_FROM_KEY, "email").Split(',')
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY, String.Empty),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY, String.Empty),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
            };
        }
Esempio n. 4
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            this.ServicesConfig = new ServicesConfig
            {
                StorageAdapterApiUrl   = configData.GetString(STORAGE_ADAPTER_URL_KEY),
                DeviceSimulationApiUrl = configData.GetString(DEVICE_SIMULATION_URL_KEY),
                TelemetryApiUrl        = configData.GetString(TELEMETRY_URL_KEY),
                SeedTemplate           = configData.GetString(SEED_TEMPLATE_KEY),
                AzureMapsKey           = configData.GetString(AZURE_MAPS_KEY)
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
            };
        }
Esempio n. 5
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            this.ServicesConfig = new ServicesConfig
            {
                JwtUserIdFrom        = configData.GetString(JWT_USER_ID_FROM_KEY, "oid").Split(','),
                JwtNameFrom          = configData.GetString(JWT_NAME_FROM_KEY, "given_name,family_name").Split(','),
                JwtEmailFrom         = configData.GetString(JWT_EMAIL_FROM_KEY, "email").Split(','),
                JwtRolesFrom         = configData.GetString(JWT_ROLES_FROM_KEY, "roles"),
                PoliciesFolder       = MapRelativePath(configData.GetString(POLICIES_FOLDER_KEY)),
                AadEndpointUrl       = configData.GetString(AAD_ENDPOINT_URL, DEFAULT_AAD_ENDPOINT_URL),
                AadTenantId          = configData.GetString(AAD_TENANT_ID, String.Empty),
                AadApplicationId     = configData.GetString(AAD_APPLICATION_ID, String.Empty),
                AadApplicationSecret = configData.GetString(AAD_APPLICATION_SECRET, String.Empty),
                ArmEndpointUrl       = configData.GetString(ARM_ENDPOINT_URL, DEFAULT_ARM_ENDPOINT_URL),
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY, String.Empty),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY, String.Empty),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
            };
        }
Esempio n. 6
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PortKey);

            this.ServicesConfig = new ServicesConfig
            {
                PcsConfigUrl   = configData.GetString(PCS_CONFIG_URL),
                SolutionType   = configData.GetString(PCS_SOLUTION_TYPE),
                DeploymentId   = configData.GetString(PCS_DEPLOYMENT_ID),
                SubscriptionId = configData.GetString(PCS_SUBSCRIPTION_ID),
                CloudType      = configData.GetString(PCS_CLOUD_TYPE),
                IoTHubName     = configData.GetString(PCS_IOTHUB_NAME),
                SolutionName   = configData.GetString(PCS_SOLUTION_NAME),
                UserConsentPollingIntervalSecs = configData.GetInt(USER_CONSENT_POLLING_INTERVAL_KEY, 300),
                AppInsightsInstrumentationKey  = configData.GetString(APPINSIGHTS_INSTRUMENTATION_KEY)
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY, String.Empty),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY, String.Empty),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
            };
        }
Esempio n. 7
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            this.ServicesConfig = new ServicesConfig
            {
                MessagesConfig = new StorageConfig(
                    configData.GetString(MESSAGES_DB_DATABASE_KEY),
                    configData.GetString(MESSAGES_DB_COLLECTION_KEY)),
                AlarmsConfig = new StorageConfig(
                    configData.GetString(ALARMS_DB_DATABASE_KEY),
                    configData.GetString(ALARMS_DB_COLLECTION_KEY)),
                StorageType              = configData.GetString(STORAGE_TYPE_KEY),
                DocumentDbConnString     = configData.GetString(DOCUMENTDB_CONNSTRING_KEY),
                DocumentDbThroughput     = configData.GetInt(DOCUMENTDB_RUS_KEY),
                StorageAdapterApiUrl     = configData.GetString(STORAGE_ADAPTER_API_URL_KEY),
                StorageAdapterApiTimeout = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY)
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY, String.Empty),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY, String.Empty),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
            };
        }
Esempio n. 8
0
        public Config(IConfigData configData)
        {
            IoTHubConfig = new IoTHubConfig
            {
                ConnectionConfig = new ConnectionConfig
                {
                    HubName          = configData.GetString(HubNameKey),
                    HubEndpoint      = configData.GetString(HubEndpointKey),
                    AccessConnString = configData.GetString(AccessConnStringKey)
                },
                StreamingConfig = new StreamingConfig
                {
                    ConsumerGroup    = configData.GetString(ConsumerGroupKey),
                    ReceiveBatchSize = configData.GetInt(ReceiveBatchSizeKey),
                    ReceiveTimeout   = configData.GetTimeSpan(ReceiveTimeoutKey)
                },
                CheckpointingConfig = new CheckpointingConfig
                {
                    Frequency      = configData.GetTimeSpan(FrequencyKey),
                    CountThreshold = configData.GetInt(CountThresholdKey),
                    TimeThreshold  = configData.GetTimeSpan(TimeThresholdKey),
                    StorageConfig  = new CheckpointingStorageConfig
                    {
                        BackendType     = configData.GetString(BackendTypeKey),
                        Namespace       = configData.GetString(NamespaceKey),
                        AzureBlobConfig = new CheckpointingStorageBlobConfig
                        {
                            Protocol       = configData.GetString(ProtocolKey),
                            Account        = configData.GetString(AccountKey),
                            Key            = configData.GetString(KeyKey),
                            EndpointSuffix = configData.GetString(EndpointSuffixKey)
                        }
                    }
                }
            };

            ServicesConfig = new ServicesConfig
            {
                MonitoringRulesUrl           = configData.GetString(MonitoringRulesUrlKey),
                DeviceGroupsUrl              = configData.GetString(DeviceGroupsUrlKey),
                DevicesUrl                   = configData.GetString(DevicesUrlKey),
                MessagesStorageServiceConfig = new StorageServiceConfig
                {
                    StorageType          = configData.GetString(MessagesStorageTypeKey),
                    DocumentDbConnString = configData.GetString(MessagesDocDbConnStringKey),
                    DocumentDbDatabase   = configData.GetString(MessagesDocDbDatabaseKey),
                    DocumentDbCollection = configData.GetString(MessagesDocDbCollectionKey),
                    DocumentDbRUs        = configData.GetInt(MessagesDocDbRUsKey)
                },
                AlarmsStorageServiceConfig = new StorageServiceConfig
                {
                    StorageType          = configData.GetString(AlarmsStorageTypeKey),
                    DocumentDbConnString = configData.GetString(AlarmsDocDbConnStringKey),
                    DocumentDbDatabase   = configData.GetString(AlarmsDocDbDatabaseKey),
                    DocumentDbCollection = configData.GetString(AlarmsDocDbCollectionKey),
                    DocumentDbRUs        = configData.GetInt(AlarmsDocDbRUsKey)
                }
            };
        }
        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)
            });
        }
Esempio n. 10
0
 private static IRateLimitingConfig GetRateLimitingConfig(IConfigData configData)
 {
     return(new RateLimitingConfig
     {
         ConnectionsPerSecond = configData.GetInt(CONNECTIONS_FREQUENCY_LIMIT_KEY, 50),
         RegistryOperationsPerMinute = configData.GetInt(REGISTRY_OPS_FREQUENCY_LIMIT_KEY, 50),
         DeviceMessagesPerSecond = configData.GetInt(DEVICE_MESSAGES_FREQUENCY_LIMIT_KEY, 50),
         TwinReadsPerSecond = configData.GetInt(TWIN_READS_FREQUENCY_LIMIT_KEY, 5),
         TwinWritesPerSecond = configData.GetInt(TWIN_WRITES_FREQUENCY_LIMIT_KEY, 5)
     });
 }
Esempio n. 11
0
 public override void InitWithData(IConfigData data)
 {
     if (Id != 0)
     {
         Logger.LogError(LogModule.Data, "已经初始化过了!");
         return;
     }
     Id     = data.GetInt("Id");
     IntVal = data.GetInt("IntVal");
     StrVal = data.GetString("StrVal");
 }
Esempio n. 12
0
        private static IClusteringConfig GetClusteringConfig(IConfigData configData)
        {
            var defaults = new ClusteringConfig();

            return(new ClusteringConfig
            {
                CheckIntervalMsecs = configData.GetInt(CLUSTERING_CHECK_INTERVAL_KEY, defaults.CheckIntervalMsecs),
                NodeRecordMaxAgeMsecs = configData.GetInt(CLUSTERING_NODE_RECORD_MAX_AGE_KEY, defaults.NodeRecordMaxAgeMsecs),
                MasterLockDurationMsecs = configData.GetInt(CLUSTERING_MASTER_LOCK_MAX_AGE_KEY, defaults.MasterLockDurationMsecs),
                MaxPartitionSize = configData.GetInt(CLUSTERING_MAX_PARTITION_SIZE_KEY, defaults.MaxPartitionSize)
            });
        }
Esempio n. 13
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            var connstring = configData.GetString(IOTHUB_CONNSTRING_KEY);

            if (connstring.ToLowerInvariant().Contains("your azure iot hub"))
            {
                // 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.
                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.");
            }

            this.ServicesConfig = new ServicesConfig
            {
                IoTHubConnString               = configData.GetString(IOTHUB_CONNSTRING_KEY),
                DevicePropertiesWhiteList      = configData.GetString(DEVICE_PROPERTIES_WHITELIST_KEY),
                DevicePropertiesTTL            = configData.GetInt(DEVICE_PROPERTIES_TTL_KEY),
                DevicePropertiesRebuildTimeout = configData.GetInt(DEVICE_PROPERTIES_REBUILD_TIMEOUT_KEY),
                StorageAdapterApiUrl           = configData.GetString(STORAGE_ADAPTER_URL_KEY),
                UserManagementApiUrl           = configData.GetString(USER_MANAGEMENT_URL_KEY),
                KafkaUrl = configData.GetString(KAFKA_URL),
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
            };

            //this.KafkaURL = configData.GetString(KAFKA_URL);
        }
Esempio n. 14
0
        private static StorageConfig GetStorageConfig(IConfigData configData, string prefix)
        {
            var defaults = new StorageConfig();

            return(new StorageConfig
            {
                StorageType = configData.GetString(prefix + STORAGE_TYPE_KEY, defaults.StorageType),
                MaxPendingOperations = configData.GetInt(STORAGE_MAX_PENDING_OPERATIONS, defaults.MaxPendingOperations),
                DocumentDbConnString = configData.GetString(prefix + DOCUMENTDB_CONNECTION_STRING_KEY),
                DocumentDbDatabase = configData.GetString(prefix + DOCUMENTDB_DATABASE_KEY),
                DocumentDbCollection = configData.GetString(prefix + DOCUMENTDB_COLLECTION_KEY),
                DocumentDbThroughput = configData.GetInt(prefix + DOCUMENTDB_THROUGHPUT_KEY, defaults.DocumentDbThroughput)
            });
        }
Esempio n. 15
0
        public Config(IConfigData configData)
        {
            Enum.TryParse(configData.GetString(LOG_LEVEL_KEY, LOG_LEVEL_DEFAULT.ToString()), out LogLevel logLevel);
            this.LogLevel = logLevel;

            this.StatusEndpointEnabled = configData.GetBool(STATUS_ENDPOINT_ENABLED_KEY, STATUS_ENDPOINT_ENABLED_DEFAULT);
            this.MaxPayloadSize        = configData.GetInt(MAX_PAYLOAD_SIZE_KEY, MAX_PAYLOAD_SIZE_DEFAULT);

            this.RedirectHttpToHttps            = configData.GetBool(REDIRECT_HTTP_KEY, REDIRECT_HTTP_DEFAULT);
            this.StrictTransportSecurityEnabled = configData.GetBool(STS_ENABLED_KEY, STS_ENABLED_DEFAULT);
            this.StrictTransportSecurityPeriod  = configData.GetInt(STS_PERIOD_KEY, STS_PERIOD_DEFAULT);


            this.SslCertThumbprint = configData.GetString(SSL_CERT_THUMBPRINT_KEY);
        }
Esempio n. 16
0
        private static IServicesConfig GetServicesConfig(IConfigData configData)
        {
            var connstring = configData.GetString(IOTHUB_CONNSTRING_KEY);

            if (connstring.ToLowerInvariant().Contains("azure iot hub"))
            {
                // 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.
                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.");
            }

            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,
                StorageAdapterApiUrl = configData.GetString(STORAGE_ADAPTER_API_URL_KEY),
                StorageAdapterApiTimeout = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY),
                TwinReadWriteEnabled = configData.GetBool(TWIN_READ_WRITE_ENABLED_KEY, true)
            });
        }
 public Config(IConfigData configData)
 {
     this.Port              = configData.GetInt(PORT_KEY);
     this.LoggingConfig     = GetLogConfig(configData);
     this.ServicesConfig    = GetServicesConfig(configData);
     this.ClientAuthConfig  = GetClientAuthConfig(configData);
     this.BlobStorageConfig = GetBlobStorageConfig(configData);
 }
        private static IServicesConfig GetServicesConfig(IConfigData configData)
        {
            var messagesStorageType = GetStorageType(configData, MESSAGES);
            var alarmsStorageType   = GetStorageType(configData, ALARMS);

            return(new ServicesConfig
            {
                DeviceTelemetryWebServiceUrl = configData.GetString(DEVICE_TELEMETRY_WEBSERVICE_URL_KEY),
                DeviceTelemetryWebServiceTimeout = configData.GetInt(DEVICE_TELEMETRY_WEBSERVICE_TIMEOUT_KEY),
                ConfigServiceUrl = configData.GetString(CONFIG_WEBSERVICE_URL_KEY),
                ConfigServiceTimeout = configData.GetInt(CONFIG_WEBSERVICE_TIMEOUT_KEY),
                IotHubManagerServiceUrl = configData.GetString(IOTHUB_MANAGER_WEBSERVICE_URL_KEY),
                IotHubManagerServiceTimeout = configData.GetInt(IOTHUB_MANAGER_WEBSERVICE_TIMEOUT_KEY),
                IotHubManagerRetryCount = configData.GetInt(IOTHUB_MANAGER_RETRY_COUNT),
                InitialIotHubManagerRetryIntervalMs = configData.GetInt(IOTHUB_MANAGER_INITIAL_RETRY_INTERVAL_MS),
                IotHubManagerRetryIntervalIncreaseFactor = configData.GetInt(IOTHUB_MANAGER_RETRY_INCREASE_FACTOR),
                MessagesStorageType = messagesStorageType,
                MessagesCosmosDbConfig = GetAsaOutputStorageConfig(configData, MESSAGES, messagesStorageType),
                AlarmsStorageType = alarmsStorageType,
                AlarmsCosmosDbConfig = GetAsaOutputStorageConfig(configData, ALARMS, alarmsStorageType),
                EventHubConnectionString = configData.GetString(EVENTHUB_CONNECTION_KEY),
                EventHubName = configData.GetString(EVENTHUB_NAME),
                EventHubCheckpointTimeMs = configData.GetInt(EVENTHUB_CHECKPOINT_INTERVAL_MS)
            });
        }
Esempio n. 19
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT);

            this.ServicesConfig = new ServicesConfig
            {
                SqlConnectionString = configData.GetString(SQL_CONNECTION_STRING)
            };
        }
Esempio n. 20
0
 public Config(IConfigData configData)
 {
     this.Port               = configData.GetInt(PORT_KEY);
     this.LoggingConfig      = GetLogConfig(configData);
     this.ServicesConfig     = GetServicesConfig(configData);
     this.ClientAuthConfig   = GetClientAuthConfig(configData);
     this.RateLimitingConfig = GetRateLimitingConfig(configData);
     this.DeploymentConfig   = GetDeploymentConfig(configData);
 }
Esempio n. 21
0
        public Config(IConfigData configData)
        {
            Enum.TryParse(configData.GetString(LOG_LEVEL_KEY, LOG_LEVEL_DEFAULT.ToString()), out LogLevel logLevel);
            this.LogLevel = logLevel;

            this.StatusEndpointEnabled = configData.GetBool(STATUS_ENDPOINT_ENABLED_KEY, STATUS_ENDPOINT_ENABLED_DEFAULT);
            this.MaxPayloadSize        = configData.GetInt(MAX_PAYLOAD_SIZE_KEY, MAX_PAYLOAD_SIZE_DEFAULT);

            this.RedirectHttpToHttps            = configData.GetBool(REDIRECT_HTTP_KEY, REDIRECT_HTTP_DEFAULT);
            this.StrictTransportSecurityEnabled = configData.GetBool(STS_ENABLED_KEY, STS_ENABLED_DEFAULT);
            this.StrictTransportSecurityPeriod  = configData.GetInt(STS_PERIOD_KEY, STS_PERIOD_DEFAULT);

            this.Endpoint          = configData.GetString(ENDPOINT_KEY);
            this.SslCertThumbprint = configData.GetString(SSL_CERT_THUMBPRINT_KEY);
            if (string.IsNullOrEmpty(this.Endpoint))
            {
                throw new InvalidConfigurationException("The remote endpoint hostname is empty.");
            }
        }
Esempio n. 22
0
        public int GetInt(string sName)
        {
            IConfigData iData = null;

            if (RowDataMap.TryGetValue(sName, out iData))
            {
                return(iData.GetInt());
            }
            return(0);
        }
Esempio n. 23
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            this.ServicesConfig = new ServicesConfig
            {
                MessagesConfig = new StorageConfig(
                    configData.GetString(MESSAGES_DB_DATABASE_KEY),
                    configData.GetString(MESSAGES_DB_COLLECTION_KEY)),
                AlarmsConfig = new AlarmsConfig(
                    configData.GetString(ALARMS_DB_DATABASE_KEY),
                    configData.GetString(ALARMS_DB_COLLECTION_KEY),
                    configData.GetInt(ALARMS_DB_MAX_DELETE_RETRIES)),
                StorageType                     = configData.GetString(MESSAGES_STORAGE_TYPE),
                CosmosDbConnString              = configData.GetString(COSMOSDB_CONNSTRING_KEY),
                CosmosDbThroughput              = configData.GetInt(COSMOSDB_RUS_KEY),
                StorageAdapterApiUrl            = configData.GetString(STORAGE_ADAPTER_API_URL_KEY),
                StorageAdapterApiTimeout        = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY),
                UserManagementApiUrl            = configData.GetString(USER_MANAGEMENT_URL_KEY),
                TimeSeriesFqdn                  = configData.GetString(TIME_SERIES_FQDN),
                TimeSeriesAuthority             = configData.GetString(TIME_SERIES_AUTHORITY),
                TimeSeriesAudience              = configData.GetString(TIME_SERIES_AUDIENCE),
                TimeSeriesExplorerUrl           = configData.GetString(TIME_SERIES_EXPLORER_URL),
                TimeSertiesApiVersion           = configData.GetString(TIME_SERIES_API_VERSION),
                TimeSeriesTimeout               = configData.GetString(TIME_SERIES_TIMEOUT),
                ActiveDirectoryTenant           = configData.GetString(AAD_TENANT),
                ActiveDirectoryAppId            = configData.GetString(AAD_APP_ID),
                ActiveDirectoryAppSecret        = configData.GetString(AAD_APP_SECRET),
                DiagnosticsApiUrl               = configData.GetString(DIAGNOSTICS_URL_KEY),
                DiagnosticsMaxLogRetries        = configData.GetInt(DIAGNOSTICS_MAX_LOG_RETRIES),
                ActionsEventHubConnectionString = configData.GetString(ACTIONS_EVENTHUB_CONNSTRING),
                ActionsEventHubName             = configData.GetString(ACTIONS_EVENTHUB_NAME),
                LogicAppEndpointUrl             = configData.GetString(ACTIONS_LOGICAPP_ENDPOINTURL),
                BlobStorageConnectionString     = configData.GetString(ACTIONS_AZUREBLOB_CONNSTRING),
                ActionsBlobStorageContainer     = configData.GetString(ACTIONS_AZUREBLOB_CONTAINER),
                SolutionUrl                     = configData.GetString(SOLUTION_URL),
                TemplateFolder                  = AppContext.BaseDirectory + Path.DirectorySeparatorChar + configData.GetString(TEMPLATE_FOLDER)
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY, String.Empty),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY, String.Empty),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
                // By default the time to live for the OpenId connect token is 7 days
                OpenIdTimeToLive = TimeSpan.FromDays(configData.GetInt(OPEN_ID_TTL_KEY, 7))
            };
        }
Esempio n. 24
0
 private static IClientAuthConfig GetClientAuthConfig(IConfigData configData)
 {
     return(new ClientAuthConfig
     {
         // By default CORS is disabled
         CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
         // By default Auth is required
         AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
         // By default auth type is JWT
         AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
         // By default the only trusted algorithms are RS256, RS384, RS512
         JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
         JwtIssuer = configData.GetString(JWT_ISSUER_KEY, String.Empty),
         JwtAudience = configData.GetString(JWT_AUDIENCE_KEY, String.Empty),
         // By default the allowed clock skew is 2 minutes
         JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
         // By default the time to live for the OpenId connect token is 7 days
         OpenIdTimeToLive = TimeSpan.FromDays(configData.GetInt(OPEN_ID_TTL_KEY, 7))
     });
 }
Esempio n. 25
0
        private static IAppConcurrencyConfig GetConcurrencyConfig(IConfigData configData)
        {
            var defaults = new AppConcurrencyConfig();

            return(new AppConcurrencyConfig
            {
                TelemetryThreads = configData.GetInt(CONCURRENCY_TELEMETRY_THREADS_KEY, defaults.TelemetryThreads),
                MaxPendingConnections = configData.GetInt(CONCURRENCY_MAX_PENDING_CONNECTIONS_KEY, defaults.MaxPendingConnections),
                MaxPendingTelemetry = configData.GetInt(CONCURRENCY_MAX_PENDING_TELEMETRY_KEY, defaults.MaxPendingTelemetry),
                MaxPendingTwinWrites = configData.GetInt(CONCURRENCY_MAX_PENDING_TWIN_WRITES_KEY, defaults.MaxPendingTwinWrites),
                MinDeviceStateLoopDuration = configData.GetInt(CONCURRENCY_MIN_DEVICE_STATE_LOOP_DURATION_KEY, defaults.MinDeviceStateLoopDuration),
                MinDeviceConnectionLoopDuration = configData.GetInt(CONCURRENCY_MIN_DEVICE_CONNECTION_LOOP_DURATION_KEY, defaults.MinDeviceConnectionLoopDuration),
                MinDeviceTelemetryLoopDuration = configData.GetInt(CONCURRENCY_MIN_DEVICE_TELEMETRY_LOOP_DURATION_KEY, defaults.MinDeviceTelemetryLoopDuration),
                MinDevicePropertiesLoopDuration = configData.GetInt(CONCURRENCY_MIN_DEVICE_PROPERTIES_LOOP_DURATION_KEY, defaults.MinDevicePropertiesLoopDuration),
                MaxPendingTasks = configData.GetInt(CONCURRENCY_MAX_PENDING_TASKS, defaults.MaxPendingTasks)
            });
        }
Esempio n. 26
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            this.ServicesConfig = new ServicesConfig
            {
                StorageAdapterApiUrl   = configData.GetString(STORAGE_ADAPTER_URL_KEY),
                DeviceSimulationApiUrl = configData.GetString(DEVICE_SIMULATION_URL_KEY),
                TelemetryApiUrl        = configData.GetString(TELEMETRY_URL_KEY),
                SolutionType           = configData.GetString(SOLUTION_TYPE_KEY),
                SeedTemplate           = configData.GetString(SEED_TEMPLATE_KEY),
                AzureMapsKey           = configData.GetString(AZURE_MAPS_KEY),
                UserManagementApiUrl   = configData.GetString(USER_MANAGEMENT_URL_KEY),
                Office365LogicAppUrl   = configData.GetString(OFFICE365_LOGIC_APP_URL_KEY),
                ResourceGroup          = configData.GetString(RESOURCE_GROUP_KEY),
                SubscriptionId         = configData.GetString(SUBSCRIPTION_ID_KEY),
                ManagementApiVersion   = configData.GetString(MANAGEMENT_API_VERSION_KEY),
                ArmEndpointUrl         = configData.GetString(ARM_ENDPOINT_URL_KEY)
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
                // By default the time to live for the OpenId connect token is 7 days
                OpenIdTimeToLive = TimeSpan.FromDays(configData.GetInt(OPEN_ID_TTL_KEY, 7))
            };
        }
        /// <summary>Read storage configuration, depending on the storage type</summary>
        /// <param name="configData">Raw configuration data</param>
        /// <param name="tableName">Name of the table</param>
        /// <param name="storageType">Type of storage, e.g. CosmosDbSql</param>
        private static CosmosDbTableConfiguration GetAsaOutputStorageConfig(
            IConfigData configData,
            string tableName,
            AsaOutputStorageType storageType)
        {
            string prefix;

            // All tables have the same configuration block, with a different prefix
            switch (tableName)
            {
            case MESSAGES:
                prefix = MESSAGES_KEY;
                break;

            case ALARMS:
                prefix = ALARMS_KEY;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown table " + tableName);
            }

            // If the table is on CosmosDb, read the configuration parameters
            if (storageType == AsaOutputStorageType.CosmosDbSql)
            {
                var consistency = configData.GetString(prefix + COSMOSDBSQL_CONSISTENCY_KEY);
                if (!Enum.TryParse <ConsistencyLevel>(consistency, true, out var consistencyLevel))
                {
                    consistencyLevel = ConsistencyLevel.Eventual;
                }

                return(new CosmosDbTableConfiguration
                {
                    Api = CosmosDbApi.Sql,
                    ConnectionString = configData.GetString(prefix + COSMOSDBSQL_CONNSTRING_KEY),
                    Database = configData.GetString(prefix + COSMOSDBSQL_DATABASE_KEY),
                    Collection = configData.GetString(prefix + COSMOSDBSQL_COLLECTION_KEY),
                    ConsistencyLevel = consistencyLevel,
                    RUs = configData.GetInt(prefix + COSMOSDBSQL_RUS_KEY),
                });
            }

            // If another storage type is added, add a similar block here,
            // and change the output type to allow multiple types. Not needed now.

            return(null);
        }
Esempio n. 28
0
        public Config(IConfigData configData)
        {
            this.Port = configData.GetInt(PORT_KEY);

            this.ServicesConfig = new ServicesConfig
            {
                MessagesConfig = new StorageConfig(
                    configData.GetString(MESSAGES_DB_DATABASE_KEY),
                    configData.GetString(MESSAGES_DB_COLLECTION_KEY)),
                AlarmsConfig = new AlarmsConfig(
                    configData.GetString(ALARMS_DB_DATABASE_KEY),
                    configData.GetString(ALARMS_DB_COLLECTION_KEY),
                    configData.GetInt(ALARMS_DB_MAX_DELETE_RETRIES)),
                StorageType              = configData.GetString(MESSAGES_STORAGE_TYPE),
                CosmosDbConnString       = configData.GetString(COSMOSDB_CONNSTRING_KEY),
                CosmosDbThroughput       = configData.GetInt(COSMOSDB_RUS_KEY),
                StorageAdapterApiUrl     = configData.GetString(STORAGE_ADAPTER_API_URL_KEY),
                StorageAdapterApiTimeout = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY),
                UserManagementApiUrl     = configData.GetString(USER_MANAGEMENT_URL_KEY),
                TimeSeriesFqdn           = configData.GetString(TIME_SERIES_FQDN),
                TimeSeriesAuthority      = configData.GetString(TIME_SERIES_AUTHORITY),
                TimeSeriesAudience       = configData.GetString(TIME_SERIES_AUDIENCE),
                TimeSeriesExplorerUrl    = configData.GetString(TIME_SERIES_EXPLORER_URL),
                TimeSertiesApiVersion    = configData.GetString(TIME_SERIES_API_VERSION),
                TimeSeriesTimeout        = configData.GetString(TIME_SERIES_TIMEOUT),
                ActiveDirectoryTenant    = configData.GetString(AAD_TENANT),
                ActiveDirectoryAppId     = configData.GetString(AAD_APP_ID),
                ActiveDirectoryAppSecret = configData.GetString(AAD_APP_SECRET),
                DiagnosticsApiUrl        = configData.GetString(DIAGNOSTICS_URL_KEY),
                DiagnosticsMaxLogRetries = configData.GetInt(DIAGNOSTICS_MAX_LOG_RETRIES)
            };

            this.ClientAuthConfig = new ClientAuthConfig
            {
                // By default CORS is disabled
                CorsWhitelist = configData.GetString(CORS_WHITELIST_KEY, string.Empty),
                // By default Auth is required
                AuthRequired = configData.GetBool(AUTH_REQUIRED_KEY, true),
                // By default auth type is JWT
                AuthType = configData.GetString(AUTH_TYPE_KEY, "JWT"),
                // By default the only trusted algorithms are RS256, RS384, RS512
                JwtAllowedAlgos = configData.GetString(JWT_ALGOS_KEY, "RS256,RS384,RS512").Split(','),
                JwtIssuer       = configData.GetString(JWT_ISSUER_KEY, String.Empty),
                JwtAudience     = configData.GetString(JWT_AUDIENCE_KEY, String.Empty),
                // By default the allowed clock skew is 2 minutes
                JwtClockSkew = TimeSpan.FromSeconds(configData.GetInt(JWT_CLOCK_SKEW_KEY, 120)),
            };
        }
Esempio n. 29
0
        public Config(IConfigData configData)
        {
            var connstring = configData.GetString(IOTHUB_CONNSTRING_KEY);

            if (connstring.ToLowerInvariant().Contains("your azure iot hub"))
            {
                // 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.
                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 limitsConf = new RateLimitingConfiguration
            {
                ConnectionsPerSecond        = configData.GetInt(CONNECTIONS_FREQUENCY_LIMIT_KEY, 50),
                RegistryOperationsPerMinute = configData.GetInt(REGISTRYOPS_FREQUENCY_LIMIT_KEY, 50),
                DeviceMessagesPerSecond     = configData.GetInt(DEVICE_MESSAGES_FREQUENCY_LIMIT_KEY, 50),
                DeviceMessagesPerDay        = configData.GetInt(DEVICE_MESSAGES_DAILY_LIMIT_KEY, 8000),
                TwinReadsPerSecond          = configData.GetInt(TWIN_READS_FREQUENCY_LIMIT_KEY, 5),
                TwinWritesPerSecond         = configData.GetInt(TWIN_WRITES_FREQUENCY_LIMIT_KEY, 5)
            };

            this.ServicesConfig = new ServicesConfig
            {
                DeviceModelsFolder        = MapRelativePath(configData.GetString(DEVICE_MODELS_FOLDER_KEY)),
                DeviceModelsScriptsFolder = MapRelativePath(configData.GetString(DEVICE_MODELS_SCRIPTS_FOLDER_KEY)),
                IoTHubConnString          = connstring,
                StorageAdapterApiUrl      = configData.GetString(STORAGE_ADAPTER_API_URL_KEY),
                StorageAdapterApiTimeout  = configData.GetInt(STORAGE_ADAPTER_API_TIMEOUT_KEY),
                RateLimiting = limitsConf
            };
        }
Esempio n. 30
0
        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)
            });
        }