Пример #1
0
		public DonationTransactionOverviewGump(
			PlayerMobile user, Gump parent, DonationProfile profile, DonationTransaction trans)
			: base(user, parent)
		{
			Profile = profile;
			Transaction = trans;
		}
Пример #2
0
		public static void DisplayTo(Mobile user, DonationProfile profile, bool refreshOnly, string node)
		{
			var info = EnumerateInstances<DonationProfileUI>(user).FirstOrDefault(g => g != null && !g.IsDisposed && g.IsOpen);

			if (info == null)
			{
				if (refreshOnly)
				{
					return;
				}

				info = new DonationProfileUI(user, profile);
			}
			else if (profile != null)
			{
				info.Profile = profile;
			}

			if (!String.IsNullOrWhiteSpace(node))
			{
				info.SelectedNode = node;
			}

			info.Refresh(true);
		}
Пример #3
0
		public DonationGiftGump(
			PlayerMobile user, Gump parent, DonationProfile profile, DonationTransaction trans, PlayerMobile to = null)
			: base(user, parent)
		{
			Profile = profile;
			Transaction = trans;
			To = to;
		}
Пример #4
0
		public static void DisplayTo(Mobile user, DonationProfile profile, bool refreshOnly, DonationTransaction trans)
		{
			var node = trans.IsPending
				? ("Transactions|Pending|" + trans.ID)
				: trans.IsProcessed //
					? ("Transactions|Claim|" + trans.ID)
					: !trans.Hidden //
						? ("History|" + trans.FullPath)
						: "History";

			DisplayTo(user, profile, refreshOnly, node);
		}
Пример #5
0
		private static Tuple<IAccount, DonationProfile> DeserializeProfiles(GenericReader reader)
		{
			IAccount key = null;
			DonationProfile val = null;

			var version = reader.GetVersion();

			reader.ReadBlock(
				r =>
				{
					key = r.ReadAccount();

					switch (version)
					{
						case 1:
							val = new DonationProfile(r);
							break;
						case 0:
							val = r.ReadTypeCreate<DonationProfile>(r);
							break;
					}
				});

			if (key == null)
			{
				if (val != null && val.Account != null)
				{
					key = val.Account;
				}
				else
				{
					return null;
				}
			}

			return Tuple.Create(key, val);
		}
Пример #6
0
		protected virtual string GetSearchKey(DonationProfile profile)
		{
			return String.Format("{0}", profile.Account);
		}
Пример #7
0
		public static void Register(IAccount a, DonationProfile dp)
		{
			if (a == null || dp == null)
			{
				if (a == null && dp == null)
				{
					OnExceptionThrown(new ArgumentNullException("a"), "Failed to register unknown DonationProfile to unknown Account");
				}
				else if (a == null)
				{
					OnExceptionThrown(
						new ArgumentNullException("a"), "Failed to register DonationProfile `{0}` to unknown Account", dp);
				}
				else
				{
					OnExceptionThrown(new ArgumentNullException("a"), "Failed to register unknown DonationProfile to Account `{0}`", a);
				}

				return;
			}

			if (!Profiles.ContainsKey(a))
			{
				Profiles.Add(a, dp);
			}
			else
			{
				Profiles[a] = dp;
			}
		}
Пример #8
0
		private static bool SerializeProfiles(GenericWriter writer, IAccount key, DonationProfile val)
		{
			var version = writer.SetVersion(1);

			writer.WriteBlock(
				w =>
				{
					w.Write(key);

					switch (version)
					{
						case 1:
							val.Serialize(w);
							break;
						case 0:
							w.WriteType(val, t => val.Serialize(w));
							break;
					}
				});

			return true;
		}
Пример #9
0
		public static void DisplayTo(Mobile user, DonationProfile profile, string node)
		{
			DisplayTo(user, profile, false, node);
		}
