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

            return(desc.Value <string>());
        }
Ejemplo n.º 2
0
 public CognativeService(ImageEntity imageEntity, BlobManager blobManager, TableManager tableManager, string subscriptionKey)
 {
     _imageEntity    = imageEntity;
     BlobManager     = blobManager;
     TableManager    = tableManager;
     SubscriptionKey = subscriptionKey;
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
                }
            }
        }
Ejemplo n.º 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();
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public ImageAnalyzer(ImageEntity imageEntity, BlobManager blobManager, TableManager tableManager, string subscriptionKey)
     : base(imageEntity, blobManager, tableManager, subscriptionKey)
 {
 }