コード例 #1
0
        private void buttonRfTS_Click(object sender, EventArgs e)
        {
            ScheduleInstaller schedule = new ScheduleInstaller(conf);

            deleteTask(schedule);
            createTask(schedule);
            getLatest(schedule);
        }
コード例 #2
0
        private void deleteTask(ScheduleInstaller schedule)
        {
            DateTime?next = schedule.nextRun();

            if (next != null)
            {
                schedule.deleteTaskAndTriggers();
                taskInstalled = false;
                setLine1("Tasks removed");
                buttonRfTS.Text = "Install Task";
            }
        }
コード例 #3
0
        private async void OnLoad(object sender, EventArgs e)
        {
            ScheduleInstaller schedule = new ScheduleInstaller(conf);

            await getLatest(schedule);

            if (conf.RunInForeground)
            {
                buttonExitOrStart.Text = "Start";
            }
            else
            {
                buttonExitOrStart.Text = "Exit";
            }
        }
コード例 #4
0
        private System.Threading.Tasks.Task getLatest(ScheduleInstaller schedule)
        {
            DateTime?next = schedule.nextRun();

            if (next != null)
            {
                setLine1("Task installed and will next run at " + next.Value);
                //setLine2("Latest is " + fetcher.lastWeHave());
                taskInstalled   = true;
                buttonRfTS.Text = "Update Task Scheduler";
            }
            else
            {
                buttonRfTS.Text = "Install Task";
            }
            return(fetcher.showLatest());
        }
コード例 #5
0
        private void createTask(ScheduleInstaller schedule)
        {
            string         path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            TaskDefinition td   = schedule.createTaskDefinition(path);

            if (conf.RunAsService)
            {
                if (schedule.installTaskAsService(td) == false)
                {
                    setLine1("Either set RunAsService false in settings or run this program with Admin privileges");
                    taskInstalled = false;
                    return;
                }
            }
            else
            {
                schedule.installUserTask(td);
            }
            schedule.runTask();
            taskInstalled = true;
        }
コード例 #6
0
        public void TaskSchedulerTest()
        {
            AppSettings conf = new AppSettings();

            conf.Hourpattern   = "*";
            conf.Minutepattern = "00,30";
            ScheduleInstaller uut = new ScheduleInstaller(conf);

            uut.deleteTaskAndTriggers();
            using (TaskService ts = new TaskService())
            {
                Assert.IsNull(ts.GetTask("BBCIngest"));
            }
            TaskDefinition td = uut.createTaskDefinition(@"C:\WINDOWS\system32\cmd.exe");

            uut.installUserTask(td);
            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 = uut.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"));
            }
        }
コード例 #7
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);
                }
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: lintal/BBCIngest
        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);
            Directory.CreateDirectory(conf.Logfolder);
            //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"))
            {
                ScheduleInstaller schedule = new ScheduleInstaller(conf);
                schedule.deleteTaskAndTriggers();
                //MessageBox.Show("Scheduled Tasks Removed", "BBCIngest", MessageBoxButtons.OK);
            }
            else if (arg.Equals("once"))
            {
                MainTask(conf).Wait();
            }
            else
            {
                Application.Run(new MainForm(conf));
            }
        }
コード例 #9
0
        private void buttonRemoveTasks_Click(object sender, EventArgs e)
        {
            ScheduleInstaller schedule = new ScheduleInstaller(conf);

            deleteTask(schedule);
        }