public static Media CreateFrom(RegionOptions regionOptions) { UserControl widget = null; Media Backing = new Media(regionOptions.Width,regionOptions.Height,regionOptions.Top,regionOptions.Left); switch (regionOptions.Name) { case "CarInfo": widget = new CarInfo(); break; case "BatteryInfo": widget = new BatteryInfo(); break; case "LocationInfo": widget = new Location(); break; case "PersonalInfo": widget = new Profile(); break; default: break; } widget.Width = regionOptions.Width; widget.Height = regionOptions.Height; //MediaGrid.Width = Width; //MediaGrid.Height = Height; widget.HorizontalAlignment = HorizontalAlignment.Center; widget.VerticalAlignment = VerticalAlignment.Center; widget.Margin = new Thickness(0, 0, 0, 0); Backing.MediaCanvas.Children.Add(widget); Backing.HasOnLoaded = true; return Backing; }
public Picture(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { this._filePath = options.Uri; if (!File.Exists(this._filePath)) { Trace.WriteLine(new LogMessage("Image - Dispose", "Cannot Create image object. Invalid Filepath."), LogType.Error.ToString()); } else { try { this._pictureBox = new MediaElement(); this._pictureBox.Stretch = Stretch.Fill; Uri uriSource = new Uri(this._filePath.Replace(@"\", "/"), UriKind.Relative); this._pictureBox.Source = uriSource; base.MediaCanvas.Background = new ImageBrush(new BitmapImage(uriSource)); base.SnapShot = uriSource; this._pictureBox.Width = base.Width; this._pictureBox.Height = base.Height; this._pictureBox.HorizontalAlignment = HorizontalAlignment.Center; this._pictureBox.VerticalAlignment = VerticalAlignment.Center; this._pictureBox.Margin = new Thickness(0.0, 0.0, 0.0, 0.0); this._pictureBox.Loaded += new RoutedEventHandler(this.PictureBoxLoaded); base.MediaCanvas.Children.Add(this._pictureBox); base.HasOnLoaded = true; } catch (Exception exception) { Trace.WriteLine(new LogMessage("Picture", string.Format("Cannot create Image Object with exception: {0}", exception.Message)), LogType.Error.ToString()); } } }
public static Media CreateFrom(RegionOptions regionOptions) { UserControl element = null; Media media = new Media(regionOptions.Width, regionOptions.Height, regionOptions.Top, regionOptions.Left); if (Widgets.ContainsKey(regionOptions.Name)) { element = Widgets[regionOptions.Name]; } else { string name = regionOptions.Name; if (name != null) { if (!(name == "CarInfo")) { if (name == "BatteryInfo") { element = new BatteryInfo(); } else if (name == "LocationInfo") { element = new Location(); } else if (name == "PersonalInfo") { element = new Profile(); } } else { element = new CarInfo(); } } } element.Width = regionOptions.Width; element.Height = regionOptions.Height; element.HorizontalAlignment = HorizontalAlignment.Stretch; element.VerticalAlignment = VerticalAlignment.Stretch; element.Margin = new Thickness(0.0, 0.0, 0.0, 0.0); Canvas parent = element.Parent as Canvas; if (parent != null) { parent.Children.Remove(element); } media.MediaCanvas.Children.Add(element); media.HasOnLoaded = true; try { Widgets.Add(regionOptions.Name, element); } catch (Exception) { } return(media); }
public static Media CreateFrom(RegionOptions regionOptions) { UserControl element = null; Media media = new Media(regionOptions.Width, regionOptions.Height, regionOptions.Top, regionOptions.Left); if (Widgets.ContainsKey(regionOptions.Name)) { element = Widgets[regionOptions.Name]; } else { string name = regionOptions.Name; if (name != null) { if (!(name == "CarInfo")) { if (name == "BatteryInfo") { element = new BatteryInfo(); } else if (name == "LocationInfo") { element = new Location(); } else if (name == "PersonalInfo") { element = new Profile(); } } else { element = new CarInfo(); } } } element.Width = regionOptions.Width; element.Height = regionOptions.Height; element.HorizontalAlignment = HorizontalAlignment.Stretch; element.VerticalAlignment = VerticalAlignment.Stretch; element.Margin = new Thickness(0.0, 0.0, 0.0, 0.0); Canvas parent = element.Parent as Canvas; if (parent != null) { parent.Children.Remove(element); } media.MediaCanvas.Children.Add(element); media.HasOnLoaded = true; try { Widgets.Add(regionOptions.Name, element); } catch (Exception) { } return media; }
public Video(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { this.filePath = options.Uri; this.duration = options.Duration; this.videoPlayer = new VideoPlayer(); this.videoPlayer.Width = options.Width; this.videoPlayer.Height = options.Height; videoPlayer.SetSize(new Size(options.Width,options.Height)); this.videoPlayer.Location = new Point(0.0, 0.0); base.MediaCanvas.Children.Add(this.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.FileType; webBrowser = new WebBrowser(); webBrowser.Height = options.Height; webBrowser.Width = options.Width; //webBrowser.ScrollBarsEnabled = false; //webBrowser.ScriptErrorsSuppressed = true; // Attach event webBrowser.LoadCompleted += (WebBrowserDocumentCompleted); if (!Settings.Default.powerpointEnabled && options.FileType == "powerpoint") { webBrowser.Source = new Uri("<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.Source = new Uri("<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 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 Point(0, 0); MediaCanvas.Children.Add(videoPlayer); }
public Flash(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { this._tempHtml = new TemporaryHtml(); this._backgroundImage = options.backgroundImage; this._backgroundColor = options.backgroundColor; this._backgroundTop = options.BackgroundTop + "px"; this._backgroundLeft = options.BackgroundLeft + "px"; this.GenerateHeadHtml(); string format = "\r\n <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'>\r\n <param name='allowScriptAccess' value='sameDomain' />\r\n <param name='movie' value='{1}' />\r\n <param name='quality' value='high' />\r\n <param name='bgcolor' value='#000' />\r\n <param name='WMODE' value='transparent' />\r\n <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' />\r\n </object>\r\n "; this._tempHtml.BodyContent = string.Format(format, new object[] { options.Uri, options.Uri, options.Width.ToString(), options.Height.ToString() }); this._webBrowser = new WebBrowser(); this._webBrowser.RenderSize = base.RenderSize; this._webBrowser.LoadCompleted += new LoadCompletedEventHandler(this._webBrowser_DocumentCompleted); this._webBrowser.Navigate(this._tempHtml.Path); }
public Picture(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { _filePath = options.Uri; if (!File.Exists(_filePath)) { // Exit Trace.WriteLine(new LogMessage("Image - Dispose", "Cannot Create image object. Invalid Filepath."), LogType.Error.ToString()); return; } try { _pictureBox = new MediaElement(); _pictureBox.Stretch = Stretch.UniformToFill; var uri = new Uri(_filePath.Replace("\\", "/"), UriKind.Relative); _pictureBox.Source = (uri); MediaCanvas.Background = new ImageBrush(new BitmapImage(uri)); // new Uri("pack://application:,,,/ApplicationName;component/"+_filePath); SnapShot = uri; _pictureBox.Width = Width; _pictureBox.Height = Height; //MediaGrid.Width = Width; //MediaGrid.Height = Height; _pictureBox.HorizontalAlignment = HorizontalAlignment.Center; _pictureBox.VerticalAlignment = VerticalAlignment.Center; _pictureBox.Margin = new Thickness(0, 0, 0, 0); // _pictureBox.BorderStyle = BorderStyle.None; // _pictureBox.BackColor = Color.Transparent; _pictureBox.Loaded += PictureBoxLoaded; MediaCanvas.Children.Add(_pictureBox); HasOnLoaded = true; } catch (Exception ex) { Trace.WriteLine( new LogMessage("Picture", String.Format("Cannot create Image Object with exception: {0}", ex.Message)), LogType.Error.ToString()); } }
/// <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.Height = options.Height; _webBrowser.Width = options.Width; _webBrowser.Margin = new Thickness(0,0,0,0); //_webBrowser.ScrollBarsEnabled = false; //_webBrowser.ScriptErrorsSuppressed = true; _webBrowser.LoadCompleted += (WebBrowserDocumentCompleted); _webBrowser.Navigated += delegate { HideScriptErrors(_webBrowser, true); }; // Navigate to temp file _webBrowser.Navigate(_tempHtml.Path); MediaCanvas.Children.Add(_webBrowser); }
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 { this._filePath = Uri.UnescapeDataString(options.Uri); } catch (Exception) { throw new ArgumentNullException("Uri", "The URI is invalid."); } this._direction = options.direction; this._backgroundImage = options.backgroundImage; this._backgroundColor = options.backgroundColor; this._copyrightNotice = options.copyrightNotice; this._mediaid = options.mediaid; this._scheduleId = options.scheduleId; this._layoutId = options.layoutId; this._scaleFactor = options.ScaleFactor; this._duration = options.Duration; this._updateInterval = options.updateInterval; this._scrollSpeed = options.scrollSpeed; this._numItems = Convert.ToInt32(options.Dictionary.Get("numItems", "0")); this._durationIsPerItem = Convert.ToInt32(options.Dictionary.Get("durationIsPerItem", "0")); this._takeItemsFrom = options.Dictionary.Get("takeItemsFrom", "start"); this._tempHtml = new TemporaryHtml(); this._backgroundTop = options.BackgroundTop + "px"; this._backgroundLeft = options.BackgroundLeft + "px"; this._documentText = options.text; this._documentTemplate = options.documentTemplate; this.GenerateHeadHtml(); this.PrepareRSS(); this._webBrowser = new WebBrowser(); if (this._rssReady) { this.LoadRssIntoTempFile(); this._webBrowser.Navigate(this._tempHtml.Path); } }
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.RenderSize = this.RenderSize; // _webBrowser.Size = this.Size; // _webBrowser.ScrollBarsEnabled = false; // _webBrowser.ScriptErrorsSuppressed = true; _webBrowser.LoadCompleted += (_webBrowser_DocumentCompleted); // Navigate to temp file _webBrowser.Navigate(_tempHtml.Path); }
public WebContent(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { this.duration = options.Duration; this.scheduleId = options.scheduleId; this.layoutId = options.layoutId; this.mediaId = options.mediaid; this.type = options.FileType; this.webBrowser = new WebBrowser(); this.webBrowser.Height = options.Height; this.webBrowser.Width = options.Width; this.webBrowser.LoadCompleted += new LoadCompletedEventHandler(this.WebBrowserDocumentCompleted); //if (/*!Settings.Default.powerpointEnabled &&*/ (options.FileType == "Powerpoint")) //{ // this.webBrowser.Source = new Uri("<html><body><h1>Powerpoint not enabled on this display</h1></body></html>"); // Trace.WriteLine(string.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", new object[] { "Powerpoint is not enabled on this display", this.scheduleId, this.layoutId, this.mediaId })); //} //else { try { try { this.filePath = Uri.UnescapeDataString(options.Uri); } catch (Exception) { } this.webBrowser.Navigate(Application.StartupPath+"\\"+ this.filePath.Replace("\\\\","\\")); MediaCanvas.Children.Add(webBrowser); } catch (Exception exception) { Trace.WriteLine(string.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", new object[] { exception.Message, this.scheduleId, this.layoutId, this.mediaId })); this.webBrowser.NavigateToString("<html><body><h1>Unable to show this web location - invalid address.</h1></body></html>"); Trace.WriteLine(string.Format("[*]ScheduleID:{1},LayoutID:{2},MediaID:{3},Message:{0}", new object[] { "Unable to show the powerpoint, cannot be located", this.scheduleId, this.layoutId, this.mediaId })); } } }
public static Media CreateFrom(RegionOptions regionOptions) { UserControl widget = null; Media Backing = new Media(regionOptions.Width, regionOptions.Height, regionOptions.Top, regionOptions.Left); switch (regionOptions.Name) { case "CarInfo": widget = new CarInfo(); break; case "BatteryInfo": widget = new BatteryInfo(); break; case "LocationInfo": widget = new Location(); break; case "PersonalInfo": widget = new Profile(); break; default: break; } widget.Width = regionOptions.Width; widget.Height = regionOptions.Height; //MediaGrid.Width = Width; //MediaGrid.Height = Height; widget.HorizontalAlignment = HorizontalAlignment.Center; widget.VerticalAlignment = VerticalAlignment.Center; widget.Margin = new Thickness(0, 0, 0, 0); Backing.MediaCanvas.Children.Add(widget); Backing.HasOnLoaded = true; return(Backing); }
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.LoadCompleted += (webBrowser_DocumentCompleted); if (HtmlReady()) { // Navigate to temp file string filePath = Settings.Default.LibraryPath + @"\" + _mediaId + ".htm"; _webBrowser.Navigate(filePath); } else { RefreshLocalHtml(); } }
public DataSetView(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { this._layoutId = options.layoutId; this._regionId = options.regionId; this._mediaId = options.mediaid; this._duration = options.Duration; this._scaleFactor = options.ScaleFactor; this._updateInterval = Convert.ToInt32(options.Dictionary.Get("updateInterval")); this._backgroundImage = options.backgroundImage; this._backgroundColor = options.backgroundColor; this._backgroundTop = options.BackgroundTop + "px"; this._backgroundLeft = options.BackgroundLeft + "px"; this._webBrowser = new WebBrowser(); this._webBrowser.LoadCompleted += new LoadCompletedEventHandler(this.webBrowser_DocumentCompleted); if (this.HtmlReady()) { string source = Settings.Default.LibraryPath + @"\" + this._mediaId + ".htm"; this._webBrowser.Navigate(source); } else { this.RefreshLocalHtml(); } }
/// <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); } }
public void PrepareLayout(string layoutPath) { Action method = null; Action start2 = null; Action start3 = null; Action<RegionOptions> action = null; LayoutModel layout; ClientManager.Instance.Stat = new ClientApp.Core.Stat(); ClientManager.Instance.Stat.FileType = StatType.Layout; ClientManager.Instance.Stat.ScheduleID = ClientManager.Instance.ScheduleId; ClientManager.Instance.Stat.LayoutID = this._layoutId; ClientManager.Instance.Stat.FromDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if ((layoutPath == (Settings.Default.LibraryPath + @"\Default.xml")) || string.IsNullOrEmpty(layoutPath)) { throw new Exception("Default layout"); } try { using (FileStream stream = File.Open(layoutPath, FileMode.Open, FileAccess.Read, FileShare.Write)) { XmlSerializer serializer = new XmlSerializer(typeof(LayoutModel)); layout = (LayoutModel)serializer.Deserialize(stream); } } catch (Exception exception) { Trace.WriteLine(string.Format("Could not find the layout file {0}: {1}", layoutPath, exception.Message)); throw; } this._layoutWidth = layout.Width; this._layoutHeight = layout.Height; int width = this._clientSize.Width; int height = this._clientSize.Height; this._regions = new Collection<ClientApp.Core.Region>(); RegionOptions options = new RegionOptions(); try { if (!string.IsNullOrEmpty(layout.Bgcolor)) { if (method == null) { method = new Action(() => { this.MediaCanvas.Background = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(layout.Bgcolor)); }); } base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, method); options.backgroundColor = layout.Bgcolor; } } catch { if (start2 == null) { start2 = new Action(() => { this.MediaCanvas.Background = new SolidColorBrush(Colors.Black); }); } base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, start2); options.backgroundColor = "#000000"; } try { if (layout.Background == null) { this.MediaCanvas.Background = null; options.backgroundImage = ""; } else { string bgFilePath = string.Concat(new object[] { Settings.Default.LibraryPath, @"\backgrounds\", width, "x", height, "_", layout.Background }); Utilities.CreateFolder(Path.GetDirectoryName(bgFilePath)); if (!File.Exists(bgFilePath)) { System.Drawing.Image original = System.Drawing.Image.FromFile(Settings.Default.LibraryPath + @"\" + layout.Background); Bitmap bitmap = new Bitmap(original, width, height); EncoderParameters encoderParams = new EncoderParameters(1); EncoderParameter parameter = new EncoderParameter(Encoder.Quality, 90L); encoderParams.Param[0] = parameter; ImageCodecInfo encoderInfo = GetEncoderInfo("image/jpeg"); bitmap.Save(bgFilePath, encoderInfo, encoderParams); original.Dispose(); bitmap.Dispose(); } base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { this.MediaCanvas.Background = new ImageBrush(new BitmapImage(new Uri(bgFilePath.Replace(@"\", "/"), UriKind.Relative))); })); options.backgroundImage = bgFilePath; } } catch (Exception) { if (start3 == null) { start3 = new Action(() => { this.MediaCanvas.Background = System.Windows.Media.Brushes.Black; }); } base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, start3); options.backgroundImage = ""; } App.DoEvents(); List<LayoutRegion> regions = layout.Regions; List<List<LayoutRegionMedia>> list2 = (from r in layout.Regions select r.Media).ToList<List<LayoutRegionMedia>>(); if ((regions.Count == 0) || (list2.Count == 0)) { Trace.WriteLine(new LogMessage("PrepareLayout", string.Format("A layout with {0} regions and {1} media has been detected.", regions.Count.ToString(), list2.Count.ToString())), LogType.Info.ToString()); if (ClientManager.Instance.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"); } Trace.WriteLine(new LogMessage("PrepareLayout", string.Format(string.Format("An empty layout detected, will show for {0} seconds.", Settings.Default.emptyLayoutDuration.ToString()), new object[0])), LogType.Info.ToString()); List<LayoutRegion> list3 = new List<LayoutRegion>(); LayoutRegion region = new LayoutRegion { Id = "blah", Width = 1, Height = 1, Top = 1, Left = 1 }; List<LayoutRegionMedia> list4 = new List<LayoutRegionMedia>(); LayoutRegionMedia media = new LayoutRegionMedia { Id = "blah", Type = "Text", Duration = 0 }; LayoutRegionMediaRaw raw = new LayoutRegionMediaRaw { Text = "" }; media.Raw = raw; list4.Add(media); region.Media = list4; list3.Add(region); regions = list3; } else {// Keep Running region, preventing visual blank out; regions.Add( new LayoutRegion() { Height = 0,Width = 0,Name = "Keep Alive Region", Media = new List<LayoutRegionMedia>() { new LayoutRegionMedia() { Duration = (int) TimeSpan.FromDays(10).TotalMilliseconds, Type = "KeepAlive" } } }); } foreach (LayoutRegion region2 in regions) { if (region2.Media.Count != 0) { options.scheduleId = ClientManager.Instance.ScheduleId; options.layoutId = this._layoutId; options.regionId = region2.Id; options.Width = (int)((((double)(region2.Width + 14)) / this._layoutWidth) * this._clientSize.Width); options.Height = (int)((((double)(region2.Height + 14)) / this._layoutHeight) * this._clientSize.Height); int left = region2.Left; if (left < 0) { left = 0; } int top = region2.Top; if (top < 0) { top = 0; } options.Left = (int)((((double)left) / this._layoutWidth) * this._clientSize.Width); options.Top = (int)((((double)top) / this._layoutHeight) * this._clientSize.Height); options.ScaleFactor = this._scaleFactor; options.BackgroundLeft = options.Left * -1; options.BackgroundTop = options.Top * -1; options.mediaNodes = region2.Media; if (action == null) { action = delegate(RegionOptions opts) { Core.Region region = new ClientApp.Core.Region(ClientManager.Instance.StatLog, ClientManager.Instance.CacheManager); region.DurationElapsedEvent += new ClientApp.Core.Region.DurationElapsedDelegate(this.TempDurationElapsedEvent); if (opts.FileType != "Widget") { region.RegionOptions = opts; this._regions.Add(region); region.Opacity = 0.0; this.MediaCanvas.Children.Add(region); region.AnimateIn(); } else if (!WidgetsFactory.Widgets.ContainsKey(opts.Name)) { region.RegionOptions = opts; region.Opacity = 0.0; this.MediaCanvas.Children.Add(region); region.AnimateIn(); } }; } base.Dispatcher.BeginInvoke(DispatcherPriority.Normal, action, options); App.DoEvents(); } } regions = null; list2 = null; }
public KeepAlive(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { this._filePath = options.Uri; }
public Text(RegionOptions options) : base(options.Width, options.Height, options.Top, options.Left) { //NavigatedEventHandler handler = null; this._filePath = options.Uri; this._direction = options.direction??"left"; this._backgroundImage = options.backgroundImage; this._backgroundColor = options.backgroundColor; //this._scaleFactor = options.ScaleFactor==0?3:options.ScaleFactor; //this._backgroundTop = options.BackgroundTop + "px"; //this._backgroundLeft = options.BackgroundLeft + "px"; //this._documentText = File.ReadAllText(_filePath);//options.text; //this._scrollSpeed = 50;//options.scrollSpeed; //this._headJavaScript = options.javaScript; //this._tempHtml = new TemporaryHtml(); //this.GenerateHeadHtml(); //this.GenerateBodyHtml(); //this._webBrowser = new WebBrowser(); //this._webBrowser.Height = options.Height; //this._webBrowser.Width = options.Width; //this._webBrowser.Margin = new Thickness(0.0, 0.0, 0.0, 0.0); //this._webBrowser.LoadCompleted += new LoadCompletedEventHandler(this.WebBrowserDocumentCompleted); //if (handler == null) //{ // handler =new NavigatedEventHandler((t,r)=>{ // this.HideScriptErrors(this._webBrowser, true); // }); //} //this._webBrowser.Navigated += handler; //this._webBrowser.Navigate(this._tempHtml.Path); //base.MediaCanvas.Children.Add(this._webBrowser); //Todo : Detect newlines and replace with tabs on horiz scroll var text = File.ReadAllText(_filePath).Replace("\n", " ").Replace("\r", " ") + " "; // var text = "Welcome to this cool app Welcome to this cool app Welcome to this cool app Welcome to this cool app Welcome to this cool app "; // text = // "WELCOME TO THIS COOL APP WELCOME TO THIS COOL APP WELCOME TO THIS COOL APP WELCOME TO THIS COOL APP "; marquee =new Marquee(); // options.Height = options.Height/2; // options.Width = options.Width/5; // Create the initial formatted text string. FormattedText formattedText = new FormattedText( text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Arial"), options.Height, Brushes.Black); //// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears. //formattedText.MaxTextWidth = 300; //formattedText.MaxTextHeight = 240; marquee.MarqueeContent = new TextBlock(); marquee.Width = options.Width; marquee.Height = options.Height; marquee.MarqueeContent.Text = text; //_marquee.MarqueeContent.ActualWidth.ToString(); marquee.MarqueeContent.FontFamily = new FontFamily("Arial"); marquee.MarqueeContent.Height = options.Height; marquee.MarqueeContent.FontSize = options.Height; marquee.MarqueeContent.TextWrapping = TextWrapping.NoWrap; marquee.VerticalAlignment = VerticalAlignment.Center; marquee.DesiredWidth = options.Width; var dur = ((formattedText.Width / options.Height)) /2 ;//1.2; // (((options.Width)*options.Height) * text.Length)/ // 211637 ; marquee.Duration = new Duration( TimeSpan.FromSeconds(dur )); marquee.MarqueeContent.Foreground = System.Windows.Media.Brushes.Black; marquee.MarqueeContent.Background = System.Windows.Media.Brushes.LawnGreen; // marquee.LeftToRight = true; //new SigMarquee() // {Message = text, Font = new SigFont() {Size = options.Height}, Speed = 8, Interval=TimeSpan.FromSeconds(100)}) // {TextBanner = {TextWrapping = TextWrapping.NoWrap}, Height = options.Height, Width = options.Width}; //marquee = new MarqueeText(); //marquee.Background =System.Windows.Media.Brushes.Red; //marquee.MarqueeTimeInSeconds = options.Duration; //marquee.Foreground = System.Windows.Media.Brushes.Black; //marquee.MarqueeType = MarqueeType.RightToLeft; ; //marquee.MarqueeContent = File.ReadAllText(_filePath); base.MediaCanvas.Children.Add(this.marquee); }
/// <summary> /// Prepares the Layout.. rendering all the necessary controls /// </summary> public void PrepareLayout(string layoutPath) { // Create a start record for this layout ClientManager.Instance.Stat = new Stat(); ClientManager.Instance.Stat.FileType = StatType.Layout; ClientManager.Instance.Stat.ScheduleID = ClientManager.Instance.ScheduleId; ClientManager.Instance.Stat.LayoutID = _layoutId; ClientManager.Instance.Stat.FromDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); LayoutModel layout; // Default or not if (layoutPath == Settings.Default.LibraryPath + @"\Default.xml" || String.IsNullOrEmpty(layoutPath)) { throw new Exception("Default layout"); } else { try { // Get this layouts XML using (var file = File.Open(layoutPath, FileMode.Open, FileAccess.Read, FileShare.Write)) { XmlSerializer serializer = new XmlSerializer(typeof(LayoutModel)); layout = (LayoutModel)serializer.Deserialize(file); } } 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 // Set the background and size of the form _layoutWidth = layout.Width; _layoutHeight = layout.Height; //// Scaling factor, will be applied to all regions //_scaleFactor = Math.Max(_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 = _clientSize.Width;// (int)(_layoutWidth * _scaleFactor); int backgroundHeight = _clientSize.Height;//(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(); // Deal with the color try { if (!String.IsNullOrEmpty(layout.Bgcolor)) { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(() => { MediaCanvas.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(layout.Bgcolor)); })); options.backgroundColor = layout.Bgcolor; } } catch { Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(() => { MediaCanvas.Background = new SolidColorBrush(Colors.Black); // Default black })); options.backgroundColor = "#000000"; } // Get the background try { if (layout.Background == null) { // Assume there is no background image MediaCanvas.Background = null; options.backgroundImage = ""; } else { string bgFilePath = Settings.Default.LibraryPath + @"\backgrounds\" + backgroundWidth + "x" + backgroundHeight + "_" + layout.Background; Utilities.CreateFolder(Path.GetDirectoryName(bgFilePath)); // Create a correctly sized background image in the temp folder if (!File.Exists(bgFilePath)) { System.Drawing.Image img = System.Drawing.Image.FromFile(Settings.Default.LibraryPath + @"\" + layout.Background); Bitmap bmp = new Bitmap(img, backgroundWidth, backgroundHeight); EncoderParameters encoderParameters = new EncoderParameters(1); EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 90L); encoderParameters.Param[0] = qualityParam; ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg"); bmp.Save(bgFilePath, jpegCodec, encoderParameters); img.Dispose(); bmp.Dispose(); } Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(() => { MediaCanvas.Background = new ImageBrush(new BitmapImage(new Uri(bgFilePath.Replace("\\", "/"), UriKind.Relative))); })); options.backgroundImage = bgFilePath; } } catch (Exception ex) { Debug.WriteLine("Unable to set background: " + ex.Message); // Assume there is no background image Dispatcher.BeginInvoke(DispatcherPriority.Normal, new ThreadStart(() => { MediaCanvas.Background = Brushes.Black; })); options.backgroundImage = ""; } // Get it to paint the background now App.DoEvents(); // Get the regions var listRegions = layout.Regions; var listMedia = layout.Regions.Select(r => r.Media).ToList(); // 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 (ClientManager.Instance.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.", 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. // Replace the list of regions (they mean nothing as they are empty) listRegions = new List<LayoutRegion>() { new LayoutRegion() { Id="blah", Width = 1, Height = 1, Top = 1,Left = 1, Media = new List<LayoutRegionMedia>() { new LayoutRegionMedia() { Id = "blah", Type = "Text", Duration = 0, Raw = new LayoutRegionMediaRaw() { Text = "" } } } } }; } } foreach (var region in listRegions) { // Is there any media if (region.Media.Count == 0) { Debug.WriteLine("A region with no media detected"); continue; } //each region options.scheduleId = ClientManager.Instance.ScheduleId; options.layoutId = _layoutId; options.regionId = region.Id; options.Width = (int)((region.Width + 30.0) / _layoutWidth * _clientSize.Width); //(int)((region.Width + 15.0) * _scaleFactor); options.Height = (int)((region.Height + 30) / _layoutHeight * _clientSize.Height);//(int)((region.Height + 15.0) * _scaleFactor); var left = region.Left - 15; if (left < 0) left = 0; var top = region.Top - 15; if (top < 0) top = 0; options.Left = (int)(left/ _layoutWidth * _clientSize.Width);//(int)(region.Left * _scaleFactor); options.Top = (int)(top / _layoutHeight * _clientSize.Height); //(int)(region.Top * _scaleFactor); options.ScaleFactor = _scaleFactor; // 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.Media; Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<RegionOptions>( (opts) => { Region temp = new Region(ClientManager.Instance.StatLog, ClientManager.Instance.CacheManager); temp.DurationElapsedEvent += new Region.DurationElapsedDelegate(TempDurationElapsedEvent); Debug.WriteLine("Created new region", "AdvertPlayer - Prepare Layout"); // Dont be fooled, this innocent little statement kicks everything off temp.RegionOptions = opts; _regions.Add(temp); temp.Opacity = 0; MediaCanvas.Children.Add(temp); temp.AnimateIn(); // new TextBox(){ //Text = "Hey", // Margin = new Thickness(options.left,options.top,0,0), // Height = options.Height, // Width = options.Width // }) ; // temp.Background = new SolidColorBrush(Colors.Coral); }), options); Debug.WriteLine("Adding region", "AdvertPlayer - Prepare Layout"); App.DoEvents(); } // Null stuff listRegions = null; listMedia = null; }