/// <summary> /// A layout file has changed /// </summary> /// <param name="layoutPath"></param> private void LayoutFileModified(string layoutPath) { Trace.WriteLine(new LogMessage("Schedule - LayoutFileModified", "Layout file changed: " + layoutPath), LogType.Info.ToString()); // Tell the schedule to refresh _scheduleManager.RefreshSchedule = true; // Are we set to expire modified layouts? If not then just return as if // nothing had happened. if (!ApplicationSettings.Default.ExpireModifiedLayouts) { return; } // If the layout that got changed is the current layout, move on try { if (_layoutSchedule[_currentLayout].layoutFile == ApplicationSettings.Default.LibraryPath + @"\" + layoutPath) { // What happens if the action of downloading actually invalidates this layout? if (!_cacheManager.IsValidLayout(layoutPath)) { Trace.WriteLine(new LogMessage("Schedule - LayoutFileModified", "The current layout is now invalid, refreshing the current schedule."), LogType.Audit.ToString()); // We should not force a change and we should tell the schedule manager to run now _scheduleManager.RunNow(); } else { Trace.WriteLine(new LogMessage("Schedule - LayoutFileModified", "Forcing the current layout to change: " + layoutPath), LogType.Audit.ToString()); // Force a change _forceChange = true; // Run the next layout NextLayout(); } } } catch (Exception ex) { Trace.WriteLine(new LogMessage("fileCollector_LayoutFileChanged", String.Format("Unable to determine current layout with exception {0}", ex.Message)), LogType.Error.ToString()); } }
/// <summary> /// Loads a new schedule from _layoutSchedules /// </summary> /// <returns></returns> private Collection <LayoutSchedule> LoadNewSchdule() { // We need to build the current schedule from the layout schedule (obeying date/time) Collection <LayoutSchedule> newSchedule = new Collection <LayoutSchedule>(); Collection <LayoutSchedule> prioritySchedule = new Collection <LayoutSchedule>(); // Temporary default Layout incase we have no layout nodes. LayoutSchedule defaultLayout = new LayoutSchedule(); // For each layout in the schedule determine if it is currently inside the _currentSchedule, and whether it should be foreach (LayoutSchedule layout in _layoutSchedule) { // Is the layout valid in the cachemanager? try { if (!_cacheManager.IsValidLayout(layout.id + ".xlf")) { Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout invalid: " + layout.id), LogType.Info.ToString()); continue; } } catch { // Ignore this layout.. raise an error? Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Unable to determine if layout is valid or not"), LogType.Error.ToString()); continue; } // Check dependents foreach (string dependent in layout.Dependents) { if (!_cacheManager.IsValidPath(dependent)) { Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout has invalid dependent: " + dependent), LogType.Info.ToString()); continue; } } // If this is the default, skip it if (layout.NodeName == "default") { // Store it before skipping it defaultLayout = layout; continue; } // Look at the Date/Time to see if it should be on the schedule or not if (layout.FromDt <= DateTime.Now && layout.ToDt >= DateTime.Now) { // Priority layouts should generate their own list if (layout.Priority) { prioritySchedule.Add(layout); } else { newSchedule.Add(layout); } } } // If we have any priority schedules then we need to return those instead if (prioritySchedule.Count > 0) { return(prioritySchedule); } // If the current schedule is empty by the end of all this, then slip the default in if (newSchedule.Count == 0) { newSchedule.Add(defaultLayout); } return(newSchedule); }