public async Task LoadAsync(ApplicationDatabase applicationDatabase) { this.matchingRules.Clear(); this.matchingRulesGroupedByBucket.Clear(); this.rulesStorageKey = applicationDatabase.FullPath(applicationDatabase.MatchingRulesCollectionStorageKey); List <MatchingRule> repoRules; try { repoRules = (await this.ruleRepository.LoadAsync(this.rulesStorageKey, applicationDatabase.IsEncrypted)) .OrderBy(r => r.Description) .ToList(); } catch (FileNotFoundException) { // If file not found occurs here, assume this is the first time the app has run, and create a new one. this.rulesStorageKey = await BuildDefaultFileName(); repoRules = this.ruleRepository.CreateNew().ToList(); } InitialiseTheRulesCollections(repoRules); this.monitorableDependencies.NotifyOfDependencyChange <ITransactionRuleService>(this); NewDataSourceAvailable?.Invoke(this, EventArgs.Empty); }
public async Task LoadAsync(ApplicationDatabase applicationDatabase) { if (applicationDatabase == null) { throw new ArgumentNullException(nameof(applicationDatabase)); } Budgets = await this.budgetRepository.LoadAsync(applicationDatabase.FullPath(applicationDatabase.BudgetCollectionStorageKey), applicationDatabase.IsEncrypted); UpdateServiceMonitor(); NewDataSourceAvailable?.Invoke(this, EventArgs.Empty); }
public async Task LoadAsync(ApplicationDatabase applicationDatabase) { if (applicationDatabase == null) { throw new ArgumentNullException(nameof(applicationDatabase)); } LedgerBook = await this.ledgerRepository.LoadAsync(applicationDatabase.FullPath(applicationDatabase.LedgerBookStorageKey), applicationDatabase.IsEncrypted); this.monitorableDependencies.NotifyOfDependencyChange(LedgerBook); NewDataSourceAvailable?.Invoke(this, EventArgs.Empty); }
public async Task SaveAsync(ApplicationDatabase applicationDatabase) { Saving?.Invoke(this, new AdditionalInformationRequestedEventArgs()); var messages = new StringBuilder(); if (!LedgerBook.Validate(messages)) { throw new ValidationWarningException("Ledger Book is invalid, cannot save at this time:\n" + messages); } await this.ledgerRepository.SaveAsync(LedgerBook, applicationDatabase.FullPath(applicationDatabase.LedgerBookStorageKey), applicationDatabase.IsEncrypted); this.monitorableDependencies.NotifyOfDependencyChange(LedgerBook); Saved?.Invoke(this, EventArgs.Empty); }
public async Task SaveAsync(ApplicationDatabase applicationDatabase) { var messages = new StringBuilder(); if (ValidateModel(messages)) { // Prefer to use the file name from the applicationDatabase in case it has been changed upstream. await this.ruleRepository.SaveAsync(MatchingRules, applicationDatabase.FullPath(applicationDatabase.MatchingRulesCollectionStorageKey), applicationDatabase.IsEncrypted); } else { throw new ValidationWarningException("Unable to save matching rules at this time, some data is invalid.\n" + messages); } this.monitorableDependencies.NotifyOfDependencyChange <ITransactionRuleService>(this); Saved?.Invoke(this, EventArgs.Empty); }
public async Task SaveAsync(ApplicationDatabase applicationDatabase) { EnsureAllBucketsUsedAreInBucketRepo(); var messages = new StringBuilder(); if (Budgets.Validate(messages)) { await this.budgetRepository.SaveAsync(applicationDatabase.FullPath(applicationDatabase.BudgetCollectionStorageKey), applicationDatabase.IsEncrypted); var savedHandler = Saved; savedHandler?.Invoke(this, EventArgs.Empty); return; } this.logger.LogWarning(l => l.Format("BudgetMaintenanceService.Save: unable to save due to validation errors:\n{0}", messages)); throw new ValidationWarningException("Unable to save Budget:\n" + messages); }
/// <summary> /// Loads a data source with the provided database reference data asynchronously. /// </summary> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="DataFormatException">Statement Model data is corrupt and has been tampered with. Unable to load.</exception> public async Task LoadAsync(ApplicationDatabase applicationDatabase) { if (applicationDatabase == null) { throw new ArgumentNullException(nameof(applicationDatabase)); } StatementModel?.Dispose(); try { StatementModel = await this.statementRepository.LoadAsync(applicationDatabase.FullPath(applicationDatabase.StatementModelStorageKey), applicationDatabase.IsEncrypted); } catch (StatementModelChecksumException ex) { throw new DataFormatException("Statement Model data is corrupt and has been tampered with. Unable to load.", ex); } NewDataAvailable(); }
/// <summary> /// Saves the application database asynchronously. This may be called using a background worker thread. /// </summary> /// <exception cref="ValidationWarningException"> /// Unable to save transactions at this time, some data is invalid. + /// messages /// </exception> public async Task SaveAsync(ApplicationDatabase applicationDatabase) { if (StatementModel == null) { return; } EventHandler <AdditionalInformationRequestedEventArgs> handler = Saving; handler?.Invoke(this, new AdditionalInformationRequestedEventArgs()); var messages = new StringBuilder(); if (!ValidateModel(messages)) { throw new ValidationWarningException("Unable to save transactions at this time, some data is invalid. " + messages); } StatementModel.StorageKey = applicationDatabase.FullPath(applicationDatabase.StatementModelStorageKey); await this.statementRepository.SaveAsync(StatementModel, applicationDatabase.IsEncrypted); this.monitorableDependencies.NotifyOfDependencyChange(StatementModel); Saved?.Invoke(this, EventArgs.Empty); }