public void TestNobPositivePinLengthException()
        {
            var pinView = new PinView();

            Assert.Throws <ArgumentException>(() => { pinView.PinLength = -2; });
            Assert.Throws <ArgumentException>(() => { pinView.PinLength = 0; });
        }
        public void TestDisplayedTextUpdatedRaised(bool clearAfterSuccess)
        {
            var pinView = new PinView
            {
                PinLength         = 5,
                ClearAfterSuccess = clearAfterSuccess
            };

            pinView.Validator = new Func <IList <char>, bool>(
                (arg) => Enumerable.SequenceEqual(new[] { '1', '2', '3', '4', '5' }, pinView.EnteredPin)
                );
            pinView.KeyPressedCommand.Execute("1");
            pinView.KeyPressedCommand.Execute("2");
            pinView.KeyPressedCommand.Execute("3");
            pinView.KeyPressedCommand.Execute("4");
            Assert.Raises(
                (EventHandler <EventArgs> obj) => { pinView.Success += obj; },
                (EventHandler <EventArgs> obj) => { pinView.Success -= obj; },
                () => { pinView.KeyPressedCommand.Execute("5"); }
                );

            if (clearAfterSuccess)
            {
                Assert.Empty(pinView.EnteredPin);
            }
            else
            {
                Assert.NotEmpty(pinView.EnteredPin);
            }
        }
        public void TestColorChange()
        {
            var pinView       = new PinView();
            var expectedValue = Color.GreenYellow;

            pinView.Color = expectedValue;

            Assert.Equal(expectedValue, pinView.Color);

            var statusLayout = (StackLayout)pinView.Children[0];

            foreach (View child in statusLayout.Children)
            {
                Assert.Equal(expectedValue, ((CircleView)child).Color);
            }
            foreach (View view in pinView.Children)
            {
                if (view is CircleView circleView)
                {
                    if (view is PinItemView pinItemView)
                    {
                        Assert.Equal(expectedValue, pinItemView.Color);
                    }
                }
            }
        }
        public void TestCorrectPin_AllSymbolsFilled()
        {
            var targetPin = new[] { '1', '2', '3', '4' };
            var view      = new PinView
            {
                PinLength         = 4,
                Validator         = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg),
                ClearAfterSuccess = false
            };

            foreach (char next in targetPin)
            {
                PinItemView btn = FindButton(view, next.ToString());
                btn.Command.Execute(btn.CommandParameter);
            }

            var sl = (StackLayout)(view).Children.First(c => c is StackLayout);

            foreach (View child in sl.Children)
            {
                var cv = (CircleView)child;
                Assert.NotNull(cv);
                Assert.True(cv.IsFilledUp);
            }
        }
        public void TestIncorrectPin()
        {
            var targetPin = new[] { '1', '2', '3', '4' };
            var view      = new PinView
            {
                PinLength = 4,
                Validator = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg)
            };

            PinItemView findButton(string arg)
            {
                return((PinItemView)(view).Children.First(c => c is PinItemView btn && btn.Text == arg));
            }

            Assert.Raises <EventArgs>(
                (EventHandler <EventArgs> obj) => view.Error += obj,
                (EventHandler <EventArgs> obj) => view.Error -= obj,
                () =>
            {
                foreach (char next in targetPin.Reverse())
                {
                    PinItemView btn = findButton(next.ToString());
                    btn.Command.Execute(btn.CommandParameter);
                }
            }
                );
        }
        public void TestCorrectPin()
        {
            var targetPin = new[] { '1', '2', '3', '4' };
            var viewModel = new PinViewModel
            {
                TargetPinLength = 4,
                ValidatorFunc   = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg)
            };
            var view = new PinView
            {
                BindingContext = viewModel
            };
            Func <string, PinItemView> findButton = (string arg) =>
            {
                return((PinItemView)((Grid)view.Content).Children.First(c => c is PinItemView btn && btn.Text == arg));
            };

            Assert.Raises <EventArgs>(
                (EventHandler <EventArgs> obj) => viewModel.Success += obj,
                (EventHandler <EventArgs> obj) => viewModel.Success -= obj,
                () =>
            {
                foreach (char next in targetPin)
                {
                    PinItemView btn = findButton(next.ToString());
                    btn.Command.Execute(btn.CommandParameter);
                }
            }
                );
        }
