Ejemplo n.º 1
0
        private async Task ClearPaymentsAsync(JobParameters args)
        {
            var settingsManager = new SettingsFacade(new SettingsAdapter());

            try
            {
                ExecutingPlatform.Current = AppPlatform.Android;

                EfCoreContext context = EfCoreContextFactory.Create();
                await new ClearPaymentAction(new ClearPaymentDbAccess(context)).ClearPaymentsAsync();
                await context.SaveChangesAsync();

                JobFinished(args, false);
            }
            catch (Exception ex)
            {
                LogManager.GetCurrentClassLogger().Fatal(ex);

                throw;
            }
            finally
            {
                settingsManager.LastExecutionTimeStampClearPayments = DateTime.Now;
            }
        }
Ejemplo n.º 2
0
        private async Task CreateRecurringPayments()
        {
            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            try
            {
                Debug.WriteLine("RecurringPayment Job started.");
                EfCoreContext.DbPath = GetLocalFilePath();

                var context = new EfCoreContext();
                await new RecurringPaymentAction(new RecurringPaymentDbAccess(context))
                .CreatePaymentsUpToRecur()
                .ConfigureAwait(true);
                context.SaveChanges();

                Debug.WriteLine("RecurringPayment Job finished.");
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampRecurringPayments = DateTime.Now;
            }
        }
Ejemplo n.º 3
0
        private async Task ClearPayments(JobParameters args)
        {
            var settingsManager = new SettingsFacade(new SettingsAdapter());

            try
            {
                Debug.WriteLine("ClearPayments Job started");
                EfCoreContext.DbPath =
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                 DatabaseConstants.DB_NAME);

                var context = new EfCoreContext();
                await new ClearPaymentAction(new ClearPaymentDbAccess(context)).ClearPayments();
                context.SaveChanges();

                Debug.WriteLine("ClearPayments Job finished.");
                JobFinished(args, false);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
            finally
            {
                settingsManager.LastExecutionTimeStampClearPayments = DateTime.Now;
            }
        }
Ejemplo n.º 4
0
        public static LineDisplay CreateLineDisplay(GameTypes.EndCondition winState, GameTypes.Player winningPlayer)
        {
            int edgOfst = 25;
            int sqSize  = 200;

            (double, double, double, double) GetRow(int row) => (-edgOfst + 0 * sqSize, edgOfst + 3 * sqSize, (row + 0.5) * sqSize + 1, (row + 0.5) * sqSize + 1);
            (double, double, double, double) GetCol(int col) => ((col + 0.5) * sqSize + 1, (col + 0.5) * sqSize + 1, -edgOfst + 0 * sqSize, edgOfst + 3 * sqSize);

            (double x1, double x2, double y1, double y2) GetLineIndexes(GameTypes.EndCondition state) =>
            state switch
            {
                GameTypes.EndCondition.Row1 => GetRow(0),
                GameTypes.EndCondition.Row2 => GetRow(1),
                GameTypes.EndCondition.Row3 => GetRow(2),
                GameTypes.EndCondition.Column1 => GetCol(0),
                GameTypes.EndCondition.Column2 => GetCol(1),
                GameTypes.EndCondition.Column3 => GetCol(2),
                GameTypes.EndCondition.DiagonalMajor => (-edgOfst / 2 - 1 + 0 * sqSize, edgOfst / 2 + 1 + 3 * sqSize, -edgOfst / 2 - 1 + 0 * sqSize, edgOfst / 2 + 1 + 3 * sqSize),
                GameTypes.EndCondition.DiagonalMinor => (edgOfst / 2 - 1 + 3 * sqSize, -edgOfst / 2 + 1 + 0 * sqSize, -edgOfst / 2 - 1 + 0 * sqSize, edgOfst / 2 + 1 + 3 * sqSize),
                _ => (-1, -1, -1, -1)
            };

            var(x1, x2, y1, y2) = GetLineIndexes(winState);

            var color = SettingsFacade.GetPlayerColor(winningPlayer);

            return(new LineDisplay
            {
                From = new Point(x1, y1),
                To = new Point(x2, y2),
                Brush = new SolidColorBrush(color)
            });
        }
