public EntryList remove_FTR2LO_entries_from_tasklist(EntryList list, string ending_later_than)
        {
            EntryList retval = new EntryList();
            int       i      = 0;



            for (i = 0; (i < list.listEntries.Count); i = i + 1)
            {
                Item tmp_item = list.listEntries[i] as Item;
                MessageBox.Show("A: " + tmp_item.enddate + "\nB: " + ending_later_than + "\nCompare: " + String.Compare(tmp_item.enddate, ending_later_than).ToString());

                //the first check it to make sure that non-FTTR2LO entries are ignored;
                //the result of the string comparison is -1 if enddate is aftern ending_later_than
                //and +1 if enddate is earlier than ending_later_than

                if ((find_substring_in_string(tmp_item.name, "FTR2LO") != 1) &&
                    (String.Compare(tmp_item.enddate, ending_later_than) == -1))
                {
                    retval.AddItem(tmp_item);
                }
            }

            return(retval);
        }
示例#2
0
        public void ftr2lo_main()
        {
            EntryList loce1               = new EntryList();
            EntryList ftrce1              = new EntryList();
            EntryList toadd               = new EntryList();
            EntryList todelete            = new EntryList();
            Hashtable guid_name_hashtable = new Hashtable();

            FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "ftr2lo_main running...");

            if (Proxies.IsInitialized) //  ServiceChannelFactories.IsInitialized)
            {
                HelpFunctions.HelpFunctions hf = new HelpFunctions.HelpFunctions();
                string filepath    = Ftr2LoService.config.FilepathLO;
                bool   _changeflag = false;
                System.Collections.Generic.List <UpcomingProgram> upcomingprograms;

                #region get Lights-Out entries

                if (File.Exists(filepath))
                {
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "TaskList.xml found at " + filepath);
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Loading LightsOut task list ....");
                    loce1 = hf.read_file(filepath);   //this is how the arraylist is read from the disk
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "ok.");
                }
                else
                {
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.WARNING, "TaskList.xml not found at " + filepath + ", file will be created if planned recordings exist.");
                }

                //FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Cleaning list....");
                //loce1 = hf.clean_tasklist(loce1, fnow);

                #endregion

                #region get FTR entries

                //using (ArgusTV.ServiceAgents.SchedulerServiceAgent tvssa = new ArgusTV.ServiceAgents.SchedulerServiceAgent())
                // ArgusTV.ServiceProxy.SchedulerServiceProxy tvssa = null; // = new SchedulerServiceProxy();
                {
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Fetching upcoming recordings ....");
                    upcomingprograms = Proxies.SchedulerService.GetAllUpcomingPrograms(ScheduleType.Recording, false);
                    // upcomingprograms = tvssa.GetAllUpcomingPrograms(ScheduleType.Recording, false);
                }

                FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Populating each upcoming recording ....");
                foreach (UpcomingProgram up in upcomingprograms)
                {
                    DateTime astart;
                    DateTime astop;
                    Guid     aprogid;
                    TimeSpan earlystart;
                    string   fstart;
                    string   fstop;
                    string   fprogid;
                    string   aname;

                    aname      = up.Title.ToString();
                    earlystart = new TimeSpan(0, Convert.ToInt16(Ftr2LoService.config.EarlyStart), 0);
                    astart     = up.ActualStartTime - earlystart;
                    astop      = up.ActualStopTime;
                    aprogid    = up.UpcomingProgramId;
                    fstart     = astart.Year.ToString() + "-" + astart.Month.ToString("00") + "-" + astart.Day.ToString("00") + "T" + astart.TimeOfDay.ToString();
                    fstop      = astop.Year.ToString() + "-" + astop.Month.ToString("00") + "-" + astop.Day.ToString("00") + "T" + astop.TimeOfDay.ToString();
                    fprogid    = "ATV2LO-" + System.Guid.NewGuid().ToString();

                    Item item_tst = new Item(fstart, fstop, fprogid);
                    ftrce1.AddItem(item_tst);
                    guid_name_hashtable.Add(fprogid, aname);
                }

                if (upcomingprograms.Count > 0)
                {
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Number of upcoming programs: " + upcomingprograms.Count);
                }

                else
                {
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "No upcoming recordings");
                }

                #endregion

                #region Calculate Add/Delete lists

                bool _purgeoldftr2loitems = false;
                Boolean.TryParse(Ftr2LoService.config.PurgeOldFTR2LOItems, out _purgeoldftr2loitems);

                foreach (Item i in ftrce1.listEntries)
                {
                    if (hf.find_task_in_list(loce1, i) == false)
                    {
                        _changeflag = true;
                        FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.INFO, "Add \"" + guid_name_hashtable[i.name] + "\" to LightsOut. Actual Start Time: " + i.startdate + ", Actual Stop Time: " + i.enddate);
                        toadd.AddItem(i);
                    }
                }

                DateTime now  = System.DateTime.Now;
                string   fnow = now.Year.ToString() + "-" + now.Month.ToString("00") + "-" + now.Day.ToString("00") + "T" + now.TimeOfDay.ToString();

                foreach (Item i in loce1.listEntries)
                {
                    if ((hf.find_substring_in_string(i.name, "ATV2LO") != -1) && // if FTRLO incl, it is greater than -1
                        (_purgeoldftr2loitems || (String.Compare(i.enddate, fnow) == 1)) && //if earlier, it is -1
                        (hf.find_task_in_list(ftrce1, i) == false))
                    {
                        _changeflag = true;
                        todelete.AddItem(i);
                    }
                }
                #endregion

                #region Do Add/Delete Actions

                foreach (Item i in toadd.listEntries)
                {
                    loce1.AddItem(i);
                }

                foreach (Item i in todelete.listEntries)
                {
                    //remove from LO Task-LIst
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.INFO, "Remove obsolete task from Lights-Out. Actual Start Time: " + i.startdate + ", Actual Stop Time: " + i.enddate);
                    loce1.RemoveItem(i);

                    // additionally, remove orphaned entries vom Windows task list
                    string tmp = DeleteWinTasks_CMD.DeleteOldWinTasks.RemoveFromWindowsTasklist(i.name);
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.INFO, "Remove obsolete task from Windows Task Scheduler: " + tmp);
                }

                #endregion

                if (_changeflag)
                {
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Sorting list....");
                    loce1.SortList();
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Writing to disk....");
                    hf.write_file(loce1, filepath);
                }
                else
                {
                    FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Nothing to do.");
                }
            }
            else
            {
                FTR2LO_Log.FTR2LO_log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Problem in ftr2lo_main: ServiceChannelFactories not initialized, trying to re-init....");
                InitializeServiceChannelFactories(Ftr2LoService.config.ServerName, Convert.ToInt32(Ftr2LoService.config.ServerPort));
            }

            this.timer1.Start();
        }
