Пример #1
0
        public void EvaluateOptions()
        {
            if (!Paused)
            {
                Action start = null;
                OldMedia = CurrentMedia;
                if (this.currentSequence == -1)
                {
                    this.Location = new Point((double)this.options.Left, (double)this.options.Top);
                    this.Size     = new System.Windows.Size((double)this.options.Width, (double)this.options.Height);
                }
                int currentSequence = this.currentSequence;
                if ((this.options.FileType != "Widget") && !this.SetNextMediaNode())
                {
                    this.hasExpired = true;
                    this.DurationElapsedEvent();
                }

                else if (((this.currentSequence != currentSequence) && !this.layoutExpired) ||
                         (this.options.FileType == "Widget"))
                {
                    try
                    {
                        if (start == null)
                        {
                            start = new Action(() =>
                            {
                                Action <Media> method = null;
                                ClientApp.Core.RegionOptions options = this.RegionOptions;
                                Console.WriteLine("type: " + options.FileType);
                                switch (options.FileType)
                                {
                                case "Image":
                                    options.Uri = Settings.Default.LibraryPath + @"\" +
                                                  options.Uri;
                                    this.CurrentMedia = new Picture(options);
                                    break;

                                case "Marquee":
                                    options.Uri = Settings.Default.LibraryPath + @"\" +
                                                  options.Uri;
                                    this.CurrentMedia = new Text(options);
                                    break;

                                case "Powerpoint":
                                    options.Uri = Settings.Default.LibraryPath + @"\" +
                                                  options.Uri;
                                    this.CurrentMedia = new WebContent(options);
                                    break;

                                case "Video":
                                    options.Uri = Settings.Default.LibraryPath + @"\" +
                                                  options.Uri;
                                    this.CurrentMedia = new Video(options);
                                    break;

                                case "Webpage":
                                    this.CurrentMedia = new WebContent(options);
                                    break;

                                case "Flash":
                                    options.Uri = Settings.Default.LibraryPath + @"\" +
                                                  options.Uri;
                                    this.CurrentMedia = new Flash(options);
                                    break;

                                case "Ticker":
                                    this.CurrentMedia = new Rss(options);
                                    break;

                                case "Embedded":
                                    this.CurrentMedia = new Text(options);
                                    break;

                                case "Datasetview":
                                    this.CurrentMedia = new DataSetView(options);
                                    break;

                                case "Widget":
                                    this.CurrentMedia = WidgetsFactory.CreateFrom(options);
                                    break;

                                case "KeepAlive":
                                    this.CurrentMedia = new KeepAlive(options);
                                    break;

                                default:
                                    this.SetNextMediaNode();
                                    return;
                                }
                                if (this.CurrentMedia != null)
                                {
                                    this.CurrentMedia.Duration              = options.Duration;
                                    this.CurrentMedia.DurationElapsedEvent +=
                                        new Media.DurationElapsedDelegate(
                                            this.MediaDurationElapsedEvent);
                                    this.CurrentMedia.Height = base.Height;
                                    this.CurrentMedia.Width  = base.Width;
                                    this.CurrentMedia.Margin = new Thickness(0.0, 0.0, 0.0,
                                                                             0.0);
                                    this.CurrentMedia.RenderMedia();
                                    if (method == null)
                                    {
                                        method = delegate(Media med)
                                        {
                                            med.AnimateIn(this.MediaCanvas,
                                                          OldMedia);
                                            if (med != null)
                                            {
                                                base.MediaCanvas.Children.Add(
                                                    med);
                                                if (med.SnapShot != null)
                                                {
                                                    base.MediaCanvas.Background
                                                        =
                                                            new ImageBrush(
                                                                med.
                                                                GetRenderTargetBitmap
                                                                    (1.0));
                                                }
                                            }
                                            if (OldMedia != null)
                                            {
                                                OldMedia.Dispose();
                                                OldMedia = null;
                                            }
                                        };
                                    }
                                    base.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                                method, this.CurrentMedia);
                                }
                                else
                                {
                                    Trace.WriteLine(new LogMessage("EvalOptions",
                                                                   "Unable to start media. media == null" +
                                                                   LogType.Error.ToString()));
                                    this.SetNextMediaNode();
                                }
                            });
                        }
                        base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, start);
                    }
                    catch (Exception exception)
                    {
                        Trace.WriteLine(
                            new LogMessage("EvalOptions", "Unable to start media. " + exception.Message),
                            LogType.Error.ToString());
                        this.SetNextMediaNode();
                    }
                    ClientApp.Core.Stat stat = new ClientApp.Core.Stat
                    {
                        FileType   = StatType.Media,
                        FromDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                        ScheduleID = this.options.scheduleId,
                        LayoutID   = this.options.layoutId,
                        MediaID    = this.options.mediaid
                    };
                    this._stat = stat;
                }
            }
        }