Ejemplo n.º 5
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            Debug.WriteLine("ClearPayment started");
            EfCoreContext.DbPath = DatabaseConstants.DB_NAME;
            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            try
            {
                var context = new EfCoreContext();
                await new ClearPaymentAction(new ClearPaymentDbAccess(context))
                .ClearPayments()
                .ConfigureAwait(false);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
                Debug.Write(ex);
                Debug.WriteLine("ClearPaymentTask stopped due to an error.");
            } finally
            {
                settingsFacade.LastExecutionTimeStampClearPayments = DateTime.Now;
                Debug.WriteLine("ClearPaymentTask finished.");
                deferral.Complete();
            }
        }
Ejemplo n.º 6
0
        private async Task SyncBackups(JobParameters args)
        {
            if (!Mvx.IoCProvider.CanResolve <IMvxFileStore>())
            {
                return;
            }

            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            try
            {
                EfCoreContext.DbPath =
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                 DatabaseConstants.DB_NAME);

                var backupManager = new BackupManager(
                    new OneDriveService(new OneDriveAuthenticator()),
                    Mvx.IoCProvider.Resolve <IMvxFileStore>(),
                    new ConnectivityAdapter());

                var backupService = new BackupService(backupManager, settingsFacade);
                await backupService.RestoreBackup();

                JobFinished(args, false);
            }
            catch (Exception ex)
            {
                Debug.Write(ex);
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
            }
        }
Ejemplo n.º 7
0
        private async Task ClearPaymentsAsync()
        {
            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            try
            {
                taskInstance.Progress = 10;

                var mediator = ServiceLocator.Current.GetInstance <IMediator>();
                await mediator.Send(new ClearPaymentsCommand());

                taskInstance.Progress = 100;
            }
            catch (Exception ex)
            {
                logManager.Error(ex, "ClearPaymentTask stopped due to an error.");
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampClearPayments = DateTime.Now;
                logManager.Debug("ClearPaymentTask finished.");
            }

            deferral?.Complete();
        }
Ejemplo n.º 8
0
        private async Task SyncBackup()
        {
            if (!Mvx.IoCProvider.CanResolve <IMvxFileStore>())
            {
                return;
            }

            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            try
            {
                EfCoreContext.DbPath = GetLocalFilePath();

                var backupManager = new BackupManager(
                    new OneDriveService(new OneDriveAuthenticator()),
                    Mvx.IoCProvider.Resolve <IMvxFileStore>(),
                    new ConnectivityAdapter());

                var backupService = new BackupService(backupManager, settingsFacade);
                await backupService.RestoreBackup()
                .ConfigureAwait(true);
            } catch (Exception ex)
            {
                Debug.Write(ex);
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
            }
        }
Ejemplo n.º 9
0
        private async Task SyncBackupAsync()
        {
            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            if (!settingsFacade.IsBackupAutouploadEnabled || !settingsFacade.IsLoggedInToBackupService)
            {
                return;
            }

            try
            {
                var backupService = ServiceLocator.Current.GetInstance <IBackupService>();
                await backupService.RestoreBackupAsync();

                var mediator = ServiceLocator.Current.GetInstance <IMediator>();
                await mediator.Send(new ClearPaymentsCommand());

                await mediator.Send(new CreateRecurringPaymentsCommand());
            }
            catch (Exception ex)
            {
                logManager.Error(ex, "Sync Backup Failed.");
                Debug.Write(ex);
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
            }
        }
Ejemplo n.º 10
0
        public async Task RunAsync(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            logManager.Debug("Sync Backup started.");

            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            if (!settingsFacade.IsBackupAutouploadEnabled || !settingsFacade.IsLoggedInToBackupService)
            {
                return;
            }

            try
            {
                var backupService = ServiceLocator.Current.GetInstance <IBackupService>();
                await backupService.RestoreBackupAsync();
            }
            catch (Exception ex)
            {
                logManager.Error(ex, "Sync Backup failed.");
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
                logManager.Debug("Sync Backup finished.");
                deferral.Complete();
            }
        }
