Exemple #1
0
		public static void WriteBar(JournalLoadingPercentChangedEventArgs args)
		{
			StringBuilder output = new StringBuilder();
			int fillLen = 0;
			char filler = '#', spacer = ' ';

			output.Append(" ");
			for (int i = 0; i < 10; i++) {
				char c = i < args.Label.Length ? args.Label[i] : ' ';
				output.Append(c);
			}
			
			output.Append(" [");
			
			fillLen = Convert.ToInt32(((decimal)args.Percent / 100) * 60);

			for (int i = 0; i < 60; i++) {
				output.Append(i <= fillLen ? filler : spacer);
			}

			output.Append("] ");
			output.Append(args.Percent + "%");

			lock (__consoleWriteLock) {
				Console.Write("\r");
				Console.ForegroundColor = ConsoleColor.Cyan;
				Console.Write(output.ToString());
				Console.ResetColor();
			}
		}
Exemple #2
0
		static void journal_JournalLoadingPercentChanged(object sender, JournalLoadingPercentChangedEventArgs e)
		{
			ConsoleEx.WriteBar(e);
		}
Exemple #3
0
		protected void Process()
		{
			sec = new SEconomy(null);
			SEconomyPlugin.Instance = sec;
			XmlTransactionJournal journal = null;
			int oldPercent = 0, skipped = 0;
			Dictionary<long, long> oldNewTransactions = new Dictionary<long, long>();
			JournalLoadingPercentChangedEventArgs args = new JournalLoadingPercentChangedEventArgs() {
				Label = "Accounts"
			};

			sec.Configuration = Config.FromFile(Config.BaseDirectory + Path.DirectorySeparatorChar + "seconomy.config.json");
			journal = new XmlTransactionJournal(sec, Config.BaseDirectory + Path.DirectorySeparatorChar + "SEconomy.journal.xml.gz");
			
			JournalLoadingPercentChanged += journal_JournalLoadingPercentChanged;
			journal.JournalLoadingPercentChanged += journal_JournalLoadingPercentChanged;
			journal.LoadJournal();

			Console.WriteLine();

			if (DatabaseExists() == false) {
				Console.WriteLine("Your SEconomy database does not exist.  Create it?");
				Console.Write("[y/n] ");
				if (Console.ReadKey().KeyChar != 'y') {
					return;
				}
				CreateDatabase();
			}

			Console.WriteLine("Your SEconomy database will be flushed.  All accounts, and transactions will be deleted before the import.");
			Console.Write("Continue? [y/n] ");

			if (Console.ReadKey().KeyChar != 'y') {
				return;
			}

			Console.WriteLine();

			Connection.Query(string.Format("DELETE FROM `{0}`.`bank_account`;", sec.Configuration.SQLConnectionProperties.DbName));
			Connection.Query(string.Format("ALTER TABLE `{0}`.`bank_account` AUTO_INCREMENT 0;", sec.Configuration.SQLConnectionProperties.DbName));
			Connection.Query(string.Format("DELETE FROM `{0}`.`bank_account_transaction`;", sec.Configuration.SQLConnectionProperties.DbName));
			Connection.Query(string.Format("ALTER TABLE `{0}`.`bank_account_transaction` AUTO_INCREMENT 0;", sec.Configuration.SQLConnectionProperties.DbName));

			Console.WriteLine("This will probably take a while...\r\n");
			Console.WriteLine();
			if (JournalLoadingPercentChanged != null) {
				JournalLoadingPercentChanged(null, args);
			}

			for (int i = 0; i < journal.BankAccounts.Count; i++) {
				IBankAccount account = journal.BankAccounts.ElementAtOrDefault(i);
				double percentComplete = (double)i / (double)journal.BankAccounts.Count * 100;
				long id = -1;
				string query = null;

				if (account == null) {
					continue;
				}

				query = @"INSERT INTO `bank_account` 
							(user_account_name, world_id, flags, flags2, description, old_bank_account_k)
						  VALUES (@0, @1, @2, @3, @4, @5);";

				try {
					Connection.QueryIdentity(query, out id, account.UserAccountName, account.WorldID,
						(int)account.Flags, 0, account.Description, account.BankAccountK);
				} catch (Exception ex) {
					TShock.Log.ConsoleError(" seconomy mysql: sql error adding bank account: " + ex.ToString());
					continue;
				}

				for (int t = 0; t < account.Transactions.Count(); t++) {
					long tranId = -1;
					ITransaction transaction = account.Transactions.ElementAtOrDefault(t);
					string txQuery = @"INSERT INTO `bank_account_transaction` 
										(bank_account_fk, amount, message, flags, flags2, transaction_date_utc, old_bank_account_transaction_k)
										VALUES (@0, @1, @2, @3, @4, @5, @6);";

					try {
						Connection.QueryIdentity(txQuery, out tranId, id, (long)transaction.Amount, transaction.Message,
							(int)BankAccountTransactionFlags.FundsAvailable, (int)transaction.Flags2, transaction.TransactionDateUtc, 
							transaction.BankAccountTransactionK);

						if (oldNewTransactions.ContainsKey(transaction.BankAccountTransactionK) == false) {
							oldNewTransactions[transaction.BankAccountTransactionK] = tranId;
						}
					} catch (Exception ex) {
						TShock.Log.ConsoleError(" seconomy mysql: Database error in BeginSourceTransaction: " + ex.Message);
						continue;
					}
				}

				if (oldPercent != (int)percentComplete) {
					args.Percent = (int)percentComplete;
					if (JournalLoadingPercentChanged != null) {
						JournalLoadingPercentChanged(null, args);
					}
					oldPercent = (int)percentComplete;
				}
			}

			args.Label = "Reseed";
			args.Percent = 0;
			if (JournalLoadingPercentChanged != null) {
				JournalLoadingPercentChanged(null, args);
			}

			string updateQuery = @"update bank_account_transaction as OLDT
									inner join (
										select bank_account_transaction_id, old_bank_account_transaction_k
										from bank_account_transaction
									) as NEWT on OLDT.old_bank_account_transaction_k = NEWT.old_bank_account_transaction_k
									set OLDT.bank_account_transaction_fk = NEWT.bank_account_transaction_id";

			Connection.Query(updateQuery);
			Connection.Query("update `bank_account_transaction` set `old_bank_account_transaction_k` = null;");
			args.Percent = 100;
			if (JournalLoadingPercentChanged != null) {
				JournalLoadingPercentChanged(null, args);
			}

			Console.WriteLine("import complete", skipped);
			Console.WriteLine("Press any key to exit");
			Console.Read();
		}