예제 #1
0
        /// <summary>
        /// Creates the Region
        /// </summary>
        /// <param name="statLog"></param>
        /// <param name="cacheManager"></param>
        public Region(ref StatLog statLog, ref CacheManager cacheManager)
        {
            // Store the statLog
            _statLog = statLog;

            // Store the cache manager
            _cacheManager = cacheManager;

            //default options
            _options = new RegionOptions();
            _options.width = 1024;
            _options.height = 768;
            _options.left = 0;
            _options.top = 0;
            _options.uri = null;

            Location = new System.Drawing.Point(_options.left, _options.top);
            Size = new System.Drawing.Size(_options.width, _options.height);
            BackColor = System.Drawing.Color.Transparent;

            if (ApplicationSettings.Default.DoubleBuffering)
            {
                SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
                SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            }

            // Create a new BlackList for us to use
            _blackList = new BlackList();
        }
예제 #2
0
        public IeWebMedia(RegionOptions options)
            : base(options.width, options.height, options.top, options.left)
        {
            // Collect some options from the Region Options passed in
            // and store them in member variables.
            _options = options;

            // Check to see if the mode option is present.
            string modeId = options.Dictionary.Get("modeid");
            bool nativeOpen = modeId != string.Empty && modeId == "1";

            if (nativeOpen)
            {
                // If we are modeid == 1, then just open the webpage without adjusting the file path
                _filePath = Uri.UnescapeDataString(options.uri).Replace('+', ' ');
            }
            else
            {
                // Set the file path
                _filePath = ApplicationSettings.Default.LibraryPath + @"\" + _options.mediaid + ".htm";
            }

            // Create the web view we will use
            _webBrowser = new WebBrowser();
            _webBrowser.DocumentCompleted += _webBrowser_DocumentCompleted;
            _webBrowser.Size = Size;
            _webBrowser.ScrollBarsEnabled = false;
            _webBrowser.ScriptErrorsSuppressed = true;
            _webBrowser.Visible = false;

            if (nativeOpen)
            {
                // Nativate directly
                _webBrowser.Navigate(_filePath);
            }
            else
            {
                // Check to see if the HTML is ready for us.
                if (HtmlReady())
                {
                    // Write to temporary file
                    ReadControlMeta();

                    // Navigate to temp file
                    _webBrowser.Navigate(_filePath);
                }
                else
                {
                    RefreshFromXmds();
                }
            }

            Controls.Add(_webBrowser);

            // Show the control
            Show();
        }
예제 #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="options"></param>
 public VideoDS(RegionOptions options)
     : base(options.width, options.height, options.top, options.left)
 {
     _filesPlayed = 0;
     _videoPlayer = new VideoPlayer();
     _videoPlayer.Width = options.width;
     _videoPlayer.Height = options.height;
     _videoPlayer.Location = new System.Drawing.Point(0, 0);
     //_videoPlayer.SetPlaylist(options.mediaNodes, options.CurrentIndex);
     
     Controls.Add(_videoPlayer);
 }
예제 #4
0
        public ImagePosition(RegionOptions options)
            : base(options.width, options.height, options.top, options.left)
        {
            _options = options;
            _filePath = options.uri;
            
            if (!System.IO.File.Exists(_filePath))
            {
                // Exit
                System.Diagnostics.Trace.WriteLine(new LogMessage("Image - Dispose", "Cannot Create image object. Invalid Filepath."), LogType.Error.ToString());
                return;
            }

            try
            {
                _pictureBox = new PictureBox();
                _pictureBox.Size = new Size(_width, _height);
                _pictureBox.Location = new Point(0, 0);
                _pictureBox.BorderStyle = BorderStyle.None;
                _pictureBox.BackColor = Color.Transparent;

                // Do we need to align the image in any way?
                if (options.Dictionary.Get("scaleType", "stretch") == "center" && (options.Dictionary.Get("align", "center") != "center" || options.Dictionary.Get("valign", "middle") != "middle"))
                {
                    // Yes we do, so we must override the paint method
                    _pictureBox.Paint += _pictureBox_Paint;
                }
                else
                {
                    // No we don't so use a normal picture box.
                    _pictureBox.SizeMode = (options.Dictionary.Get("scaleType", "center") == "stretch") ? PictureBoxSizeMode.StretchImage : PictureBoxSizeMode.Zoom;
                    _pictureBox.Image = new Bitmap(_filePath);
                }

                Controls.Add(this._pictureBox);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(new LogMessage("ImagePosition", String.Format("Cannot create Image Object with exception: {0}", ex.Message)), LogType.Error.ToString());
            }
        }
