Ejemplo n.º 1
0
        /// <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.IsValidPath(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());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads a new schedule from _layoutSchedules
        /// </summary>
        /// <returns></returns>
        private Collection <ScheduleItem> LoadNewSchedule()
        {
            // We need to build the current schedule from the layout schedule (obeying date/time)
            Collection <ScheduleItem> newSchedule          = new Collection <ScheduleItem>();
            Collection <ScheduleItem> prioritySchedule     = new Collection <ScheduleItem>();
            Collection <ScheduleItem> layoutChangeSchedule = new Collection <ScheduleItem>();

            // Temporary default Layout incase we have no layout nodes.
            ScheduleItem defaultLayout = new ScheduleItem();

            // Store the valid layout id's
            List <int> validLayoutIds = new List <int>();
            List <int> invalidLayouts = new List <int>();

            // Store the highest priority
            int highestPriority = 0;

            // For each layout in the schedule determine if it is currently inside the _currentSchedule, and whether it should be
            foreach (ScheduleItem layout in _layoutSchedule)
            {
                // Is this already invalid
                if (invalidLayouts.Contains(layout.id))
                {
                    continue;
                }

                // If we haven't already assessed this layout before, then check that it is valid
                if (!validLayoutIds.Contains(layout.id))
                {
                    if (!ApplicationSettings.Default.ExpireModifiedLayouts && layout.id == CurrentLayoutId)
                    {
                        Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Skipping validity test for current layout."), LogType.Audit.ToString());
                    }
                    else
                    {
                        // Is the layout valid in the cachemanager?
                        try
                        {
                            if (!_cacheManager.IsValidPath(layout.id + ".xlf"))
                            {
                                invalidLayouts.Add(layout.id);
                                Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout invalid: " + layout.id), LogType.Info.ToString());
                                continue;
                            }
                        }
                        catch
                        {
                            // Ignore this layout.. raise an error?
                            invalidLayouts.Add(layout.id);
                            Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Unable to determine if layout is valid or not"), LogType.Error.ToString());
                            continue;
                        }

                        // Check dependents
                        bool validDependents = true;
                        foreach (string dependent in layout.Dependents)
                        {
                            if (!string.IsNullOrEmpty(dependent) && !_cacheManager.IsValidPath(dependent))
                            {
                                invalidLayouts.Add(layout.id);
                                Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout has invalid dependent: " + dependent), LogType.Info.ToString());

                                validDependents = false;
                                break;
                            }
                        }

                        if (!validDependents)
                        {
                            continue;
                        }
                    }
                }

                // Add to the valid layout ids
                validLayoutIds.Add(layout.id);

                // 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)
                {
                    // Change Action and Priority layouts should generate their own list
                    if (layout.Override)
                    {
                        layoutChangeSchedule.Add(layout);
                    }
                    else if (layout.Priority >= 1)
                    {
                        // Is this higher than our priority already?
                        if (layout.Priority > highestPriority)
                        {
                            prioritySchedule.Clear();
                            prioritySchedule.Add(layout);

                            // Store the new highest priority
                            highestPriority = layout.Priority;
                        }
                        else if (layout.Priority == highestPriority)
                        {
                            prioritySchedule.Add(layout);
                        }
                        // Layouts with a priority lower than the current highest are discarded.
                    }
                    else
                    {
                        newSchedule.Add(layout);
                    }
                }
            }

            // If we have any layout change scheduled then we return those instead
            if (layoutChangeSchedule.Count > 0)
            {
                return(layoutChangeSchedule);
            }

            // 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);
        }
