예제 #1
0
        private string GetDescription(ImageEntity entity)
        {
            var data = JObject.Parse(entity.ImageAnalyzerResults);
            var desc = data["description"]?["captions"]?[0]?["text"];

            return(desc.Value <string>());
        }
예제 #2
0
 public CognativeService(ImageEntity imageEntity, BlobManager blobManager, TableManager tableManager, string subscriptionKey)
 {
     _imageEntity    = imageEntity;
     BlobManager     = blobManager;
     TableManager    = tableManager;
     SubscriptionKey = subscriptionKey;
 }
예제 #3
0
        public async Task UpdateRecord(ImageEntity imageEntity)
        {
            // initialize
            await Initialzie();

            // TODO should check the response and handle appropriately
            await CloudTable.ExecuteAsync(TableOperation.Merge(imageEntity));
        }
예제 #4
0
        public async Task <ImageEntity> AddOriginalImage(string url)
        {
            // initialize
            await Initialzie();

            // compose the record and add it
            var record = new ImageEntity {
                OriginalImageUrl = url
            };

            // todo add some handling for invalid results
            await CloudTable.ExecuteAsync(TableOperation.Insert(record));

            // return the row key
            return(record);
        }
예제 #5
0
        public async Task UpdateRecord(string id, Action <ImageEntity> mergeRecordCallback)
        {
            await Initialzie();

            var result = await CloudTable.ExecuteAsync(TableOperation.Retrieve <ImageEntity>(ImageEntity.PARTITION_KEY, id));

            if (result.HttpStatusCode == (int)System.Net.HttpStatusCode.OK)
            {
                ImageEntity entity = result.Result as ImageEntity;
                if (entity != null)
                {
                    mergeRecordCallback(entity);
                    // TODO should check the response and handle appropriately
                    await CloudTable.ExecuteAsync(TableOperation.Merge(entity));
                }
            }
        }
예제 #6
0
        public async Task SendNewImageEvent(ImageEntity imageEntity)
        {
            // should be sending an array but we only have one item to send at a time
            var items = new List <GridEvent <ImageEntity> >
            {
                new GridEvent <ImageEntity>
                {
                    Data      = imageEntity,
                    Subject   = "newImage",
                    EventType = "newImage"
                }
            };

            using (HttpClient client = new HttpClient())
            {
                // set the headers
                client.DefaultRequestHeaders.Add("aeg-sas-key", Key);
                client.DefaultRequestHeaders.UserAgent.ParseAdd("xai");

                // create the request
                using (var msg = new HttpRequestMessage(HttpMethod.Post, TopicEndpoint))
                {
                    msg.Headers.Add("Accept", "application/json");

                    // set the body for the POST
                    msg.Content = new StringContent(JsonConvert.SerializeObject(items), Encoding.UTF8, "application/json");
                    msg.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    // send the response
                    using (var response = await client.SendAsync(msg, HttpCompletionOption.ResponseContentRead))
                    {
                        var responseContent = await response.Content.ReadAsStringAsync();
                    }
                }
            }
        }
예제 #7
0
 public ImageAnalyzer(ImageEntity imageEntity, BlobManager blobManager, TableManager tableManager, string subscriptionKey)
     : base(imageEntity, blobManager, tableManager, subscriptionKey)
 {
 }