Esempio n. 7
0
        public CreateAuthPage(Account OldAccount)
        {
            string first  = "";
            string second = "";

            PinViewModel = new PinViewModel
            {
                TargetPinLength = 6,
                ValidatorFunc   = (arg) =>
                {
                    second = "";
                    foreach (char c in arg)
                    {
                        second += c;
                    }

                    if (second.Equals(first))
                    {
                        Account acc = new Account(first);
                        acc.Properties.Add("FingerPrint", OldAccount.Properties["FingerPrint"]);
                        if (OldAccount.Properties.ContainsKey("PrivateKey"))
                        {
                            acc.Properties.Add("PrivateKey", OldAccount.Properties["PrivateKey"]);
                        }
                        AccountStore.Create().Delete(OldAccount, App.AppName);
                        AccountStore.Create().Save(acc, App.AppName);
                        App.Current.Properties["Pin"] = acc;
                        Navigation.PopToRootAsync();
                        return(true);
                    }
                    else
                    {
                        if (first.Equals(""))
                        {
                            first    += second;
                            PIN.Title = "Confirm your pin";
                        }
                        else
                        {
                            DisplayAlert("Error", "Passcode doesn't match.\nTry it again.", "OK");
                            first     = "";
                            second    = "";
                            PIN.Title = "Create your pin";
                        }
                        return(false);
                    }
                }
            };

            PIN = new PinView
            {
                Title             = "Create your pin",
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = PinViewModel,
            };

            Content = PIN;
        }
        public void TestValidatorPropertyChangedRaised()
        {
            var PinView       = new PinView();
            var expectedValue = new Func <IList <char>, bool>((arg) => false);

            Assert.PropertyChanged(PinView,
                                   nameof(PinView.Validator),
                                   () => PinView.Validator = expectedValue);
            Assert.Same(expectedValue, PinView.Validator);
        }
        public void TestPinLengthPropertyChangedRaised()
        {
            var pinView       = new PinView();
            int expectedValue = 3;

            Assert.PropertyChanged(pinView,
                                   nameof(PinView.PinLength),
                                   () => pinView.PinLength = expectedValue);
            Assert.Equal(expectedValue, pinView.PinLength);
        }
 /// <summary>
 ///     Draw the connecting line between for single slider.
 /// </summary>
 /// <param name="canvas">the Canvas to draw to</param>
 /// <param name="leftMargin">the right thumb</param>
 /// <param name="rightThumb">the left margin</param>
 public void Draw(Canvas canvas, float leftMargin, PinView rightThumb)
 {
     try
     {
         canvas.DrawLine(leftMargin, this._y, rightThumb.GetX(), this._y, this._paint);
     }
     catch (NullReferenceException nullReferenceException)
     {
         Log.Error(nameof(ConnectingLine), $"{nameof(Draw)}: {nullReferenceException.Message}");
     }
 }
        public void TestEnteredPinPropertyChangedRaised()
        {
            var PinView       = new PinView();
            var expectedValue = new List <char> {
                'a', 'b'
            };

            Assert.PropertyChanged(PinView,
                                   nameof(PinView.EnteredPin),
                                   () => PinView.EnteredPin = expectedValue);
            Assert.Same(expectedValue, PinView.EnteredPin);
        }
        public void TestBackspacePressed()
        {
            var pinView = new PinView
            {
                PinLength = 5,
                Validator = new Func <IList <char>, bool>((arg) => false)
            };

            pinView.KeyPressedCommand.Execute("1");
            pinView.KeyPressedCommand.Execute("1");
            pinView.KeyPressedCommand.Execute("2");
            pinView.KeyPressedCommand.Execute("Backspace");
            Assert.True(Enumerable.SequenceEqual(new[] { '1', '1' }, pinView.EnteredPin));
        }
        public void TestRippleColorChange()
        {
            var pinView       = new PinView();
            var expectedValue = Color.Red;

            pinView.RippleColor = expectedValue;

            Assert.Equal(expectedValue, pinView.RippleColor);
            foreach (View view in pinView.Children)
            {
                if (view is PinItemView pinItemView)
                {
                    Assert.Equal(expectedValue, pinItemView.RippleColor);
                }
            }
        }
        public void TestSuccessCommand()
        {
            bool invoked   = false;
            var  targetPin = new[] { '1', '2', '3', '4' };
            var  view      = new PinView
            {
                PinLength      = 4,
                Validator      = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg),
                SuccessCommand = new Command(() => invoked = true)
            };

            foreach (char next in targetPin)
            {
                PinItemView btn = FindButton(view, next.ToString());
                btn.Command.Execute(btn.CommandParameter);
            }
            Assert.True(invoked);
        }
        public void TestErrorRaised()
        {
            var pinView = new PinView
            {
                PinLength = 5,
                Validator = new Func <IList <char>, bool>((arg) => false)
            };

            pinView.KeyPressedCommand.Execute("1");
            pinView.KeyPressedCommand.Execute("2");
            pinView.KeyPressedCommand.Execute("3");
            pinView.KeyPressedCommand.Execute("4");
            Assert.Raises(
                (EventHandler <EventArgs> obj) => { pinView.Error += obj; },
                (EventHandler <EventArgs> obj) => { pinView.Error -= obj; },
                () => { pinView.KeyPressedCommand.Execute("5"); }
                );
            Assert.Empty(pinView.EnteredPin);
        }
        public void TestFewSymboldEntered()
        {
            var pinView = new PinView
            {
                PinLength = 5,
                Validator = new Func <IList <char>, bool>((arg) => false)
            };

            Assert.Raises(
                (EventHandler <EventArgs> obj) => { pinView.DisplayedTextUpdated += obj; },
                (EventHandler <EventArgs> obj) => { pinView.DisplayedTextUpdated -= obj; },
                () =>
            {
                pinView.KeyPressedCommand.Execute("1");
                pinView.KeyPressedCommand.Execute("1");
            }
                );
            Assert.True(Enumerable.SequenceEqual(new[] { '1', '1' }, pinView.EnteredPin));
        }
