public bool Charge(UUID agentID, int amount, string text, int daysUntilNextCharge)
        {
            IMoneyModule moneyModule = m_registry.RequestModuleInterface<IMoneyModule>();
            if (moneyModule != null)
            {
                bool success = moneyModule.Charge(agentID, amount, text);
                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);
                    SchedulerItem item = new SchedulerItem("ScheduledPayment",
                        OSDParser.SerializeJsonString(itemInfo), false,
                        DateTime.Now.AddDays(daysUntilNextCharge) - DateTime.Now);
                    itemInfo.Add("SchedulerID", item.id);
                    scheduler.Save(item);

                }
            }
            return true;
        }
 public string SchedulerSave(SchedulerItem I)
 {
     if (SchedulerExist(I.id))
     {
         m_Gd.Update("scheduler", GetDBValues(I), theFields, new[] { "id" }, new object[] { I.id });
     }
     else
     {
         m_Gd.Insert("scheduler", theFields, GetDBValues(I));
     }
     return I.id;
 }
        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;
        }
Example #4
0
        private void FireEvent(SchedulerItem I)
        {
            try
            {
                // save chagnes before it fires in case its chagned during the fire
                I = m_database.SaveHistory(I);

                if (I.RunOnce) I.Enabled = false;
                if (I.Enabled) I.CalculateNextRunTime(I.TimeToRun);

                if (!I.HisotryKeep)
                    m_database.HistoryDeleteOld(I);
                m_database.SchedulerSave(I);

                // now fire
                List<Object> reciept = EventManager.FireGenericEventHandler(I.FireFunction, I.FireParams);
                if (!I.HistoryReciept)
                    I = m_database.SaveHistoryComplete(I);
                else
                {
#if (!ISWIN)
                    foreach (Object o in reciept)
                    {
                        string results = (string)o;
                        if (results != "")
                        {
                            m_database.SaveHistoryCompleteReciept(I.HistoryLastID, results);
                        }
                    }
#else
                    foreach (string results in reciept.Cast<string>().Where(results => results != ""))
                    {
                        m_database.SaveHistoryCompleteReciept(I.HistoryLastID, results);
                    }
#endif
                }
            
                
            }
            catch (Exception e)
            {
                MainConsole.Instance.Error("[Scheduler] FireEvent Error " + I.id, e);
            }
        }
Example #5
0
 public string Save(SchedulerItem I)
 {
     return m_database.SchedulerSave(I);
 }
Example #6
0
 public string Save(SchedulerItem I)
 {
     if (m_doRemoteCalls)
         return (string)DoRemote(I);
     return m_database.SchedulerSave(I);
 }
Example #7
0
 public bool Register(SchedulerItem I, OnGenericEventHandler handler)
 {
     if (m_doRemoteCalls) return false;
     EventManager.RegisterEventHandler(I.FireFunction, handler);
     return true;
 }
 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);
     }
 }
 private object[] GetDBValues(SchedulerItem I)
 {
     return new object[]
                {
                    I.id, I.FireFunction, I.FireParams, (I.RunOnce)?1:0, I.RunEvery, Util.ToUnixTime(I.TimeToRun), 
                    (I.HisotryKeep)?1:0,(I.HistoryReciept)?1:0, I.HistoryLastID, Util.ToUnixTime(I.CreateTime), 
                    (I.Enabled)?1:0
                };
 }
        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;
        }
 private object[] GetDBValues(SchedulerItem I)
 {
     return new object[]{
         I.id, 
         I.FireFunction, 
         I.FireParams, 
         I.RunOnce,
         I.RunEvery, 
         I.TimeToRun,
         I.HisotryKeep,
         I.HistoryReciept,
         I.HistoryLastID,
         I.CreateTime,
         I.StartTime,
         (int)I.RunEveryType,
         I.Enabled,
         I.ScheduleFor
     };
 }
        private void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (m_scheduler == null) return; // might be a long startup;
            taskTimer.Enabled = false;
            IDirectoryServiceConnector DSC = DataManager.RequestPlugin<IDirectoryServiceConnector>();

            int startAT = 0;
            bool keepGoing;
            do
            {
                keepGoing = false;
                List<DirClassifiedReplyData> classifieds = DSC.FindClassifieds("", ((int)DirectoryManager.ClassifiedCategories.Any).ToString(CultureInfo.InvariantCulture),
                                (uint)DirectoryManager.ClassifiedFlags.Enabled, startAT, UUID.Zero);
                startAT += classifieds.Count;
                if (classifieds.Count >= 1) keepGoing = true;
                foreach (DirClassifiedReplyData data in classifieds)
                {
                    if (m_scheduler.Exist(data.classifiedID.ToString())) continue;
                    SchedulerItem si = new SchedulerItem("CLASSBILL", OSDParser.SerializeJsonString(new BillingClassified(data.classifiedID).ToOSD()), false,
                                                         UnixTimeStampToDateTime((int)data.creationDate), 1,
                                                         RepeatType.months, data.classifiedID) { id = data.classifiedID.ToString() };
                    m_scheduler.Save(si);
                }
            } while (keepGoing);
        }
 public void HistoryDeleteOld(SchedulerItem I)
 {
     if ((I.id != "") && (I.HistoryLastID != ""))
         m_Gd.Delete("scheduler_history", "WHERE id != '" + I.HistoryLastID + "' AND scheduler_id = '" + I.id + "'");
 }
 public SchedulerItem SaveHistoryComplete(SchedulerItem I)
 {
     m_Gd.Update("scheduler_history", new object[] { 1, Util.ToUnixTime(I.TimeToRun), "" },
                 new[] { "is_complete", "complete_time", "reciept" }, new[] { "id" },
                 new object[] { I.HistoryLastID });
     return I;
 }
 public SchedulerItem SaveHistory(SchedulerItem I)
 {
     string his_id = UUID.Random().ToString();
     m_Gd.Insert("scheduler_history",
                 new[]
                     {"id", "scheduler_id", "ran_time", "run_time", "is_complete", "complete_time", "reciept"},
                 new object[]
                     {his_id, I.id, Util.ToUnixTime(DateTime.UtcNow), Util.ToUnixTime(I.TimeToRun), 0, 0, ""}
         );
     I.HistoryLastID = his_id;
     return I;
 }
Example #16
0
 public bool Register(SchedulerItem I, OnGenericEventHandler handler)
 {
     EventManager.RegisterEventHandler(I.FireFunction, handler);
     return true;
 }
        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;
        }
Example #18
0
        private void FireEvent(SchedulerItem I)
        {
            try
            {
                I = m_database.SaveHistory(I);
                List<Object> reciept = EventManager.FireGenericEventHandler(I.FireFunction, I.FireParams);
                if (!I.HistoryReciept)
                    I = m_database.SaveHistoryComplete(I);
                else
                {
                    foreach (Object o in reciept)
                    {
                        string results = (string)o;
                        if (results != "")
                        {
                            m_database.SaveHistoryCompleteReciept(I.HistoryLastID, results);
                        }
                    }
                }
            
                if (I.RunOnce) I.Enabled = false;
                if (I.Enabled) I.TimeToRun = I.TimeToRun.AddSeconds(I.RunEvery);

                if (!I.HisotryKeep)
                    m_database.HistoryDeleteOld(I);

                m_database.SchedulerSave(I);
            }
            catch (Exception e)
            {
                MainConsole.Instance.Error("[Scheduler] FireEvent Error " + I.id, e);
            }
        }