Ejemplo n.º 11
0
        private async Task CheckRecurringPayments(JobParameters args)
        {
            var settingsManager = new SettingsFacade(new SettingsAdapter());

            try
            {
                Debug.WriteLine("RecurringPayment Job started.");
                ExecutingPlatform.Current = AppPlatform.Android;

                var context = new EfCoreContext();
                await new RecurringPaymentAction(new RecurringPaymentDbAccess(context)).CreatePaymentsUpToRecur();
                context.SaveChanges();

                Debug.WriteLine("RecurringPayment Job finished.");
                JobFinished(args, false);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
            finally
            {
                settingsManager.LastExecutionTimeStampRecurringPayments = DateTime.Now;
            }
        }
Ejemplo n.º 12
0
        private async Task SynBackupAsync()
        {
            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            if (!settingsFacade.IsBackupAutouploadEnabled || !settingsFacade.IsLoggedInToBackupService)
            {
                return;
            }

            try
            {
                taskInstance.Progress = 10;

                var backupService = ServiceLocator.Current.GetInstance <IBackupService>();
                await backupService.RestoreBackupAsync();

                taskInstance.Progress = 100;
            }
            catch (Exception ex)
            {
                logManager.Error(ex, "Sync Backup failed.");
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
                logManager.Debug("Sync Backup finished.");
            }
            deferral?.Complete();
        }
Ejemplo n.º 13
0
        public App()
        {
            Xamarin.Forms.Device.SetFlags(new[] {
                "AppTheme_Experimental",
                "SwipeView_Experimental"
            });

            App.Current.UserAppTheme = App.Current.RequestedTheme != OSAppTheme.Unspecified
                ? App.Current.RequestedTheme
                : OSAppTheme.Dark;

            App.Current.RequestedThemeChanged += (s, a) =>
            {
                App.Current.UserAppTheme = a.RequestedTheme;
            };

            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            CultureHelper.CurrentCulture = new CultureInfo(settingsFacade.DefaultCulture);

            InitializeComponent();
            MainPage = new AppShell();

            if (!settingsFacade.IsSetupCompleted)
            {
#pragma warning disable S4462 // Calls to "async" methods should not be blocking
                Shell.Current.GoToAsync(ViewModelLocator.WelcomeViewRoute).Wait();
#pragma warning restore S4462 // Calls to "async" methods should not be blocking
            }
        }
Ejemplo n.º 14
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            Debug.WriteLine("Sync Backup started.");
            EfCoreContext.DbPath = DatabaseConstants.DB_NAME;
            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            try
            {
                var backupManager = new BackupManager(
                    new OneDriveService(new OneDriveAuthenticator()),
                    new MvxWindowsFileStore(),
                    new ConnectivityAdapter());

                var backupService = new BackupService(backupManager, settingsFacade);

                await backupService.RestoreBackup()
                .ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Debug.WriteLine("Sync Backup failed.");
            }
            finally
            {
                Debug.WriteLine("Sync Backup finished.");
                deferral.Complete();
            }
        }
Ejemplo n.º 15
0
        private async Task SyncBackupsAsync(JobParameters args)
        {
            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            if (!settingsFacade.IsBackupAutouploadEnabled || !settingsFacade.IsLoggedInToBackupService)
            {
                return;
            }

            try
            {
                var backupService = ServiceLocator.Current.GetInstance <IBackupService>();
                await backupService.RestoreBackupAsync();

                var mediator = ServiceLocator.Current.GetInstance <IMediator>();
                await mediator.Send(new ClearPaymentsCommand());

                await mediator.Send(new CreateRecurringPaymentsCommand());

                logger.Info("Backup synced.");
                JobFinished(args, false);
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
                throw;
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
            }
        }
Ejemplo n.º 16
0
        public App()
        {
            Locator.CurrentMutable.RegisterLazySingleton(() => new SettingsFacade(), typeof(SettingsFacade));
            Locator.CurrentMutable.RegisterLazySingleton(() => new ADFacade(), typeof(ADFacade));
            Locator.CurrentMutable.RegisterConstant(new FileLoggerService(), typeof(ILogger));

            this.Log().Info("Application start");

            RxApp.DefaultExceptionHandler = Observer.Create <Exception>(
                error =>
            {
                this.Log().ErrorException("Application failure", error);
                Shutdown();
            },
                error =>
            {
                this.Log().ErrorException("Application failure failure", error);
                Shutdown();
            },
                () =>
            {
                this.Log().Info("Exception handler completed");
                Shutdown();
            });

            this.Events()
            .Exit
            .Subscribe(_ => SettingsFacade.Shutdown());
        }
