public void t13_AddCollectionImages_Success() { VisualRecognitionService service = new VisualRecognitionService(); service.SetCredential(apikey); using (FileStream imageStream = File.OpenRead(_localGiraffeFilePath), metadataStream = File.OpenRead(_localImageMetadataPath)) { var result = service.AddImage(_createdCollectionId, imageStream.ReadAllBytes(), Path.GetFileName(_localGiraffeFilePath), metadataStream.ReadAllBytes()); _addedImageId = result.Images[0].ImageId; Console.WriteLine(string.Format("Added image {0}", _addedImageId)); Assert.IsNotNull(result); Assert.IsTrue(result.ImagesProcessed > 0); Assert.IsTrue(!string.IsNullOrEmpty(_addedImageId)); } }
private void AddCollectionImages() { if (string.IsNullOrEmpty(_createdCollectionId)) { throw new ArgumentNullException(nameof(_createdCollectionId)); } using (FileStream imageStream = File.OpenRead(_localGiraffeFilePath), metadataStream = File.OpenRead(_localImageMetadataPath)) { Console.WriteLine(string.Format("\nCalling AddImage(\"{0}\", \"{1}\")...", _createdCollectionId, _localGiraffeFilePath)); var result = _visualRecognition.AddImage(_createdCollectionId, imageStream.ReadAllBytes(), Path.GetFileName(_localGiraffeFilePath), metadataStream.ReadAllBytes()); if (result != null) { Console.WriteLine("Number of images processed: {0}", result.ImagesProcessed); foreach (CollectionImagesConfig image in result.Images) { Console.WriteLine("file: {0} | id: {1}", image.ImageFile, image.ImageId); if (image.Metadata != null && image.Metadata.Count > 0) { foreach (KeyValuePair <string, string> kvp in image.Metadata) { Console.WriteLine("\t{0} : {1}", kvp.Key, kvp.Value); } } else { Console.WriteLine("There is no metadata for this image."); } _addedImageId = image.ImageId; } } else { Console.WriteLine("Result is null."); } } }