/// <summary> /// Record a complete Media Event /// </summary> /// <param name="fromDT"></param> /// <param name="toDT"></param> /// <param name="layoutID"></param> /// <param name="mediaID"></param> public void RecordMedia(String fromDT, String toDT, int layoutID, String mediaID) { if (!ApplicationSettings.Default.StatsEnabled) return; Stat stat = new Stat(); stat.type = StatType.Media; stat.fromDate = fromDT; stat.toDate = toDT; stat.layoutID = layoutID; stat.mediaID = mediaID; _stats.Add(stat); return; }
/// <summary> /// Record a complete Layout Event /// </summary> /// <param name="fromDT"></param> /// <param name="toDT"></param> /// <param name="scheduleID"></param> /// <param name="layoutID"></param> public void RecordLayout(String fromDT, String toDT, int scheduleID, int layoutID) { if (!ApplicationSettings.Default.StatsEnabled) return; Stat stat = new Stat(); stat.type = StatType.Layout; stat.fromDate = fromDT; stat.toDate = toDT; stat.scheduleID = scheduleID; stat.layoutID = layoutID; _stats.Add(stat); return; }
///<summary> /// Evaulates the change in options ///</summary> private void EvalOptions() { if (currentSequence == -1) { //evaluate the width, etc this.Location = new System.Drawing.Point(options.left, options.top); this.Size = new System.Drawing.Size(options.width, options.height); } int temp = currentSequence; //set the next media node for this panel if (!SetNextMediaNode()) { // For some reason we cannot set a media node... so we need this region to become invalid hasExpired = true; DurationElapsedEvent(); return; } // If the sequence hasnt been changed, OR the layout has been expired if (currentSequence == temp || layoutExpired) { //there has been no change to the sequence, therefore the media we have already created is still valid //or this media has actually been destroyed and we are working out way out the call stack return; } System.Diagnostics.Debug.WriteLine(String.Format("Creating new media: {0}, {1}", options.type, options.mediaid), "Region - EvalOptions"); try { switch (options.type) { case "image": options.uri = Properties.Settings.Default.LibraryPath + @"\" + options.uri; media = new ImagePosition(options); break; case "text": media = new Text(options); break; case "powerpoint": options.uri = Properties.Settings.Default.LibraryPath + @"\" + options.uri; media = new WebContent(options); break; case "video": options.uri = Properties.Settings.Default.LibraryPath + @"\" + options.uri; media = new Video(options); break; case "webpage": media = new WebContent(options); break; case "flash": options.uri = Properties.Settings.Default.LibraryPath + @"\" + options.uri; media = new Flash(options); break; case "ticker": media = new Rss(options); break; case "embedded": media = new Text(options); break; case "datasetview": media = new DataSetView(options); break; default: //do nothing SetNextMediaNode(); return; } //sets up the timer for this media media.Duration = options.duration; //add event handler media.DurationElapsedEvent += new Media.DurationElapsedDelegate(media_DurationElapsedEvent); //any additional media specific render options (and starts the timer) media.RenderMedia(); Controls.Add(media); } catch (Exception ex) { Trace.WriteLine(new LogMessage("EvalOptions", "Unable to start media. " + ex.Message), LogType.Error.ToString()); SetNextMediaNode(); } // This media has started and is being replaced _stat = new Stat(); _stat.type = StatType.Media; _stat.fromDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); _stat.scheduleID = options.scheduleId; _stat.layoutID = options.layoutId; _stat.mediaID = options.mediaid; System.Diagnostics.Debug.WriteLine("Showing new media", "Region - Eval Options"); }
/// <summary> /// Opens a stat record for the current media /// </summary> private void OpenStatRecordForMedia() { // This media has started and is being replaced _stat = new Stat(); _stat.type = StatType.Media; _stat.fromDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); _stat.scheduleID = _options.scheduleId; _stat.layoutID = _options.layoutId; _stat.mediaID = _options.mediaid; }
/// <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> /// RecordStat /// </summary> /// <param name="stat"></param> public void RecordStat(Stat stat) { if (!ApplicationSettings.Default.StatsEnabled) return; Debug.WriteLine(String.Format("Recording a Stat Record. Current Count = {0}", _stats.Count.ToString()), LogType.Audit.ToString()); _stats.Add(stat); // At some point we will need to flush the stats if (_stats.Count >= ApplicationSettings.Default.StatsFlushCount) { Flush(); } return; }
/// <summary> /// Record a complete Event /// </summary> /// <param name="fromDT"></param> /// <param name="toDT"></param> /// <param name="tag"></param> public void RecordEvent(String fromDT, String toDT, String tag) { if (!ApplicationSettings.Default.StatsEnabled) return; Stat stat = new Stat(); stat.type = StatType.Event; stat.fromDate = fromDT; stat.toDate = toDT; stat.tag = tag; _stats.Add(stat); return; }