Exemplo n.º 1
0
 public SyncKustoTableWorker(
     IKustoClient kustoClient,
     IDocDbClient docDbClient,
     ILoggerFactory loggerFactory,
     IConfiguration configuration)
 {
     _kustoClient    = kustoClient;
     _docDbClient    = docDbClient;
     _logger         = loggerFactory.CreateLogger <SyncKustoTableWorker>();
     _kustoSettings  = configuration.GetConfiguredSettings <KustoSettings>();
     _jsonSerializer = new JsonSerializer();
     _jsonSerializer.Converters.Add(new StringEnumConverter());
     _jsonSerializer.ContractResolver = new DefaultContractResolver()
     {
         NamingStrategy = new CamelCaseNamingStrategy()
         {
             OverrideSpecifiedNames = false
         }
     };
 }
Exemplo n.º 2
0
        public DocDbRepository(IServiceProvider serviceProvider, ILoggerFactory loggerFactory)
        {
            logger = loggerFactory.CreateLogger <DocDbRepository <T> >();
            var configuration        = serviceProvider.GetRequiredService <IConfiguration>();
            var cosmosDbRepoSettings = configuration.GetConfiguredSettings <CosmosDbRepoSettings>();
            var prop = cosmosDbRepoSettings.GetType().GetProperties()
                       .FirstOrDefault(p =>
            {
                var customAttr = p.GetCustomAttribute <ModelBindAttribute>();
                if (customAttr != null && customAttr.ModelType == typeof(T))
                {
                    return(true);
                }

                return(false);
            });

            if (prop == null)
            {
                throw new Exception($"Missing backend mapping for model: {typeof(T).Name}");
            }
            var settings = prop.GetValue(cosmosDbRepoSettings) as CosmosDbSettings;

            logger.LogInformation($"initializing doc db repo: {settings.Account}/{settings.Db}/{settings.Collection}");

            docDbClient = new DocDbClient(
                serviceProvider,
                loggerFactory,
                new OptionsWrapper <CosmosDbSettings>(settings));

            jsonSerializer = new JsonSerializer();
            jsonSerializer.Converters.Add(new StringEnumConverter());
            jsonSerializer.ContractResolver = new DefaultContractResolver()
            {
                NamingStrategy = new CamelCaseNamingStrategy()
                {
                    OverrideSpecifiedNames = false
                }
            };
        }