Ejemplo n.º 1
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            var settings            = configuration.GetSection("CosmosSettings");
            var cosmosStoreSettings = new CosmosStoreSettings(settings["DatabaseName"], settings["AccountUri"], settings["AccountKey"], new ConnectionPolicy());

            services.AddCosmosStore <CosmosPostDto>(cosmosStoreSettings);
        }
Ejemplo n.º 2
0
        public MainGenericDb(AgroDbArguments args)
        {
            var storeSettings = new CosmosStoreSettings(args.NameDb, args.EndPointUrl, args.PrimaryKey);

            Store      = new CosmosStore <T>(storeSettings);
            BatchStore = new CosmosStore <EntityContainer>(storeSettings);
        }
Ejemplo n.º 3
0
        private void SetupCosmos(IServiceCollection services)
        {
            var databaseName = Configuration.GetValue <string>("CosmosDb:DatabaseName");
            var endpointUrl  = Configuration.GetValue <string>("CosmosDb:Account");
            var authKey      = Configuration.GetValue <string>("CosmosDb:AuthKey");
            var settings     = new CosmosStoreSettings(databaseName, endpointUrl, authKey)
            {
                JsonSerializerSettings = new JsonSerializerSettings()
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver(),
                    Converters       = new List <JsonConverter> {
                        new Newtonsoft.Json.Converters.StringEnumConverter()
                    },
                    NullValueHandling = NullValueHandling.Ignore
                }
            };

            //Register stores here
            services.AddCosmosStore <Director>(settings);
            services.AddCosmosStore <Sponsor>(settings);
            services.AddCosmosStore <BrandingSponsorship>(settings);
            services.AddCosmosStore <Sponsorship>(settings);
            services.AddCosmosStore <Setting>(settings);
            services.AddCosmosStore <Advertisement>(settings);
            services.AddCosmosStore <EtapesterySetting>(settings);
            services.AddCosmosStore <Contender>(settings);
            services.AddCosmosStore <FoodTruck>(settings);
            services.AddCosmosStore <Liquor>(settings);
            services.AddCosmosStore <ToastAdvertisement>(settings);
            services.AddCosmosStore <ToastSponsor>(settings);
            services.AddCosmosStore <ToastSponsorship>(settings);
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string databaseName = Configuration.GetSection("CosmosSettings:DatabaseName").Value;
            string databaseUri  = Configuration.GetSection("CosmosSettings:DatabaseUri").Value;
            string authKey      = Configuration.GetSection("CosmosSettings:DatabaseKey").Value;

            CosmosStoreSettings cosmosSettings = new CosmosStoreSettings(databaseName, databaseUri, authKey);

            services.AddCosmosStore <User>(cosmosSettings);
            services.AddCosmosStore <TodoItem>(cosmosSettings);

            services.AddSingleton <IUserRepository, UserRepository>();
            services.AddSingleton <ITodoItemRepository, TodoItemRepository>();

            services.AddGraphQLServices();
            services.AddGraphQL()
            .AddSystemTextJson();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc(name: "v1", new OpenApiInfo {
                    Title = "REST API", Version = "v1"
                });
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.XML";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            services.AddControllers();
        }
Ejemplo n.º 5
0
        public async Task CosmosStoreSettings_CreatesCollectionWithUniqueKeyPolicy()
        {
            var cosmosStoreSettings = new CosmosStoreSettings(_databaseId, _emulatorUri, _emulatorKey, settings =>
            {
                settings.ProvisionInfrastructureIfMissing = true;
                settings.ConnectionPolicy = _connectionPolicy;
                settings.UniqueKeyPolicy  = new UniqueKeyPolicy
                {
                    UniqueKeys =
                    {
                        new UniqueKey
                        {
                            Paths =
                            {
                                "/name",
                                "/bladiebla"
                            }
                        }
                    }
                };
            });

            var store      = new CosmosStore <Lion>(cosmosStoreSettings);
            var collection = await store.CosmonautClient.GetCollectionAsync(_databaseId, store.CollectionName);

            collection.UniqueKeyPolicy.UniqueKeys.Should().HaveCount(1);
        }
