Exemple #1
0
        public static async Task <bool> AddUserToStorageAsync(WHUser user, ConfigValues values)
        {
            var credentials = new StorageCredentials(values.StorageAccountName, values.StorageAccountKey);
            var blob        = new CloudBlockBlob(new Uri($"{values.StorageAccountUrl}{user.Mail}"), credentials);
            await blob.UploadFromByteArrayAsync(user.Image, 0, user.Image.Length);

            return(true);
        }
        public static async Task <bool> AddUserToFaceApiAsync(WHUser user, ConfigValues values)
        {
            var faceClient = new FaceClient(new ApiKeyServiceClientCredentials(values.FaceApiKey), new DelegatingHandler[] { })
            {
                Endpoint = FaceUrl
            };

            await WaitCallLimitPerSecondAsync();

            using (var stream = new MemoryStream(user.Image))
            {
                try
                {
                    var existingList = await faceClient.PersonGroup.GetAsync(PersonGroupId);
                }
                catch (APIErrorException)
                {
                    try
                    {
                        await faceClient.PersonGroup.CreateAsync(PersonGroupId, "WhosHereFaces", "Faces from graph", "recognition_02");
                    }
                    catch (Exception) { }
                }
                try
                {
                    var person = await faceClient.PersonGroupPerson.CreateAsync(PersonGroupId, user.Mail, user.Mail);

                    await faceClient.PersonGroupPerson.AddFaceFromStreamAsync(PersonGroupId, person.PersonId, stream, user.Mail);
                }
                catch (APIErrorException)
                {
                    return(false);
                }
            }
            return(true);
        }