public static void InvokeStateChanged(DonationTransaction trans, DonationTransactionState oldState) { if (OnStateChanged != null) { OnStateChanged.Invoke(new StateChangedEventArgs(trans, oldState)); } }
public void Deserialize(GenericReader reader) { int version = reader.GetVersion(); switch (version) { case 0: { ID = reader.ReadString(); _State = reader.ReadFlag <DonationTransactionState>(); Account = reader.ReadAccount(); Email = reader.ReadString(); Total = reader.ReadDecimal(); _Credit = reader.ReadLong(); _Time = reader.ReadDouble(); Version = reader.ReadInt(); _InternalVersion = reader.ReadInt(); _Notes = reader.ReadString(); _Extra = reader.ReadString(); DeliverFrom = reader.ReadMobile(); DeliverTo = reader.ReadMobile(); DeliveryTime = reader.ReadDouble(); } break; } }
private static void ExportMySQL(DonationTransactionState state) { Connection.UseDatabase(CMOptions.MySQL.Database); int count = 0; foreach (DonationTransaction trans in Profiles.Values.AsParallel().SelectMany(dp => dp.Where(t => t != null && t.State == state))) { VitaNexCore.TryCatch( () => { bool success; if (Connection.Contains(CMOptions.TableName, "id", new[] { new MySQLCondition("id", trans.ID) })) { success = Connection.Update( CMOptions.TableName, new[] { new MySQLData("state", trans.State.ToString().ToUpper()), new MySQLData("version", trans.Version), new MySQLData("notes", trans.Notes), new MySQLData("extra", trans.Extra) }, new[] { new MySQLCondition("id", trans.ID) }); } else { success = Connection.Insert( CMOptions.TableName, new[] { new MySQLData("id", trans.ID), new MySQLData("state", trans.State.ToString().ToUpper()), new MySQLData("account", trans.Account.Username), new MySQLData("email", trans.Email), new MySQLData("total", trans.Total), new MySQLData("credit", trans.Credit.Value), new MySQLData("time", trans.Time.Stamp), new MySQLData("version", trans.Version), new MySQLData("notes", trans.Notes), new MySQLData("extra", trans.Extra) }); } if (success) { ++count; } }, e => OnExceptionThrown(e, "Could not save MySQL data for transaction ID {0}", trans.ID)); } CMOptions.ToConsole("Exported {0} {1} transactions.", count, state); }
public DonationTransaction( string id, DonationTransactionState state, IAccount account, string email, decimal total, DonationCredits credit, TimeStamp time, int version = 0, string notes = null, string extra = null) { ID = id; _State = state; Account = account; Email = email; Total = total; _Credit = credit; _Time = time; Version = version; _InternalVersion = version; _Notes = notes ?? String.Empty; _Extra = extra ?? String.Empty; }
public StateChangedEventArgs(DonationTransaction trans, DonationTransactionState oldState) { Transaction = trans; OldState = oldState; }
private static void ImportMySQL(DonationTransactionState state) { Connection.UseDatabase(CMOptions.MySQL.Database); int count = 0; var rows = Connection.Select( CMOptions.TableName, null, new[] { new MySQLCondition("state", state.ToString().ToUpper()) }, "time", MySQLSortOrder.ASC); if (Connection.HasError) { if (!CMOptions.ModuleQuietMode) { foreach (OdbcError e in Connection.Errors) { OnExceptionThrown(new Exception(e.Message), "OdbcError"); } } } else if (rows.Length > 0) { var gTrans = new List <DonationTransaction>(rows.Length); foreach (MySQLRow row in rows) { VitaNexCore.TryCatch( () => { var total = row["total"].GetValue <decimal>(); var credit = row["credit"].GetValue <long>(); int time = row["time"].GetValue <int>(), version = row["version"].GetValue <int>(); string id = row["id"].GetValue <string>(), email = row["email"].GetValue <string>(), notes = row["notes"].GetValue <string>(), extra = row["extra"].GetValue <string>(), status = row["state"].GetValue <string>(), account = row["account"].GetValue <string>(); IAccount a = Accounts.GetAccount(account ?? String.Empty) ?? Accounts.GetAccounts().FirstOrDefault(ac => ac.AccessLevel == AccessLevel.Owner); DonationTransactionState s; if (a == null || !Enum.TryParse(status, true, out s)) { s = DonationTransactionState.Void; } gTrans.Add(new DonationTransaction(id, s, a, email, total, credit, time, version, notes, extra)); ++count; }, e => OnExceptionThrown(e, "Could not load MySQL data for transaction in row {0:#,0}", row.ID)); } gTrans.TrimExcess(); foreach (DonationTransaction trans in gTrans) { VitaNexCore.TryCatch( () => { DonationProfile dp; if (!Profiles.TryGetValue(trans.Account, out dp)) { Profiles.Add(trans.Account, dp = new DonationProfile(trans.Account)); } else if (dp == null) { Profiles[trans.Account] = dp = new DonationProfile(trans.Account); } if (!dp.Contains(trans)) { dp.Add(trans); } switch (trans.State) { case DonationTransactionState.Pending: { if (dp.Process(trans)) { } } break; case DonationTransactionState.Processed: break; case DonationTransactionState.Claimed: break; case DonationTransactionState.Void: { if (dp.Void(trans)) { } } break; } }, e => OnExceptionThrown(e, "Could not load MySQL data for transaction ID {0}", trans.ID)); } } CMOptions.ToConsole("Imported {0} {1} transactions.", count, state); }
public DonationTransaction[] Find(DonationTransactionState state) { return(Transactions.Values.Where(trans => trans.State == state).ToArray()); }
public void Deserialize(GenericReader reader) { int version = reader.GetVersion(); switch (version) { case 0: { ID = reader.ReadString(); _State = reader.ReadFlag<DonationTransactionState>(); Account = reader.ReadAccount(); Email = reader.ReadString(); Total = reader.ReadDecimal(); _Credit = reader.ReadLong(); _Time = reader.ReadDouble(); Version = reader.ReadInt(); _InternalVersion = reader.ReadInt(); _Notes = reader.ReadString(); _Extra = reader.ReadString(); DeliverFrom = reader.ReadMobile(); DeliverTo = reader.ReadMobile(); DeliveryTime = reader.ReadDouble(); } break; } }
private void OnStateChanged(DonationTransactionState oldState) { DonationEvents.InvokeStateChanged(this, oldState); }
private static void ExportMySQL(DonationTransactionState state) { Connection.UseDatabase(CMOptions.MySQL.Database); int count = 0; foreach (DonationTransaction trans in Profiles.Values.AsParallel().SelectMany(dp => dp.Where(t => t != null && t.State == state))) { VitaNexCore.TryCatch( () => { bool success; if (Connection.Contains(CMOptions.TableName, "id", new[] {new MySQLCondition("id", trans.ID)})) { success = Connection.Update( CMOptions.TableName, new[] { new MySQLData("state", trans.State.ToString().ToUpper()), new MySQLData("version", trans.Version), new MySQLData("notes", trans.Notes), new MySQLData("extra", trans.Extra) }, new[] {new MySQLCondition("id", trans.ID)}); } else { success = Connection.Insert( CMOptions.TableName, new[] { new MySQLData("id", trans.ID), new MySQLData("state", trans.State.ToString().ToUpper()), new MySQLData("account", trans.Account.Username), new MySQLData("email", trans.Email), new MySQLData("total", trans.Total), new MySQLData("credit", trans.Credit.Value), new MySQLData("time", trans.Time.Stamp), new MySQLData("version", trans.Version), new MySQLData("notes", trans.Notes), new MySQLData("extra", trans.Extra) }); } if (success) { ++count; } }, e => OnExceptionThrown(e, "Could not save MySQL data for transaction ID {0}", trans.ID)); } CMOptions.ToConsole("Exported {0} {1} transactions.", count, state); }
private static void ImportMySQL(DonationTransactionState state) { Connection.UseDatabase(CMOptions.MySQL.Database); int count = 0; var rows = Connection.Select( CMOptions.TableName, null, new[] {new MySQLCondition("state", state.ToString().ToUpper())}, "time", MySQLSortOrder.ASC); if (Connection.HasError) { if (!CMOptions.ModuleQuietMode) { foreach (OdbcError e in Connection.Errors) { OnExceptionThrown(new Exception(e.Message), "OdbcError"); } } } else if (rows.Length > 0) { var gTrans = new List<DonationTransaction>(rows.Length); foreach (MySQLRow row in rows) { VitaNexCore.TryCatch( () => { var total = row["total"].GetValue<decimal>(); var credit = row["credit"].GetValue<long>(); int time = row["time"].GetValue<int>(), version = row["version"].GetValue<int>(); string id = row["id"].GetValue<string>(), email = row["email"].GetValue<string>(), notes = row["notes"].GetValue<string>(), extra = row["extra"].GetValue<string>(), status = row["state"].GetValue<string>(), account = row["account"].GetValue<string>(); IAccount a = Accounts.GetAccount(account ?? String.Empty) ?? Accounts.GetAccounts().FirstOrDefault(ac => ac.AccessLevel == AccessLevel.Owner); DonationTransactionState s; if (a == null || !Enum.TryParse(status, true, out s)) { s = DonationTransactionState.Void; } gTrans.Add(new DonationTransaction(id, s, a, email, total, credit, time, version, notes, extra)); ++count; }, e => OnExceptionThrown(e, "Could not load MySQL data for transaction in row {0:#,0}", row.ID)); } gTrans.TrimExcess(); foreach (DonationTransaction trans in gTrans) { VitaNexCore.TryCatch( () => { DonationProfile dp; if (!Profiles.TryGetValue(trans.Account, out dp)) { Profiles.Add(trans.Account, dp = new DonationProfile(trans.Account)); } else if (dp == null) { Profiles[trans.Account] = dp = new DonationProfile(trans.Account); } if (!dp.Contains(trans)) { dp.Add(trans); } switch (trans.State) { case DonationTransactionState.Pending: { if (dp.Process(trans)) { } } break; case DonationTransactionState.Processed: break; case DonationTransactionState.Claimed: break; case DonationTransactionState.Void: { if (dp.Void(trans)) { } } break; } }, e => OnExceptionThrown(e, "Could not load MySQL data for transaction ID {0}", trans.ID)); } } CMOptions.ToConsole("Imported {0} {1} transactions.", count, state); }