Ejemplo n.º 6
0
        public FamilyServiceCosmonaut(CosmosStoreSettings cosmonaultStore, ILogger <FamilyServiceCosmonaut> logger)
        {
            _cosmonaultStore = cosmonaultStore;
            _logger          = logger;

            store = new CosmosStore <Family>(_cosmonaultStore);
        }
Ejemplo n.º 7
0
        public static IServiceCollection ConfigureToolBox(this IServiceCollection services, CosmosDbSettings cosmosDbSettings)
        {
            var cosmosSettings = new CosmosStoreSettings(
                cosmosDbSettings.DatabaseId,
                cosmosDbSettings.URL,
                cosmosDbSettings.PrimaryKey);

            services.AddCosmosStore <MeUser>(cosmosSettings, "Users");
            services.AddCosmosStore <Location>(cosmosSettings, "Locations");
            services.AddCosmosStore <Examination>(cosmosSettings, "Examinations");

            services.AddScoped <IDocumentClientFactory, DocumentClientFactory>();
            services.AddScoped <IDatabaseAccess, DatabaseAccess>();

            services.AddScoped <IUserConnectionSettings>(s => new UserConnectionSettings(
                                                             new Uri(cosmosDbSettings.URL),
                                                             cosmosDbSettings.PrimaryKey,
                                                             cosmosDbSettings.DatabaseId));

            services.AddScoped <IAsyncQueryHandler <UserRetrievalByIdQuery, MeUser>, UserRetrievalByIdService>();
            services.AddScoped <IAsyncQueryHandler <UserUpdateQuery, MeUser>, UserUpdateService>();

            services.AddScoped <IAsyncQueryHandler <UsersRetrievalQuery, IEnumerable <MeUser> >, UsersRetrievalService>();

            services.AddScoped <ImpersonateUserService>();
            services.AddScoped <GenerateConfigurationService>();
            services.AddScoped <ImportDocumentService>();
            services.AddScoped <GetLocationTreeService>();

            return(services);
        }
Ejemplo n.º 8
0
        public static IServiceCollection InjectCosmosStore <TQuery, TModel>(this IServiceCollection services, CosmosConfig config)
            where TQuery : class
            where TModel : class
        {
            if (config.DatabaseName == null || config.EndpointUri == null || config.PrimaryKey == null)
            {
                // allow server to be started up without these settings
                // in case they're just trying to seed their environment
                // in the future we'll remove this in favor of centralized seeding capability
                return(services);
            }
            var settings = new CosmosStoreSettings(config.DatabaseName, config.EndpointUri, config.PrimaryKey,
                                                   new ConnectionPolicy
            {
                ConnectionProtocol = Protocol.Tcp,
                ConnectionMode     = ConnectionMode.Direct,
                RequestTimeout     = config.RequestTimeout
            }, defaultCollectionThroughput: 400)
            {
                UniqueKeyPolicy = new UniqueKeyPolicy()
                {
                    UniqueKeys =
                        (Collection <UniqueKey>) typeof(TModel).GetMethod("GetUniqueKeys")?.Invoke(null, null) ??
                        new Collection <UniqueKey>()
                }
            };

            services.AddSingleton(typeof(TQuery), typeof(TQuery));
            return(services.AddCosmosStore <TModel>(settings));
        }
Ejemplo n.º 9
0
        public static IServiceProvider GetServices()
        {
            var serviceCollection = new ServiceCollection();

            var cosmosDbUri            = Environment.GetEnvironmentVariable("CosmosDbUri");
            var cosmosDbKey            = Environment.GetEnvironmentVariable("CosmosDbKey");
            var iotHubConnectionString = Environment.GetEnvironmentVariable("IotHubConnectionString");
            var cosmosSettings         = new CosmosStoreSettings("turino-iot", new Uri(cosmosDbUri), cosmosDbKey);

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            serviceCollection.AddCosmosStore <Device>(cosmosSettings);
            serviceCollection.AddTransient <DeviceStatusCommandHandler>();
            serviceCollection.AddTransient <GetDevicesQueryHandler>();
            serviceCollection.AddTransient <GetDeviceQueryHandler>();
            serviceCollection.AddTransient <SwitchDeviceLightCommandHandler>();
            serviceCollection.AddTransient(s =>
                                           ServiceClient.CreateFromConnectionString(iotHubConnectionString));

            serviceCollection.AddTransient <IDeviceRepository, DeviceRepository>();

            return(serviceCollection.BuildServiceProvider());
        }
