public async Task SignIn() { try { // 1. Try to identify the person await customerFace.DetectFacesAsync(); await customerFace.IdentifyFacesAsync(); // TODO: consider looping over identified persons to find matching DB record customerInfo = new CustomerRegistrationInfo(); customerInfo.CustomerFaceHash = customerFace.IdentifiedPersons.First().Person.PersonId.ToString(); customerInfo.CustomerName = customerFace.IdentifiedPersons.First().Person.Name; // 2. Try to obtain customer info from DB CustomerInfo dbCustomerInfo = IgniteDataAccess.GetCustomerInfo(customerInfo.CustomerFaceHash); customerInfo.RegistrationDate = dbCustomerInfo.PreviousVisitDate; // 3. Update status StatusText = $"Welcome, {customerInfo.CustomerName}!"; StatusTextColor = Util.ToBrush("green"); PauseCamera?.Invoke(this, EventArgs.Empty); } catch (Exception) { customerInfo = null; StatusText = "Please try again."; StatusTextColor = Util.ToBrush("red"); ResumeCamera?.Invoke(this, EventArgs.Empty); } }
private async Task ProcessCameraCapture(ImageAnalyzer e) { if (this.isEngagingCustomer) { this.isProcessingPhoto = false; return; } if (e == null) { this.allowSendingOffMsg = false; this.ViewModel.Update(DemoScreenState.NoFace); this.isProcessingPhoto = false; return; } await e.DetectFacesAsync(); if (e.DetectedFaces.Any()) { await e.IdentifyFacesAsync(); bool recognized = false; if (e.IdentifiedPersons.Any()) { var candidate = e.IdentifiedPersons.First().Person; // Check if this is a registered customer, who made purchases, before recognizing CustomerInfo ci = IgniteDataAccess.GetCustomerInfo(candidate.PersonId.ToString()); if (ci != null) { recognized = true; await EngageRecognizedCustomer(ci); } } if (!recognized) { await EngageUnrecognized(); } } // else CameraControl captured a face, but ImageAnalyzer cannot detect any - no change of state in this case this.isProcessingPhoto = false; }
private CustomerRegistrationInfo customerRegistrationInfo; // obtained form registration UI public void UpdateCustomer(CustomerRegistrationInfo info) { customerRegistrationInfo = info; if (info != null && info.CustomerName.Length > 0) { customerInfo = IgniteDataAccess.GetCustomerInfo(info.CustomerFaceHash); if (customerInfo == null) // first visit { IsRecognized = true; IsUnrecognized = false; CustomerName = info.CustomerName; VisitDateStr = ""; PreviousPurchase = ""; RecommendedActions = IgniteDataServices.GetRecommendedActions(customerInfo); IsWarningNoCheckout = true; // we want to avoid having registered customers without transactions } else // second visit { IsRecognized = true; IsUnrecognized = false; CustomerName = customerInfo.CustomerName; VisitDateStr = customerInfo.PreviousVisitDate.ToString("MM/dd/yyyy"); PreviousPurchase = ProductCatalog.Instance.GetProductById(customerInfo.SourceItemId).ItemDescription; RecommendedActions = IgniteDataServices.GetRecommendedActions(customerInfo); } } else { customerInfo = null; IsRecognized = false; IsUnrecognized = true; CustomerName = ""; VisitDateStr = ""; PreviousPurchase = ""; RecommendedActions = ""; } }
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}"; } }