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(); }
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(); }