コード例 #1
0
ファイル: Region.cs プロジェクト: cnxsoft/xibo4arm
        /// <summary>
        /// Sets the next media node. Should be used either from a mediaComplete event, or an options reset from 
        /// the parent.
        /// </summary>
        private bool SetNextMediaNode()
        {
            int playingSequence = currentSequence;

            // What if there are no media nodes?
            if (options.mediaNodes.Count == 0)
            {
                System.Diagnostics.Debug.WriteLine("No media nodes to display", "Region - SetNextMediaNode");
                hasExpired = true;
                return false;
            }

            if (options.mediaNodes.Count == 1 && currentSequence != -1)
            {
                //dont bother discarding this media, keep all the same details, but still trigger an expired event
                System.Diagnostics.Debug.WriteLine("Media Expired:" + options.ToString() + " . Nothing else to show", "Region - SetNextMediaNode");
                hasExpired = true;

                DurationElapsedEvent();
                return true;
            }

            // Move the sequence on
            currentSequence++;

            if (currentSequence >= options.mediaNodes.Count)
            {
                currentSequence = 0; //zero it

                hasExpired = true; //we have expired (want to raise an expired event to the parent)

                System.Diagnostics.Debug.WriteLine("Media Expired:" + options.ToString() + " . Reached the end of the sequence. Starting from the beginning.", "Region - SetNextMediaNode");

                DurationElapsedEvent();

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

            //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.Dictionary = new MediaDictionary();

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

            while (!validNode)
            {
                numAttempts++;

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

                XmlAttributeCollection nodeAttributes = mediaNode.Attributes;

                if (nodeAttributes["id"].Value != null) options.mediaid = nodeAttributes["id"].Value;

                // Check isnt blacklisted
                if (blackList.BlackListed(options.mediaid))
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("The File [{0}] has been blacklisted", options.mediaid), "Region - SetNextMediaNode");

                    // Increment and Loop
                    currentSequence++;

                    if (currentSequence >= options.mediaNodes.Count)
                    {
                        currentSequence = 0; //zero it

                        hasExpired = true; //we have expired (want to raise an expired event to the parent)

                        System.Diagnostics.Debug.WriteLine("Media Expired:" + options.ToString() + " . Reached the end of the sequence. Starting from the beginning.", "Region - SetNextMediaNode");

                        DurationElapsedEvent();

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

                    // New version has a different schema - the right way to do it would be to pass the <options> and <raw> nodes to
                    // the relevant media class - however I dont feel like engineering such a change so the alternative is to
                    // parse all the possible media type nodes here.

                    // Type and Duration will always be on the media node
                    options.type        = nodeAttributes["type"].Value;

                    //TODO: Check the type of node we have, and make sure it is supported.

                    if (nodeAttributes["duration"].Value != "")
                    {
                        options.duration = int.Parse(nodeAttributes["duration"].Value);
                    }
                    else
                    {
                        options.duration = 60;
                        System.Diagnostics.Trace.WriteLine("Duration is Empty, using a default of 60.", "Region - SetNextMediaNode");
                    }

                    // We cannot have a 0 duration here... not sure why we would... but
                    if (options.duration == 0 && options.type != "video")
                    {
                        int emptyLayoutDuration = int.Parse(Properties.Settings.Default.emptyLayoutDuration.ToString());
                        options.duration = (emptyLayoutDuration == 0) ? 10 : emptyLayoutDuration;
                    }

                    // There will be some stuff on option nodes
                    XmlNode optionNode = mediaNode.FirstChild;

                    foreach (XmlNode option in optionNode.ChildNodes)
                    {
                        if (option.Name == "direction")
                        {
                            options.direction = option.InnerText;
                        }
                        else if (option.Name == "uri")
                        {
                            options.uri = option.InnerText;
                        }
                        else if (option.Name == "copyright")
                        {
                            options.copyrightNotice = option.InnerText;
                        }
                        else if (option.Name == "scrollSpeed")
                        {
                            try
                            {
                                options.scrollSpeed = int.Parse(option.InnerText);
                            }
                            catch
                            {
                                System.Diagnostics.Trace.WriteLine("Non integer scrollSpeed in XLF", "Region - SetNextMediaNode");
                            }
                        }
                        else if (option.Name == "updateInterval")
                        {
                            try
                            {
                                options.updateInterval = int.Parse(option.InnerText);
                            }
                            catch
                            {
                                System.Diagnostics.Trace.WriteLine("Non integer updateInterval in XLF", "Region - SetNextMediaNode");
                            }
                        }

                        // Add this to the options object
                        options.Dictionary.Add(option.Name, option.InnerText);
                    }

                    // And some stuff on Raw nodes
                    XmlNode rawNode = mediaNode.LastChild;

                    foreach (XmlNode raw in rawNode.ChildNodes)
                    {
                        if (raw.Name == "text")
                        {
                            options.text = raw.InnerText;
                        }
                        else if (raw.Name == "template")
                        {
                            options.documentTemplate = raw.InnerText;
                        }
                        else if (raw.Name == "embedHtml")
                        {
                            options.text = raw.InnerText;
                        }
                        else if (raw.Name == "embedScript")
                        {
                            options.javaScript = raw.InnerText;
                        }
                    }

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

                if (numAttempts > options.mediaNodes.Count)
                {
                    // There are no valid nodes in this region, so just signify that the region is ending, and show nothing.
                    System.Diagnostics.Trace.WriteLine("No Valid media nodes to display", "Region - SetNextMediaNode");

                    hasExpired = true;
                    return false;
                }
            }

            System.Diagnostics.Debug.WriteLine("New media detected " + options.type, "Region - SetNextMediaNode");

            // Remove the old one if we have found a valid node - otherwise keep it
            if ((validNode && playingSequence != -1) && playingSequence != currentSequence)
            {
                System.Diagnostics.Debug.WriteLine("Trying to dispose of the current media", "Region - SetNextMediaNode");
                // Dispose of the current media
                try
                {
                    media.Hide();
                    Application.DoEvents();

                    // Remove the controls
                    Controls.Remove(media);

                    media.Dispose();
                    media = null;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("No media to remove");
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }

                try
                {
                    // Here we say that this media is expired
                    _stat.toDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                    // Record this stat event in the statLog object
                    _statLog.RecordStat(_stat);
                }
                catch
                {
                    System.Diagnostics.Trace.WriteLine("No Stat record when one was expected", LogType.Error.ToString());
                }
            }

            return true;
        }
コード例 #2
0
ファイル: Region.cs プロジェクト: cnxsoft/xibo4arm
        /// <summary>
        /// Performs the disposal.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    media.Dispose();
                    media = null;

                    System.Diagnostics.Debug.WriteLine("Media Disposed by Region", "Region - Dispose");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    System.Diagnostics.Debug.WriteLine("There was no media to dispose", "Region - Dispose");
                }
                finally
                {
                    if (media != null) media = null;
                }
            }

            base.Dispose(disposing);
        }
