public async Task <HttpStatusCode> CreateUser(ClaimsPrincipal user, string deskId)
        {
            UserInfo userInfoObj = new UserInfo()
            {
                email     = user.FindFirst("emails").Value,
                firstName = user.FindFirst(ClaimTypes.GivenName).Value,
                lastName  = user.FindFirst(ClaimTypes.Surname).Value,
                id        = user.FindFirst(ClaimTypes.NameIdentifier).Value,
                deskId    = deskId
            };

            //returnMessage = JsonConvert.SerializeObject(userInfoObj);
            Microsoft.Azure.Cosmos.CosmosClient client   = new Microsoft.Azure.Cosmos.CosmosClient(_cosmosDBOptions.DatabaseEndpoint, _cosmosDBOptions.SecretKey);
            Microsoft.Azure.Cosmos.Database     database = await client.CreateDatabaseIfNotExistsAsync(_cosmosDBOptions.DatabaseName);

            Microsoft.Azure.Cosmos.Container container = await database.CreateContainerIfNotExistsAsync(
                "users",
                "/email",
                400);

            // Upsert an item
            Microsoft.Azure.Cosmos.ItemResponse <UserInfo> createResponse = await container.UpsertItemAsync(userInfoObj);

            return(createResponse.StatusCode);
        }
Esempio n. 2
0
        private static async Task <CosmosDbService <ClientData> > InitializeCosmosClientInstanceClientDataAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ClientsContainerName").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.CosmosClient client          = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            CosmosDbService <ClientData>        cosmosDbService = new CosmosDbService <ClientData>(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            //Upsert client seeding data
            if (await cosmosDbService.GetItemAsync(CreateBcnOfficeClient().Id) == null)
            {
                await cosmosDbService.AddItemAsync(CreateBcnOfficeClient());
            }
            else
            {
                // await cosmosDbService.UpdateItemAsync(CreateBcnOfficeClient().Id, CreateBcnOfficeClient());
            }

            return(cosmosDbService);
        }
Esempio n. 3
0
        /// <summary>
        /// Initialises Cosmos DB client connection and container.
        /// </summary>
        /// <param name="configurationSection"></param>
        /// <returns></returns>
        private static async Task <CosmosDBService> InitialiseCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            // Set connection parameters
            string databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ContainerName").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            // Build client and services
            Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder =
                new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key);

            Microsoft.Azure.Cosmos.CosmosClient client =
                clientBuilder.WithConnectionModeDirect().Build();

            CosmosDBService dBService = new CosmosDBService(client, databaseName, containerName);

            // Initialise database, if required
            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            // Build the database container
            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            return(dBService);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a Cosmos DB database and a container with the specified partition key.
        /// </summary>
        /// <returns></returns>
        private async Task <CosmosDbService <T> > InitializeCosmosClientInstanceAsync <T>()
        {
            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(Configuration.GetValue <string>("ConnectionStrings:Default", null));
            var databaseName    = "Fagkveld";
            var containerName   = "ViktigeData";
            var cosmosDbService = new CosmosDbService <T>(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/_partitionKey");

            return(cosmosDbService);
        }
Esempio n. 5
0
        // Creates a Cosmos DB database and a container with the specified partition key.
        private static async Task <PatientService> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            var databaseName   = configurationSection.GetSection("DatabaseName").Value;
            var containerName  = configurationSection.GetSection("ContainerName").Value;
            var account        = configurationSection.GetSection("Account").Value;
            var key            = configurationSection.GetSection("Key").Value;
            var client         = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            var patientService = new PatientService(client, databaseName, containerName);
            var database       = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            return(patientService);
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a Cosmos DB database and a container with the specified partition key.
        /// </summary>
        /// <returns></returns>
        private static async Task <CosmosDBService> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ContainerName").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            CosmosDBService cosmosDbService            = new CosmosDBService(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            return(cosmosDbService);
        }
Esempio n. 7
0
        public static async Task <UserCosmosDbRepository> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = configurationSection.GetSection("Radiometry").Value;
            string containerName = configurationSection.GetSection("Users").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            UserCosmosDbRepository cosmosDbService     = new UserCosmosDbRepository(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            return(cosmosDbService);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a Cosmos DB database and a container with the specified partition key.
        /// </summary>
        /// <returns></returns>
        private static async Task <CosmosDbService> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = Environment.GetEnvironmentVariable("DATABASE_NAME");  // configurationSection.GetSection("DatabaseName").Value;
            string containerName = Environment.GetEnvironmentVariable("CONTAINER_NAME"); // configurationSection.GetSection("ContainerName").Value;
            string account       = Environment.GetEnvironmentVariable("ACCOUNT");        // configurationSection.GetSection("Account").Value;
            string key           = Environment.GetEnvironmentVariable("COSMOS_DB_KEY");  // configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            CosmosDbService cosmosDbService            = new CosmosDbService(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            return(cosmosDbService);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a Cosmos DB database and a container with the specified partition key.
        /// </summary>
        /// <returns></returns>
        private static async Task <CosmosDbService> InitializeCosmosClientInstanceAsync(string url, string key)
        {
            string databaseName  = Environment.GetEnvironmentVariable("CosmosDbName");
            string containerName = Environment.GetEnvironmentVariable("CosmosDbContainerName");

            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(url, key);
            CosmosDbService cosmosDbService            = new CosmosDbService(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            await database.Database.CreateContainerIfNotExistsAsync("Identity", "/id");

            return(cosmosDbService);
        }
Esempio n. 10
0
        private static async Task <ProductsDBServices> InitializeCosmosProductDBAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ContainerName").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            ProductsDBServices productsDBServices      = new ProductsDBServices(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/type");

            return(productsDBServices);
        }
