示例#1
0
        //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);
        }
示例#2
0
        public Recorder(IConfiguration _configuration)
        {
            configuration = _configuration;
            mre           = new ManualResetEvent(false);

            //Instanciate recordings
            recordings = new Recordings(configuration, mre);

            //Test Authentication
            Task <string> authTask  = Authenticate();
            string        hashValue = authTask.Result;

            if (string.IsNullOrEmpty(hashValue))
            {
                Console.WriteLine($"ERROR: Unable to authenticate.  Check username and password?  Bad auth URL?");
                Environment.Exit(1);
            }
        }
示例#3
0
        public void SendDailyDigest(IConfiguration configuration, Recordings recordings)
        {
            string scheduledShows   = "";
            string notScheduleShows = "";
            string recordedShows    = "";
            string partialShows     = "";
            string notRecordedShows = "";
            string tooManyShows     = "";

            //Build each portion of the mail
            List <RecordInfo> sortedRecordInfoList = recordings.GetSortedMasterRecordList();

            foreach (RecordInfo recordInfo in sortedRecordInfoList)
            {
                string showText = BuildTableRow(recordInfo);

                if (recordInfo.queuedFlag && !recordInfo.completedFlag)
                {
                    scheduledShows = scheduledShows + showText;
                }
                else if (recordInfo.tooManyFlag)
                {
                    tooManyShows = tooManyShows + showText;
                }
                else if (!recordInfo.processSpawnedFlag && recordInfo.GetStartDT() > DateTime.Now)
                {
                    notScheduleShows = notScheduleShows + showText;
                }
                else if (recordInfo.completedFlag && !recordInfo.partialFlag)
                {
                    recordedShows = recordedShows + showText;
                }
                else if (recordInfo.partialFlag)
                {
                    partialShows = partialShows + showText;
                }
                else
                {
                    notRecordedShows = notRecordedShows + showText;
                }
            }
            string emailText = "";

            if (!string.IsNullOrEmpty(scheduledShows))
            {
                emailText = emailText + StartTable("Scheduled Shows") + scheduledShows + EndTable();
            }
            if (!string.IsNullOrEmpty(tooManyShows))
            {
                emailText = emailText + StartTable("Shows NOT Scheduled (too many at once)") + tooManyShows + EndTable();
            }
            if (!string.IsNullOrEmpty(notScheduleShows))
            {
                emailText = emailText + StartTable("Shows not scheduled yet") + notScheduleShows + EndTable();
            }
            if (!string.IsNullOrEmpty(recordedShows))
            {
                emailText = emailText + StartTable("Shows Recorded") + recordedShows + EndTable();
            }
            if (!string.IsNullOrEmpty(partialShows))
            {
                emailText = emailText + StartTable("Shows PARTIALLY Recorded") + partialShows + EndTable();
            }
            if (!string.IsNullOrEmpty(notRecordedShows))
            {
                emailText = emailText + StartTable("Shows NOT Recorded") + notRecordedShows + EndTable();
            }

            //Send mail
            if (!string.IsNullOrEmpty(emailText))
            {
                SendMail(configuration, "Daily Digest", emailText);
            }
        }
示例#4
0
        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);
            }
        }