예제 #5
0
        public Flash (RegionOptions options)
            : base(options.width, options.height, options.top, options.left) 
        {
            _tempHtml = new TemporaryHtml();

            _backgroundImage = options.backgroundImage;
            _backgroundColor = options.backgroundColor; 
            _backgroundTop = options.backgroundTop + "px";
            _backgroundLeft = options.backgroundLeft + "px";

            // Create the HEAD of the document
            GenerateHeadHtml();

            // Set the body
            string html = @"
                <object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='{2}' height='{3}' id='analog_clock' align='middle'>
                    <param name='allowScriptAccess' value='sameDomain' />
                    <param name='movie' value='{1}' />
                    <param name='quality' value='high' />
                    <param name='bgcolor' value='#000' />
                    <param name='WMODE' value='transparent' />
                    <embed src='{1}' quality='high' wmode='transparent' bgcolor='#ffffff' width='{2}' height='{3}' name='analog_clock' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />
                </object>
            ";

            _tempHtml.BodyContent = string.Format(html, options.uri, options.uri, options.width.ToString(), options.height.ToString());

            // Fire up a webBrowser control to display the completed file.
            _webBrowser = new WebBrowser();
            _webBrowser.Size = this.Size;
            _webBrowser.ScrollBarsEnabled = false;
            _webBrowser.ScriptErrorsSuppressed = true;
            _webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(_webBrowser_DocumentCompleted);

            // Navigate to temp file
            _webBrowser.Navigate(_tempHtml.Path);
            Controls.Add(_webBrowser);

            // Show the control
            Show();
        }
예제 #6
0
        public PowerPoint(RegionOptions options)
            : base(options.width, options.height, options.top, options.left)
        {
            duration = options.duration;
            scheduleId = options.scheduleId;
            layoutId = options.layoutId;
            mediaId = options.mediaid;
            type = options.type;
            _filePath = Uri.UnescapeDataString(options.uri).Replace('+', ' ');

            webBrowser = new WebBrowser();
            webBrowser.Size = this.Size;
            webBrowser.ScrollBarsEnabled = false;
            webBrowser.ScriptErrorsSuppressed = true;
            webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
            webBrowser.Visible = false;

            if (!ApplicationSettings.Default.PowerpointEnabled)
            {
                webBrowser.DocumentText = "<html><body><h1>Powerpoint not enabled on this display</h1></body></html>";

                Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", "Powerpoint is not enabled on this display", scheduleId, layoutId, mediaId));
            }
            else
            {
                try
                {
                    webBrowser.Navigate(_filePath);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(new LogMessage("WebContent", "Unable to show webpage. Exception: " + ex.Message, scheduleId, layoutId), LogType.Error.ToString());
                    throw new InvalidOperationException("Cannot navigate to PowerPoint file");
                }
            }

            Controls.Add(webBrowser);
            Show();
        }
예제 #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="options"></param>
        public Video(RegionOptions options)
            : base(options.width, options.height, options.top, options.left)
        {
            _filePath = Uri.UnescapeDataString(options.uri).Replace('+',' ');
            _duration = options.duration;

            _videoPlayer = new VideoPlayer();
            _videoPlayer.Width = options.width;
            _videoPlayer.Height = options.height;
            _videoPlayer.Location = new System.Drawing.Point(0, 0);

            // Should we loop?
            _videoPlayer.SetLooping((options.Dictionary.Get("loop", "0") == "1" && _duration != 0));

            // Should we mute?
            _videoPlayer.SetMute((options.Dictionary.Get("mute", "0") == "1"));

            // Capture any video errors
            _videoPlayer.VideoError += new VideoPlayer.VideoErrored(_videoPlayer_VideoError);
            _videoPlayer.VideoEnd += new VideoPlayer.VideoFinished(_videoPlayer_VideoEnd);

            Controls.Add(_videoPlayer);
        }