Ejemplo n.º 17
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            Debug.WriteLine("ClearPayment started");
            ExecutingPlatform.Current = AppPlatform.UWP;

            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            try
            {
                var context = EfCoreContextFactory.Create();
                await new ClearPaymentAction(new ClearPaymentDbAccess(context))
                .ClearPayments();
                await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                Debug.Write(ex);
                Debug.WriteLine("ClearPaymentTask stopped due to an error.");
            } finally
            {
                settingsFacade.LastExecutionTimeStampClearPayments = DateTime.Now;
                Debug.WriteLine("ClearPaymentTask finished.");
                deferral.Complete();
            }
        }
Ejemplo n.º 18
0
        public BaseService()
        {
            ISettingsFileAccess fileAccess = new SettingsFileAccess();
            SettingsFacade      facade     = new SettingsFacade(fileAccess);

            _settings = facade.GetSettings();
        }
Ejemplo n.º 19
0
        public void Ctor_DefaultValues_LastExecutionTimeStampSyncBackupMinDate()
        {
            // Arrange

            // Act
            var settingsfacade = new SettingsFacade(settingsAdapter);

            // Assert
            settingsfacade.LastExecutionTimeStampSyncBackup.ShouldEqual(DateTime.MinValue);
        }
Ejemplo n.º 20
0
        public void Ctor_DefaultValues_BackupSyncRecurrenceThreeHours()
        {
            // Arrange

            // Act
            var settingsfacade = new SettingsFacade(settingsAdapter);

            // Assert
            settingsfacade.BackupSyncRecurrence.ShouldEqual(3);
        }
Ejemplo n.º 21
0
        public void Ctor_DefaultValues_IsLoggedInToBackupServiceFalse()
        {
            // Arrange

            // Act
            var settingsfacade = new SettingsFacade(settingsAdapter);

            // Assert
            settingsfacade.IsLoggedInToBackupService.ShouldBeFalse();
        }
Ejemplo n.º 22
0
        public void Ctor_DefaultValues_ThemeLight()
        {
            // Arrange

            // Act
            var settingsfacade = new SettingsFacade(settingsAdapter);

            // Assert
            settingsfacade.Theme.ShouldEqual(AppTheme.Light);
        }
Ejemplo n.º 23
0
        public void Ctor_DefaultValues_LastDatabaseUpdateMinDate()
        {
            // Arrange

            // Act
            var settingsfacade = new SettingsFacade(settingsAdapter);

            // Assert
            settingsfacade.LastDatabaseUpdate.ShouldEqual(DateTime.MinValue);
        }
Ejemplo n.º 24
0
        public void Ctor_DefaultValues_PasswordRequiredFalse()
        {
            // Arrange

            // Act
            var settingsfacade = new SettingsFacade(settingsAdapter);

            // Assert
            settingsfacade.PasswordRequired.ShouldBeFalse();
        }
Ejemplo n.º 25
0
        public void Ctor_DefaultValues_SessionTimestampEmpty()
        {
            // Arrange

            // Act
            var settingsfacade = new SettingsFacade(settingsAdapter);

            // Assert
            settingsfacade.SessionTimestamp.ShouldBeEmpty();
        }
Ejemplo n.º 26
0
        public void Ctor_DefaultValues_IsBackupAutouploadEnabledFalse()
        {
            // Arrange

            // Act
            var settingsfacade = new SettingsFacade(settingsAdapter);

            // Assert
            settingsfacade.IsBackupAutouploadEnabled.ShouldBeFalse();
        }
Ejemplo n.º 27
0
        private async Task SyncBackups(JobParameters args)
        {
            if (!Mvx.IoCProvider.CanResolve <IMvxFileStore>())
            {
                return;
            }

            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            if (!settingsFacade.IsBackupAutouploadEnabled || !settingsFacade.IsLoggedInToBackupService)
            {
                return;
            }

            try
            {
                EfCoreContext.DbPath =
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                 DatabaseConstants.DB_NAME);

                var pca = PublicClientApplicationBuilder
                          .Create(ServiceConstants.MSAL_APPLICATION_ID)
                          .WithRedirectUri($"msal{ServiceConstants.MSAL_APPLICATION_ID}://auth")
                          .Build();

                var backupManager = new BackupManager(
                    new OneDriveService(pca),
                    Mvx.IoCProvider.Resolve <IMvxFileStore>(),
                    new ConnectivityAdapter());

                var backupService = new BackupService(backupManager, settingsFacade);

                var backupDate = await backupService.GetBackupDate();

                if (settingsFacade.LastDatabaseUpdate > backupDate)
                {
                    return;
                }

                await backupService.RestoreBackup();

                JobFinished(args, false);
            } catch (Exception ex)
            {
                Debug.Write(ex);
            } finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
            }
        }
