private VisionOcrModel GetVisionOcrModel(VisionOcrAttribute attribute) { if (attribute.ImageSource == Bindings.ImageSource.Client) { throw new ArgumentException($"ImageSource of Client does not support binding to vision models. Use Url or BlobStorage instead. "); } attribute.Validate(); var client = new VisionOcrClient(this, attribute, _loggerFactory); VisionOcrRequest request = new VisionOcrRequest(); if (attribute.ImageSource == ImageSource.BlobStorage) { var fileTask = StorageServices.GetFileBytes(attribute.BlobStoragePath, attribute.BlobStorageAccount); fileTask.Wait(); request.ImageBytes = fileTask.Result; } else { request.ImageUrl = attribute.ImageUrl; } var result = client.OCRAsync(request); result.Wait(); return(result.Result); }
private async Task <VisionOcrRequest> MergeProperties(VisionOcrRequest operation, IVisionBinding config, VisionOcrAttribute attr) { var visionOperation = new VisionOcrRequest { Url = attr.VisionUrl ?? operation.Url, Key = attr.VisionKey ?? operation.Key, AutoResize = attr.AutoResize, ImageUrl = string.IsNullOrEmpty(operation.ImageUrl) ? attr.ImageUrl : operation.ImageUrl, ImageBytes = operation.ImageBytes, DetectOrientation = attr.DetectOrientation.HasValue ? attr.DetectOrientation.Value : operation.DetectOrientation }; if (string.IsNullOrEmpty(visionOperation.Key)) { _log.LogWarning(VisionExceptionMessages.KeyMissing); throw new ArgumentException(VisionExceptionMessages.KeyMissing); } return(visionOperation); }
public VisionOcrClient(IVisionBinding config, VisionOcrAttribute attr, ILoggerFactory loggerFactory) { this._config = config; this._attr = attr; this._log = loggerFactory?.CreateLogger("Host.Bindings.VisionOcr"); }
private async Task <VisionOcrRequest> MergeProperties(VisionOcrRequest operation, IVisionBinding config, VisionOcrAttribute attr) { var visionOperation = new VisionOcrRequest { Url = attr.VisionUrl ?? operation.Url, Key = attr.VisionKey ?? operation.Key, SecureKey = attr.SecureKey ?? attr.SecureKey, AutoResize = attr.AutoResize, ImageUrl = string.IsNullOrEmpty(operation.ImageUrl) ? attr.ImageUrl : operation.ImageUrl, ImageBytes = operation.ImageBytes, DetectOrientation = attr.DetectOrientation.HasValue ? attr.DetectOrientation.Value : operation.DetectOrientation }; if (string.IsNullOrEmpty(visionOperation.Key) && string.IsNullOrEmpty(visionOperation.SecureKey)) { _log.LogWarning(VisionExceptionMessages.KeyMissing); throw new ArgumentException(VisionExceptionMessages.KeyMissing); } if (!string.IsNullOrEmpty(visionOperation.SecureKey)) { HttpClient httpClient = this._config.Client.GetHttpClientInstance(); visionOperation.Key = await KeyVaultServices.GetValue(visionOperation.SecureKey, httpClient); } return(visionOperation); }