Пример #1
0
        private bool CollectionExists()
        {
            ListCollectionsRequest  request  = new ListCollectionsRequest();
            ListCollectionsResponse response = Client.ListCollections(request);

            return(response.CollectionIds.Contains(CollectionName));
        }
        // snippet-start:[Rekognition.dotnetv3.ListCollectionsExample]
        public static async Task Main()
        {
            var rekognitionClient = new AmazonRekognitionClient();

            Console.WriteLine("Listing collections");
            int limit = 10;

            var listCollectionsRequest = new ListCollectionsRequest
            {
                MaxResults = limit,
            };

            var listCollectionsResponse = new ListCollectionsResponse();

            do
            {
                if (listCollectionsResponse is not null)
                {
                    listCollectionsRequest.NextToken = listCollectionsResponse.NextToken;
                }

                listCollectionsResponse = await rekognitionClient.ListCollectionsAsync(listCollectionsRequest);

                listCollectionsResponse.CollectionIds.ForEach(id =>
                {
                    Console.WriteLine(id);
                });
            }while (listCollectionsResponse.NextToken is not null);
        }
Пример #3
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListCollectionsResponse response = new ListCollectionsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("CollectionIds", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance);
                    response.CollectionIds = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("FaceModelVersions", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance);
                    response.FaceModelVersions = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Пример #4
