private static void SaveLastPeriodicTaskStartTime(CmsBackgroundTask task, DateTime startTime)
        {
            string persistentVariableName = getLastStartPersistentVariableName(task);
            CmsPersistentVariable v       = CmsPersistentVariable.Fetch(persistentVariableName);

            v.Name           = persistentVariableName;
            v.PersistedValue = startTime;

            v.SaveToDatabase();
        }
        /// <summary>
        /// returns DateTime.MinValue if the task has never been run, or if the last run time could not be determined.
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        private static DateTime GetLastPeriodicTaskStartTime(CmsBackgroundTask task)
        {
            string persistentVariableName = getLastStartPersistentVariableName(task);
            CmsPersistentVariable v       = CmsPersistentVariable.Fetch(persistentVariableName);

            if (v.Name == persistentVariableName)
            {
                return((DateTime)v.PersistedValue);
            }
            return(DateTime.MinValue);
        }
        private static CmsBackgroundTask[] getAllBackgroundTasks()
        {
            // -- note: do not cache this function.
            List <CmsBackgroundTask> ret = new List <CmsBackgroundTask>();

            Type[] backgroundTaskTypes = AssemblyHelpers.LoadAllAssembliesAndGetAllSubclassesOf(typeof(CmsBackgroundTask));
            foreach (Type taskType in backgroundTaskTypes)
            {
                try
                {
                    CmsBackgroundTask taskObj = (CmsBackgroundTask)taskType.Assembly.CreateInstance(taskType.FullName);
                    ret.Add(taskObj);
                }
                catch
                {
                    Console.Write("Error: could not load module info " + taskType.FullName);
                }
            } // foreach

            CmsBackgroundTask[] arr = ret.ToArray();
            return(arr);
        }
 private static string getLastStartPersistentVariableName(CmsBackgroundTask task)
 {
     return("LastPeriodicTaskStartTime_" + task.GetType().FullName);
 }