Exemple #1
0
        private Byte[] GetVisionDescribeModel(VisionThumbnailAttribute 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 VisionThumbnailClient(this, attribute, _loggerFactory);

            VisionThumbnailRequest request = new VisionThumbnailRequest();

            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.ThumbnailAsync(request);

            result.Wait();

            return(result.Result);
        }
 public VisionThumbnailClient(IVisionBinding config, VisionThumbnailAttribute attr, ILoggerFactory loggerFactory)
 {
     this._config = config;
     this._attr   = attr;
     this._log    = loggerFactory?.CreateLogger("Host.Bindings.VisionThumbnail");
 }
        private async Task <VisionThumbnailRequest> MergeProperties(VisionThumbnailRequest operation, IVisionBinding config, VisionThumbnailAttribute attr)
        {
            var visionOperation = new VisionThumbnailRequest
            {
                Url           = attr.VisionUrl ?? operation.Url,
                Key           = attr.VisionKey ?? operation.Key,
                SecureKey     = attr.SecureKey ?? attr.SecureKey,
                AutoResize    = attr.AutoResize,
                Height        = attr.Height,
                Width         = attr.Width,
                SmartCropping = attr.SmartCropping,
                ImageUrl      = string.IsNullOrEmpty(operation.ImageUrl) ? attr.ImageUrl : operation.ImageUrl,
                ImageBytes    = operation.ImageBytes,
            };


            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);
        }
        private async Task <VisionThumbnailRequest> MergeProperties(VisionThumbnailRequest operation, IVisionBinding config, VisionThumbnailAttribute attr)
        {
            var visionOperation = new VisionThumbnailRequest
            {
                Url           = attr.VisionUrl ?? operation.Url,
                Key           = attr.VisionKey ?? operation.Key,
                AutoResize    = attr.AutoResize,
                Height        = attr.Height,
                Width         = attr.Width,
                SmartCropping = attr.SmartCropping,
                ImageUrl      = string.IsNullOrEmpty(operation.ImageUrl) ? attr.ImageUrl : operation.ImageUrl,
                ImageBytes    = operation.ImageBytes,
            };


            if (string.IsNullOrEmpty(visionOperation.Key))
            {
                _log.LogWarning(VisionExceptionMessages.KeyMissing);
                throw new ArgumentException(VisionExceptionMessages.KeyMissing);
            }

            return(visionOperation);
        }