示例#3
0
        public void ftr2lo_main()
        {
            //create and initialize configuration
            string FilepathLO = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\LightsOut\\TaskList.xml";
            string EarlyStart = "3";
            string ServerName = "server";
            string ServerPort = "49942";
            //int LogLevel = 0;

            EntryList loce1    = new EntryList();
            EntryList ftrce1   = new EntryList();
            EntryList toadd    = new EntryList();
            EntryList todelete = new EntryList();



            InitializeServiceChannelFactories(ServerName, Convert.ToInt32(ServerPort));

            ////Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "ftr2lo_main running...");

            if (ServiceChannelFactories.IsInitialized)
            {
                HelpFunctionsPlayground.HelpFunctions hf = new HelpFunctionsPlayground.HelpFunctions();
                string filepath  = FilepathLO;
                bool   _newitems = false;

                /*UpcomingRecording[] upcomingrecordings;
                 * UpcomingRecordingsFilter filter = UpcomingRecordingsFilter.Recordings;
                 * ActiveRecording[] activerecordings;
                 * TvControlServiceAgent tvcsa = new TvControlServiceAgent();*/
                UpcomingProgram[]       upcomingprograms;
                TvSchedulerServiceAgent tvssa = new TvSchedulerServiceAgent();

                if (File.Exists(filepath))
                {
                    ////Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "TaskList.xml found at " + filepath);
                    ////Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Loading LightsOut task list ....");
                    loce1 = hf.read_file(filepath);   //this is how the arraylist is read from the disk
                    ////Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "ok.");
                }

                if (checkBoxClearEntries.Checked == true)
                {
                    DateTime now  = System.DateTime.Now;
                    string   fnow = now.Year.ToString() + "-" + now.Month.ToString("00") + "-" + now.Day.ToString("00") + "T" + now.TimeOfDay.ToString();
                    loce1 = hf.remove_FTR2LO_entries_from_tasklist(loce1, fnow);
                }


                upcomingprograms = tvssa.GetAllUpcomingPrograms(ScheduleType.Recording, true);

                textBox1.Text        = "****There are " + upcomingprograms.Length + " items scheduled in FTR (including cancelled) *****" + Environment.NewLine;
                textBox2.Text        = "****There are " + loce1.listEntries.Count + " in total in the task list *****" + Environment.NewLine;
                textBoxToAdd.Text    = "To be added to task list" + Environment.NewLine;
                textBoxToDelete.Text = "To be deleted from tast list" + Environment.NewLine;



                if (upcomingprograms.Length > 0)
                {
                    ////Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Number of upcoming programs: " + upcomingprograms.Length);

                    foreach (UpcomingProgram up in upcomingprograms)
                    {
                        DateTime astart;
                        DateTime astop;
                        Guid     aprogid;
                        TimeSpan earlystart;
                        string   fstart;
                        string   fstop;
                        string   fprogid;
                        bool     iscancelled = up.IsCancelled;

                        if (iscancelled == false)
                        {
                            string aname = up.Title.ToString();
                            earlystart = new TimeSpan(0, Convert.ToInt16(EarlyStart), 0);
                            astart     = up.ActualStartTime - earlystart;
                            astop      = up.ActualStopTime;
                            aprogid    = up.UpcomingProgramId;
                            fstart     = astart.Year.ToString() + "-" + astart.Month.ToString("00") + "-" + astart.Day.ToString("00") + "T" + astart.TimeOfDay.ToString();
                            fstop      = astop.Year.ToString() + "-" + astop.Month.ToString("00") + "-" + astop.Day.ToString("00") + "T" + astop.TimeOfDay.ToString();
                            fprogid    = "FTR2LO-" + System.Guid.NewGuid().ToString();

                            Item item_tst = new Item(fstart, fstop, fprogid);
                            //textBox1.Refresh();
                            ftrce1.AddItem(item_tst);
                        }
                    }

                    DateTime now  = System.DateTime.Now;
                    string   snow = now.Year.ToString() + "-" + now.Month.ToString("00") + "-" + now.Day.ToString("00") + "T" + now.TimeOfDay.ToString();

                    foreach (Item i in loce1.listEntries)
                    {
                        if ((hf.find_task_in_list(ftrce1, i) == false) &&
                            (String.Compare(i.enddate, snow) == -1))
                        {
                            todelete.AddItem(i);
                        }
                    }

                    foreach (Item i in ftrce1.listEntries)
                    {
                        if (hf.find_task_in_list(loce1, i) == false)
                        {
                            toadd.AddItem(i);
                        }
                    }

                    foreach (Item i in loce1.listEntries)
                    {
                        if (hf.find_substring_in_string(i.name, "FTR2LO") != -1)
                        {
                            textBox2.Text = textBox2.Text + " " + i.startdate + " " + i.enddate + " " + i.name + Environment.NewLine;
                        }
                    }

                    foreach (Item i in ftrce1.listEntries)
                    {
                        textBox1.Text = textBox1.Text + " " + i.startdate + " " + i.enddate + " " + i.name + Environment.NewLine;
                    }

                    foreach (Item i in toadd.listEntries)
                    {
                        textBoxToAdd.Text = textBoxToAdd.Text + " " + i.startdate + " " + i.enddate + " " + i.name + Environment.NewLine;
                    }

                    foreach (Item i in todelete.listEntries)
                    {
                        textBoxToDelete.Text = textBoxToDelete.Text + " " + i.startdate + " " + i.enddate + " " + i.name + Environment.NewLine;
                    }

                    if (!_newitems)
                    {
                        ////Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Nothing to add.");
                    }
                    else
                    {
                        ////Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Sorting list....");
                        loce1.SortList();
                        ////Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.DEBUG, "Writing to disk....");
                        hf.write_file(loce1, filepath);
                    }
                }
                else
                {
                    textBox1.Text = "ServiceChannelFactories not initialized";
                }
            }
        }