/// <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 (Settings.Default.DoubleBuffering) { SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); } // Create a new BlackList for us to use _blackList = new BlackList(); }
public static Media GetHtmlPackage(RegionOptions options) { string pathToMediaFile = Path.Combine(ApplicationSettings.Default.LibraryPath, options.uri); string pathToPackageFolder = Path.Combine(ApplicationSettings.Default.LibraryPath, "package_" + options.FileId); string pathToStatusFile = Path.Combine(pathToPackageFolder, "_updated"); // Configure the file path to indicate which file should be opened by the browser var _filePath = ApplicationSettings.Default.EmbeddedServerAddress + "package_" + options.FileId + "/" + options.Dictionary.Get("nominatedFile", "index.html"); // Check to see if our package has been extracted already // if not, then extract it if (!(Directory.Exists(pathToPackageFolder) && IsUpdated(pathToStatusFile, File.GetLastWriteTime(pathToMediaFile)))) { // Extract our file into the specified folder. ZipFile.ExtractToDirectory(pathToMediaFile, pathToPackageFolder); // Add in our extraction date. WriteUpdatedFlag(pathToStatusFile); } //Set URI to file path options.uri = _filePath; //Set modeid = 1 options.Dictionary.Replace("modeid", "1"); return(GetWebMedia(options)); }
public ImagePosition(RegionOptions options) : base(options.width, options.height, options.top, options.left) { _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.SizeMode = (options.Dictionary.Get("scaleType", "center") == "stretch") ? PictureBoxSizeMode.StretchImage : PictureBoxSizeMode.Zoom; _pictureBox.Image = new Bitmap(_filePath); _pictureBox.Size = new Size(_width, _height); _pictureBox.Location = new Point(0, 0); _pictureBox.BorderStyle = BorderStyle.None; _pictureBox.BackColor = Color.Transparent; /*if (options.Dictionary.Get("scaleType", "stretch") == "center") * { * string align = options.Dictionary.Get("align", "center"); * string valign = options.Dictionary.Get("valign", "middle"); * }*/ 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()); } }
/// <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(); }
/// <summary> /// Creates a Text display control /// </summary> /// <param name="options">Region Options for this control</param> public Text(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. _filePath = options.uri; _direction = options.direction; _backgroundImage = options.backgroundImage; _backgroundColor = options.backgroundColor; _scaleFactor = options.scaleFactor; _backgroundTop = options.backgroundTop + "px"; _backgroundLeft = options.backgroundLeft + "px"; _documentText = options.text; _scrollSpeed = options.scrollSpeed; _headJavaScript = options.javaScript; // Generate a temporary file to store the rendered object in. _tempHtml = new TemporaryHtml(); // Generate the Head Html and store to file. GenerateHeadHtml(); // Generate the Body Html and store to file. GenerateBodyHtml(); // 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); }
public ImagePosition(RegionOptions options) : base(options.width, options.height, options.top, options.left) { _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.SizeMode = PictureBoxSizeMode.Zoom; _pictureBox.Image = new Bitmap(_filePath); _pictureBox.Size = new Size(_width, _height); _pictureBox.Location = new Point(0, 0); _pictureBox.BorderStyle = BorderStyle.None; _pictureBox.BackColor = Color.Transparent; this.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()); } }
/// <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? if (options.Dictionary.Get("loop", "0") == "1" && _duration == 0) { _videoPlayer.SetLooping(true); } // Should we mute? _videoPlayer.SetMute((options.Dictionary.Get("mute", "0") == "1")); // Capture any video errors _videoPlayer.VideoError += new VideoPlayer.VideoErrored(_videoPlayer_VideoError); Controls.Add(_videoPlayer); }
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(); }
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; // Set the file path _filePath = ApplicationSettings.Default.LibraryPath + @"\" + _options.mediaid + ".htm"; Color backgroundColor = ColorTranslator.FromHtml(_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 (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(); }
/// <summary> /// Get WebMedia object /// </summary> /// <param name="options"></param> /// <returns></returns> public static Media GetWebMedia(RegionOptions options) { if (UsingChrome()) { return(new CefWebMedia(options)); } else { return(new IeWebMedia(options)); } }
/// <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); }
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"); // Default to launching through CMS for backwards compatiblity _launchThroughCmd = (options.Dictionary.Get("launchThroughCmd", "1") == "1"); // Termination _terminateCommand = (options.Dictionary.Get("terminateCommand") == "1"); _useTaskKill = (options.Dictionary.Get("useTaskkill") == "1"); }
public Video(RegionOptions options) : base(options.width, options.height, options.top, options.left) { this.filePath = options.uri; this.duration = options.duration; videoPlayer = new VideoPlayer(); videoPlayer.Width = options.width; videoPlayer.Height = options.height; videoPlayer.Location = new System.Drawing.Point(0, 0); this.Controls.Add(videoPlayer); }
public WebContent(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; webBrowser = new WebBrowser(); webBrowser.Size = this.Size; webBrowser.ScrollBarsEnabled = false; webBrowser.ScriptErrorsSuppressed = true; // Attach event webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted); if (!Properties.Settings.Default.powerpointEnabled && options.type == "powerpoint") { webBrowser.DocumentText = "<html><body><h1>Powerpoint not enabled on this display</h1></body></html>"; System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", "Powerpoint is not enabled on this display", scheduleId, layoutId, mediaId)); } else { try { // Try to make a URI out of the file path try { this.filePath = Uri.UnescapeDataString(options.uri); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message, "WebContent"); } // Navigate webBrowser.Navigate(this.filePath); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", ex.Message, scheduleId, layoutId, mediaId)); webBrowser.DocumentText = "<html><body><h1>Unable to show this web location - invalid address.</h1></body></html>"; System.Diagnostics.Trace.WriteLine(String.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", "Unable to show the powerpoint, cannot be located", scheduleId, layoutId, mediaId)); } } }
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; 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 { // Try to make a URI out of the file path try { _filePath = Uri.UnescapeDataString(options.uri).Replace('+', ' '); } catch (Exception ex) { Trace.WriteLine(new LogMessage("WebContent", "Unable to get a URI with exception: " + ex.Message), LogType.Audit.ToString()); } webBrowser.Navigate(_filePath); } catch (Exception ex) { webBrowser.DocumentText = "<html><body><h1>Unable to show this web location - invalid address.</h1></body></html>"; Trace.WriteLine(new LogMessage("WebContent", "Unable to show webpage. Exception: " + ex.Message, scheduleId, layoutId), LogType.Error.ToString()); } } Controls.Add(webBrowser); Show(); }
/// <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); // Capture any video errors _videoPlayer.VideoError += new VideoPlayer.VideoErrored(_videoPlayer_VideoError); Controls.Add(_videoPlayer); }
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; // Set the file path/local web path if (IsNativeOpen()) { // 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"; _localWebPath = ApplicationSettings.Default.EmbeddedServerAddress + _options.mediaid + ".htm"; } }
public DataSetView(RegionOptions options) : base(options.width, options.height, options.top, options.left) { _layoutId = options.layoutId; _regionId = options.regionId; _mediaId = options.mediaid; _duration = options.duration; _scaleFactor = options.scaleFactor; _updateInterval = Convert.ToInt32(options.Dictionary.Get("updateInterval")); _backgroundImage = options.backgroundImage; _backgroundColor = options.backgroundColor; // Set up the backgrounds _backgroundTop = options.backgroundTop + "px"; _backgroundLeft = options.backgroundLeft + "px"; // Create a webbrowser to take the temp file loc _webBrowser = new WebBrowser(); _webBrowser.ScriptErrorsSuppressed = true; _webBrowser.Size = this.Size; _webBrowser.ScrollBarsEnabled = false; _webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted); // Construct a sensible file path to store this resource _filePath = Settings.Default.LibraryPath + @"\" + _mediaId + ".htm"; if (HtmlReady()) { // Write to temporary file SaveToTemporaryFile(); // Navigate to temp file _webBrowser.Navigate(_temporaryFile.Path); } else { RefreshLocalHtml(); } }
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()); } }
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(); }
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(); }
/// <summary> /// Constructor /// </summary> /// <param name="options"></param> public Video(RegionOptions options) : base(options.width, options.height, options.top, options.left) { _options = options; _filePath = Uri.UnescapeDataString(options.uri).Replace('+', ' '); _duration = options.duration; _videoPlayer = new VideoPlayer(); // Should this video be full screen? if (options.Dictionary.Get("showFullScreen", "0") == "1") { Width = options.LayoutSize.Width; Height = options.LayoutSize.Height; _videoPlayer.Width = options.LayoutSize.Width; _videoPlayer.Height = options.LayoutSize.Height; } else { _videoPlayer.Width = options.width; _videoPlayer.Height = options.height; } // Assert the location after setting the control size _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); }
/// <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); }
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; // 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; // 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(); }
/// <summary> /// Constructor /// </summary> /// <param name="options"></param> public Audio(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 = 0; _videoPlayer.Height = 0; _videoPlayer.Location = new System.Drawing.Point(0, 0); _videoPlayer.SetVisible(false); // Should we loop? _videoPlayer.SetLooping((options.Dictionary.Get("loop", "0") == "1" && _duration != 0)); // Should we mute? _videoPlayer.SetVolume(options.Dictionary.Get("volume", 100)); // Capture any video errors _videoPlayer.VideoError += new VideoPlayer.VideoErrored(_videoPlayer_VideoError); _videoPlayer.VideoEnd += new VideoPlayer.VideoFinished(_videoPlayer_VideoEnd); Controls.Add(_videoPlayer); }
public WebContent(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; webBrowser = new WebBrowser(); webBrowser.Size = this.Size; webBrowser.ScrollBarsEnabled = false; webBrowser.ScriptErrorsSuppressed = true; // Offset? double offsetTop = Convert.ToDouble(options.Dictionary.Get("offsetTop", "0")); double offsetLeft = Convert.ToDouble(options.Dictionary.Get("offsetLeft", "0")); double scaling = Convert.ToDouble(options.Dictionary.Get("scaling", "100")); // Attach event webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted); if (!Properties.Settings.Default.powerpointEnabled && options.type == "powerpoint") { 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 { // Try to make a URI out of the file path try { _filePath = Uri.UnescapeDataString(options.uri).Replace('+', ' '); } catch (Exception ex) { Trace.WriteLine(new LogMessage("WebContent", "Unable to get a URI with exception: " + ex.Message), LogType.Audit.ToString()); } if (offsetLeft == 0 && offsetTop == 0 && scaling == 100) { webBrowser.Navigate(_filePath); } else { double w = Convert.ToDouble(options.width); double h = Convert.ToDouble(options.height); string zoom = ""; // Scale? if (scaling != 100) { // Convert from percentage scaling = scaling / 100; // Alter the width and height w = w * (1 / scaling); h = h * (1 / scaling); zoom = "zoom: " + scaling.ToString(CultureInfo.InvariantCulture) + ";"; } // Load an IFRAME into the DocumentText string iframe = "<html><body style='margin:0; border:0;'><iframe style='border:0;margin-left:-" + offsetLeft.ToString(CultureInfo.InvariantCulture) + "px; margin-top:-" + offsetTop.ToString(CultureInfo.InvariantCulture) + "px;" + zoom + "' scrolling=\"no\" width=\"" + (w + offsetLeft).ToString(CultureInfo.InvariantCulture) + "px\" height=\"" + (h + offsetTop).ToString(CultureInfo.InvariantCulture) + "px\" src=\"" + _filePath + "\"></body></html>"; webBrowser.DocumentText = iframe; } } catch (Exception ex) { webBrowser.DocumentText = "<html><body><h1>Unable to show this web location - invalid address.</h1></body></html>"; Trace.WriteLine(new LogMessage("WebContent", "Unable to show webpage. Exception: " + ex.Message, scheduleId, layoutId), LogType.Error.ToString()); } base.Duration = duration; base.RenderMedia(); } }
/// <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()); if (options.render == "html") { media = new IeWebMedia(options); } else { // We've set our next media node in options already // this includes checking that file based media is valid. 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 "audio": options.uri = ApplicationSettings.Default.LibraryPath + @"\" + options.uri; media = new Audio(options); break; case "datasetview": case "embedded": case "ticker": case "text": case "webpage": 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; case "htmlpackage": media = new HtmlPackage(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); }
/// <summary> /// Parse options for the media node /// </summary> /// <param name="mediaNode"></param> /// <param name="nodeAttributes"></param> private void ParseOptionsForMediaNode(XmlNode mediaNode, XmlAttributeCollection nodeAttributes) { // 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; // Render as if (nodeAttributes["render"] != null) { _options.render = nodeAttributes["render"].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; Trace.WriteLine("Duration is Empty, using a default of 60.", "Region - SetNextMediaNode"); } // Widget From/To dates (v2 onward) try { if (nodeAttributes["fromDt"] != null) { _options.FromDt = DateTime.Parse(nodeAttributes["fromDt"].Value, CultureInfo.InvariantCulture); } if (nodeAttributes["toDt"] != null) { _options.ToDt = DateTime.Parse(nodeAttributes["toDt"].Value, CultureInfo.InvariantCulture); } } catch (Exception e) { Trace.WriteLine(new LogMessage("Region", "ParseOptionsForMediaNode: Unable to parse widget from/to dates."), LogType.Error.ToString()); } // We cannot have a 0 duration here... not sure why we would... but if (_options.duration == 0 && _options.type != "video" && _options.type != "localvideo") { int emptyLayoutDuration = int.Parse(ApplicationSettings.Default.EmptyLayoutDuration.ToString()); _options.duration = (emptyLayoutDuration == 0) ? 10 : emptyLayoutDuration; } // There will be some stuff on option nodes XmlNode optionNode = mediaNode.SelectSingleNode("options"); // Track if an update interval has been provided in the XLF bool updateIntervalProvided = false; // Loop through each option node 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") { updateIntervalProvided = true; try { _options.updateInterval = int.Parse(option.InnerText); } catch { // Update interval not defined, so assume a high value _options.updateInterval = 3600; 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.SelectSingleNode("raw"); if (rawNode != null) { 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; } } } // Audio Nodes? XmlNode audio = mediaNode.SelectSingleNode("audio"); if (audio != null) { foreach (XmlNode audioNode in audio.ChildNodes) { RegionOptions options = new RegionOptions(); options.Dictionary = new MediaDictionary(); options.duration = 0; options.uri = ApplicationSettings.Default.LibraryPath + @"\" + audioNode.InnerText; if (audioNode.Attributes["loop"] != null) { options.Dictionary.Add("loop", audioNode.Attributes["loop"].Value); if (options.Dictionary.Get("loop", 0) == 1) { // Set the media duration to be equal to the duration of the parent media options.duration = (_options.duration == 0) ? int.MaxValue : _options.duration; } } if (audioNode.Attributes["volume"] != null) { options.Dictionary.Add("volume", audioNode.Attributes["volume"].Value); } Media audioMedia = new Audio(options); // Bind to the media complete event audioMedia.DurationElapsedEvent += audio_DurationElapsedEvent; _options.Audio.Add(audioMedia); } } // Media Types without an update interval should have a sensible default (xibosignage/xibo#404) // This means that items which do not provide an update interval will still refresh. if (!updateIntervalProvided) { // Special handling for text/webpages because we know they should never have a default update interval applied if (_options.type == "webpage" || _options.type == "text") { // Very high (will expire eventually, but shouldn't cause a routine request for a new resource _options.updateInterval = int.MaxValue; } else { // Default to 5 minutes for those items that do not provide an update interval _options.updateInterval = 5; } } }
public ShellCommand(RegionOptions options) : base(options.width, options.height, options.top, options.left) { _command = Uri.UnescapeDataString(options.Dictionary.Get("windowsCommand")).Replace('+', ' '); }
/// <summary> /// Manage Overlays /// </summary> /// <param name="overlays"></param> public void ManageOverlays(Collection <ScheduleItem> overlays) { try { // Parse all overlays and compare what we have now to the overlays we have already created (see OverlayRegions) // Take the ones we currently have up and remove them if they aren't in the new list // We use a for loop so that we are able to remove the region from the collection for (int i = 0; i < _overlays.Count; i++) { Region region = _overlays[i]; bool found = false; foreach (ScheduleItem item in overlays) { if (item.scheduleid == region.scheduleId && _cacheManager.GetMD5(item.id + ".xlf") == region.hash) { found = true; break; } } if (!found) { Debug.WriteLine("Removing overlay which is no-longer required. Overlay: " + region.scheduleId, "Overlays"); region.Clear(); region.Dispose(); Controls.Remove(region); _overlays.Remove(region); } } // Take the ones that are in the new list and add them foreach (ScheduleItem item in overlays) { // Check its not already added. bool found = false; foreach (Region region in _overlays) { if (region.scheduleId == item.scheduleid) { found = true; break; } } if (found) { continue; } // Parse the layout for regions, and create them. string layoutPath = item.layoutFile; // Get this layouts XML XmlDocument layoutXml = new XmlDocument(); 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(); } } catch (Exception ex) { Trace.WriteLine(new LogMessage("MainForm - _schedule_OverlayChangeEvent", string.Format("Could not find the layout file {0}: {1}", layoutPath, ex.Message)), LogType.Info.ToString()); continue; } // Attributes of the main layout node XmlNode layoutNode = layoutXml.SelectSingleNode("/layout"); XmlAttributeCollection layoutAttributes = layoutNode.Attributes; // Set the background and size of the form double layoutWidth = int.Parse(layoutAttributes["width"].Value, CultureInfo.InvariantCulture); double layoutHeight = int.Parse(layoutAttributes["height"].Value, CultureInfo.InvariantCulture); // Scaling factor, will be applied to all regions double 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 RegionOptions options = new RegionOptions(); // Get the regions XmlNodeList listRegions = layoutXml.SelectNodes("/layout/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 = item.scheduleid; options.layoutId = item.id; 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.scheduleId = item.scheduleid; temp.hash = _cacheManager.GetMD5(item.id + ".xlf"); temp.BorderStyle = _borderStyle; // Dont be fooled, this innocent little statement kicks everything off temp.regionOptions = options; _overlays.Add(temp); Controls.Add(temp); temp.BringToFront(); } // Null stuff listRegions = null; } _clientInfoForm.ControlCount = Controls.Count; } catch (Exception e) { Trace.WriteLine(new LogMessage("MainForm - _schedule_OverlayChangeEvent", "Unknown issue managing overlays. Ex = " + e.Message), LogType.Info.ToString()); } }
/// <summary> /// Creates an RSS position with the RegionOptions parameter /// </summary> /// <param name="options"></param> public Rss(RegionOptions options) : base(options.width, options.height, options.top, options.left) { if (String.IsNullOrEmpty(options.uri)) { throw new ArgumentNullException("Uri", "The Uri for the RSS feed can not be empty"); } // Try to make a URI out of the file path try { _filePath = Uri.UnescapeDataString(options.uri); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message, "Rss"); throw new ArgumentNullException("Uri", "The URI is invalid."); } Debug.WriteLine("Ticker URL: " + _filePath + ". Options count: " + options.Dictionary.Count.ToString()); // Set the parameters based on the RegionOptions _direction = options.direction; _backgroundImage = options.backgroundImage; _backgroundColor = options.backgroundColor; _copyrightNotice = options.copyrightNotice; _mediaid = options.mediaid; _scheduleId = options.scheduleId; _layoutId = options.layoutId; _scaleFactor = options.scaleFactor; _duration = options.duration; // Update interval and scrolling speed _updateInterval = options.updateInterval; _scrollSpeed = options.scrollSpeed; Debug.WriteLine(String.Format("Scrolling Speed: {0}, Update Interval: {1})", _scrollSpeed.ToString(), _updateInterval.ToString()), "Rss - Constructor"); // Items to show and duration _numItems = Convert.ToInt32(options.Dictionary.Get("numItems", "0")); _durationIsPerItem = Convert.ToInt32(options.Dictionary.Get("durationIsPerItem", "0")); _takeItemsFrom = options.Dictionary.Get("takeItemsFrom", "start"); // Generate a temporary file to store the rendered object in. _tempHtml = new TemporaryHtml(); // Set up the backgrounds _backgroundTop = options.backgroundTop + "px"; _backgroundLeft = options.backgroundLeft + "px"; _documentText = options.text; _documentTemplate = options.documentTemplate; // Generate the HTML for the HEAD of the document GenerateHeadHtml(); // Prepare the RSS PrepareRSS(); // Create a webbrowser to take the temp file loc _webBrowser = new WebBrowser(); _webBrowser.ScriptErrorsSuppressed = true; _webBrowser.Size = this.Size; _webBrowser.ScrollBarsEnabled = false; _webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted); // Is the RSS ready to be loaded into the temp location? if (_rssReady) { // Load the RSS LoadRssIntoTempFile(); // Navigate to temp file _webBrowser.Navigate(_tempHtml.Path); } }
/// <summary> /// Creates a Text display control /// </summary> /// <param name="options">Region Options for this control</param> public Text(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; _backgroundImage = options.backgroundImage; _backgroundColor = options.backgroundColor; _backgroundTop = options.backgroundTop + "px"; _backgroundLeft = options.backgroundLeft + "px"; // 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); // XMDS feed? if (options.Dictionary.Get("xmds", "0") == "1") { // Set the file path _filePath = Settings.Default.LibraryPath + @"\" + _options.mediaid + ".htm"; // Check to see if the HTML is ready for us. if (HtmlReady()) { // Write to temporary file SaveToTemporaryFile(); // Navigate to temp file _webBrowser.Navigate(_temporaryFile.Path); } else { RefreshFromXmds(); } return; } // Non XMDS substitutes manually _filePath = options.uri; _direction = options.direction; _documentText = options.text; _scrollSpeed = options.scrollSpeed; _headJavaScript = options.javaScript; _fitText = (options.Dictionary.Get("fitText", "0") == "0" ? false : true); // Scale Factor _scaleFactor = options.scaleFactor; // Generate a temporary file to store the rendered object in. _tempHtml = new TemporaryHtml(); // Generate the Head Html and store to file. GenerateHeadHtml(); // Generate the Body Html and store to file. GenerateBodyHtml(); // Navigate to temp file _webBrowser.Navigate(_tempHtml.Path); }
/// <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 == Properties.Settings.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 = Settings.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.", Properties.Settings.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>", Properties.Settings.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; }
/// <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()); switch (options.type) { case "image": options.uri = Settings.Default.LibraryPath + @"\" + options.uri; media = new ImagePosition(options); break; case "text": media = new Text(options); break; case "powerpoint": options.uri = Settings.Default.LibraryPath + @"\" + options.uri; media = new WebContent(options); break; case "video": options.uri = Settings.Default.LibraryPath + @"\" + options.uri; // Which video engine are we using? if (Settings.Default.VideoRenderingEngine == "DirectShow") media = new VideoDS(options); else media = new Video(options); break; case "localvideo": // Which video engine are we using? if (Settings.Default.VideoRenderingEngine == "DirectShow") media = new VideoDS(options); else media = new Video(options); break; case "webpage": media = new WebContent(options); break; case "flash": options.uri = 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; 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 media.Duration = options.duration; // Add event handler for when this completes media.DurationElapsedEvent += new Media.DurationElapsedDelegate(media_DurationElapsedEvent); return media; }
/// <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; }
/// <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; }