Пример #1
0
        public static async Task ProcessQueueMessage([QueueTrigger("users")] UserFaceUpdateRequest request,
                                                     TextWriter log)
        {
            var cloudAccount =
                CloudStorageAccount.Parse(
                    ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString);
            var blobClient    = cloudAccount.CreateCloudBlobClient();
            var logTable      = cloudAccount.CreateCloudTableClient().GetTableReference("logs");
            var blobContainer =
                blobClient.GetContainerReference(ConfigurationManager.AppSettings["UsersImagesContainerName"]);

            try
            {
                var blob = blobContainer.GetBlockBlobReference(request.Image);

                var faceClient = new FaceServiceClient(OxfordKey);

                using (var stream = await blob.OpenReadAsync())
                    await faceClient.AddPersonFaceAsync(XebienzaPersonGroup, request.Id, stream);

                await faceClient.TrainPersonGroupAsync(XebienzaPersonGroup);

                await LogAsunc(logTable, "Message processed !", Level.Info);
            }
            catch (Exception e)
            {
                await LogAsunc(logTable, "Error while processing message", Level.Error, e);
            }
        }
Пример #2
0
        public async Task AddPersonFaceAsync(Guid id, byte[] image)
        {
            var container = _blobClient.GetContainerReference(StorageAccount.UsersImagesContainerName);
            var blob      = container.GetBlockBlobReference($"{DateTime.UtcNow.ToString("yyMMddhhmmss")}_{id}.jpg");

            using (var stream = new MemoryStream(image))
                await blob.UploadFromStreamAsync(stream);

            var request = new UserFaceUpdateRequest
            {
                Id    = id,
                Image = blob.Name
            };

            var queue = _queueClient.GetQueueReference(StorageAccount.UsersQueueName);
            await queue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(request)));
        }