コード例 #3
0
ファイル: Region.cs プロジェクト: cnxsoft/xibo4arm
        ///<summary>
        /// Evaulates the change in options
        ///</summary>
        private void EvalOptions()
        {
            if (currentSequence == -1)
            {
                //evaluate the width, etc
                this.Location = new System.Drawing.Point(options.left, options.top);
                this.Size = new System.Drawing.Size(options.width, options.height);
            }

            int temp = currentSequence;

            //set the next media node for this panel
            if (!SetNextMediaNode())
            {
                // For some reason we cannot set a media node... so we need this region to become invalid
                hasExpired = true;
                DurationElapsedEvent();
                return;
            }

            // If the sequence hasnt been changed, OR the layout has been expired
            if (currentSequence == temp || layoutExpired)
            {
                //there has been no change to the sequence, therefore the media we have already created is still valid
                //or this media has actually been destroyed and we are working out way out the call stack
                return;
            }

            System.Diagnostics.Debug.WriteLine(String.Format("Creating new media: {0}, {1}", options.type, options.mediaid), "Region - EvalOptions");

            try
            {
                switch (options.type)
                {
                    case "image":
                        options.uri = Properties.Settings.Default.LibraryPath + @"\" + options.uri;
                        media = new ImagePosition(options);
                        break;

                    case "text":
                        media = new Text(options);
                        break;

                    case "powerpoint":
                        options.uri = Properties.Settings.Default.LibraryPath + @"\" + options.uri;
                        media = new WebContent(options);
                        break;

                    case "video":
                        options.uri = Properties.Settings.Default.LibraryPath + @"\" + options.uri;
                        media = new Video(options);
                        break;

                    case "webpage":
                        media = new WebContent(options);
                        break;

                    case "flash":
                        options.uri = Properties.Settings.Default.LibraryPath + @"\" + options.uri;
                        media = new Flash(options);
                        break;

                    case "ticker":
                        media = new Rss(options);
                        break;

                    case "embedded":
                        media = new Text(options);
                        break;

                    case "datasetview":
                        media = new DataSetView(options);
                        break;

                    default:
                        //do nothing
                        SetNextMediaNode();
                        return;
                }

                //sets up the timer for this media
                media.Duration = options.duration;

                //add event handler
                media.DurationElapsedEvent += new Media.DurationElapsedDelegate(media_DurationElapsedEvent);

                //any additional media specific render options (and starts the timer)
                media.RenderMedia();

                Controls.Add(media);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(new LogMessage("EvalOptions", "Unable to start media. " + ex.Message), LogType.Error.ToString());
                SetNextMediaNode();
            }

            // This media has started and is being replaced
            _stat = new Stat();
            _stat.type = StatType.Media;
            _stat.fromDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            _stat.scheduleID = options.scheduleId;
            _stat.layoutID = options.layoutId;
            _stat.mediaID = options.mediaid;

            System.Diagnostics.Debug.WriteLine("Showing new media", "Region - Eval Options");
        }