Esempio n. 17
0
        public ChangePinPage()
        {
            pinAccount = App.Current.Properties["Pin"] as Account;
            string oldPin = pinAccount.Username;

            PinViewModel = new PinViewModel
            {
                TargetPinLength = 6,
                ValidatorFunc   = (arg) =>
                {
                    string input = "";

                    foreach (char c in arg)
                    {
                        input += c;
                    }

                    if (input.Equals(oldPin))
                    {
                        Navigation.PushAsync(new CreateAuthPage(pinAccount));
                        return(true);
                    }
                    else
                    {
                        DisplayAlert("Error", "Passcode doesn't match.\nTry it again.", "OK");
                        return(false);
                    }
                }
            };

            PIN = new PinView
            {
                Title             = "Old Pin",
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = PinViewModel,
            };

            Content = PIN;
        }
        public void TestCorrectPin()
        {
            var targetPin = new[] { '1', '2', '3', '4' };
            var view      = new PinView
            {
                PinLength = 4,
                Validator = (IList <char> arg) => Enumerable.SequenceEqual(targetPin, arg)
            };

            Assert.Raises <EventArgs>(
                (EventHandler <EventArgs> obj) => view.Success += obj,
                (EventHandler <EventArgs> obj) => view.Success -= obj,
                () =>
            {
                foreach (char next in targetPin)
                {
                    PinItemView btn = FindButton(view, next.ToString());
                    btn.Command.Execute(btn.CommandParameter);
                }
            }
                );
        }
            public void RecalcCoordinates()
            {
                {
                    PinView Pin1 = connectionViewModel.PinView1;
                    System.Windows.Point ConnectionPointInPin = new System.Windows.Point();
                    ConnectionPointInPin.X = Pin1.ConnectionPointX;
                    ConnectionPointInPin.Y = Pin1.ConnectionPointY;

                    //WorkArea "Canvas"
                    DependencyObject container = Pin1;
                    while (container.GetType() != typeof(Canvas))
                    {
                        container = VisualTreeHelper.GetParent(container);
                    }
                    System.Windows.Point relativeLocation = Pin1.TranslatePoint(ConnectionPointInPin, container as UIElement);

                    X1 = relativeLocation.X;
                    Y1 = relativeLocation.Y;
                }
                {
                    PinView Pin2 = connectionViewModel.PinView2;
                    System.Windows.Point ConnectionPointInPin = new System.Windows.Point();
                    ConnectionPointInPin.X = Pin2.ConnectionPointX;
                    ConnectionPointInPin.Y = Pin2.ConnectionPointY;

                    //WorkArea "Canvas"
                    DependencyObject container = Pin2;
                    while (container.GetType() != typeof(Canvas))
                    {
                        container = VisualTreeHelper.GetParent(container);
                    }
                    System.Windows.Point relativeLocation = Pin2.TranslatePoint(ConnectionPointInPin, container as UIElement);

                    X2 = relativeLocation.X;
                    Y2 = relativeLocation.Y;
                }
            }