Ejemplo n.º 10
0
        public static void AddCosmosDependencies(this IServiceCollection services, IConfiguration configuration)
        {
            var cosmosSettings = new CosmosStoreSettings("nbaplayers",
                                                         "https://cvzeu2playersapicdb.documents.azure.com:443/",
                                                         "A37an6Ph0HbdFbteDC2cwwVeFIZyKYEdfjbINxd0tEQJ5driobTd7wmYLbTMUQspYmnkxSnhfwKbfkUOqucn7A==");

            services.AddCosmosStore <PlayerDocument>(cosmosSettings);
        }
Ejemplo n.º 11
0
        public void InstallService(IServiceCollection services, IConfiguration configuration)
        {
            var cosmosStoreSettings = new CosmosStoreSettings(configuration["CosmosSettings:DatabaseName"], configuration["CosmosSettings:AccountUri"], configuration["CosmosSettings:AccountKey"], new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            });

            services.AddCosmosStore <Domain.Post>(cosmosStoreSettings); // similar to EF DbSet
        }
Ejemplo n.º 12
0
 private static IServiceCollection AddPersistedGrantCosmonautStore(
     this IServiceCollection services,
     CosmosStoreSettings settings,
     string overriddenCollectionName = "")
 {
     services.AddCosmosStore <PersistedGrantEntity>(settings, overriddenCollectionName);
     return(services);
 }
Ejemplo n.º 13
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var setting = new CosmosStoreSettings("tutorial", "https://localhost:8081", "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
                                                  defaultCollectionThroughput: 1000);

            services.AddCosmosStore <Car>(setting);

            services.AddMvc();
        }
        public static IServiceCollection AddCosmosStore <TEntity>(this IServiceCollection services,
                                                                  string databaseName, Uri endpointUri, string authKey, Action <CosmosStoreSettings> settingsAction = null,
                                                                  string overriddenCollectionName = "") where TEntity : class
        {
            var settings = new CosmosStoreSettings(databaseName, endpointUri, authKey);

            settingsAction?.Invoke(settings);
            return(services.AddCosmosStore <TEntity>(settings, overriddenCollectionName));
        }
Ejemplo n.º 15
0
 public void IntallServices(IServiceCollection services, IConfiguration configuration)
 {
     var cosmosStoreSettings = new CosmosStoreSettings(configuration["CosmosSettings:DatabaseName"],
                                                       configuration["CosmosSettings:AccountUri"],
                                                       configuration["CosmosSettings:AccountKey"],
                                                       new ConnectionPolicy {
         ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
     });
 }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var setting = new CosmosStoreSettings("carmanagement", "https://car-management.documents.azure.com:443/", "Nl2jtiIGLKGqaMkPNpZuIPw36KFBvrIkTQOEdt7Y408SU8UXKcv3e3SPTGCAgHubYALvfj5rcdRuXrNdiYSHLQ==",
                                                  defaultCollectionThroughput: 1000);

            services.AddCosmosStore <Car>(setting);

            services.AddMvc();
        }
Ejemplo n.º 17
0
 /// <summary>
 ///     Add Operational Store
 /// </summary>
 /// <param name="builder">The IIdentity Server Builder</param>
 /// <param name="setupAction"></param>
 /// <param name="tokenCleanUpOptions"></param>
 /// <returns></returns>
 public static IIdentityServerBuilder AddOperationalStore(
     this IIdentityServerBuilder builder,
     CosmosStoreSettings settings,
     string overriddenCollectionName = "")
 {
     builder.Services.AddPersistedGrantCosmonautStore(settings, overriddenCollectionName);
     builder.Services.AddTransient <IPersistedGrantStore, PersistedGrantStore>();
     return(builder);
 }