コード例 #4
0
ファイル: Region.cs プロジェクト: keyanmca/xibo-custom
        /// <summary>
        /// Start the provided media
        /// </summary>
        /// <param name="media"></param>
        private void StartMedia(Media media)
        {
            media.RenderMedia();

            Trace.WriteLine(new LogMessage("Region - StartMedia", "Starting media"), LogType.Audit.ToString());

            Controls.Add(media);
        }
コード例 #5
0
ファイル: Region.cs プロジェクト: keyanmca/xibo-custom
        /// <summary>
        /// Stop the provided media
        /// </summary>
        private void StopMedia(Media media)
        {
            Trace.WriteLine(new LogMessage("Region - Stop Media", "Stopping media"), LogType.Audit.ToString());

            // Hide the media
            media.Hide();

            // Remove the controls
            Controls.Remove(media);

            // Dispose of the current media
            try
            {
                // Dispose of the media
                media.Dispose();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("No media to remove");
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #6
0
ファイル: Region.cs プロジェクト: keyanmca/xibo-custom
        ///<summary>
        /// Evaulates the change in options
        ///</summary>
        private void EvalOptions()
        {
            // First time
            bool initialMedia = (_currentSequence == -1);

            if (initialMedia)
            {
                // Evaluate the width, etc
                Location = new System.Drawing.Point(_options.left, _options.top);
                Size = new System.Drawing.Size(_options.width, _options.height);
            }

            // Try to populate a new media object for this region
            Media newMedia = new Media(0, 0, 0, 0);

            // Loop around trying to start the next media
            bool startSuccessful = false;
            int countTries = 0;

            while (!startSuccessful)
            {
                // If we go round this the same number of times as media objects, then we are unsuccessful and should exception
                if (countTries >= _options.mediaNodes.Count)
                    throw new ArgumentOutOfRangeException("Unable to set and start a media node");

                // Lets try again
                countTries++;

                // Store the current sequence
                int temp = _currentSequence;

                // Set the next media node for this panel
                if (!SetNextMediaNodeInOptions())
                {
                    // For some reason we cannot set a media node... so we need this region to become invalid
                    _hasExpired = true;
                    DurationElapsedEvent();
                    return;
                }

                // If the sequence hasnt been changed, OR the layout has been expired
                // there has been no change to the sequence, therefore the media we have already created is still valid
                // or this media has actually been destroyed and we are working out way out the call stack
                if (_currentSequence == temp || _layoutExpired)
                    return;

                // Store the Current Index
                _options.CurrentIndex = _currentSequence;

                // See if we can start the new media object
                try
                {
                    newMedia = CreateNextMediaNode(_options);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(new LogMessage("Region - Eval Options", "Unable to create new " + _options.type + "  object: " + ex.Message), LogType.Error.ToString());

                    // Try the next node
                    startSuccessful = false;
                    continue;
                }

                // First thing we do is stop the current stat record
                if (!initialMedia)
                    CloseCurrentStatRecord();

                // Start the new media
                try
                {
                    StartMedia(newMedia);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(new LogMessage("Region - Eval Options", "Unable to start new " + _options.type + "  object: " + ex.Message), LogType.Error.ToString());
                    startSuccessful = false;
                    continue;
                }

                startSuccessful = true;

                // Remove the old media
                if (!initialMedia)
                {
                    StopMedia(_media);
                    _media = null;
                }

                // Change the reference
                _media = newMedia;

                // Open a stat record
                OpenStatRecordForMedia();
            }
        }
コード例 #7
0
ファイル: Region.cs プロジェクト: keyanmca/xibo-custom
        /// <summary>
        /// Performs the disposal.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    _media.Dispose();
                    _media = null;

                    Debug.WriteLine("Media Disposed by Region", "Region - Dispose");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine("There was no media to dispose", "Region - Dispose");
                }
                finally
                {
                    if (_media != null)
                        _media = null;
                }
            }

            base.Dispose(disposing);
        }
