Esempio n. 1
0
        async partial void LeftGate_TouchUpInside(UIButton sender)
        {
            BTProgressHUD.Show("Contacting Gates...", maskType: ProgressHUD.MaskType.Gradient);
            APISignInHelper signIn = new APISignInHelper();

            if (string.IsNullOrWhiteSpace(Settings.AuthToken))
            {
                await signIn.SignIn(Keys.Email, Keys.Password);

                BTProgressHUD.Dismiss();
            }
            else
            {
                if (TokenValidator.HasExpired(Settings.AuthToken))
                {
                    if (await signIn.SignIn(Keys.Email, Keys.Password))
                    {
                        APIDeviceHelper sendMessage = new APIDeviceHelper();

                        if (await sendMessage.SendDeviceMessage(Strings.deviceId, Strings.left_gpio_pin, Strings.mode, Strings.left_max_ticks, Strings.left_time_span))
                        {
                            BTProgressHUD.Dismiss();
                            BTProgressHUD.ShowSuccessWithStatus("Left Gate Toggled", 1000);
                        }
                        else
                        {
                            BTProgressHUD.Dismiss();
                            BTProgressHUD.ShowErrorWithStatus(Settings.ErrorMessage, 1000);
                        }
                    }
                    else
                    {
                        BTProgressHUD.Dismiss();
                        BTProgressHUD.ShowErrorWithStatus(Settings.ErrorMessage, 1000);
                    }
                }
                else
                {
                    APIDeviceHelper sendMessage = new APIDeviceHelper();

                    if (await sendMessage.SendDeviceMessage(Strings.deviceId, Strings.left_gpio_pin, Strings.mode, Strings.left_max_ticks, Strings.left_time_span))
                    {
                        BTProgressHUD.Dismiss();
                        BTProgressHUD.ShowSuccessWithStatus("Left Gate Toggled", 1000);
                    }
                    else
                    {
                        BTProgressHUD.Dismiss();
                        BTProgressHUD.ShowErrorWithStatus(Settings.ErrorMessage, 1000);
                    }
                }
            }
        }
Esempio n. 2
0
        private async void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            APISignInHelper signIn = new APISignInHelper();

            AndHUD.Shared.Show(this);
            if (string.IsNullOrWhiteSpace(Settings.AuthToken))
            {
                if (await signIn.SignIn(Keys.Email, Keys.Password))
                {
                    AndHUD.Shared.Dismiss(this);
                    var intent = new Intent(this, typeof(MainActivity));
                    intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask);
                    StartActivity(intent);
                }
                else
                {
                    AndHUD.Shared.Dismiss(this);
                    AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3));
                }
            }
            else
            {
                if (TokenValidator.HasExpired(Settings.AuthToken))
                {
                    if (await signIn.SignIn(Keys.Email, Keys.Password))
                    {
                        AndHUD.Shared.Dismiss(this);
                        var intent = new Intent(this, typeof(MainActivity));
                        intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask);
                        StartActivity(intent);
                    }
                    else
                    {
                        AndHUD.Shared.Dismiss(this);
                        AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3));
                    }
                }
                else
                {
                    AndHUD.Shared.Dismiss(this);
                    var intent = new Intent(this, typeof(MainActivity));
                    intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.ClearTask);
                    StartActivity(intent);
                }
            }
        }
Esempio n. 3
0
        private async void LeftGateClick(object sender, EventArgs e)
        {
            AndHUD.Shared.Show(this, "Contacting Gate...", maskType: MaskType.Black);
            if (TokenValidator.HasExpired(Settings.AuthToken))
            {
                APISignInHelper signIn = new APISignInHelper();
                if (await signIn.SignIn(Keys.Email, Keys.Password))
                {
                    APIDeviceHelper sendMessage = new APIDeviceHelper();

                    if (await sendMessage.SendDeviceMessage(Strings.deviceId, Strings.left_gpio_pin, Strings.mode, Strings.left_max_ticks, Strings.left_time_span))
                    {
                        AndHUD.Shared.Dismiss(this);
                        AndHUD.Shared.ShowSuccess(this, "Left Gate Toggled", MaskType.Black, TimeSpan.FromSeconds(3));
                    }
                    else
                    {
                        AndHUD.Shared.Dismiss(this);
                        AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3));
                    }
                }
                else
                {
                    AndHUD.Shared.Dismiss(this);
                    AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3));
                }
            }
            else
            {
                APIDeviceHelper sendMessage = new APIDeviceHelper();

                if (await sendMessage.SendDeviceMessage(Strings.deviceId, Strings.left_gpio_pin, Strings.mode, Strings.left_max_ticks, Strings.left_time_span))
                {
                    AndHUD.Shared.Dismiss(this);
                    AndHUD.Shared.ShowSuccess(this, "Left Gate Toggled", MaskType.Black, TimeSpan.FromSeconds(3));
                }
                else
                {
                    AndHUD.Shared.Dismiss(this);
                    AndHUD.Shared.ShowError(this, Settings.ErrorMessage, MaskType.Black, TimeSpan.FromSeconds(3));
                }
            }
        }
Esempio n. 4
0
        public override async Task <AuthToken> GetCurrentToken()
        {
            var authToken = _dbContext.Token.SingleOrDefault();

            if (authToken == null)
            {
                return(null);
            }

            if (TokenValidator.HasExpired(authToken.IdToken))
            {
                var idToken = await _authenticator.RefreshToken(authToken.RefreshToken).ConfigureAwait(false);

                _dbContext.Token.DeleteAll();

                authToken.IdToken = idToken;
                _dbContext.Token.Add(authToken);
            }
            Insights.Identify(authToken);

            return(authToken);
        }