0
        public ListCollectionsResponse ListCollections(string environmentId, string name = null)
        {
            if (string.IsNullOrEmpty(environmentId))
            {
                throw new ArgumentNullException(nameof(environmentId));
            }

            if (string.IsNullOrEmpty(VersionDate))
            {
                throw new ArgumentNullException("versionDate cannot be null. Use 'DISCOVERY_VERSION_DATE_2016_12_01'");
            }

            ListCollectionsResponse result = null;

            try
            {
                result = this.Client.WithAuthentication(this.UserName, this.Password)
                         .GetAsync($"{this.Endpoint}/v1/environments/{environmentId}/collections")
                         .WithArgument("version", VersionDate)
                         .WithArgument("name", name)
                         .As <ListCollectionsResponse>()
                         .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
Пример #5
0
    public static void Example()
    {
        AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();

        Console.WriteLine("Listing collections");
        int limit = 10;

        ListCollectionsResponse listCollectionsResponse = null;
        String paginationToken = null;

        do
        {
            if (listCollectionsResponse != null)
            {
                paginationToken = listCollectionsResponse.NextToken;
            }

            ListCollectionsRequest listCollectionsRequest = new ListCollectionsRequest()
            {
                MaxResults = limit,
                NextToken  = paginationToken
            };

            listCollectionsResponse = rekognitionClient.ListCollections(listCollectionsRequest);

            foreach (String resultId in listCollectionsResponse.CollectionIds)
            {
                Console.WriteLine(resultId);
            }
        } while (listCollectionsResponse != null && listCollectionsResponse.NextToken != null);
    }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonRekognitionConfig config = new AmazonRekognitionConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonRekognitionClient client = new AmazonRekognitionClient(creds, config);

            ListCollectionsResponse resp = new ListCollectionsResponse();

            do
            {
                ListCollectionsRequest req = new ListCollectionsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListCollections(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.CollectionIds)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Пример #7
0
        public static string Collection(string collectionId)
        {
            try
            {
                var rekognitionClient = new AmazonRekognitionClient(RegionEndpoint.APSouth1);


                Console.WriteLine("Creating collection: " + collectionId);

                var createCollectionRequest = new CreateCollectionRequest()
                {
                    CollectionId = collectionId
                };

                int limit = 10;

                ListCollectionsResponse listCollectionsResponse = null;
                String paginationToken = null;

                if (listCollectionsResponse != null)
                {
                    paginationToken = listCollectionsResponse.NextToken;
                }

                ListCollectionsRequest listCollectionsRequest = new ListCollectionsRequest()
                {
                    MaxResults = limit,
                    NextToken  = paginationToken
                };

                listCollectionsResponse = rekognitionClient.ListCollectionsAsync(listCollectionsRequest).Result;

                foreach (var resultId in listCollectionsResponse.CollectionIds)
                {
                    if (resultId == collectionId)
                    {
                        return("OK");
                    }
                    else
                    {
                        var createCollectionResponse =
                            rekognitionClient.CreateCollectionAsync(createCollectionRequest);
                        Console.WriteLine("CollectionArn : " + createCollectionResponse.Result.CollectionArn);
                        if (createCollectionResponse.Result.StatusCode == 200)
                        {
                            return("OK");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception occurred" + ex);
                return("");
            }


            return("");
        }
Пример #8
0
        public static List <String> GetFaceCollectionList()
        {
            List <String> _faceCollectionList = new List <string>();

            _faceCollectionList.Clear();

            using (rekognitionClient = new AmazonRekognitionClient(collectionRegion))
            {
                ListingCollections();
            }

            void ListingCollections()
            {
                try
                {
                    int limit = 10;

                    ListCollectionsResponse listCollectionsResponse = null;
                    String paginationToken = null;
                    do
                    {
                        if (listCollectionsResponse != null)
                        {
                            paginationToken = listCollectionsResponse.NextToken;
                        }

                        ListCollectionsRequest listCollectionsRequest = new ListCollectionsRequest()
                        {
                            MaxResults = limit,
                            NextToken  = paginationToken
                        };

                        listCollectionsResponse = rekognitionClient.ListCollections(listCollectionsRequest);

                        foreach (String resultId in listCollectionsResponse.CollectionIds)
                        {
                            _faceCollectionList.Add(resultId);
                        }
                    } while (listCollectionsResponse != null && listCollectionsResponse.NextToken != null);
                }
                catch (AmazonRekognitionException e)
                {
                    Console.WriteLine("AmazonRekognitionException: " + e);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e);
                }
            }

            return(_faceCollectionList);
        }
Пример #9
0
        private async Task <List <string> > GetCollections(AmazonRekognitionClient rekognitionClient)
        {
            ListCollectionsResponse listCollectionsResponse = null;
            ListCollectionsRequest  listCollectionsRequest  = new ListCollectionsRequest()
            {
                //MaxResults = limit, //declare a limit
                //NextToken = paginationToken
            };

            listCollectionsResponse = await rekognitionClient.ListCollectionsAsync(listCollectionsRequest);

            return(listCollectionsResponse.CollectionIds);
        }
Пример #10
0
    private IEnumerator ExampleListCollections()
    {
        Log.Debug("DiscoveryServiceV2", "ListCollections");
        ListCollectionsResponse listCollectionsResponse = null;

        service.ListCollections(
            callback: (DetailedResponse <ListCollectionsResponse> response, IBMError error) =>
        {
            Log.Debug("DiscoveryServiceV2", "ListCollections result: {0}", response.Response);
            listCollectionsResponse = response.Result;
        },
            projectId: "{project_id}"
            );

        while (listCollectionsResponse == null)
        {
            yield return(null);
        }
    }
Пример #11
0
        public IEnumerator TestListCollections()
        {
            Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to ListCollections...");
            ListCollectionsResponse listCollectionsResponse = null;

            service.ListCollections(
                callback: (DetailedResponse <ListCollectionsResponse> response, IBMError error) =>
            {
                Log.Debug("DiscoveryServiceV2IntegrationTests", "ListCollections result: {0}", response.Response);
                listCollectionsResponse = response.Result;
                Assert.IsNotNull(listCollectionsResponse);
                Assert.IsNotNull(listCollectionsResponse.Collections);
                Assert.IsTrue(listCollectionsResponse.Collections.Count > 0);
                Assert.IsNull(error);
            },
                projectId: projectId
                );

            while (listCollectionsResponse == null)
            {
                yield return(null);
            }
        }