コード例 #8
0
ファイル: Region.cs プロジェクト: bugrag/xibo-dotnetclient
        ///<summary>
        /// Evaulates the change in options
        ///</summary>
        private void EvalOptions()
        {
            // First time
            bool initialMedia = (_currentSequence == -1);

            if (initialMedia)
            {
                // Evaluate the width, etc
                Location = new System.Drawing.Point(_options.left, _options.top);
                Size     = new System.Drawing.Size(_options.width, _options.height);
            }

            // Try to populate a new media object for this region
            Media newMedia = new Media(0, 0, 0, 0);

            // Loop around trying to start the next media
            bool startSuccessful = false;
            int  countTries      = 0;

            while (!startSuccessful)
            {
                // If we go round this the same number of times as media objects, then we are unsuccessful and should exception
                if (countTries >= _options.mediaNodes.Count)
                {
                    throw new ArgumentOutOfRangeException("Unable to set and start a media node");
                }

                // Lets try again
                countTries++;

                // Store the current sequence
                int temp = _currentSequence;

                // Set the next media node for this panel
                if (!SetNextMediaNodeInOptions())
                {
                    // For some reason we cannot set a media node... so we need this region to become invalid
                    _hasExpired = true;
                    DurationElapsedEvent();
                    return;
                }

                // If the sequence hasnt been changed, OR the layout has been expired
                // there has been no change to the sequence, therefore the media we have already created is still valid
                // or this media has actually been destroyed and we are working out way out the call stack
                if (_layoutExpired || (_currentSequence == temp))
                {
                    return;
                }

                // Store the Current Index
                _options.CurrentIndex = _currentSequence;

                // See if we can start the new media object
                try
                {
                    newMedia = CreateNextMediaNode(_options);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(new LogMessage("Region - Eval Options", "Unable to create new " + _options.type + "  object: " + ex.Message), LogType.Error.ToString());

                    // Try the next node
                    startSuccessful = false;
                    continue;
                }

                // First thing we do is stop the current stat record
                if (!initialMedia)
                {
                    CloseCurrentStatRecord();
                }

                // Start the new media
                try
                {
                    StartMedia(newMedia);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(new LogMessage("Region - Eval Options", "Unable to start new " + _options.type + "  object: " + ex.Message), LogType.Error.ToString());
                    startSuccessful = false;
                    continue;
                }

                startSuccessful = true;

                // Remove the old media
                if (!initialMedia)
                {
                    StopMedia(_media);
                    _media = null;
                }

                // Change the reference
                _media = newMedia;

                // Open a stat record
                OpenStatRecordForMedia();
            }
        }