Ejemplo n.º 18
0
 public static IIdentityServerBuilder AddCosmonautIdentityServerCacheStore(
     this IIdentityServerBuilder builder,
     CosmosStoreSettings settings,
     string overriddenCollectionName = "")
 {
     builder.Services.AddIdentityServerCacheCosmonautStore(settings, overriddenCollectionName);
     builder.Services.AddTransient(typeof(ICache <>), typeof(CosmonautCache <>));
     return(builder);
 }
Ejemplo n.º 19
0
        private static void AddCosmosStore(CosmosStoreSettings cosmosSettings, ServiceCollection serviceCollection,
                                           MethodInfo CreateListInternalMethod, Type ObjectType)
        {
            //this method is actually an extension,https://github.com/Elfocrash/Cosmonaut/blob/develop/src/Cosmonaut.Extensions.Microsoft.DependencyInjection/ServiceCollectionExtensions.cs
            var generic = CreateListInternalMethod.MakeGenericMethod(ObjectType);

            generic.Invoke(serviceCollection, new object[3] {
                serviceCollection, cosmosSettings, ""
            });
        }
Ejemplo n.º 20
0
        private static IServiceCollection AddIdentityServerCacheCosmonautStore(
            this IServiceCollection services,
            CosmosStoreSettings settings,
            string overriddenCollectionName = "")
        {
            services.AddTransient <ICacheStore <CacheItem>, CacheStore>();

            services.AddCosmosStore <CacheEntity>(settings, overriddenCollectionName);
            return(services);
        }
Ejemplo n.º 21
0
        public void AddOperationalStore(IServiceCollection services, IIdentityServerBuilder builder)
        {
            bool useRedis  = Convert.ToBoolean(Configuration["appOptions:redis:useRedis"]);
            bool useCosmos = Convert.ToBoolean(Configuration["appOptions:cosmos:useCosmos"]);

            if (useCosmos)
            {
                /*
                 *
                 * "identityServerOperationalStore": {
                 *  "database": "identityServer",
                 *  "collection": "operational"
                 * }
                 */
                var uri                 = Configuration["appOptions:cosmos:uri"];
                var primaryKey          = Configuration["appOptions:cosmos:primaryKey"];
                var databaseName        = Configuration["appOptions:cosmos:identityServerOperationalStore:database"];
                var collection          = Configuration["appOptions:cosmos:identityServerOperationalStore:collection"];
                var cosmosStoreSettings = new CosmosStoreSettings(
                    databaseName,
                    uri,
                    primaryKey,
                    s =>
                {
                    s.ConnectionPolicy = _connectionPolicy;
                });
                builder.AddOperationalStore(cosmosStoreSettings, collection);
                builder.AddCosmonautIdentityServerCacheStore(cosmosStoreSettings, collection);
            }
            else if (useRedis)
            {
                var redisConnectionString = Configuration["appOptions:redis:redisConnectionString"];
                builder.AddOperationalStore(options =>
                {
                    options.RedisConnectionString = redisConnectionString;
                    options.Db = 1;
                })
                .AddRedisCaching(options =>
                {
                    options.RedisConnectionString = redisConnectionString;
                    options.KeyPrefix             = "prefix";
                });

                services.AddDistributedRedisCache(options =>
                {
                    options.Configuration = redisConnectionString;
                });
            }
            else
            {
                builder.AddInMemoryCaching();
                builder.AddInMemoryPersistedGrants();
                services.AddDistributedMemoryCache();
            }
        }
Ejemplo n.º 22
0
        public void ValidStringEndpointCreatesUri()
        {
            // Arrange
            var expectedUri = new Uri("http://test.com");

            // Act
            var settings = new CosmosStoreSettings("dbName", "http://test.com", "key");

            // Assert
            Assert.Equal(expectedUri, settings.EndpointUrl);
        }
