private VisionDomainRequest BuildRequest(VisionDomainAttribute attribute)
        {
            VisionDomainRequest request = new VisionDomainRequest();

            if (attribute.ImageSource == ImageSource.BlobStorage)
            {
                var fileTask = StorageServices.GetFileBytes(attribute.BlobStoragePath, attribute.BlobStorageAccount);
                fileTask.Wait();

                request.ImageBytes = fileTask.Result;
            }
            else
            {
                request.ImageUrl = attribute.ImageUrl;
            }

            return(request);
        }
        private VisionDomainLandmarkModel GetVisionLandmarkModel(VisionDomainAttribute 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 VisionDomainClient(this, attribute, _loggerFactory);
            var request = BuildRequest(attribute);

            var result = client.AnalyzeLandmarkAsync(request);

            result.Wait();

            return(result.Result);
        }
 public VisionDomainClient(IVisionBinding config, VisionDomainAttribute attr, ILoggerFactory loggerFactory)
 {
     this._config = config;
     this._attr   = attr;
     this._log    = loggerFactory?.CreateLogger("Host.Bindings.VisionDomain");
 }
        private async Task <VisionDomainRequest> MergeProperties(VisionDomainRequest operation, IVisionBinding config, VisionDomainAttribute attr)
        {
            //Attributes do not allow for enum types so we have to validate
            //the string passed into the attribute to ensure it matches
            //a valid VisionDomainOption.
            VisionDomainOptions attrDomain = VisionDomainOptions.None;

            if (!string.IsNullOrEmpty(attr.Domain))
            {
                var valid = Enum.TryParse <VisionDomainOptions>(attr.Domain, out attrDomain);

                if (!valid)
                {
                    var message = string.Format(VisionExceptionMessages.InvalidDomainName, attr.Domain);
                    _log.LogWarning(message);

                    throw new ArgumentException(message);
                }
            }
            else
            {
                if (operation.Domain == VisionDomainOptions.None)
                {
                    var message = string.Format(VisionExceptionMessages.InvalidDomainName, "None");
                    _log.LogWarning(message);

                    throw new ArgumentException(message);
                }
            }


            var visionOperation = new VisionDomainRequest
            {
                Url        = attr.VisionUrl ?? operation.Url,
                Key        = attr.VisionKey ?? operation.Key,
                SecureKey  = attr.SecureKey ?? attr.SecureKey,
                AutoResize = attr.AutoResize,
                Domain     = attrDomain == VisionDomainOptions.None ? operation.Domain : attrDomain,
                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);
        }