public Visibility IsRecognized(DemoScreenState dss)
 {
     return(dss == DemoScreenState.Recognized ? Visibility.Visible : Visibility.Collapsed);
 }
 public Visibility IsFace(DemoScreenState dss)
 {
     return(dss != DemoScreenState.NoFace ? Visibility.Visible : Visibility.Collapsed);
 }
 public Visibility IsSelectionOrSelected(DemoScreenState dss)
 {
     return((dss == DemoScreenState.Selection || dss == DemoScreenState.RightSelected || dss == DemoScreenState.LeftSelected) ? Visibility.Visible : Visibility.Collapsed);
 }
 public Visibility IsRightSelected(DemoScreenState dss)
 {
     return(dss == DemoScreenState.RightSelected ? Visibility.Visible : Visibility.Collapsed);
 }
 public Visibility IsSelection(DemoScreenState dss)
 {
     return(dss == DemoScreenState.Selection ? Visibility.Visible : Visibility.Collapsed);
 }
 public Visibility IsGreeting(DemoScreenState dss)
 {
     return(dss == DemoScreenState.Greeting || dss == DemoScreenState.NoFaceGreeting ? Visibility.Visible : Visibility.Collapsed);
 }
        /// <summary>
        /// Change the current state of UI, if allowed by timeouts
        /// </summary>
        /// <param name="newState">the state to change to</param>
        /// <param name="ci">customer informatiom</param>
        /// <param name="force">always change the state and update timer</param>
        /// <returns>true iff the change was "officially" made (timeouts are reset)</returns>
        /// Note: we want to prevent too frequent updates here so the customer can react to the prompts
        public bool Update(DemoScreenState newState, CustomerInfo ci = null, bool force = false)
        {
            if (!force)
            {
                // Take care of the cases when there is no real change of state
                if (newState == CurrentScreenState)
                {
                    if (newState == DemoScreenState.Recognized)
                    {
                        if (ci != null && lastCustomerInfo != null)
                        {
                            if (ci.CustomerName == lastCustomerInfo.CustomerName &&
                                ci.CustomerFaceHash == lastCustomerInfo.CustomerFaceHash)
                            {
                                return(false);  // same customer as before - keep waiting for change of state
                            }
                        }
                    }
                    else
                    {
                        return(false);  // keep waiting for change of state
                    }
                }

                // Delay state change upon ofering user a choice or giving instructions
                TimeSpan sinceLastUpdate = DateTime.Now - lastStateChangeTime;

                switch (CurrentScreenState)
                {
                case DemoScreenState.Greeting:
                    if (newState != DemoScreenState.Selection &&
                        newState != DemoScreenState.LeftSelected &&
                        newState != DemoScreenState.RightSelected)
                    {
                        if (sinceLastUpdate.TotalMilliseconds < 10000)
                        {
                            return(false);    // stay with greeting for some time if user does not act
                        }
                    }
                    break;

                case DemoScreenState.Selection:
                    if (newState != DemoScreenState.LeftSelected &&
                        newState != DemoScreenState.RightSelected &&
                        newState != DemoScreenState.NoFaceGreeting)
                    {
                        if (sinceLastUpdate.TotalMilliseconds < 15000)
                        {
                            return(false);    // stay with selection for some time if user does not act
                        }
                    }
                    break;

                case DemoScreenState.LeftSelected:
                case DemoScreenState.RightSelected:
                    if (newState != DemoScreenState.Selection)
                    {
                        if (sinceLastUpdate.TotalMilliseconds < 9000)
                        {
                            return(false);    // let user to read directions, unless they chose to go back to selection
                        }
                    }
                    break;

                case DemoScreenState.Recognized:
                    if (sinceLastUpdate.TotalMilliseconds < 10000)
                    {
                        return(false);    // let user to read directions
                    }
                    break;

                default:
                    break;
                }
            }

            // Now do change the state
            switch (newState)
            {
            case DemoScreenState.NoFace:
                CustomerPrompt = "";
                break;

            case DemoScreenState.Greeting:
                CustomerPrompt = CustomerPromptNoRecognized;
                break;

            case DemoScreenState.Selection:
                UpdateSelectionOfferedSubstate();
                break;

            case DemoScreenState.Recognized:
                UpdateRecognizedSubstate(ci);
                break;

            case DemoScreenState.LeftSelected:
                UpdateSelectedSubstate("left");
                break;

            case DemoScreenState.RightSelected:
                UpdateSelectedSubstate("right");
                break;
            }

            lastStateChangeTime = DateTime.Now;

            CurrentScreenState = newState;
            return(true);
        }