예제 #1
0
 void Create(DataStoreContext store)
 {
     store.CreateDatabase();
     var schemaUpdater = store.CreateDatabaseSchemaUpdater();
     schemaUpdater.DatabaseSchemaVersion = CURRENT_VERSION;
     schemaUpdater.Execute();
 }
예제 #2
0
파일: Updater.cs 프로젝트: cpmcgrath/Bankr
        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()
                });
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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;
        }
예제 #5
0
        public LoginViewModel()
        {
            using (var store = new DataStoreContext())
                Username = store.LoginDetails.First().Username;

            Username = "******" + Username.Substring(Username.Length - 3);
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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();
        }
예제 #8
0
 public void Load(int id)
 {
     Existing = true;
     using (var store = new DataStoreContext())
     {
         Data = store.Replacements.First(x => x.Id == id);
     }
 }
예제 #9
0
 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);
 }
예제 #11
0
 public ReplacementsViewModel(INavigationService navigationService)
     : base(navigationService)
 {
     using (var store = new DataStoreContext())
     {
         Replacements = store.Replacements.OrderByDescending(x => x.Id).ToArray();
     }
 }
예제 #12
0
        protected override void OnLoad()
        {
            using (var store = new DataStoreContext())
            {
                YourAccounts = store.Accounts.ToArray();
            }

            FirePropertyChanged(() => YourAccounts);
        }
예제 #13
0
 public bool Login()
 {
     using (var store = new DataStoreContext())
     {
         var hash   = store.LoginDetails.First().Password;
         var actual = new TwoWayEncryption().Decrypt(hash);
         return Password == actual;
     }
 }
예제 #14
0
 void OnLogonFailed()
 {
     using (var store = new DataStoreContext())
     {
         store.LoginDetails.DeleteAllOnSubmit(store.LoginDetails);
         store.SubmitChanges();
     }
     Status.SetAction("Error occured while trying to log on", true);
 }
예제 #15
0
        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 ", "");
            }
        }
예제 #16
0
        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();
        }
예제 #17
0
        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();
        }
예제 #18
0
        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();
        }
예제 #19
0
        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;
            }
        }
예제 #20
0
        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);
            }
        }
예제 #22
0
파일: Updater.cs 프로젝트: cpmcgrath/Bankr
        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;
        }
예제 #23
0
 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();
 }
예제 #24
0
파일: Updater.cs 프로젝트: cpmcgrath/Bankr
        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;
        }
예제 #25
0
        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();
        }
예제 #26
0
파일: App.xaml.cs 프로젝트: cpmcgrath/Bankr
        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;
        }
예제 #27
0
        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();
        }
예제 #28
0
        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();
        }
예제 #29
0
        public void MarkAsSeen()
        {
            using (var store = new DataStoreContext())
            {
                foreach (var transaction in store.Transactions)
                    transaction.IsSeen = true;

                store.SubmitChanges();
            }
            Load();
        }
예제 #30
0
        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();
        }