Esempio n. 20
0
        public CreateAuthPage()
        {
            string first  = "";
            string second = "";

            PinViewModel = new PinViewModel
            {
                TargetPinLength = 6,
                ValidatorFunc   = (arg) =>
                {
                    second = "";
                    foreach (char c in arg)
                    {
                        second += c;
                    }

                    if (second.Equals(first))
                    {
                        Account acc = new Account(first);
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            var res = await DisplayAlert("Finger Print", "Do you want to enable finger print unlock?", "Yes", "No");
                            if (res)
                            {
                                acc.Properties.Add("FingerPrint", "True");
                            }
                            else
                            {
                                acc.Properties.Add("FingerPrint", "False");
                            }
                            AccountStore.Create().Save(acc, App.AppName);
                            App.Current.Properties.Add("Pin", acc);
                            App.Current.MainPage = new RootView();
                        });
                        return(true);
                    }
                    else
                    {
                        if (first.Equals(""))
                        {
                            first    += second;
                            PIN.Title = "Confirm your pin";
                        }
                        else
                        {
                            DisplayAlert("Error", "Passcode doesn't match.\nTry it again.", "OK");
                            first     = "";
                            second    = "";
                            PIN.Title = "Create your pin";
                        }
                        return(false);
                    }
                }
            };

            PIN = new PinView
            {
                Title             = "Create your pin",
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = PinViewModel,
            };

            Content = PIN;
        }
Esempio n. 21
0
 /// <summary>
 ///     Gets the zero-based index of the nearest tick to the given thumb.
 /// </summary>
 /// <param name="thumb">the Thumb to find the nearest tick for</param>
 /// <returns>the zero-based index of the nearest tick</returns>
 public int GetNearestTickIndex(PinView thumb)
 {
     return((int)((thumb.GetX() - this._leftX + this._tickDistance / 2f) / this._tickDistance));
 }
Esempio n. 22
0
        /// <summary>
        ///     Gets the x-coordinate of the nearest tick to the given x-coordinate.
        /// </summary>
        /// <param name="thumb">the thumb to find the nearest tick for</param>
        /// <returns>the x-coordinate of the nearest tick</returns>
        public float GetNearestTickCoordinate(PinView thumb)
        {
            var nearestTickIndex = this.GetNearestTickIndex(thumb);

            return(this._leftX + nearestTickIndex * this._tickDistance);
        }
Esempio n. 23
0
 public ReleasePinListener(View view, PinView thumb)
 {
     this._view  = view;
     this._thumb = thumb;
 }
Esempio n. 24
0
 public PinSubmitEventArg(PinView sender, string pin)
 {
     Source = sender;
     Pin    = pin;
 }
Esempio n. 25
0
 public PinChangedEventArg(PinView sender, string pin)
 {
     Source = sender;
     Pin    = pin;
 }
