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;
        }
Exemple #2
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";
                }
            }
        }