Ejemplo n.º 3
0
        /// <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());

            // Determine if we need to reassess the overlays
            foreach (ScheduleItem item in _overlaySchedule)
            {
                if (item.layoutFile == ApplicationSettings.Default.LibraryPath + @"\" + layoutPath)
                {
                    if (OverlayChangeEvent != null)
                    {
                        OverlayChangeEvent(_overlaySchedule);
                    }

                    break;
                }
            }

            // 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?
                    bool valid = _cacheManager.IsValidPath(layoutPath);

                    if (valid)
                    {
                        // Check dependents
                        foreach (string dependent in _layoutSchedule[_currentLayout].Dependents)
                        {
                            if (!string.IsNullOrEmpty(dependent) && !_cacheManager.IsValidPath(dependent))
                            {
                                valid = false;
                                break;
                            }
                        }
                    }

                    if (!valid)
                    {
                        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());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the next media node. Should be used either from a mediaComplete event, or an options reset from
        /// the parent.
        /// </summary>
        private bool SetNextMediaNodeInOptions()
        {
            // What if there are no media nodes?
            if (_options.mediaNodes.Count == 0)
            {
                Trace.WriteLine(new LogMessage("Region - SetNextMediaNode", "No media nodes to display"), LogType.Audit.ToString());

                return(false);
            }

            // Zero out the options that are persisted
            _options.text             = "";
            _options.documentTemplate = "";
            _options.copyrightNotice  = "";
            _options.scrollSpeed      = 30;
            _options.updateInterval   = 6;
            _options.uri        = "";
            _options.direction  = "none";
            _options.javaScript = "";
            _options.FromDt     = DateTime.MinValue;
            _options.ToDt       = DateTime.MaxValue;
            _options.Dictionary = new MediaDictionary();

            // Tidy up old audio if necessary
            foreach (Media audio in _options.Audio)
            {
                try
                {
                    // Unbind any events and dispose
                    audio.DurationElapsedEvent -= audio_DurationElapsedEvent;
                    audio.Dispose();
                }
                catch
                {
                    Trace.WriteLine(new LogMessage("Region - SetNextMediaNodeInOptions", "Unable to dispose of audio item"), LogType.Audit.ToString());
                }
            }

            // Empty the options node
            _options.Audio.Clear();

            // Get a media node
            bool validNode   = false;
            int  numAttempts = 0;

            // Loop through all the nodes in order
            while (numAttempts < _options.mediaNodes.Count)
            {
                // Move the sequence on
                _currentSequence++;

                if (_currentSequence >= _options.mediaNodes.Count)
                {
                    // Start from the beginning
                    _currentSequence = 0;

                    // We have expired (want to raise an expired event to the parent)
                    _hasExpired = true;

                    Trace.WriteLine(new LogMessage("Region - SetNextMediaNode", "Media Expired:" + _options.ToString() + " . Reached the end of the sequence. Starting from the beginning."), LogType.Audit.ToString());

                    // Region Expired
                    if (DurationElapsedEvent != null)
                    {
                        DurationElapsedEvent();
                    }

                    // We want to continue on to show the next media (unless the duration elapsed event triggers a region change)
                    if (_layoutExpired)
                    {
                        return(true);
                    }
                }

                // Get the media node for this sequence
                XmlNode mediaNode = _options.mediaNodes[_currentSequence];
                XmlAttributeCollection nodeAttributes = mediaNode.Attributes;

                // Set the media id
                if (nodeAttributes["id"].Value != null)
                {
                    _options.mediaid = nodeAttributes["id"].Value;
                }

                // Set the file id
                if (nodeAttributes["fileId"] != null)
                {
                    _options.FileId = int.Parse(nodeAttributes["fileId"].Value);
                }

                // Check isnt blacklisted
                if (_blackList.BlackListed(_options.mediaid))
                {
                    Trace.WriteLine(new LogMessage("Region - SetNextMediaNode", string.Format("MediaID [{0}] has been blacklisted.", _options.mediaid)), LogType.Error.ToString());

                    // Increment the number of attempts and try again
                    numAttempts++;

                    // Carry on
                    continue;
                }

                // Assume we have a valid node at this point
                validNode = true;

                // Parse the options for this media node
                ParseOptionsForMediaNode(mediaNode, nodeAttributes);

                // Is this widget inside the from/to date?
                if (!(_options.FromDt <= DateTime.Now && _options.ToDt > DateTime.Now))
                {
                    Trace.WriteLine(new LogMessage("Region", "SetNextMediaNode: Widget outside from/to date."), LogType.Audit.ToString());

                    // Increment the number of attempts and try again
                    numAttempts++;

                    // Carry on
                    continue;
                }

                // Is this a file based media node?
                if (_options.type == "video" || _options.type == "flash" || _options.type == "image" || _options.type == "powerpoint" || _options.type == "audio" || _options.type == "htmlpackage")
                {
                    // Use the cache manager to determine if the file is valid
                    validNode = _cacheManager.IsValidPath(_options.uri);
                }

                // If we have a valid node, break out of the loop
                if (validNode)
                {
                    break;
                }

                // Increment the number of attempts and try again
                numAttempts++;
            }

            // If we dont have a valid node out of all the nodes in the region, then return false.
            if (!validNode)
            {
                return(false);
            }

            Trace.WriteLine(new LogMessage("Region - SetNextMediaNode", "New media detected " + _options.type), LogType.Audit.ToString());

            return(true);
        }
Ejemplo n.º 5
0
        /// <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)
            {
                if (!ApplicationSettings.Default.ExpireModifiedLayouts && layout.id == CurrentLayoutId)
                {
                    Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Skipping validity test for current layout."), LogType.Audit.ToString());
                }
                else
                {
                    // Is the layout valid in the cachemanager?
                    try
                    {
                        if (!_cacheManager.IsValidPath(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 (!string.IsNullOrEmpty(dependent) && !_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);
        }