private string GetDescription(ImageEntity entity) { var data = JObject.Parse(entity.ImageAnalyzerResults); var desc = data["description"]?["captions"]?[0]?["text"]; return(desc.Value <string>()); }
public CognativeService(ImageEntity imageEntity, BlobManager blobManager, TableManager tableManager, string subscriptionKey) { _imageEntity = imageEntity; BlobManager = blobManager; TableManager = tableManager; SubscriptionKey = subscriptionKey; }
public async Task UpdateRecord(ImageEntity imageEntity) { // initialize await Initialzie(); // TODO should check the response and handle appropriately await CloudTable.ExecuteAsync(TableOperation.Merge(imageEntity)); }
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); }
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)); } } }
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(); } } } }
public ImageAnalyzer(ImageEntity imageEntity, BlobManager blobManager, TableManager tableManager, string subscriptionKey) : base(imageEntity, blobManager, tableManager, subscriptionKey) { }