Ejemplo n.º 1
0
 public void TaskSchedulerTest()
 {
     AppSettings conf = new AppSettings();
     conf.Hourpattern = "*";
     conf.Minutepattern = "00,30";
     Schedule schedule = new Schedule(conf);
     Win32ScheduleInstaller uut = new Win32ScheduleInstaller(schedule);
     uut.deleteTaskAndTriggers();
     using (TaskService ts = new TaskService())
     {
         Assert.IsNull(ts.GetTask("BBCIngest"));
     }
     uut.installTask(@"C:\WINDOWS\system32\cmd.exe", "");
     using (TaskService ts = new TaskService())
     {
         Microsoft.Win32.TaskScheduler.Task t = ts.GetTask("BBCIngest");
         Assert.IsNotNull(t);
         DateTime sod = DateTime.UtcNow.Date;
         // getruntimes is exclusive of the start time
         DateTime[] runtimes = t.GetRunTimes(sod.AddMilliseconds(-1), sod.AddMilliseconds(-1).AddDays(1));
         Assert.AreEqual(48, runtimes.Length);
         DateTime[] events = schedule.events(sod);
         Assert.AreEqual(48, events.Length);
         for (int i = 0; i < 48; i++)
         {
             Assert.AreEqual(events[i], runtimes[i]);
         }
     }
     uut.deleteTaskAndTriggers();
     using (TaskService ts = new TaskService())
     {
         Assert.IsNull(ts.GetTask("BBCIngest"));
     }
 }
Ejemplo n.º 2
0
 private IScheduleInstaller getScheduleInstaller(Schedule schedule)
 {
     if (Environment.OSVersion.Platform == PlatformID.Unix)
     {
         return(new ScheduleInstaller(schedule));
     }
     else
     {
         Win32ScheduleInstaller si = new Win32ScheduleInstaller(schedule);
         si.addTerseMessageListener(new TerseMessageDelegate(setLine1));
         si.addLogListener(logDelegate);
         return(si);
     }
 }
Ejemplo n.º 3
0
        static void Main(String[] args)
        {
            String arg = "";

            if (args.Length > 0)
            {
                arg = args[0];
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            AppSettings conf = new AppSettings();

            if (args.Length == 2)
            {
                conf.SettingsPath = args[1];
            }
            conf.LoadAppSettings();
            Directory.CreateDirectory(conf.PublishFolder);
            Directory.CreateDirectory(conf.Archive);
            //MessageBox.Show(arg, "BBCIngest", MessageBoxButtons.OK);
            if (arg.Equals("install"))
            {
                if (File.Exists(init_file))
                {
                    foreach (var row in File.ReadAllLines(init_file))
                    {
                        string[] s = row.Split('=');
                        if (s[0].Equals("postLogs"))
                        {
                            conf.PostLogs = s[1].Equals("1");
                        }
                        if (s[0].Equals("city"))
                        {
                            conf.City = s[1];
                        }
                        if (s[0].Equals("station"))
                        {
                            conf.Station = s[1];
                        }
                        if (s[0].Equals("logUrl"))
                        {
                            conf.LogUrl = s[1];
                        }
                    }
                }
                conf.SaveAppSettings();
            }
            else if (arg.Equals("uninstall"))
            {
                Schedule           schedule = new Schedule(conf);
                IScheduleInstaller si;
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    si = new ScheduleInstaller(schedule);
                }
                else
                {
                    si = new Win32ScheduleInstaller(schedule);
                }
                si.deleteTaskAndTriggers();
            }
            else
            {
                HttpClientHandler httpClientHandler = new HttpClientHandler()
                {
                    Proxy = WebRequest.GetSystemWebProxy()
                };
                HttpClient      hc      = new HttpClient(httpClientHandler);
                Logging         log     = new Logging(conf, hc);
                FetchAndPublish fetcher = new FetchAndPublish(conf, hc);
                LogDelegate     ld      = new LogDelegate(log.WriteLine);
                fetcher.addLogListener(ld);
                if (arg.Equals("once"))
                {
                    MainTask(conf, fetcher).Wait();
                }
                else
                {
                    if (arg.Equals("fg"))
                    {
                        conf.RunInForeground = true;
                    }
                    if (arg.Equals("bg"))
                    {
                        conf.RunInForeground = false;
                    }
                    MainForm mf = new MainForm(conf, fetcher);
                    mf.addLogListener(ld);
                    Application.Run(mf);
                }
            }
        }