Esempio n. 26
0
        private static void TcpClient_Complated(object sender, MessageModel e)
        {
            try
            {
                if (e.MessageId != 0x01)
                {
                    return;
                }
                TcpClient.Complated -= TcpClient_Complated;
                StatusResponse statusResponse = JsonConvert.DeserializeObject<StatusResponse>(e.Message);
                if (statusResponse != null)
                {
                    //
                    Const.IsHasGetStatus = true;
                    //保存软件信息--此处处理未分开(每次都保存),正式使用的时候请
                    var info = (from a in Const.dB.PosInfo
                                select a).FirstOrDefault();
                    if (info != null)
                    {
                        Const.dB.Update<PosInfo>(new PosInfo { Id = info.Id, CompanyName = statusResponse.Manufacture, Desc = statusResponse.Model, Version = statusResponse.SoftwareVersion, IssueDate = info.IssueDate });
                    }
                    //记录税种信息
                    if (statusResponse.TaxInfo != null && statusResponse.TaxInfo.Count > 0)
                    {
                        Const.dB.CodeTaxtype.Delete();
                        foreach (var item in statusResponse.TaxInfo)
                        {
                            if (item.Category != null && item.Category.Count > 0)
                            {
                                foreach (var itm in item.Category)
                                {
                                    Const.dB.Insert<CodeTaxtype>(new CodeTaxtype
                                    {
                                        TaxTypeName = item.TaxTpye,
                                        TaxTypeCode = item.TaxTpye,
                                        TaxItemName = itm.TaxName,
                                        TaxItemCode = itm.CategoryId.ToString(),
                                        TaxRate = itm.TaxRate,
                                        EffectDate = itm.EffectiveDate,
                                        ExpireDate = itm.ExpiredDate
                                    });
                                }
                            }
                        }
                    }
                    //记录monitor信息

                    if (!statusResponse.isInitialized)
                    {
                        AttentionResponse attentionResponse = ServiceHelper.AttentionRequest();
                        if (attentionResponse.ATT_GSC == "0000")
                        {
                            //校验pin
                            PinView pinView = new PinView();
                        }
                        else
                        {
                            ShowMessageBegin("E-SDC is not available");
                        }
                    }
                    else
                    {
                        if (statusResponse.isLocked)
                        {
                            ShowMessageBegin("E-SDC is locked.");
                        }
                        else
                        {
                            ShowMessageBegin("E-SDC is available");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMessageBegin(ex.Message);
            }
        }
 private PinItemView FindButton(PinView view, string text)
 {
     return((PinItemView)(view).Children.First(c => c is PinItemView btn && btn.Text == text));
 }
Esempio n. 28
0
        public AuthenticationPage()
        {
            string pin       = "";
            bool   FPEnabled = false;

            var Credentials = AccountStore.Create().FindAccountsForService(App.AppName) as List <Account>;

            //Account account = Credentials[0];AccountStore.Create().Delete(account, App.AppName);Credentials = AccountStore.Create().FindAccountsForService(App.AppName) as List<Account>;

            if (Credentials.Count == 0)
            {
                Device.BeginInvokeOnMainThread(() => App.Current.MainPage = new CreateAuthPage());
            }
            else
            {
                acc = Credentials[0];
                pin = acc.Username;
                App.Current.Properties.TryAdd("Pin", acc);

                if (!acc.Properties.ContainsKey("FingerPrint"))
                {
                    Device.BeginInvokeOnMainThread(async() => {
                        var res = await DisplayAlert("Built-in Unlock", "Do you want to enable built-in unlock?", "Yes", "No");
                        if (res)
                        {
                            AccountStore.Create().Delete(acc, App.AppName);
                            acc.Properties.Add("FingerPrint", "True");
                            AccountStore.Create().Save(acc, App.AppName);
                            App.Current.Properties.TryAdd("Pin", acc);
                            Authenticate();
                        }
                        else
                        {
                            AccountStore.Create().Delete(acc, App.AppName);
                            acc.Properties.Add("FingerPrint", "False");
                            AccountStore.Create().Save(acc, App.AppName);
                            App.Current.Properties.TryAdd("Pin", acc);
                        }
                    });
                }
                else
                {
                    if (acc.Properties["FingerPrint"].Equals("True"))
                    {
                        FPEnabled = true;
                    }
                }
            }

            PinViewModel = new PinViewModel
            {
                TargetPinLength = 6,
                ValidatorFunc   = (arg) =>
                {
                    string m = "";
                    foreach (char c in arg)
                    {
                        m += c;
                    }

                    if (m.Equals(pin))
                    {
                        GoToHome();
                        return(true);
                    }
                    else
                    {
                        DisplayAlert("Error", "Wrong Passcode", "OK");
                        return(false);
                    }
                }
            };

            PIN = new PinView
            {
                Title             = "Enter your pin",
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = PinViewModel,
            };

            if (FPEnabled)
            {
                //Device.BeginInvokeOnMainThread(async () => await DisplayAlert("alert", "Finger print enaled", "OK"));
                Authenticate();
            }

            Content = PIN;
        }
Esempio n. 29
0
 public PressPinListener(View view, PinView thumb)
 {
     this._view  = view;
     this._thumb = thumb;
 }