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; } }
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; } }