public async Task <MatchResult> MatchImageAsync(Stream content, bool cacheImage, string listid) { var imageType = ModeratorHelper.GetImageFormat(content); if (imageType.Equals(ModeratorHelper.ImageFormat.unknown)) { throw new Exception($"Image type: {imageType} not supported"); } content.Position = 0; List <KeyValue> metaData = new List <KeyValue>(); metaData.Add(new KeyValue() { Key = "CacheImage", Value = cacheImage.ToString() }); metaData.Add(new KeyValue() { Key = "subscription-key", Value = _subscriptionKey }); metaData.Add(new KeyValue() { Key = "listid", Value = listid }); return(await InvokeImageModeratorAsync <Stream, MatchResult>(content, Constants.Operations.Match.ToString(), metaData).ConfigureAwait(false)); }
public async Task <OcrImageResult> OCRImageAsync(Stream content, bool cacheImage, bool enhanced = true, string language = "eng") { var imageType = ModeratorHelper.GetImageFormat(content); if (imageType.Equals(ModeratorHelper.ImageFormat.unknown)) { throw new Exception($"Image type: {imageType} not supported"); } content.Position = 0; List <KeyValue> metaData = new List <KeyValue>(); metaData.Add(new KeyValue() { Key = "CacheImage", Value = cacheImage.ToString() }); metaData.Add(new KeyValue() { Key = "enhanced", Value = enhanced.ToString() }); metaData.Add(new KeyValue() { Key = "language", Value = language }); return(await this.InvokeImageModeratorAsync <Stream, OcrImageResult>(content, Constants.Operations.OCR.ToString(), metaData).ConfigureAwait(false)); }
private async Task <S> InvokeTextModeratorAsync <T, S>(dynamic textRequest, string operation, List <KeyValue> metaData, Constants.MediaType mediaType) { StringBuilder requestUrl = new StringBuilder(string.Concat(_apiRoot, $"/ProcessText/{operation}?")); foreach (var k in metaData) { requestUrl.Append(string.Concat(k.Key, "=", k.Value)); requestUrl.Append("&"); } var request = WebRequest.Create(requestUrl.ToString()); request.ContentType = ModeratorHelper.GetEnumDescription(mediaType); return (await this.SendAsync <T, S>("POST", textRequest, request) .ConfigureAwait(false)); }
public async Task <CreateJobResult> CreateJob(string teamName, Stream content, ContentType contentType, string contentId, string workFlowName, string callBackEndpoint) { var imageType = ModeratorHelper.GetImageFormat(content); if (imageType.Equals(ModeratorHelper.ImageFormat.unknown)) { throw new Exception($"Image type: {imageType} not supported"); } content.Position = 0; List <KeyValue> metaData = new List <KeyValue>(); metaData.Add(new KeyValue() { Key = "ContentType", Value = contentType.ToString() }); metaData.Add(new KeyValue() { Key = "ContentId", Value = contentId }); metaData.Add(new KeyValue() { Key = "WorkflowName", Value = workFlowName }); metaData.Add(new KeyValue() { Key = "CallBackEndpoint", Value = callBackEndpoint }); return (await InvokeAsync <Stream, CreateJobResult>(content, string.Format(Constants.CREATE_JOB, teamName), Constants.HttpMethod.POST, metaData) .ConfigureAwait(false)); }
public async Task <DetectFacesResult> DetectFacesImageAsync(Stream content, bool cacheImage) { var imageType = ModeratorHelper.GetImageFormat(content); if (imageType.Equals(ModeratorHelper.ImageFormat.unknown)) { throw new Exception($"Image type: {imageType} not supported"); } content.Position = 0; List <KeyValue> metaData = new List <KeyValue>(); metaData.Add(new KeyValue() { Key = "CacheImage", Value = cacheImage.ToString() }); return(await this.InvokeImageModeratorAsync <Stream, DetectFacesResult>(content, Constants.Operations.FindFaces.ToString(), metaData).ConfigureAwait(false)); }