Exemplo n.º 1
0
        public static CronJob Parse(ConfigReader.JobArgs jobArgs, Settings settings = null)
        {
            if (jobArgs == null)
            return null;

              var job = new CronJob { Settings = settings != null ? settings.Clone() : new Settings() };

              if (jobArgs.Reboot)
              {
            job.Reboot = true;
            job.Command = jobArgs.Command;
            return job;
              }

              try
              {
            ParseValue(ref job.Minutes, jobArgs.Minute, 0, 59, false);
            ParseValue(ref job.Hours, jobArgs.Hour, 0, 23, false);
            ParseValue(ref job.Days, jobArgs.Day, 1, 31, false);
            ParseValue(ref job.Months, jobArgs.Month, 1, 12, false);
            ParseValue(ref job.Weekdays, jobArgs.Weekday, 0, 6, true);

            job.Command = jobArgs.Command;
            job.RecalcNextExecTime();

            return job;
              }
              catch (Exception e)
              {
            Logger.Error(e.Message);
            return null;
              }
        }
Exemplo n.º 2
0
        private void ConfigReaderOnDefinitionRead(object sender, ConfigReader.DefinitionArgs args)
        {
            // This is handled another way..
              if (args.Definition.Equals("LogPath", StringComparison.InvariantCultureIgnoreCase))
            return;

              if (Settings.Exists(args.Definition))
            Settings.Set(args.Definition, args.Value);
              else
            Logger.Error("Invalid definition: {0}", args.Definition);
        }
Exemplo n.º 3
0
        public static ServiceJob Parse(ConfigReader.JobArgs jobArgs, Settings settings = null)
        {
            if (jobArgs == null)
            return null;

              return new ServiceJob
              {
            Settings = settings != null ? settings.Clone() : new Settings(),
            Command = jobArgs.Command
              };
        }
Exemplo n.º 4
0
        public Config(string filename)
        {
            File = new FileInfo(filename);
              Path = File.Directory ?? new DirectoryInfo(Directory.GetCurrentDirectory());

              Reader = new ConfigReader();
              Reader.DefinitionRead += ConfigReaderOnDefinitionRead;
              Reader.JobRead += ConfigReaderOnJobRead;
              Reader.InvalidConfig += ConfigReaderOnInvalidConfig;

              Reload();
        }
Exemplo n.º 5
0
        private void ConfigReaderOnJobRead(object sender, ConfigReader.JobArgs jobArgs)
        {
            var job = jobArgs.Service ? (Job) ServiceJob.Parse(jobArgs, Settings) : CronJob.Parse(jobArgs, Settings);
              if (job == null)
            return;

              if (string.IsNullOrEmpty(job.Settings.Home))
            job.Settings.Home = Path.FullName;

              job.VerifyExecutableExists();
              Jobs.Add(job);
        }
Exemplo n.º 6
0
 private void ConfigReaderOnInvalidConfig(object sender, ConfigReader.InvalidConfigArgs args)
 {
     Logger.Error("Invalid definition on line {0}: {1}", args.LineNo, args.Text);
 }