Holds an XML representation of the SEconomy transaction journal.
Inheritance: ITransactionJournal
Esempio n. 1
0
        protected bool LoadJournal()
        {
            Journal.ITransactionJournal journal = null;
            if (Configuration == null)
            {
                return(false);
            }

            if (Configuration.JournalType.Equals("xml", StringComparison.InvariantCultureIgnoreCase) == true)
            {
                Wolfje.Plugins.SEconomy.Journal.XMLJournal.XmlTransactionJournal xmlJournal = new Journal.XMLJournal.XmlTransactionJournal(this, Config.JournalPath);
                xmlJournal.JournalLoadingPercentChanged += (sender, args) => ConsoleEx.WriteBar(args);

                journal = xmlJournal;
            }
            else if (Configuration.JournalType.Equals("mysql", StringComparison.InvariantCultureIgnoreCase) == true ||
                     Configuration.JournalType.Equals("sql", StringComparison.InvariantCultureIgnoreCase) == true)
            {
                Wolfje.Plugins.SEconomy.Journal.MySQLJournal.MySQLTransactionJournal sqlJournal = new Journal.MySQLJournal.MySQLTransactionJournal(this, Configuration.SQLConnectionProperties);
                sqlJournal.JournalLoadingPercentChanged += (sender, args) => ConsoleEx.WriteBar(args);

                journal = sqlJournal;
            }

            this.RunningJournal = journal;
            if (this.RunningJournal.LoadJournal() == false)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
		protected bool LoadJournal()
		{
			Journal.ITransactionJournal journal = null;
			if (Configuration == null) {
				return false;
			}

			if (Configuration.JournalType.Equals("xml", StringComparison.InvariantCultureIgnoreCase) == true) {
				Wolfje.Plugins.SEconomy.Journal.XMLJournal.XmlTransactionJournal xmlJournal = new Journal.XMLJournal.XmlTransactionJournal(this, Config.JournalPath);
				xmlJournal.JournalLoadingPercentChanged += (sender, args) => ConsoleEx.WriteBar(args);

				journal = xmlJournal;
			} else if (Configuration.JournalType.Equals("mysql", StringComparison.InvariantCultureIgnoreCase) == true
			           || Configuration.JournalType.Equals("sql", StringComparison.InvariantCultureIgnoreCase) == true) {
				Wolfje.Plugins.SEconomy.Journal.MySQLJournal.MySQLTransactionJournal sqlJournal = new Journal.MySQLJournal.MySQLTransactionJournal(this, Configuration.SQLConnectionProperties);
				sqlJournal.JournalLoadingPercentChanged += (sender, args) => ConsoleEx.WriteBar(args);

				journal = sqlJournal;
			}

			this.RunningJournal = journal;
			if (this.RunningJournal.LoadJournal() == false) {
				return false;
			}

			return true;
		}
Esempio n. 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();
		}