コード例 #9
0
        /// <summary>
        /// Performs the disposal.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    _media.DurationElapsedEvent -= media_DurationElapsedEvent;
                    _media.Dispose();
                    _media = null;

                    Debug.WriteLine("Media Disposed by Region", "Region - Dispose");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(new LogMessage("Region - Dispose", "Unable to dispose media. Ex = " + ex.Message), LogType.Audit.ToString());
                }
                finally
                {
                    if (_media != null) 
                        _media = null;
                }
            }

            base.Dispose(disposing);
        }
コード例 #10
0
        ///<summary>
        /// Evaulates the change in options
        ///</summary>
        private void EvalOptions()
        {
            // First time
            bool initialMedia = (_currentSequence == -1);

            if (initialMedia)
            {
                // Evaluate the width, etc
                SetDimensions(_options.left, _options.top, _options.width, _options.height);
            }

            // Try to populate a new media object for this region
            Media newMedia = new Media(0, 0, 0, 0);

            // Loop around trying to start the next media
            bool startSuccessful = false;
            int  countTries      = 0;

            while (!startSuccessful)
            {
                // If we go round this the same number of times as media objects, then we are unsuccessful and should exception
                if (countTries >= _options.mediaNodes.Count)
                {
                    throw new ArgumentOutOfRangeException("Unable to set and start a media node");
                }

                // Lets try again
                countTries++;

                // Store the current sequence
                int temp = _currentSequence;

                // Before we can try to set the next media node, we need to stop any currently running Audio
                StopAudio();

                // Set the next media node for this panel
                if (!SetNextMediaNodeInOptions())
                {
                    // For some reason we cannot set a media node... so we need this region to become invalid
                    throw new InvalidOperationException("Unable to set any region media nodes.");
                }

                // If the sequence hasnt been changed, OR the layout has been expired
                // there has been no change to the sequence, therefore the media we have already created is still valid
                // or this media has actually been destroyed and we are working out way out the call stack
                if (_layoutExpired)
                {
                    return;
                }
                else if (_currentSequence == temp)
                {
                    // Media has not changed, we are likely the only valid media item in the region
                    // the layout has not yet expired, so depending on whether we loop or not, we either
                    // reload the same media item again
                    // or do nothing (return)
                    // This could be made more succinct, but is clearer written as an elseif.
                    if (!_options.RegionLoop)
                    {
                        return;
                    }
                }

                // Store the Current Index
                _options.CurrentIndex = _currentSequence;

                // See if we can start the new media object
                try
                {
                    newMedia = CreateNextMediaNode(_options);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(new LogMessage("Region - Eval Options", "Unable to create new " + _options.type + "  object: " + ex.Message), LogType.Error.ToString());

                    // Try the next node
                    startSuccessful = false;
                    continue;
                }

                // First thing we do is stop the current stat record
                if (!initialMedia)
                {
                    CloseCurrentStatRecord();
                }

                // Start the new media
                try
                {
                    // See if we need to change our Region Dimensions
                    if (newMedia.RegionSizeChangeRequired())
                    {
                        SetDimensions(newMedia.GetRegionLocation(), newMedia.GetRegionSize());
                        _sizeResetRequired = true;
                    }
                    else if (_sizeResetRequired)
                    {
                        SetDimensions(_options.left, _options.top, _options.width, _options.height);
                        _sizeResetRequired = false;
                    }

                    StartMedia(newMedia);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(new LogMessage("Region - Eval Options", "Unable to start new " + _options.type + "  object: " + ex.Message), LogType.Error.ToString());
                    startSuccessful = false;
                    continue;
                }

                startSuccessful = true;

                // Remove the old media
                if (!initialMedia)
                {
                    StopMedia(_media);
                    _media = null;
                }

                // Change the reference
                _media = newMedia;

                // Open a stat record
                OpenStatRecordForMedia();
            }
        }