Esempio n. 11
0
        // ReSharper disable once UnusedMember.Local
        private static async Task <ItemsRepoCosmos> InitializeCosmosClientInstanceAsync(CosmosDbOptions cosmosDbOptions)
        {
            var client = new Microsoft.Azure.Cosmos.CosmosClient(
                cosmosDbOptions.Account, cosmosDbOptions.Key);

            var cosmosDbService = new ItemsRepoCosmos(
                client, cosmosDbOptions.DatabaseName, cosmosDbOptions.ContainerName);

            var database = await client.CreateDatabaseIfNotExistsAsync(
                cosmosDbOptions.DatabaseName);

            await database.Database.CreateContainerIfNotExistsAsync(
                cosmosDbOptions.ContainerName, "/id");

            return(cosmosDbService);
        }
Esempio n. 12
0
        public static async Task <PersonService> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string dbName        = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ContainerName").Value;
            string accountName   = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.CosmosClient cosmosClient = new Microsoft.Azure.Cosmos.CosmosClient(accountName, key);
            PersonService personService = new PersonService(cosmosClient, dbName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse databaseResponse = await cosmosClient.CreateDatabaseIfNotExistsAsync(dbName);

            await databaseResponse.Database.CreateContainerIfNotExistsAsync(containerName, "/cprnumber");

            return(personService);
        }
Esempio n. 13
0
        /// Creates a Cosmos DB database and a container with the specified partition key.
        private static CosmosDBService InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ContainerName").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key);
            Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder
                                                         .WithConnectionModeDirect()
                                                         .Build();
            CosmosDBService cosmosDbService = new CosmosDBService(client, databaseName);

            client.CreateDatabaseIfNotExistsAsync(databaseName);
            return(cosmosDbService);
        }
Esempio n. 14
0
        /// <summary>
        /// Creates a Cosmos DB database and a container with the specified partition key.
        /// </summary>
        /// <returns></returns>
        private static async Task <ICosmosDbService> InitializeCosmosClientInstanceAsync()
        {
            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            CosmosDbService cosmosDbService            = new CosmosDbService(client, databaseName, containerName);

            AuditStatus a = new AuditStatus {
                id = "0C805497-2BA1-4524-9D41-E5D556488F9D", BatchId = "C8F9F1C1-4BD1-447F-9F0E-D8E96DF8A1E7", Status = "start", TimeStamp = DateTime.Now
            };


            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");

            await cosmosDbService.AddAuditStatusAsync(a);

            return(cosmosDbService);
        }
Esempio n. 15
0
        private static async Task <CosmosDbImpl> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ContainerName").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder clientBuilder = new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder(account, key);
            Microsoft.Azure.Cosmos.CosmosClient client = clientBuilder
                                                         .WithConnectionModeDirect()
                                                         .Build();
            CosmosDbImpl cosmosDbService = new CosmosDbImpl(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.CreateContainerIfNotExistsAsync(containerName, "/legendname");

            return(cosmosDbService);
        }
Esempio n. 16
0
        /// <summary>
        /// Creates a Cosmos DB database and a container with the specified partition key.
        /// </summary>
        /// <returns></returns>
        private static async Task <CosmosDbService> InitializeCosmosClientInstanceAsync(IConfigurationSection configurationSection)
        {
            string databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string containerName = configurationSection.GetSection("ContainerName").Value;
            string account       = configurationSection.GetSection("Account").Value;
            string key           = configurationSection.GetSection("Key").Value;

            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            CosmosDbService cosmosDbService            = new CosmosDbService(client, databaseName, containerName);

            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            await database.Database.DefineContainer(name : containerName, partitionKeyPath : "/id")
            .WithUniqueKey()
            .Path("/emailAddress")
            .Attach()
            .CreateIfNotExistsAsync();

            return(cosmosDbService);
        }
        private static async Task <CosmosDBService> InitializeCosmosClientInstanceAsync(IConfiguration Configuration)
        {
            // CosmosDB connection information
            string account = Configuration["CosmosDB:Account"];
            string key     = Configuration["CosmosDB:Key"];

            // CosmosDB database
            string databaseName = Configuration["CosmosDB:DatabaseName"];

            // CosmosDB containers
            var containerNames = Configuration
                                 .AsEnumerable()
                                 .Where(o => o.Key.Contains("CosmosDB:ContainerName:"))
                                 .Select(o => o.Value)
                                 .ToList();

            // initialize CosmosDB client
            Microsoft.Azure.Cosmos.CosmosClient client = new Microsoft.Azure.Cosmos.CosmosClient(account, key);
            // create database if missing
            Microsoft.Azure.Cosmos.DatabaseResponse database = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            // initialize service
            CosmosDBService cosmosDbService = new CosmosDBService(client);

            // for each container in list:
            containerNames.ForEach(async containerName =>
            {
                // create container inside database, if missing
                await database.Database.CreateContainerIfNotExistsAsync(containerName, "/id");
                // add container to the list inside service
                await cosmosDbService.AddContainerDefinition(databaseName, containerName);
            });

            // Do nothing. Satisfy debugger's requirement to have "await" in it
            //await Task.Run(() => {});

            return(cosmosDbService);
        }
Esempio n. 18
0
 private async Task CreateDatabaseIfNotExistsAsync()
 {
     var throughputProperties = Microsoft.Azure.Cosmos.ThroughputProperties.CreateAutoscaleThroughput(MaxAutoScaleThroughput);
     await cosmosClient.CreateDatabaseIfNotExistsAsync(databaseId, throughputProperties);
 }