示例#1
0
        /// <summary>
        /// The media has elapsed
        /// </summary>
        private void media_DurationElapsedEvent(int filesPlayed)
        {
            Trace.WriteLine(new LogMessage("Region", string.Format("DurationElapsedEvent: Media Elapsed: {0}", this.options.uri)), LogType.Audit.ToString());

            if (filesPlayed > 1)
            {
                // Increment the _current sequence by the number of filesPlayed (minus 1)
                this.currentSequence = this.currentSequence + (filesPlayed - 1);
            }

            // Indicate that this media has expired.
            MediaExpiredEvent?.Invoke();

            // If this layout has been expired we know that everything will soon be torn down, so do nothing
            if (IsLayoutExpired)
            {
                Debug.WriteLine("DurationElapsedEvent: Layout Expired, therefore we don't StartNext", "Region");
                return;
            }

            // If we are now paused, we don't start the next media
            if (this._isPaused)
            {
                Debug.WriteLine("DurationElapsedEvent: Paused, therefore we don't StartNext", "Region");
                return;
            }

            // If Pause Pending, then stop here as we will be removed
            if (IsPausePending)
            {
                Debug.WriteLine("DurationElapsedEvent: Pause Pending, therefore we don't StartNext", "Region");
                return;
            }

            // TODO:
            // Animate out at this point if we need to
            // the result of the animate out complete event should then move us on.
            // this.currentMedia.TransitionOut();

            // make some decisions about what to do next
            try
            {
                StartNext(0);
            }
            catch (Exception e)
            {
                Trace.WriteLine(new LogMessage("Region", "DurationElapsedEvent: E=" + e.Message), LogType.Error.ToString());

                // What do we do if there is an exception moving to the next media node?
                // For some reason we cannot set a media node... so we need this region to become invalid
                IsExpired = true;

                // Fire elapsed
                DurationElapsedEvent?.Invoke();

                return;
            }
        }
示例#2
0
        /// <summary>
        /// Signals that an event is elapsed
        /// Will raise a DurationElapsedEvent
        /// </summary>
        public void SignalElapsedEvent()
        {
            Expired = true;

            Trace.WriteLine(new LogMessage("Media - SignalElapsedEvent", "Media Complete"), LogType.Audit.ToString());

            // We're complete
            DurationElapsedEvent?.Invoke(_filesPlayed);
        }
示例#3
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 (this.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
            this.options.text             = "";
            this.options.documentTemplate = "";
            this.options.copyrightNotice  = "";
            this.options.scrollSpeed      = 30;
            this.options.updateInterval   = 6;
            this.options.uri        = "";
            this.options.direction  = "none";
            this.options.javaScript = "";
            this.options.FromDt     = DateTime.MinValue;
            this.options.ToDt       = DateTime.MaxValue;
            this.options.Dictionary = new MediaDictionary();

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

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

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

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

                if (this.currentSequence >= this.options.mediaNodes.Count)
                {
                    Trace.WriteLine(new LogMessage("Region", "SetNextMediaNodeInOptions: Region " + this.options.regionId + " Expired"), LogType.Audit.ToString());

                    // Start from the beginning
                    this.currentSequence = 0;

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

                    // Region Expired
                    DurationElapsedEvent?.Invoke();

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

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

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

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

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

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

                    // Carry on
                    continue;
                }

                // Stats enabled?
                this.options.isStatEnabled = (nodeAttributes["enableStat"] == null) ? true : (int.Parse(nodeAttributes["enableStat"].Value) == 1);

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

                // Is this widget inside the from/to date?
                if (!(this.options.FromDt <= DateTime.Now && this.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++;

                    // Watermark the next earliest time we can expect this Widget to be available.
                    if (this.options.FromDt > DateTime.Now)
                    {
                        if (_widgetAvailableTtl == 0)
                        {
                            _widgetAvailableTtl = (int)(this.options.FromDt - DateTime.Now).TotalSeconds;
                        }
                        else
                        {
                            _widgetAvailableTtl = Math.Min(_widgetAvailableTtl, (int)(this.options.FromDt - DateTime.Now).TotalSeconds);
                        }
                    }

                    // Carry on
                    continue;
                }

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

                // Is this a file based media node?
                if (this.options.type == "video" || this.options.type == "flash" || this.options.type == "image" || this.options.type == "powerpoint" || this.options.type == "audio" || this.options.type == "htmlpackage")
                {
                    // Use the cache manager to determine if the file is valid
                    validNode = CacheManager.Instance.IsValidPath(this.options.uri) && !CacheManager.Instance.IsUnsafeMedia(this.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 " + this.options.type), LogType.Audit.ToString());

            return(true);
        }