Пример #1
0
        static async Task UpdateAppAsync()
        {
            var app = new
            {
                id          = "87cca0bb-76cb-49ba-ab49-e1f393d9fbaa",
                name        = "App 2-u",
                description = "Description of App 2",
                icon        = "app2.png",
                coverPhoto  = "cover2.jpg",
                category    = "Business",
                developer   = new
                {
                    name = "Developer 2",
                    icon = "developer2.png",
                    url  = "some url"
                },
                version    = "2.0.6",
                packageUrl = "package.exe",
                reviews    = new[]
                {
                    new { name = "Some user", title = "That's a nice app", rate = 4 }
                }
            };

            var result = await _container.ReplaceItemAsync(app, app.id);

            Console.WriteLine(result.StatusCode);
        }
Пример #2
0
        public static async Task ReplaceFreshDeskBotStateAsync(BotConversationState botConversationState, ILogger log)
        {
            try
            {
                //Connect to DB
                await EnsureCosmosDBAsync(log);

                ItemResponse <BotConversationState> botConversationStateResponse = await botStateContainer.ReadItemAsync <BotConversationState>(botConversationState.FreshDeskId, new PartitionKey(botConversationState.FreshDeskId));

                var itemBody = botConversationStateResponse.Resource;

                // update bot watermark
                itemBody.BotWatermark = botConversationState.BotWatermark;

                // replace the item with the updated content
                botConversationStateResponse = await botStateContainer.ReplaceItemAsync <BotConversationState>(itemBody, botConversationState.FreshDeskId, new PartitionKey(botConversationState.FreshDeskId));

                log.LogInformation("Updated watermark to {0} for FreshDesk ID {1} with conversation ID {2}\n", itemBody.BotWatermark, itemBody.FreshDeskId, itemBody.BotConversationId);
            }
            catch (Exception ex)
            {
                log.LogError("Exception occurred in ReplaceFreshDeskBotStateAsync: {1}", ex);
                throw;
            }
        }
Пример #3
0
        public static async Task <DateTime> UpdateLastRun(ILogger log)
        {
            // Set variable to keep lastRun time
            DateTime lastRun;

            // Bootstrap object to update DB with new date
            BotLastRun freshDeskBotLastRun = new BotLastRun()
            {
                Id = "0"
            };

            try
            {
                //Connect to DB
                await EnsureCosmosDBAsync(log);

                // Create LastRun container in DB if not existing
                lastRunContainer = await database.CreateContainerIfNotExistsAsync("LastRun", "/id");

                // Read the item to see if it exists.
                ItemResponse <BotLastRun> freshDeskBotLastRunResponse;
                freshDeskBotLastRunResponse = await lastRunContainer.ReadItemAsync <BotLastRun>(freshDeskBotLastRun.Id, new PartitionKey(freshDeskBotLastRun.Id));

                log.LogInformation("Last run time (GMT) was: {0}\n", freshDeskBotLastRunResponse.Resource.LastRun);

                // Keep the last run time as return parameter of the function
                lastRun = freshDeskBotLastRunResponse.Resource.LastRun;

                // Update the lastrun time in DB
                freshDeskBotLastRun.LastRun = DateTime.Now.ToUniversalTime();
                freshDeskBotLastRunResponse = await lastRunContainer.ReplaceItemAsync <BotLastRun>(freshDeskBotLastRun, freshDeskBotLastRun.Id, new PartitionKey(freshDeskBotLastRun.Id));

                return(lastRun);
            }
            catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                try
                {
                    lastRun = DateTime.Now;

                    // Set current time as initial value in DB
                    log.LogInformation("Setting initial last run time to: {0}", freshDeskBotLastRun.LastRun);
                    freshDeskBotLastRun.LastRun = DateTime.Now.ToUniversalTime();
                    ItemResponse <BotLastRun> botConversationStateResponse = await lastRunContainer.CreateItemAsync(freshDeskBotLastRun, new PartitionKey(freshDeskBotLastRun.Id));

                    return(lastRun);
                }
                catch (Exception ex2)
                {
                    log.LogError("Exception occurred in ReplaceFreshDeskBotStateAsync: {1}", ex2);
                    throw;
                }
            }
        }
Пример #4
0
 static async Task UpdateItem(Film f)
 {
     f.Name = $"New {f.Name}";
     var response = await container.ReplaceItemAsync <Film>(f, f.Id, new PartitionKey(f.Country));
 }
Пример #5
0
 public async Task <ItemResponse <T> > ReplaceItemAsync(string id, T item)
 {
     return(await _container.ReplaceItemAsync <T>(item, id));
 }