public async Task<bool> CreateWhitelistFromFolderAsync(string whitelistId, StorageFolder whitelistFolder = null, IProgress<int> progress = null)
        {
            bool isSuccess = true;
            double progressCnt = 0;

            WhitelistId = whitelistId;
            _whitelist = new FaceApiWhitelist(WhitelistId);

            try
            {
                // whitelist folder default to picture library
                if (whitelistFolder == null)
                {
                    whitelistFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("WhiteList");
                }

                _whitelistFolder = whitelistFolder;

                // detele person group if already exists
                try
                {
                    // An exception throwed if the person group doesn't exist
                    await _faceApiClient.GetPersonGroupAsync(whitelistId);
                    UpdateProgress(progress, ++progressCnt);

                    await _faceApiClient.DeletePersonGroupAsync(whitelistId);
                    UpdateProgress(progress, ++progressCnt);

                    Debug.WriteLine("Deleted old group");
                }
                catch (FaceAPIException fe)
                {
                    if (fe.ErrorCode == "PersonGroupNotFound")
                    {
                        Debug.WriteLine("The person group doesn't exist");
                    }
                    else
                    {
                        throw fe;
                    }

                }

                await _faceApiClient.CreatePersonGroupAsync(WhitelistId, "White List");
                UpdateProgress(progress, ++progressCnt);

                await BuildWhiteListAsync(progress, progressCnt);
            }
            
            catch(FaceAPIException fe)
            {
                isSuccess = false;
                Debug.WriteLine("FaceAPIException in CreateWhitelistFromFolderAsync : " + fe.ErrorMessage);
            }
            catch(Exception e)
            {
                isSuccess = false;
                Debug.WriteLine("Exception in CreateWhitelistFromFolderAsync : " + e.Message);
            }

            // progress to 100%
            UpdateProgress(progress, 100);

            return isSuccess;
        }
示例#2
0
        public async Task <bool> CreateWhitelistFromFolderAsync(string whitelistId, StorageFolder whitelistFolder = null, IProgress <int> progress = null)
        {
            bool   isSuccess   = true;
            double progressCnt = 0;

            WhitelistId = whitelistId;
            _whitelist  = new FaceApiWhitelist(WhitelistId);

            try
            {
                // whitelist folder default to picture library
                if (whitelistFolder == null)
                {
                    whitelistFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("WhiteList");
                }

                _whitelistFolder = whitelistFolder;

                // detele person group if already exists
                try
                {
                    // An exception throwed if the person group doesn't exist
                    await _faceApiClient.GetPersonGroupAsync(whitelistId);

                    UpdateProgress(progress, ++progressCnt);

                    await _faceApiClient.DeletePersonGroupAsync(whitelistId);

                    UpdateProgress(progress, ++progressCnt);

                    Debug.WriteLine("Deleted old group");
                }
                catch (ClientException ce)
                {
                    // Group not found
                    if (ce.Error.Code == "PersonGroupNotFound")
                    {
                        Debug.WriteLine("The group doesn't exists before");
                    }
                    else
                    {
                        throw ce;
                    }
                }

                await _faceApiClient.CreatePersonGroupAsync(WhitelistId, "White List");

                UpdateProgress(progress, ++progressCnt);

                await BuildWhiteListAsync(progress, progressCnt);
            }
            catch (ClientException ce)
            {
                isSuccess = false;
                Debug.WriteLine("ClientException in CreateWhitelistFromFolderAsync : " + ce.Error.Code);
            }
            catch (Exception e)
            {
                isSuccess = false;
                Debug.WriteLine("Exception in CreateWhitelistFromFolderAsync : " + e.Message);
            }

            // progress to 100%
            UpdateProgress(progress, 100);

            return(isSuccess);
        }
        public async Task <bool> CreateWhitelistFromFolderAsync(string whitelistId, StorageFolder whitelistFolder = null, IProgress <int> progress = null)
        {
            bool   isSuccess   = true;
            double progressCnt = 0;

            WhitelistId = whitelistId;
            _whitelist  = new FaceApiWhitelist(WhitelistId);

            try
            {
                // whitelist folder default to picture library
                if (whitelistFolder == null)
                {
                    whitelistFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("WhiteList");
                }

                _whitelistFolder = whitelistFolder;

                // detele person group if already exists
                try
                {
                    // An exception throwed if the person group doesn't exist
                    await FaceServiceHelper.GetPersonGroupAsync(whitelistId);

                    UpdateProgress(progress, ++progressCnt);

                    await FaceServiceHelper.DeletePersonGroupAsync(whitelistId);

                    UpdateProgress(progress, ++progressCnt);

                    Debug.WriteLine("Deleted old group");
                }
                catch (FaceAPIException ce)
                {
                    // Group not found
                    if (ce.ErrorCode == "PersonGroupNotFound")
                    {
                        Debug.WriteLine("The group doesn't exists before");
                        speechError("Создание новой группы доступа ");
                    }
                    else
                    {
                        throw ce;
                    }
                }

                await FaceServiceHelper.CreatePersonGroupAsync(WhitelistId, "White List", string.Empty);

                UpdateProgress(progress, ++progressCnt);

                await BuildWhiteListAsync(progress, progressCnt);
            }
            catch (FaceAPIException ce)
            {
                isSuccess = false;
                Debug.WriteLine("ClientException in CreateWhitelistFromFolderAsync : " + ce.ErrorCode);
                speechError("Ошибка подключения к ФэйсАпи: " + ce.ErrorMessage);
            }
            catch (Exception e)
            {
                isSuccess = false;
                Debug.WriteLine("Exception in CreateWhitelistFromFolderAsync : " + e.Message);
                speechError("Ошибка регистрации списка доступа на сервисе: " + e.Message);
            }

            // progress to 100%
            UpdateProgress(progress, 100);

            return(isSuccess);
        }