//Does a dryrun using keywords.json - showing what it *would* do, but not actually doing it public void DryRun() { //Create new recordings object to manage our recordings Recordings recordings = new Recordings(configuration); //Create channel history object ChannelHistory channelHistory = new ChannelHistory(); //Grabs schedule and builds a recording list based on keywords List <RecordInfo> recordInfoList = recordings.BuildRecordSchedule(); //Go through record list and display foreach (RecordInfo recordInfo in recordInfoList) { //Dump record info DumpRecordInfo(Console.Out, recordInfo); //Create servers object Servers servers = new Servers(configuration["ServerList"]); //Create the server/channel selector object ServerChannelSelector scs = new ServerChannelSelector(new StreamWriter(Console.OpenStandardOutput()), channelHistory, servers, recordInfo); } Thread.Sleep(3000); }
public void MonitorMode() { //Create new recordings object to manage our recordings Recordings recordings = new Recordings(configuration); //Create channel history object ChannelHistory channelHistory = new ChannelHistory(); try { //Grab schedule from interwebs and loop forever, checking every n hours for new shows to record while (true) { //Grabs schedule and builds a recording list based on keywords List <RecordInfo> recordInfoList = recordings.BuildRecordSchedule(); //Go through record list, spawn a new process for each show found foreach (RecordInfo recordInfo in recordInfoList) { //If show is not already queued, let's go! bool showQueued = recordInfo.processSpawnedFlag; if (!showQueued) { recordInfo.processSpawnedFlag = true; DumpRecordInfo(Console.Out, recordInfo); // Queue show to be recorded now Task.Factory.StartNew(() => QueueRecording(channelHistory, recordInfo, configuration, true)); } } //Determine how long to sleep before next check string[] times = configuration["scheduleCheck"].Split(','); DateTime nextRecord = DateTime.Now; //find out if schedule time is still today if (DateTime.Now.Hour < Convert.ToInt32(times[times.Length - 1])) { for (int i = 0; i < times.Length; i++) { int recHour = Convert.ToInt32(times[i]); if (DateTime.Now.AddMinutes(10).Hour < recHour) //add fudge factor for bad timers { nextRecord = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, recHour, 0, 0, 0, DateTime.Now.Kind); break; } } } else { //build date tomorrow int recHour = Convert.ToInt32(times[0]); //grab first time in the list nextRecord = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, recHour, 0, 0, 0, DateTime.Now.Kind); nextRecord = nextRecord.AddDays(1); } //Since we're awake, let's see if there are any files needing cleaning up VideoFileManager.CleanOldFiles(configuration); //Wait TimeSpan timeToWait = nextRecord - DateTime.Now; Console.WriteLine($"{DateTime.Now}: Now sleeping for {timeToWait.Hours+1} hours before checking again at {nextRecord.ToString()}"); Thread.Sleep(timeToWait); Console.WriteLine($"{DateTime.Now}: Woke up, now checking again..."); } } catch (Exception e) { Console.WriteLine("======================"); Console.WriteLine($"{DateTime.Now}: ERROR - Exception!"); Console.WriteLine("======================"); Console.WriteLine($"{e.Message}\n{e.StackTrace}"); //Send alert mail string body = "NO LONGER RECORDING! Main loop failed with Exception " + e.Message; body = body + "\n" + e.StackTrace; new Mailer().SendErrorMail(configuration, "NO LONGER RECORDING! StreamCapture Exception: (" + e.Message + ")", body); } }