Ejemplo n.º 23
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            var cosmosStoreSettings = new CosmosStoreSettings(configuration["CosmosSettings:DatabaseName"],
                                                              configuration["CosmosSettings:AccountUri"],
                                                              configuration["CosmosSettings:AccountKey"],
                                                              new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            });

            services.AddCosmosStore <CosmosPostDto>(cosmosStoreSettings); // probably like that
        }
        void IInstaller.InstallService(IConfiguration configuration, IServiceCollection services)
        {
            var cosmosStoreSettings = new CosmosStoreSettings(
                configuration["CosmosSettings:DatabaseName"],
                configuration["CosmosSettings:AccountUri"],
                configuration["CosmosSettings:AccountKey"],
                new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            });

            services.AddCosmosStore <CosmosPostDto>(cosmosStoreSettings);
        }
Ejemplo n.º 25
0
        public void InstallServices(IServiceCollection services, IConfiguration configuration)
        {
            var cosmosStoreSettings = new CosmosStoreSettings(
                databaseName: configuration["CosmosSettings:DatabaseName"],
                endpointUrl: configuration["CosmosSettings:AccountUri"],
                authKey: configuration["CosmosSettings:AccountKey"],
                new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            });

            //services.AddCosmosStore<CosmosPostDto>(cosmosStoreSettings);will fix later
        }
Ejemplo n.º 26
0
 public static IIdentityServerBuilder AddCosmonautResourceStore(
     this IIdentityServerBuilder builder,
     CosmosStoreSettings settings,
     string overriddenApiResourceCollectionName      = "",
     string overriddenIdentityResourceCollectionName = "")
 {
     builder.Services.TryAddTransient <IResourceStore, ResourcesStore>();
     builder.Services.TryAddTransient <IFullResourceStore, ResourcesStore>();
     builder.Services.AddCosmosStore <ApiResourceEntity>(settings, overriddenApiResourceCollectionName);
     builder.Services.AddCosmosStore <IdentityResourceEntity>(settings, overriddenIdentityResourceCollectionName);
     return(builder);
 }
Ejemplo n.º 27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var setting = new CosmosStoreSettings("cryptocurrencies", "https://kendouiexample.documents.azure.com:443/", "b8wSOhaGWdsk2I2ZWYF3jY8kLjDaIaXC8Sc7W9L7QYF2fz28V6Dez48IIdlyey5CNAPIUvBNWfQmFoDpTdr39A==",
                                                  defaultCollectionThroughput: 400);

            services.AddCosmosStore <CryptoViewModel>(setting);
            services
            .AddMvc()
            .AddJsonOptions(options =>
                            options.SerializerSettings.ContractResolver = new DefaultContractResolver());
            services.AddKendo();
        }
Ejemplo n.º 28
0
        public Repozitorijum(ILoggerFactory dnevnikFabrika, IKonfiguracijaServis konfiguracijaServis)
        {
            _dnevnik             = dnevnikFabrika.CreateLogger <Repozitorijum <T> >();
            _konfiguracijaServis = konfiguracijaServis;

            _cosmosStorePodesavanja = new CosmosStoreSettings(
                _konfiguracijaServis.CosmosDbNazivBaze,
                _konfiguracijaServis.CosmosDbUrl,
                _konfiguracijaServis.CosmosDbAutKljuc);

            _cosmosStore = new CosmosStore <T>(_cosmosStorePodesavanja);
        }
Ejemplo n.º 29
0
        public void RegisterSevices(IServiceCollection services, IConfiguration configuration)
        {
            var cosmosStroeSetting = new CosmosStoreSettings(
                configuration["CosmosSettings:DatabaseName"],
                configuration["CosmosSettings:AccountUri"],
                configuration["CosmosSettings:AccountKey"],
                new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            });

            services.AddCosmosStore <CosmosProduct>(cosmosStroeSetting);
        }
Ejemplo n.º 30
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            var dbSettings = new DatabaseSettings();

            Configuration.Bind(nameof(DatabaseSettings), dbSettings);
            var cosmosStoreSettings = new CosmosStoreSettings(dbSettings.DatabaseName, dbSettings.DatabaseUrl, dbSettings.DatabaseKey,
                                                              new ConnectionPolicy {
                ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp
            });

            services.AddCosmosStore <Customer>(cosmosStoreSettings);
        }