private void OnTestBackendFlyoutOpened(object sender, object e)
        {
            try
            {
                // Run DB tests
                var    customers         = IgniteDataAccess.GetCustomers();
                string testGetCustomers  = (customers != null) ? customers.Count.ToString() : "FAIL";
                string unregCustomerGuid = "00000000-0000-0000-0000-000000000000";

                bool   createCustomerRes        = IgniteDataAccess.CreateCustomerRecord(unregCustomerGuid, "UNREGISTERED");
                string testCreateCustomerRecord = createCustomerRes ? "OK" : "FAIL";

                bool   createNewTransactionRes  = IgniteDataAccess.CreateNewTransaction(11110, 1, unregCustomerGuid);
                string testCreateNewTransaction = createNewTransactionRes ? "OK" : "FAIL";

                var    customerInfo        = IgniteDataAccess.GetCustomerInfo(unregCustomerGuid);
                string testGetCustomerInfo = (customerInfo?.CustomerName == "UNREGISTERED" &&
                                              customerInfo?.SourceItemId == 11110) ? "OK" : "FAIL";

                var    inventoryStats        = IgniteDataAccess.GetInventoryStats();
                string testGetInventoryStats = "FAIL";
                foreach (InventoryItemStats iist in inventoryStats)
                {
                    if (iist.ItemId == 11110)
                    {
                        testGetInventoryStats = iist.RemainingInventory.ToString();
                    }
                }

                this.backendTestResultTextBox.Text = $"GetCustomers.Count: {testGetCustomers}\n" +
                                                     $"CreateCutomerRecord: {testCreateCustomerRecord}\n" +
                                                     $"CreateNewTransaction: {testCreateNewTransaction}\n" +
                                                     $"GetCustomerInfo: {testGetCustomerInfo}\n" +
                                                     $"GetInventoryStats.RemainingInventory: {testGetInventoryStats}";
            }
            catch (Exception ex)
            {
                this.backendTestResultTextBox.Text = $"Exception: {ex.Message}";
            }
        }
Ejemplo n.º 2
0
        public async Task Register()
        {
            IsRegistrationEnabled = false;
            try
            {
                IEnumerable <PersonGroup> PersonGroups = null;
                int i = 3; //retry count

                // 1. Select group
                // If the group is full, another one needs to added manually with alphabetically preceeding name
                do
                {
                    PersonGroups = await FaceServiceHelper.ListPersonGroupsAsync(SettingsHelper.Instance.WorkspaceKey);

                    if (PersonGroups.Count() > 0)
                    {
                        CurrentPersonGroup = PersonGroups.OrderBy(pg => pg.Name).First();
                    }
                    // Do not forget to create a persons group if there is not one
                    else
                    {
                        await FaceServiceHelper.CreatePersonGroupAsync(Guid.NewGuid().ToString(), "DefaultGroup", SettingsHelper.Instance.WorkspaceKey);
                    }

                    i--;
                } while (PersonGroups.Count() < 1 && i >= 0);

                // 2. Create a person in that group
                CurrentPerson = await FaceServiceHelper.CreatePersonAsync(this.CurrentPersonGroup.PersonGroupId, FullName);

                // 3. Add face to that person
                CurrentFace = await FaceServiceHelper.AddPersonFaceFromStreamAsync(
                    CurrentPersonGroup.PersonGroupId,
                    CurrentPerson.PersonId,
                    imageStreamCallback : customerFace.GetImageStreamCallback,
                    userData : customerFace.LocalImagePath,
                    targetFaceRect : null);

                // 4. Train model
                await FaceServiceHelper.TrainPersonGroupAsync(CurrentPersonGroup.PersonGroupId);

                bool trainingSucceeded = false;
                bool recordAdded       = false;

                while (true)
                {
                    TrainingStatus trainingStatus = await FaceServiceHelper.GetPersonGroupTrainingStatusAsync(CurrentPersonGroup.PersonGroupId);

                    if (trainingStatus.Status == TrainingStatusType.Succeeded)
                    {
                        trainingSucceeded = true;
                        break;
                    }
                    else if (trainingStatus.Status == TrainingStatusType.Failed)
                    {
                        break;
                    }

                    await Task.Delay(100);
                }

                // 5. Add record to the database
                if (trainingSucceeded)
                {
                    customerInfo = new CustomerRegistrationInfo
                    {
                        CustomerFaceHash = CurrentPerson.PersonId.ToString(),
                        CustomerName     = FullName,
                        RegistrationDate = DateTime.Now
                    };

                    recordAdded = IgniteDataAccess.CreateCustomerRecord(customerInfo.CustomerFaceHash, customerInfo.CustomerName);
                }

                // 6. Update status
                if (trainingSucceeded && recordAdded)
                {
                    StatusText      = "Success!";
                    StatusTextColor = Util.ToBrush("green");
                }
                else
                {
                    customerInfo          = null;
                    IsRegistrationEnabled = true;
                    StatusText            = "Please try again later";
                    StatusTextColor       = Util.ToBrush("red");
                    ResumeCamera?.Invoke(this, EventArgs.Empty);
                }
            }
            catch (Exception)
            {
                customerInfo          = null;
                IsRegistrationEnabled = true;
                StatusText            = "Please try again";
                StatusTextColor       = Util.ToBrush("red");
                ResumeCamera?.Invoke(this, EventArgs.Empty);
            }
        }