Пример #10
0
		public static void DisplayTo(Mobile user, DonationProfile profile, bool refreshOnly)
		{
			DisplayTo(user, profile, refreshOnly, String.Empty);
		}
Пример #11
0
		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);
		}
Пример #12
0
			public TransExchangeEventArgs(DonationTransaction trans, DonationProfile dp)
			{
				Transaction = trans;
				Profile = dp;

				Exchanged = Transaction.Credit;
			}
Пример #13
0
		protected override void Compile()
		{
			_Admin = User.AccessLevel >= AutoDonate.Access;

			if (Profile == null || Profile.Account == null ||
				(!_Admin && User.AccessLevel <= Profile.Account.AccessLevel && !Profile.Account.IsSharedWith(User.Account)))
			{
				Profile = AutoDonate.EnsureProfile(User.Account);
			}

			if (Profile != null)
			{
				_DonationTier = Profile.Tier;
				_DonationValue = Profile.TotalValue;
				_DonationCredit = Profile.TotalCredit;
				_DonationCount = _Admin ? Profile.Transactions.Count : Profile.Visible.Count();

				Title = "Donations: " + Profile.Account;
			}

			base.Compile();
		}
Пример #14
0
		public static IAccount Find(DonationProfile dp)
		{
			return dp != null && Profiles.ContainsValue(dp) ? Profiles.FirstOrDefault(kvp => kvp.Value == dp).Key : null;
		}
Пример #15
0
		public DonationProfileUI(Mobile user, DonationProfile profile = null)
			: base(user, null, null, null, null, null, "Donations")
		{
			_Indicies = new int[3, 2];
			_Transactions = new List<DonationTransaction>();

			Profile = profile;

			CanMove = true;
			CanClose = true;
			CanDispose = true;
			CanResize = false;

			AutoRefreshRate = TimeSpan.FromMinutes(1.0);
			AutoRefresh = true;

			ForceRecompile = true;
		}
Пример #16
0
			public TransPackEventArgs(DonationTransaction trans, DonationProfile dp, Container cont)
			{
				Transaction = trans;
				Profile = dp;

				Container = cont;
			}
Пример #17
0
		public static Container InvokeTransPack(DonationTransaction trans, DonationProfile dp)
		{
			var cont = new Bag
			{
				Name = "A Donation Reward Bag",
				Hue = 1152
			};

			var e = new TransPackEventArgs(trans, dp, cont);

			if (OnTransPack != null)
			{
				OnTransPack(e);
			}

			return e.Container;
		}
Пример #18
0
		protected virtual void OnProfileInfo(DonationProfile profile)
		{
			Refresh(true);

			DonationProfileUI.DisplayTo(User, profile, false);
		}
Пример #19
0
		public static void DisplayTo(Mobile user, DonationProfile profile)
		{
			DisplayTo(user, profile, String.Empty);
		}
Пример #20
0
		public static void DisplayTo(Mobile user, DonationProfile profile, DonationTransaction trans)
		{
			DisplayTo(user, profile, false, trans);
		}
Пример #21
0
		public static long InvokeTransExchange(DonationTransaction trans, DonationProfile dp)
		{
			var e = new TransExchangeEventArgs(trans, dp);

			if (OnTransExchange != null)
			{
				OnTransExchange(e);
			}

			return e.Exchanged;
		}
Пример #22
0
		private static bool SerializeProfiles(GenericWriter writer, IAccount key, DonationProfile val)
		{
			int version = writer.SetVersion(0);

			switch (version)
			{
				case 0:
					{
						writer.WriteBlock(
							w =>
							{
								w.Write(key);
								w.WriteType(val, t => val.Serialize(w));
							});
					}
					break;
			}

			return true;
		}
Пример #23
0
		public static DonationProfile EnsureProfile(IAccount a)
		{
			var p = Profiles.GetValue(a);

			if (p == null && a != null)
			{
				Profiles[a] = p = new DonationProfile(a);
			}

			return p;
		}