Does save config function exist?

Aug 23, 2011 at 12:53 AM
Edited Aug 23, 2011 at 12:55 AM

Just to check I'm not missing something, is there a SaveConfig function to go with SchedulerRuntime.StartWithConfig() ?

 (This would be useful for creating tasks dynamically at runtime, then saving them to be reloaded next time the program starts).

 I'll make this tommorow if it doesn't turn out it already exists, and if plain xml serialization doesnt do the job.

 

Thanks,

chris

Aug 23, 2011 at 7:23 PM

Sorry I didnt have time to work out how to upload to CodePlex. I made a very simple solution -

Add to top of SchedulerRunTime.cs:

using System.Runtime.Serialization;using System.Runtime.Serialization.Formatters.Binary;

namespace TaskSchedulerEngine{    public static class SchedulerRuntime    {        

//Second list just for serialization -ugly but quick way of creating exports      

 public static List<Schedule> scheduleList = new List<Schedule>();

... Code

        public static void loadSchedule(string path)
        {
            try {
            using (Stream stream = File.Open(path, FileMode.Open))
			{
			    BinaryFormatter bin = new BinaryFormatter();
			    scheduleList = (List)bin.Deserialize(stream);
                TaskEvaluationPump pump = TaskEvaluationPump.GetInstance();
                pump._schedule.Clear();

                 //Now add all to pump
                foreach(Schedule s in scheduleList) {
                    pump.AddSchedule(s);
                }
			}
            }
            catch(Exception ex) {
                logError(ex.ToString());
            }
        }
        

        private static void logError(string error)
        {
                Console.WriteLine(error);
                TextWriter t = new StreamWriter("errorLog.txt");
                t.Write(error);
                t.Close();
        }


        public static void writeSchedule(string path)
        {
            try
            {
                scheduleList.Add(new Schedule());
                using (Stream stream = File.Open(path, FileMode.Create))
                {
                    BinaryFormatter bin = new BinaryFormatter();
                    bin.Serialize(stream, scheduleList);
                }
            }
            catch (Exception ex)
            {
                logError(ex.ToString());
            }
        }

 

Then add to Schedule.cs

namespace TaskSchedulerEngine.Fluent{      

 [Serializable()] 
    public class Schedule    {