예제 #8
0
        /// <summary>
        /// Prepares the Layout.. rendering all the necessary controls
        /// </summary>
        private void PrepareLayout(string layoutPath)
        {
            // Create a start record for this layout
            _stat = new Stat();
            _stat.type = StatType.Layout;
            _stat.scheduleID = _scheduleId;
            _stat.layoutID = _layoutId;
            _stat.fromDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            // Get this layouts XML
            XmlDocument layoutXml = new XmlDocument();
            DateTime layoutModifiedTime;

            // Default or not
            if (layoutPath == ApplicationSettings.Default.LibraryPath + @"\Default.xml" || String.IsNullOrEmpty(layoutPath))
            {
                throw new Exception("Default layout");
            }
            else
            {
                try
                {
                    // try to open the layout file
                    using (FileStream fs = File.Open(layoutPath, FileMode.Open, FileAccess.Read, FileShare.Write))
                    {
                        using (XmlReader reader = XmlReader.Create(fs))
                        {
                            layoutXml.Load(reader);

                            reader.Close();
                        }
                        fs.Close();
                    }

                    layoutModifiedTime = File.GetLastWriteTime(layoutPath);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(string.Format("Could not find the layout file {0}: {1}", layoutPath, ex.Message));
                    throw;
                }
            }

            // Attributes of the main layout node
            XmlNode layoutNode = layoutXml.SelectSingleNode("/layout");

            XmlAttributeCollection layoutAttributes = layoutNode.Attributes;

            // Set the background and size of the form
            _layoutWidth = int.Parse(layoutAttributes["width"].Value, CultureInfo.InvariantCulture);
            _layoutHeight = int.Parse(layoutAttributes["height"].Value, CultureInfo.InvariantCulture);


            // Scaling factor, will be applied to all regions
            _scaleFactor = Math.Min(_clientSize.Width / _layoutWidth, _clientSize.Height / _layoutHeight);

            // Want to be able to center this shiv - therefore work out which one of these is going to have left overs
            int backgroundWidth = (int)(_layoutWidth * _scaleFactor);
            int backgroundHeight = (int)(_layoutHeight * _scaleFactor);

            double leftOverX;
            double leftOverY;

            try
            {
                leftOverX = Math.Abs(_clientSize.Width - backgroundWidth);
                leftOverY = Math.Abs(_clientSize.Height - backgroundHeight);

                if (leftOverX != 0) leftOverX = leftOverX / 2;
                if (leftOverY != 0) leftOverY = leftOverY / 2;
            }
            catch
            {
                leftOverX = 0;
                leftOverY = 0;
            }

            // New region and region options objects
            _regions = new Collection<Region>();
            RegionOptions options = new RegionOptions();
            options.LayoutModifiedDate = layoutModifiedTime;

            // Deal with the color
            try
            {
                if (layoutAttributes["bgcolor"].Value != "")
                {
                    this.BackColor = ColorTranslator.FromHtml(layoutAttributes["bgcolor"].Value);
                    options.backgroundColor = layoutAttributes["bgcolor"].Value;
                }
            }
            catch
            {
                this.BackColor = Color.Black; // Default black
                options.backgroundColor = "#000000";
            }

            // Get the background
            try
            {
                if (layoutAttributes["background"] != null && !string.IsNullOrEmpty(layoutAttributes["background"].Value))
                {
                    string bgFilePath = ApplicationSettings.Default.LibraryPath + @"\backgrounds\" + backgroundWidth + "x" + backgroundHeight + "_" + layoutAttributes["background"].Value;

                    // Create a correctly sized background image in the temp folder
                    if (!File.Exists(bgFilePath))
                        GenerateBackgroundImage(layoutAttributes["background"].Value, backgroundWidth, backgroundHeight, bgFilePath);

                    BackgroundImage = new Bitmap(bgFilePath);
                    options.backgroundImage = bgFilePath;
                }
                else
                {
                    // Assume there is no background image
                    BackgroundImage = null;
                    options.backgroundImage = "";
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(new LogMessage("MainForm - PrepareLayout", "Unable to set background: " + ex.Message), LogType.Error.ToString());
                
                // Assume there is no background image
                this.BackgroundImage = null;
                options.backgroundImage = "";
            }

            // Get the regions
            XmlNodeList listRegions = layoutXml.SelectNodes("/layout/region");
            XmlNodeList listMedia = layoutXml.SelectNodes("/layout/region/media");

            // Check to see if there are any regions on this layout.
            if (listRegions.Count == 0 || listMedia.Count == 0)
            {
                Trace.WriteLine(new LogMessage("PrepareLayout",
                    string.Format("A layout with {0} regions and {1} media has been detected.", listRegions.Count.ToString(), listMedia.Count.ToString())),
                    LogType.Info.ToString());

                if (_schedule.ActiveLayouts == 1)
                {
                    Trace.WriteLine(new LogMessage("PrepareLayout", "Only 1 layout scheduled and it has nothing to show."), LogType.Info.ToString());

                    throw new Exception("Only 1 layout schduled and it has nothing to show");
                }
                else
                {
                    Trace.WriteLine(new LogMessage("PrepareLayout",
                        string.Format(string.Format("An empty layout detected, will show for {0} seconds.", ApplicationSettings.Default.EmptyLayoutDuration.ToString()))), LogType.Info.ToString());

                    // Put a small dummy region in place, with a small dummy media node - which expires in 10 seconds.
                    XmlDocument dummyXml = new XmlDocument();
                    dummyXml.LoadXml(string.Format("<region id='blah' width='1' height='1' top='1' left='1'><media id='blah' type='text' duration='{0}'><raw><text></text></raw></media></region>",
                        ApplicationSettings.Default.EmptyLayoutDuration.ToString()));

                    // Replace the list of regions (they mean nothing as they are empty)
                    listRegions = dummyXml.SelectNodes("/region");
                }
            }

            foreach (XmlNode region in listRegions)
            {
                // Is there any media
                if (region.ChildNodes.Count == 0)
                {
                    Debug.WriteLine("A region with no media detected");
                    continue;
                }

                //each region
                XmlAttributeCollection nodeAttibutes = region.Attributes;

                options.scheduleId = _scheduleId;
                options.layoutId = _layoutId;
                options.regionId = nodeAttibutes["id"].Value.ToString();
                options.width = (int)(Convert.ToDouble(nodeAttibutes["width"].Value, CultureInfo.InvariantCulture) * _scaleFactor);
                options.height = (int)(Convert.ToDouble(nodeAttibutes["height"].Value, CultureInfo.InvariantCulture) * _scaleFactor);
                options.left = (int)(Convert.ToDouble(nodeAttibutes["left"].Value, CultureInfo.InvariantCulture) * _scaleFactor);
                options.top = (int)(Convert.ToDouble(nodeAttibutes["top"].Value, CultureInfo.InvariantCulture) * _scaleFactor);
                options.scaleFactor = _scaleFactor;

                // Store the original width and original height for scaling
                options.originalWidth = (int)Convert.ToDouble(nodeAttibutes["width"].Value, CultureInfo.InvariantCulture);
                options.originalHeight = (int)Convert.ToDouble(nodeAttibutes["height"].Value, CultureInfo.InvariantCulture);

                // Set the backgrounds (used for Web content offsets)
                options.backgroundLeft = options.left * -1;
                options.backgroundTop = options.top * -1;

                // Account for scaling
                options.left = options.left + (int)leftOverX;
                options.top = options.top + (int)leftOverY;

                // All the media nodes for this region / layout combination
                options.mediaNodes = region.SelectNodes("media");

                Region temp = new Region(ref _statLog, ref _cacheManager);
                temp.DurationElapsedEvent += new Region.DurationElapsedDelegate(temp_DurationElapsedEvent);

                Debug.WriteLine("Created new region", "MainForm - Prepare Layout");

                // Dont be fooled, this innocent little statement kicks everything off
                temp.regionOptions = options;

                _regions.Add(temp);
                Controls.Add(temp);

                Debug.WriteLine("Adding region", "MainForm - Prepare Layout");
            }

            // Null stuff
            listRegions = null;
            listMedia = null;
        }
예제 #9
0
        public CefWebMedia(RegionOptions options)
            : base(options.width, options.height, options.top, options.left)
        {
            // Collect some options from the Region Options passed in
            // and store them in member variables.
            _options = options;

            // Check to see if the mode option is present.
            string modeId = options.Dictionary.Get("modeid");
            bool nativeOpen = modeId != string.Empty && modeId == "1";

            if (nativeOpen)
            {
                // If we are modeid == 1, then just open the webpage without adjusting the file path
                _filePath = Uri.UnescapeDataString(options.uri).Replace('+', ' ');
            }
            else
            {
                // Set the file path
                _filePath = ApplicationSettings.Default.LibraryPath + @"\" + _options.mediaid + ".htm";
            }
            
            Color backgroundColor = ColorTranslator.FromHtml(_options.Dictionary.Get("backgroundColor", _options.backgroundColor));

            CefBrowserSettings settings = new CefBrowserSettings();
            settings.BackgroundColor = new CefColor(backgroundColor.A, backgroundColor.R, backgroundColor.G, backgroundColor.B);

            // Create the web view we will use
            _webView = new CefWebBrowser();
            _webView.BrowserSettings = settings;
            _webView.Dock = DockStyle.Fill;
            _webView.BrowserCreated += _webView_BrowserCreated;
            _webView.LoadEnd += _webView_LoadEnd;
            _webView.Size = Size;

            // Check to see if the HTML is ready for us.
            if (nativeOpen)
            {
                _startWhenReady = true;
            }
            else
            {
                if (HtmlReady())
                {
                    // Write to temporary file
                    ReadControlMeta();

                    _startWhenReady = true;
                }
                else
                {
                    RefreshFromXmds();
                }
            }

            // We need to come up with a way of setting this control to Visible = false here and still kicking
            // off the webbrowser.
            // I think we can do this by hacking some bits into the Cef.WinForms dll.
            // Currently if we set this to false a browser isn't initialised by the library because it initializes it in OnHandleCreated
            // We also need a way to protect against the web browser never being created for some reason.
            // If it isn't then the control will never exipre (we might need to start the timer and then reset it).
            // Maybe:
            // Start the timer and then base.RestartTimer() in _webview_LoadEnd
            //base.StartTimer();
            
            //_webView.Visible = false;

            Controls.Add(_webView);

            // Show the control
            Show();
        }
예제 #10
0
        /// <summary>
        /// Create the next media node based on the provided options
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        private Media CreateNextMediaNode(RegionOptions options)
        {
            Media media;

            Trace.WriteLine(new LogMessage("Region - CreateNextMediaNode", string.Format("Creating new media: {0}, {1}", options.type, options.mediaid)), LogType.Audit.ToString());
            
            bool useCef = ApplicationSettings.Default.UseCefWebBrowser;

            if (options.render == "html")
            {
                if (useCef)
                    media = new CefWebMedia(options);
                else
                    media = new IeWebMedia(options);
            }
            else
            {
                switch (options.type)
                {
                    case "image":
                        options.uri = ApplicationSettings.Default.LibraryPath + @"\" + options.uri;
                        media = new ImagePosition(options);
                        break;

                    case "powerpoint":
                        options.uri = ApplicationSettings.Default.LibraryPath + @"\" + options.uri;
                        media = new PowerPoint(options);
                        break;

                    case "video":
                        options.uri = ApplicationSettings.Default.LibraryPath + @"\" + options.uri;

                        // Which video engine are we using?
                        if (ApplicationSettings.Default.VideoRenderingEngine == "DirectShow")
                            media = new VideoDS(options);
                        else
                            media = new Video(options);

                        break;

                    case "localvideo":
                        // Which video engine are we using?
                        if (ApplicationSettings.Default.VideoRenderingEngine == "DirectShow")
                            media = new VideoDS(options);
                        else
                            media = new Video(options);

                        break;

                    case "datasetview":
                    case "embedded":
                    case "ticker":
                    case "text":
                    case "webpage":
                        if (useCef)
                            media = new CefWebMedia(options);
                        else
                            media = new IeWebMedia(options);

                        break;

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

                    case "shellcommand":
                        media = new ShellCommand(options);
                        break;

                    default:
                        throw new InvalidOperationException("Not a valid media node type: " + options.type);
                }
            }

            // Sets up the timer for this media, if it hasn't already been set
            if (media.Duration == 0)
                media.Duration = options.duration;

            // Add event handler for when this completes
            media.DurationElapsedEvent += new Media.DurationElapsedDelegate(media_DurationElapsedEvent);

            return media;
        }
예제 #11
0
 public ShellCommand(RegionOptions options)
     : base(options.width, options.height, options.top, options.left)
 {
     _command = Uri.UnescapeDataString(options.Dictionary.Get("windowsCommand")).Replace('+', ' ');
     _code = options.Dictionary.Get("commandCode");
 }