Exemple #1
0
        public static async Task RunAsync([CosmosDBTrigger(
                                               databaseName: DatabaseName,
                                               collectionName: "QuestionSets",
                                               ConnectionStringSetting = "AzureCosmosDBConnection",
                                               LeaseCollectionName = "leases",
                                               CreateLeaseCollectionIfNotExists = true)] IReadOnlyList <Document> input,
                                          ILogger log,
                                          [Inject] IBlobStorageService blobStorageService,
                                          [Inject] IOptions <ServiceBusSettings> serviceBusSettingsOptions)
        {
            var serviceBusSettings = serviceBusSettingsOptions.Value;

            foreach (var doc in input)
            {
                var partitionKey = doc.GetPropertyValue <string>("partitionKey");

                if (partitionKey.Contains("filtered") || partitionKey.Contains("ncs"))
                {
                    var questionSet = (QuestionSet)(dynamic)doc;
                    log.LogInformation($"Handling questionset update id={questionSet.QuestionSetVersion}");

                    // Create a blob
                    var blobName    = Guid.NewGuid().ToString();
                    var blobContent = JsonConvert.SerializeObject(questionSet);
                    var blockBlob   = await blobStorageService.CreateBlob(blobName, blobContent);

                    log.LogInformation($"Added {questionSet.QuestionSetVersion} to blob {blobName}");


                    // Add message to queue
                    var messageContent = new ChangeFeedQueueItem()
                    {
                        Type     = "QuestionSet",
                        BlobName = blockBlob.Name
                    };

                    // Add to service bus queue
                    var queueClient = new QueueClient(serviceBusSettings.ServiceBusConnectionString,
                                                      serviceBusSettings.QueueName);
                    var     json    = JsonConvert.SerializeObject(messageContent);
                    Message message = new Message(System.Text.Encoding.ASCII.GetBytes(json));
                    await queueClient.SendAsync(message);

                    log.LogInformation(
                        $"Added {questionSet.QuestionSetVersion} to queue {serviceBusSettings.QueueName}");
                }
            }
        }
Exemple #2
0
        public static async Task RunAsync([CosmosDBTrigger(
                                               databaseName: DatabaseName,
                                               collectionName: "UserSessions",
                                               ConnectionStringSetting = "AzureCosmosDBConnection",
                                               LeaseCollectionName = "leases",
                                               CreateLeaseCollectionIfNotExists = true)] IReadOnlyList <Document> input,
                                          ILogger log,
                                          [Inject] IBlobStorageService blobStorageService,
                                          [Inject] IOptions <ServiceBusSettings> serviceBusSettingsOptions)
        {
            var serviceBusSettings = serviceBusSettingsOptions.Value;

            foreach (var doc in input)
            {
                var userSession = (Dfc.DiscoverSkillsAndCareers.Models.UserSession)(dynamic) doc;
                log.LogInformation($"Handling usersession update id={userSession.UserSessionId}");

                // Create a blob
                var blobName    = Guid.NewGuid().ToString();
                var blobContent = JsonConvert.SerializeObject(userSession);
                var blockBlob   = await blobStorageService.CreateBlob(blobName, blobContent);

                log.LogInformation($"Added {userSession.UserSessionId} to blob {blobName}");


                // Add message to queue
                var messageContent = new ChangeFeedQueueItem()
                {
                    Type     = "UserSession",
                    BlobName = blockBlob.Name
                };

                // Add to service bus queue
                var     queueClient = new QueueClient(serviceBusSettings.ServiceBusConnectionString, serviceBusSettings.QueueName);
                var     json        = JsonConvert.SerializeObject(messageContent);
                Message message     = new Message(System.Text.Encoding.ASCII.GetBytes(json));
                await queueClient.SendAsync(message);

                log.LogInformation($"Added {userSession.UserSessionId} to queue {serviceBusSettings.QueueName}");
            }
        }