public bool Charge(UUID agentID, int amount, string text, int daysUntilNextCharge, TransactionType type, string identifer, bool chargeImmediately) { IMoneyModule moneyModule = m_registry.RequestModuleInterface<IMoneyModule>(); if (moneyModule != null) { if (chargeImmediately) { bool success = moneyModule.Charge(agentID, amount, text, type); if (!success) return false; } IScheduleService scheduler = m_registry.RequestModuleInterface<IScheduleService>(); if (scheduler != null) { OSDMap itemInfo = new OSDMap(); itemInfo.Add("AgentID", agentID); itemInfo.Add("Amount", amount); itemInfo.Add("Text", text); itemInfo.Add("Type", (int)type); SchedulerItem item = new SchedulerItem("ScheduledPayment " + identifer, OSDParser.SerializeJsonString(itemInfo), false, DateTime.UtcNow, daysUntilNextCharge, RepeatType.days, agentID); itemInfo.Add("SchedulerID", item.id); scheduler.Save(item); } } return true; }
void FireScheduleEvent (SchedulerItem I, DateTime nextPayTime) { if (I.FireFunction.StartsWith ("ScheduledPayment", StringComparison.Ordinal)) { try { // save changes before it fires in case its changed during the fire I = sched_database.SaveHistory (I); if (I.RunOnce) I.Enabled = false; if (I.Enabled) I.TimeToRun = nextPayTime; // next stipend payment cycle + delay if (!I.HistoryKeep) sched_database.HistoryDeleteOld (I); // save the new schedule item sched_database.SchedulerSave (I); // now fire List<object> reciept = eventManager.FireGenericEventHandler ("ScheduledPayment", I.FireParams); if (!I.HistoryReceipt) I = sched_database.SaveHistoryComplete (I); else { foreach (string results in reciept.Cast<string> ().Where (results => results != "")) { sched_database.SaveHistoryCompleteReciept (I.HistoryLastID, results); } } } catch (Exception e) { MainConsole.Instance.ErrorFormat ("[Scheduler]: FireEvent Error {0}: {1}", I.id, e); } } }
public bool Charge (UUID agentID, int amount, string description, TransactionType transType, string identifer, bool chargeImmediately, bool runOnce) { var userService = m_registry.RequestModuleInterface<IUserAccountService> (); var user = userService.GetUserAccount (null, agentID); if (moneyModule != null) { if (chargeImmediately) { bool success = moneyModule.Transfer ( (UUID)Constants.BankerUUID, // pay the Banker agentID, amount, description, transType ); if (!success) { MainConsole.Instance.WarnFormat ("[Currency]: Unable to process {0} payment of {1}{2} from {3}", description, currencySymbol, amount, user.Name); return false; } MainConsole.Instance.WarnFormat ("[Currency]: Payment for {0} of {1}{2} from {3} has been paid", description, currencySymbol, amount, user.Name); } if (!runOnce) { // add a re-occurring scheduled payment if (scheduler != null) { string scid = UUID.Random ().ToString (); OSDMap itemInfo = new OSDMap (); itemInfo.Add ("AgentID", agentID); itemInfo.Add ("Amount", amount); itemInfo.Add ("Text", description); itemInfo.Add ("Type", (int)transType); itemInfo.Add ("SchedulerID", scid); SchedulerItem item = new SchedulerItem ( "ScheduledPayment " + identifer, // name OSDParser.SerializeJsonString (itemInfo), // scheduled payment details false, // run once GetStipendPaytime (Constants.SCHEDULED_PAYMENTS_DELAY), // next cycle + delay agentID); // user to charge // we need to use our own id here item.id = scid; scheduler.Save (item); } else MainConsole.Instance.WarnFormat ("[Currency]: Unable to add a new scheduled {0} payment of {1}{2} for {3}", description, currencySymbol, amount, user.Name); } } return true; }
private void FireEvent(SchedulerItem I) { try { // save changes before it fires in case its changed during the fire I = m_database.SaveHistory(I); if (I.RunOnce) I.Enabled = false; if (I.Enabled) I.CalculateNextRunTime(I.TimeToRun); if (!I.HistoryKeep) m_database.HistoryDeleteOld(I); m_database.SchedulerSave(I); // now fire List<Object> reciept = EventManager.FireGenericEventHandler(I.FireFunction, I.FireParams); if (!I.HistoryReceipt) I = m_database.SaveHistoryComplete(I); else { foreach (string results in reciept.Cast<string>().Where(results => results != "")) { m_database.SaveHistoryCompleteReciept(I.HistoryLastID, results); } } } catch (Exception e) { MainConsole.Instance.ErrorFormat("[Scheduler] FireEvent Error {0}: {1}", I.id, e.ToString()); } }
public string Save(SchedulerItem I) { if (m_doRemoteCalls) return (string) DoRemote(I); return m_database.SchedulerSave(I); }
public bool Register(SchedulerItem I, OnGenericEventHandler handler) { if (m_doRemoteCalls) return false; EventManager.RegisterEventHandler(I.FireFunction, handler); return true; }
private object[] GetDBValues(SchedulerItem I) { return new object[] { I.id, I.FireFunction, I.FireParams, I.RunOnce, I.RunEvery, I.TimeToRun, I.HistoryKeep, I.HistoryReceipt, I.HistoryLastID, I.CreateTime, I.StartTime, (int) I.RunEveryType, I.Enabled, I.ScheduleFor }; }
public string SchedulerSave(SchedulerItem I) { object[] dbv = GetDBValues(I); Dictionary<string, object> values = new Dictionary<string, object>(dbv.Length); int i = 0; foreach (object value in dbv) { values[theFields[i++]] = value; } if (SchedulerExist(I.id)) { QueryFilter filter = new QueryFilter(); filter.andFilters["id"] = I.id; m_Gd.Update("scheduler", values, null, filter, null, null); } else { m_Gd.Insert("scheduler", values); } return I.id; }
public SchedulerItem SaveHistoryComplete(SchedulerItem I) { Dictionary<string, object> values = new Dictionary<string, object>(3); values["is_complete"] = true; values["complete_time"] = DateTime.UtcNow; values["reciept"] = ""; QueryFilter filter = new QueryFilter(); filter.andFilters["id"] = I.HistoryLastID; m_Gd.Update("scheduler_history", values, null, filter, null, null); return I; }
public SchedulerItem SaveHistory(SchedulerItem I) { string his_id = UUID.Random().ToString(); Dictionary<string, object> row = new Dictionary<string, object>(7); row["id"] = his_id; row["scheduler_id"] = I.id; row["ran_time"] = DateTime.UtcNow; row["run_time"] = I.TimeToRun; row["is_complete"] = 0; row["complete_time"] = DateTime.UtcNow; row["reciept"] = ""; m_Gd.Insert("scheduler_history", row); I.HistoryLastID = his_id; return I; }
public void HistoryDeleteOld(SchedulerItem I) { if ((I.id != "") && (I.HistoryLastID != "")) { QueryFilter filter = new QueryFilter(); filter.andNotFilters["id"] = I.HistoryLastID; filter.andFilters["scheduler_id"] = I.id; m_Gd.Delete("scheduler_history", filter); } }