Exemplo n.º 1
0
        public static CosmosDbConfig GetCosmosDbConfig(
            )
        {
            CosmosDbConfig cosmosDbConfig = new CosmosDbConfig()
            {
                AccountEndPoint = ConfigurationManager.AppSettings["endpoint"],
                Key             = ConfigurationManager.AppSettings["secretKey"],
                DbName          = ConfigurationManager.AppSettings["dbName"],
                CollectionName  = ConfigurationManager.AppSettings["collectionName"],
                Throughput      = int.Parse(ConfigurationManager.AppSettings["throughput"]),
                PartitionKey    = ConfigurationManager.AppSettings["partitionKey"]
            };

            if (ConfigurationManager.AppSettings["partitionKey"] != null)
            {
                cosmosDbConfig.PartitionKey = ConfigurationManager.AppSettings["partitionKey"];
            }

            if (ConfigurationManager.AppSettings["includePaths"] != null)
            {
                cosmosDbConfig.IncludePaths =
                    ConfigurationManager.AppSettings["includePaths"].Split(';').ToList();
            }

            return(cosmosDbConfig);
        }
Exemplo n.º 2
0
        public static CosmosDbConfig GetDestinationConfig(ILogger logger)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            CosmosDbConfig cosmosDbConfig = new CosmosDbConfig()
            {
                AccountEndPoint = ConfigurationManager.AppSettings["destUri"],
                Key             = ConfigurationManager.AppSettings["destSecretKey"],
                DbName          = ConfigurationManager.AppSettings["destDbName"],
                CollectionName  = ConfigurationManager.AppSettings["destCollectionName"],
                Throughput      = int.Parse(ConfigurationManager.AppSettings["destThroughput"])
            };

            if (ConfigurationManager.AppSettings["destPartitionKey"] != null)
            {
                cosmosDbConfig.PartitionKey = ConfigurationManager.AppSettings["destPartitionKey"];
            }

            if (ConfigurationManager.AppSettings["destIncludePaths"] != null)
            {
                cosmosDbConfig.IncludePaths =
                    ConfigurationManager.AppSettings["destIncludePaths"].Split(';').ToList();
            }
            ValidateConfig(logger, cosmosDbConfig, "Destination");
            return(cosmosDbConfig);
        }
Exemplo n.º 3
0
 private static void ValidateConfig(CosmosDbConfig config, string collectionType)
 {
     if (string.IsNullOrEmpty(config.AccountEndPoint) ||
         string.IsNullOrEmpty(config.Key) ||
         string.IsNullOrEmpty(config.DbName) ||
         string.IsNullOrEmpty(config.CollectionName))
     {
         Logger.LogError(string.Format("Missing values in app.config for Cosmos DB Config for collection type {0}",
                                       collectionType), true);
     }
 }
Exemplo n.º 4
0
        public static CosmosDbConfig GetLeaseConfig()
        {
            CosmosDbConfig cosmosDbConfig = new CosmosDbConfig()
            {
                AccountEndPoint = ConfigurationManager.AppSettings["leaseUri"],
                Key             = ConfigurationManager.AppSettings["leaseSecretKey"],
                DbName          = ConfigurationManager.AppSettings["leaseDbName"],
                CollectionName  = ConfigurationManager.AppSettings["leaseCollectionName"],
                Throughput      = int.Parse(ConfigurationManager.AppSettings["leaseThroughput"])
            };

            ValidateConfig(cosmosDbConfig, "Lease");
            return(cosmosDbConfig);
        }
Exemplo n.º 5
0
        public static CosmosDbConfig GetMonitorConfig()
        {
            CosmosDbConfig cosmosDbConfig = new CosmosDbConfig()
            {
                AccountEndPoint = ConfigurationManager.AppSettings["monitoredUri"],
                Key             = ConfigurationManager.AppSettings["monitoredSecretKey"],
                DbName          = ConfigurationManager.AppSettings["monitoredDbName"],
                CollectionName  = ConfigurationManager.AppSettings["monitoredCollectionName"],
                Throughput      = int.Parse(ConfigurationManager.AppSettings["monitoredThroughput"])
            };

            ValidateConfig(cosmosDbConfig, "Monitor");
            return(cosmosDbConfig);
        }
Exemplo n.º 6
0
        public static CosmosDbConfig GetMonitorConfig(ILogger logger)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            CosmosDbConfig cosmosDbConfig = new CosmosDbConfig()
            {
                AccountEndPoint = ConfigurationManager.AppSettings["monitoredUri"],
                Key             = ConfigurationManager.AppSettings["monitoredSecretKey"],
                DbName          = ConfigurationManager.AppSettings["monitoredDbName"],
                CollectionName  = ConfigurationManager.AppSettings["monitoredCollectionName"],
                Throughput      = int.Parse(ConfigurationManager.AppSettings["monitoredThroughput"])
            };

            ValidateConfig(logger, cosmosDbConfig, "Monitor");
            return(cosmosDbConfig);
        }
Exemplo n.º 7
0
        private static void ValidateConfig(
            ILogger logger,
            CosmosDbConfig config,
            string collectionType)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (string.IsNullOrEmpty(config.AccountEndPoint) ||
                string.IsNullOrEmpty(config.Key) ||
                string.IsNullOrEmpty(config.DbName) ||
                string.IsNullOrEmpty(config.CollectionName))
            {
                string message = $"Missing values in app.config for Cosmos DB Config for collection type '{collectionType}'";
                logger.LogError(message);

                throw new NotSupportedException(message);
            }
        }