Пример #2
0
        ///<summary>
        /// Evaulates the change in options
        ///</summary>
        private void EvaluateOptions()
        {
            if (currentSequence == -1)
            {
                //evaluate the Width, etc
                this.Location = new Point(options.Left, options.Top);
                this.Size     = new Size(options.Width, options.Height);
            }

            int temp = currentSequence;


            //set the next media node for this panel
            if (!SetNextMediaNode() && options.FileType != "Widget")
            {
                // 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) && options.FileType != "Widget")
            {
                //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;
            }
            var oldmedia = media;

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

            try
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(() =>
                {
                    var regionOptions = RegionOptions;
                    switch (regionOptions.FileType)
                    {
                    case "Image":
                        regionOptions.Uri = Settings.Default.LibraryPath + @"\" + regionOptions.Uri;
                        media             = new ImagePosition(regionOptions);
                        break;

                    case "Text":
                        media =
                            new Text(regionOptions);
                        break;

                    case "Powerpoint":
                        regionOptions.Uri = Settings.Default.LibraryPath + @"\" + regionOptions.Uri;
                        media             = new WebContent(regionOptions);
                        break;

                    case "Video":
                        regionOptions.Uri = Settings.Default.LibraryPath + @"\" + regionOptions.Uri;
                        media             = new Video(regionOptions);
                        break;

                    case "Webpage":
                        media =
                            new WebContent(regionOptions);
                        break;

                    case "Flash":
                        regionOptions.Uri = Settings.Default.LibraryPath + @"\" + regionOptions.Uri;
                        media             = new Flash(regionOptions);
                        break;

                    case "Ticker":
                        media =
                            new Rss(regionOptions);
                        break;

                    case "Embedded":
                        media =
                            new Text(regionOptions);
                        break;

                    case "Datasetview":
                        media =
                            new DataSetView(regionOptions);
                        break;

                    case  "Widget":
                        media =
                            WidgetsFactory.CreateFrom(regionOptions);
                        break;

                    default:
                        //do nothing
                        SetNextMediaNode();
                        return;
                    }
                    //Dispatcher.BeginInvoke(
                    //    DispatcherPriority.Normal,
                    //    new ThreadStart(() =>
                    // {
                    if (media != null)
                    {
                        //sets up the timer for this media
                        media.Duration = regionOptions.Duration;

                        //add event handler
                        media.DurationElapsedEvent += media_DurationElapsedEvent;



                        media.Height = this.Height;
                        media.Width  = this.Width;
                        media.Margin = new Thickness(0, 0, 0, 0);

                        media.RenderMedia();
                        //  media.Opacity = 0;
                        //media.OldOne = oldmedia;
                        //if (!media.HasOnLoaded)
                        //    //not so useful
                        //{
                        //    media.AnimateIn(MediaCanvas,oldmedia);
                        //}
                        Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action <Media>((med) =>
                        {
                            if (med != null)
                            {
                                MediaCanvas.Children.Add(med);
                            }
                        }), media);
                    }
                    else
                    {
                        Trace.WriteLine(new LogMessage("EvalOptions", "Unable to start media. media == null" + LogType.Error.ToString()));
                        SetNextMediaNode();
                    }

                    //  }));

                    //any additional media specific render options (and starts the timer)
                }));
            }
            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
            {
                FileType =
                    StatType.Media,
                FromDate =
                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                ScheduleID = options.scheduleId,
                LayoutID   = options.layoutId,
                MediaID    = options.mediaid
            };

            Debug.WriteLine("Showing new media", "Region - Eval Options");
        }