private void Update() { if (PrimaryBankAccount == null && BankAccounts.Count() > 0) { BankAccounts.First(); } }
private void Start() { if (BankAccounts.Count() > 0) { PrimaryBankAccount = BankAccounts.First(); } else { PrimaryBankAccount = The.DefaultBank.OpenBankAccount(this); } }
public override void DialogOkClicked() { // copy selected accounts to entity.CashflowBankAccounts // need to copy incrementally // then check this in repo if (this.AllAccounts) { entity.CashflowBankAccounts.Clear(); } else { // add new accounts this.BankAccounts.Where(a => a.IsSelected).ToList().ForEach(s => { if (entity.CashflowBankAccounts.Count(e => e.BankAccount.BankAccountId == s.BankAccountId) == 0) { entity.CashflowBankAccounts.Add(new CashflowBankAccount() { BankAccount = allBankAccounts[s.BankAccountId] }); } } ); // remove deleted accounts entity.CashflowBankAccounts.ToList().ForEach(e => { if (BankAccounts.Count(a => a.BankAccountId == e.BankAccount.BankAccountId && a.IsSelected) == 0) { entity.CashflowBankAccounts.Remove(e); } } ); } }
public async Task SquashJournalAsync() { int bankAccountCount = BankAccounts.Count(); bool responsibleForTurningBackupsBackOn = false; Console.WriteLine(SEconomyPlugin.Locale.StringOrDefault(81, "seconomy xml: beginning Squash")); if (SEconomyInstance.RunningJournal.BackupsEnabled == true) { SEconomyInstance.RunningJournal.BackupsEnabled = false; responsibleForTurningBackupsBackOn = true; } for (int i = 0; i < bankAccountCount; i++) { IBankAccount account = BankAccounts.ElementAtOrDefault(i); if (account == null) { continue; } // Add the squished summary ITransaction squash = new XmlTransaction(account) { Amount = account.Transactions.Sum(x => x.Amount), Flags = BankAccountTransactionFlags.FundsAvailable | BankAccountTransactionFlags.Squashed, TransactionDateUtc = DateTime.UtcNow, Message = "Transaction squash" }; account.Transactions.Clear(); account.AddTransaction(squash); } //abandon the old journal and assign the squashed one Console.WriteLine(SEconomyPlugin.Locale.StringOrDefault(82, "re-syncing online accounts.")); foreach (TSPlayer player in TShockAPI.TShock.Players) { IBankAccount account = null; if (player == null || SEconomyPlugin.Instance == null || (account = SEconomyPlugin.Instance.GetBankAccount(player)) == null) { return; } Console.WriteLine("re-syncing {0}", player.Name); await account.SyncBalanceAsync(); } await SaveJournalAsync(); if (responsibleForTurningBackupsBackOn) { /* * the backups could already have been disabled by something else. * We don't want to be the ones turning it back on */ SEconomyInstance.RunningJournal.BackupsEnabled = true; } }
protected void LoadBankAccounts() { long bankAccountCount = 0, tranCount = 0; int index = 0, oldPercent = 0; double percentComplete = 0; JournalLoadingPercentChangedEventArgs parsingArgs = new JournalLoadingPercentChangedEventArgs() { Label = "Loading" }; try { if (JournalLoadingPercentChanged != null) { JournalLoadingPercentChanged(this, parsingArgs); } bankAccounts = new List <IBankAccount>(); bankAccountCount = Connection.QueryScalar <long>("select count(*) from `bank_account`;"); tranCount = Connection.QueryScalar <long>("select count(*) from `bank_account_transaction`;"); QueryResult bankAccountResult = Connection.QueryReader(@"select bank_account.*, sum(bank_account_transaction.amount) as balance from bank_account inner join bank_account_transaction on bank_account_transaction.bank_account_fk = bank_account.bank_account_id group by bank_account.bank_account_id;"); Action <int> percentCompleteFunc = i => { percentComplete = (double)i / (double)bankAccountCount * 100; if (oldPercent != (int)percentComplete) { parsingArgs.Percent = (int)percentComplete; if (JournalLoadingPercentChanged != null) { JournalLoadingPercentChanged(this, parsingArgs); } oldPercent = (int)percentComplete; } }; foreach (var acc in bankAccountResult.AsEnumerable()) { MySQLBankAccount sqlAccount = null; sqlAccount = new MySQLBankAccount(this) { BankAccountK = acc.Get <long>("bank_account_id"), Description = acc.Get <string>("description"), Flags = (BankAccountFlags)Enum.Parse(typeof(BankAccountFlags), acc.Get <int>("flags").ToString()), UserAccountName = acc.Get <string>("user_account_name"), WorldID = acc.Get <long>("world_id"), Balance = acc.Get <long>("balance") }; //sqlAccount.SyncBalance(); lock (BankAccounts) { BankAccounts.Add(sqlAccount); } Interlocked.Increment(ref index); percentCompleteFunc(index); } parsingArgs.Percent = 100; if (JournalLoadingPercentChanged != null) { JournalLoadingPercentChanged(this, parsingArgs); } // CleanJournal(PurgeOptions.RemoveOrphanedAccounts | PurgeOptions.RemoveZeroBalanceAccounts); Console.WriteLine("\r\n"); ConsoleEx.WriteLineColour(ConsoleColor.Cyan, " Journal clean: {0} accounts, {1} transactions", BankAccounts.Count(), tranCount); } catch (Exception ex) { TShock.Log.ConsoleError(" seconomy mysql: db error in LoadJournal: " + ex.Message); throw; } }
/// <summary> /// Compresses all transactions into one line. Doing this is going to remove all transaction history but you gain space and processing speed /// </summary> public static void SquashJournal() { int bankAccountCount = BankAccounts.Count(); int tranCount = Transactions.Count(); XDocument newJournal = NewJournal(); bool responsibleForTurningBackupsBackOn = false; Console.WriteLine("seconomy xml: beginning Squash"); if (SEconomyPlugin.BackupCanRun == true) { SEconomyPlugin.BackupCanRun = false; responsibleForTurningBackupsBackOn = true; } for (int i = 0; i < bankAccountCount; i++) { XBankAccount account = BankAccounts.ElementAtOrDefault(i); if (account != null) { //update account balance account.SyncBalance(); string line = string.Format("\r [squash] {0:p} {1}", (double)i / (double)bankAccountCount, account.UserAccountName); SEconomyPlugin.FillWithSpaces(ref line); Console.Write(line); //copy the bank account from the old journal into the new one newJournal.Element("Journal").Element("BankAccounts").Add((XElement)account); //Add the squished summary XTransaction transSummary = new XTransaction(account.Balance); transSummary.BankAccountTransactionK = RandomString(13); transSummary.BankAccountFK = account.BankAccountK; transSummary.Flags = BankAccountTransactionFlags.FundsAvailable | BankAccountTransactionFlags.Squashed; transSummary.Message = "Transaction squash"; transSummary.TransactionDateUtc = DateTime.UtcNow; newJournal.Element("Journal").Element("Transactions").Add((XElement)transSummary); } } //abandon the old journal and assign the squashed one XmlJournal = newJournal; Console.WriteLine("re-syncing online accounts."); foreach (XBankAccount account in BankAccounts) { XBankAccount runtimeAccount = GetBankAccount(account.BankAccountK); if (runtimeAccount != null && runtimeAccount.Owner != null) { Console.WriteLine("re-syncing {0}", runtimeAccount.Owner.TSPlayer.Name); runtimeAccount.SyncBalance(); } } SaveXml(Configuration.JournalPath); //the backups could already have been disabled by something else. We don't want to be the ones turning it back on if (responsibleForTurningBackupsBackOn) { SEconomyPlugin.BackupCanRun = true; } }