void Create(DataStoreContext store) { store.CreateDatabase(); var schemaUpdater = store.CreateDatabaseSchemaUpdater(); schemaUpdater.DatabaseSchemaVersion = CURRENT_VERSION; schemaUpdater.Execute(); }
public void UpdateLiveTile() { using (var store = new DataStoreContext()) { var account = store.CurrentOptions.GetSelectedAccount(store); if (account == null) return; string amount = account.AccountAmount.ToString("$0.00"); var tile = ShellTile.ActiveTiles.First(); var count = account.TransactionList.Count(x => !x.IsSeen); var transactions = store.UpcomingTransactions.OrderBy(x => x.EffectiveDate).Select(x => x.Summary).ToArray(); tile.Update(new IconicTileData { Title = amount, Count = count, WideContent1 = "Upcoming Transactions", WideContent2 = transactions.FirstOrDefault(), WideContent3 = transactions.Skip(1).FirstOrDefault() }); } }
protected override void ProcessResult(string response, bool hasError) { var result = JsonConvert.DeserializeObject<Account>(response); using (var store = new DataStoreContext()) { var account = store.Accounts.FirstOrDefault(x => x.AccountNumber == result.AccountNumber); var toDelete = account.TransactionList.Where(x => !AlreadyExists(result .Transactions, x)).ToArray(); var transactions = result .Transactions .Where(x => !AlreadyExists(account.TransactionList, x)).ToArray(); store.Transactions.DeleteAllOnSubmit(toDelete); foreach (var transaction in transactions.Reverse()) account.TransactionList.Add(transaction); store.SubmitChanges(); var action = transactions.Length + " new transactions found."; string more; if (transactions.Length == 1) more = string.Format("${0:0.00} {1}", transactions[0].AbsAmount, transactions[0].Summary); else { decimal amount = transactions.Sum(x => x.Amount); more = string.Format("Totalling ${0:0.00} {1}.", Math.Abs(amount), amount > 0 ? "in" : "out"); } Status.SetImportantAction(action, more, true); var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); } }
void UpdateAccounts(string message) { var result = JsonConvert.DeserializeObject<LoginResult>(message); using (var store = new DataStoreContext()) { foreach (var account in result.AccountGroups.SelectMany(x => x.ListAccount)) { account.LastUpdate = DateTime.Now; var original = store.Accounts.FirstOrDefault(x => x.AccountNumber == account.AccountNumber); if (original == null) store.Accounts.InsertOnSubmit(account); else { original.Balance = account.Balance; original.AvailableFunds = account.AvailableFunds; original.LastUpdate = account.LastUpdate; } } store.SubmitChanges(); } SessionId = result.SID; }
public LoginViewModel() { using (var store = new DataStoreContext()) Username = store.LoginDetails.First().Username; Username = "******" + Username.Substring(Username.Length - 3); }
protected override void ProcessResult(string response, bool hasError) { var result = JsonConvert.DeserializeObject<TransferAccountResult>(response); foreach (var account in result.AccountsToLinked) { account.Type = TransferToAccount.AccountType.Linked; account.SenderId = result.AccountsFrom.Where(x => x.AccountNumber == account.AccountNumber).Select(x => x.Id).FirstOrDefault(); } foreach (var account in result.AccountsToNotLinked) account.Type = TransferToAccount.AccountType.ThirdParty; var accounts = result.AccountsToLinked.Union(result.AccountsToNotLinked); foreach (var account in accounts.Where(x => x.LastUsed == DateTime.MinValue)) account.LastUsed = new DateTime(2000, 1, 1); using (var store = new DataStoreContext()) { var inDatabase = store.TransferToAccounts.ToArray(); var toDelete = inDatabase.Where(x => !AlreadyExists(accounts, x)).ToArray(); var toInsert = accounts.Where(x => !AlreadyExists(inDatabase, x)).ToArray(); store.TransferToAccounts.DeleteAllOnSubmit(toDelete); store.TransferToAccounts.InsertAllOnSubmit(toInsert); store.SubmitChanges(); Status.SetAction("Accounts loaded", true); } }
public void Upgrade(DataStoreContext store) { if (!store.DatabaseExists()) { Create(store); return; } var schema = store.CreateDatabaseSchemaUpdater(); int version = schema.DatabaseSchemaVersion; switch (version) { case 0 : schema.AddColumn<Options>("AutoRefresh"); goto case 1; case 1 : schema.AddTable<UpcomingTransaction>(); goto case 2; case 2 : schema.AddColumn<LoginDetails>("Pin"); goto case 3; case 3 : schema.AddTable<TransferToAccount>(); goto case 4; case 4 : schema.AddColumn<TransferToAccount>("SenderId"); goto case 5; case 5 : schema.AddTable<ScreenSecurity>(); break; default : return; } schema.DatabaseSchemaVersion = CURRENT_VERSION; schema.Execute(); }
public void Load(int id) { Existing = true; using (var store = new DataStoreContext()) { Data = store.Replacements.First(x => x.Id == id); } }
protected override void OnLoad() { using (var store = new DataStoreContext()) { FromAccount = store.Accounts.First(x => x.Id == FromAccountId); ToAccount = store.TransferToAccounts.First(x => x.Id == ToAccountId); } }
void Load() { using (var store = new DataStoreContext()) { Transactions = store.UpcomingTransactions.OrderBy(x => x.EffectiveDate).ToArray(); } FirePropertyChanged(() => Transactions); }
public ReplacementsViewModel(INavigationService navigationService) : base(navigationService) { using (var store = new DataStoreContext()) { Replacements = store.Replacements.OrderByDescending(x => x.Id).ToArray(); } }
protected override void OnLoad() { using (var store = new DataStoreContext()) { YourAccounts = store.Accounts.ToArray(); } FirePropertyChanged(() => YourAccounts); }
public bool Login() { using (var store = new DataStoreContext()) { var hash = store.LoginDetails.First().Password; var actual = new TwoWayEncryption().Decrypt(hash); return Password == actual; } }
void OnLogonFailed() { using (var store = new DataStoreContext()) { store.LoginDetails.DeleteAllOnSubmit(store.LoginDetails); store.SubmitChanges(); } Status.SetAction("Error occured while trying to log on", true); }
public void Create(int transactionId) { Data = new Replacement(); using (var store = new DataStoreContext()) { var transaction = store.Transactions.First(x => x.Id == transactionId); Data.Original = transaction.Summary.Replace("Sent to ", "").Replace("Received from ", ""); } }
public void Save() { using (var store = new DataStoreContext()) { store.ScreenSecurity.DeleteAllOnSubmit(store.ScreenSecurity.ToArray()); store.SubmitChanges(); store.ScreenSecurity.InsertAllOnSubmit(Items.Where(x => x.AccessLevel != AccessLevel.None)); store.SubmitChanges(); } App.Current.Security.LoadFromDatabase(); Navigator.GoBack(); }
public void Save() { var encryptedPin = new TwoWayEncryption().Encrypt(Pin); using (var store = new DataStoreContext()) { var details = store.LoginDetails.First(); details.Pin = encryptedPin; store.SubmitChanges(); } Navigator.GoBack(); }
public void Delete() { if (!Existing) return; using (var store = new DataStoreContext()) { var data = store.Replacements.First(x => x.Id == Data.Id); store.Replacements.DeleteOnSubmit(data); store.SubmitChanges(); } Navigator.GoBack(); }
protected override bool CanRun() { using (var store = new DataStoreContext()) { bool hasAccount = store.Options.Any(); if (hasAccount) m_accountId = store.CurrentOptions.SelectedAccountId; else Status.SetAction("Account not set.", true); return hasAccount; } }
public OptionsViewModel(INavigationService navigationService) : base(navigationService) { AutoRefresh = true; using (var store = new DataStoreContext()) { Accounts = store.Accounts.ToArray(); if (store.Options.Any()) { SelectedAccount = store.CurrentOptions.GetSelectedAccount(store); AutoRefresh = store.CurrentOptions.AutoRefresh; } } }
protected override void ProcessResult(string response, bool hasError) { var result = JsonConvert.DeserializeObject<UpcomingTransResult>(response); using (var store = new DataStoreContext()) { var toDelete = store.UpcomingTransactions.ToArray().Where(x => !AlreadyExists(result.Transactions, x)); var toInsert = result.Transactions.Where(x => !AlreadyExists(store.UpcomingTransactions, x)).ToArray(); store.UpcomingTransactions.DeleteAllOnSubmit(toDelete); store.UpcomingTransactions.InsertAllOnSubmit(toInsert); store.SubmitChanges(); Status.SetAction("Upcoming transactions found.", true); } }
public bool Refresh(DataStoreContext store, Action afterUpdate) { var retriever = new DataRetriever { Status = new AppStatus { UseToast = true } }; retriever.Callback = () => { UpdateLiveTile(); afterUpdate.Invoke(); }; bool canLoad = retriever.CanLoadData; if (canLoad) retriever.LoadData(); return canLoad; }
public void Save() { using (var store = new DataStoreContext()) { if (Existing) { var data = store.Replacements.First(x => x.Id == Data.Id); data.Original = Data.Original; data.NewValue = Data.NewValue; } else store.Replacements.InsertOnSubmit(Data); store.SubmitChanges(); Existing = true; } Navigator.GoBack(); }
public bool Update(Action afterUpdate) { using (var store = new DataStoreContext()) { bool autoRefresh = store.CurrentOptions.AutoRefresh; var account = store.CurrentOptions.GetSelectedAccount(store); bool hasLogon = store.LoginDetails.Any(); if (account == null || !hasLogon) { SetLiveTileToError(); return false; } var sinceUpdate = DateTime.Now - account.LastUpdate; if (sinceUpdate > TimeSpan.FromMinutes(45) && autoRefresh) return Refresh(store, afterUpdate); } return false; }
void GlobalUnhandledExceptionHandler(object sender, ApplicationUnhandledExceptionEventArgs e) { if (Debugger.IsAttached) Debugger.Break(); var error = new Error { Time = DateTime.Now, Message = e.ExceptionObject.Message, Extended = e.ExceptionObject.ToVerboseString() }; using (var store = new DataStoreContext()) { store.Errors.InsertOnSubmit(error); store.SubmitChanges(); } e.Handled = true; NotifyComplete(); }
void GlobalUnhandledExceptionHandler(object sender, ApplicationUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); var error = new Error { Time = DateTime.Now, Message = e.ExceptionObject.Message, Extended = e.ExceptionObject.ToVerboseString() }; using (var store = new DataStoreContext()) { store.Errors.InsertOnSubmit(error); store.SubmitChanges(); } Status.SetAction("Unknown error occurred", true); e.Handled = true; }
public void SendErrorReport() { string message = ""; using (var store = new DataStoreContext()) { if (!store.Errors.Any()) return; message = store.Errors.ToArray().Select(x => x.ToString()).Aggregate((a, b) => a + "\n-----------\n\n" + b); store.Errors.DeleteAllOnSubmit(store.Errors); store.SubmitChanges(); } var emailComposeTask = new EmailComposeTask { Subject = "Bankr Error Report", Body = message, To = "*****@*****.**", }; emailComposeTask.Show(); }
public void Save() { if (SelectedAccount == null) return; using (var store = new DataStoreContext()) { if (store.Options.Any()) { store.CurrentOptions.SelectedAccountId = SelectedAccount.Id; store.CurrentOptions.AutoRefresh = AutoRefresh; } else store.Options.InsertOnSubmit(new Data.Options { SelectedAccountId = SelectedAccount.Id, AutoRefresh = AutoRefresh }); store.SubmitChanges(); var account = store.CurrentOptions.GetSelectedAccount(store); account.UseAvailableFunds = SelectedAccount.UseAvailableFunds; account.CreditLimit = SelectedAccount.CreditLimit; store.SubmitChanges(); } Navigator.GoBack(); }
public void MarkAsSeen() { using (var store = new DataStoreContext()) { foreach (var transaction in store.Transactions) transaction.IsSeen = true; store.SubmitChanges(); } Load(); }
void Load() { using (var store = new DataStoreContext()) { Account = store.CurrentOptions.GetSelectedAccount(store); AutoRefresh = store.CurrentOptions.AutoRefresh; m_allTransactions = store.Transactions.OrderByDescending(x => x.Id).ToArray(); var replacements = store.Replacements.ToArray(); foreach (var transaction in m_allTransactions) transaction.Replacements = replacements; } Refresh(); new Updater().UpdateLiveTile(); }