Ejemplo n.º 28
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var deferral = taskInstance.GetDeferral();

            Debug.WriteLine("Sync Backup started.");
            ExecutingPlatform.Current = AppPlatform.UWP;

            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            if (!settingsFacade.IsBackupAutouploadEnabled || !settingsFacade.IsLoggedInToBackupService)
            {
                return;
            }

            try
            {
                var pca = PublicClientApplicationBuilder
                          .Create(ServiceConstants.MSAL_APPLICATION_ID)
                          .WithRedirectUri($"msal{ServiceConstants.MSAL_APPLICATION_ID}://auth")
                          .Build();

                var backupManager = new BackupManager(
                    new OneDriveService(pca),
                    new WindowsFileStore(),
                    new ConnectivityAdapter());

                var backupService = new BackupService(backupManager, settingsFacade);

                var backupDate = await backupService.GetBackupDate();

                if (settingsFacade.LastDatabaseUpdate > backupDate)
                {
                    return;
                }

                await backupService.RestoreBackup();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Debug.WriteLine("Sync Backup failed.");
            }
            finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
                Debug.WriteLine("Sync Backup finished.");
                deferral.Complete();
            }
        }
Ejemplo n.º 29
0
        public void SettingsTest_ReadSettings()
        {
            ISettingsFileAccess fileAccess = new SettingsFileAccess();  //Do I need mock version ?
            SettingsFacade      facade     = new SettingsFacade(fileAccess);
            Settings            settings   = facade.GetSettings();

            Assert.AreEqual("https://api.spotify.com/v1", settings.Spotify.ApiBaseUrl);
            Assert.AreEqual("https://accounts.spotify.com/api/token", settings.Spotify.AuthKeyUrl);
            Assert.AreEqual("*****@*****.**", settings.Spotify.UserId);
            Assert.AreEqual("773d6796930f47ccbbc2a0b7a248f666", settings.Spotify.ClientId);
            Assert.AreEqual("https://www.shazam.com", settings.Shazam.BaseUrl);

            Assert.IsNotEmpty(settings.Spotify.AuthToken.AccessToken);
            Assert.IsNotEmpty(settings.Spotify.AuthToken.RefreshToken);
            Assert.IsNotEmpty(settings.Spotify.AuthToken.TokenType);
        }
Ejemplo n.º 30
0
        private async Task SyncBackup()
        {
            if (!Mvx.IoCProvider.CanResolve <IMvxFileStore>())
            {
                return;
            }

            var settingsFacade = new SettingsFacade(new SettingsAdapter());

            if (!settingsFacade.IsBackupAutouploadEnabled || !settingsFacade.IsLoggedInToBackupService)
            {
                return;
            }

            try
            {
                EfCoreContext.DbPath = GetLocalFilePath();

                var pca = PublicClientApplicationBuilder
                          .Create(ServiceConstants.MSAL_APPLICATION_ID)
                          .WithRedirectUri($"msal{ServiceConstants.MSAL_APPLICATION_ID}://auth")
                          .WithIosKeychainSecurityGroup("com.microsoft.adalcache")
                          .Build();

                var backupManager = new BackupManager(
                    new OneDriveService(pca),
                    Mvx.IoCProvider.Resolve <IMvxFileStore>(),
                    new ConnectivityAdapter());

                var backupService = new BackupService(backupManager, settingsFacade);

                var backupDate = await backupService.GetBackupDate();

                if (settingsFacade.LastDatabaseUpdate > backupDate)
                {
                    return;
                }

                await backupService.RestoreBackup();
            } catch (Exception ex)
            {
                Debug.Write(ex);
            } finally
            {
                settingsFacade.LastExecutionTimeStampSyncBackup = DateTime.Now;
            }
        }
 public override void TestInit()
 {
     this.user = new TestUser();
     this.SettingsFacade = new SettingsFacade();
 }