diff --git a/Logic/ApplicationSettings.cs b/Logic/ApplicationSettings.cs index 63f2af1b..664fdc7f 100644 --- a/Logic/ApplicationSettings.cs +++ b/Logic/ApplicationSettings.cs @@ -37,9 +37,9 @@ public class ApplicationSettings private static string _default = "default"; // Application Specific Settings we want to protect - private string _clientVersion = "1.7.6"; + private string _clientVersion = "1.7.7"; private string _version = "4"; - private int _clientCodeVersion = 110; + private int _clientCodeVersion = 111; public string ClientVersion { get { return _clientVersion; } } public string Version { get { return _version; } } diff --git a/Logic/ScheduleManager.cs b/Logic/ScheduleManager.cs index fbaf791b..af3714ef 100644 --- a/Logic/ScheduleManager.cs +++ b/Logic/ScheduleManager.cs @@ -277,7 +277,7 @@ private Collection LoadNewSchdule() { if (!_cacheManager.IsValidLayout(layout.id + ".xlf")) { - Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout invalid: " + layout.id), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("ScheduleManager - LoadNewSchedule", "Layout invalid: " + layout.id), LogType.Info.ToString()); continue; } } diff --git a/MainForm.cs b/MainForm.cs index 30304ab9..bd9a4612 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -50,6 +50,7 @@ public partial class MainForm : Form private int _scheduleId; private int _layoutId; private bool _screenSaver = false; + private bool _showingSplash = false; double _layoutWidth; double _layoutHeight; @@ -483,16 +484,19 @@ private void ChangeToNextLayout(string layoutPath) catch (Exception ex) { Trace.WriteLine(new LogMessage("MainForm - ChangeToNextLayout", "Layout Change to " + layoutPath + " failed. Exception raised was: " + ex.Message), LogType.Error.ToString()); - - ShowSplashScreen(); - // In 10 seconds fire the next layout? - System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); - timer.Interval = 10000; - timer.Tick += new EventHandler(splashScreenTimer_Tick); + if (!_showingSplash) + { + ShowSplashScreen(); + + // In 10 seconds fire the next layout? + System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); + timer.Interval = 15000; + timer.Tick += new EventHandler(splashScreenTimer_Tick); - // Start the timer - timer.Start(); + // Start the timer + timer.Start(); + } } // We have finished changing the layout @@ -512,6 +516,8 @@ void splashScreenTimer_Tick(object sender, EventArgs e) timer.Stop(); timer.Dispose(); + _showingSplash = false; + _schedule.NextLayout(); } @@ -520,13 +526,6 @@ void splashScreenTimer_Tick(object sender, EventArgs e) /// 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; @@ -677,6 +676,13 @@ 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"); + foreach (XmlNode region in listRegions) { // Is there any media @@ -763,6 +769,8 @@ private static void GenerateBackgroundImage(string sourceFile, int backgroundWid /// private void ShowSplashScreen() { + _showingSplash = true; + if (!string.IsNullOrEmpty(ApplicationSettings.Default.SplashOverride)) { try diff --git a/Media/CefWebMedia.cs b/Media/CefWebMedia.cs index 659a12ff..24df28e2 100644 --- a/Media/CefWebMedia.cs +++ b/Media/CefWebMedia.cs @@ -193,7 +193,7 @@ private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourc // Success / Failure if (e.Error != null) { - Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Info.ToString()); // We have failed to update from XMDS, do we have a cached file we can revert to if (File.Exists(_filePath)) diff --git a/Media/IeWebMedia.cs b/Media/IeWebMedia.cs index 29fa4e5a..48ffab6c 100644 --- a/Media/IeWebMedia.cs +++ b/Media/IeWebMedia.cs @@ -38,6 +38,7 @@ class IeWebMedia : Media private RegionOptions _options; private WebBrowser _webBrowser; private int _documentCompletedCount = 0; + private bool _reloadOnXmdsRefresh = false; public IeWebMedia(RegionOptions options) : base(options.width, options.height, options.top, options.left) @@ -74,21 +75,17 @@ public IeWebMedia(RegionOptions options) // Nativate directly _webBrowser.Navigate(_filePath); } - else + else if (HtmlReady()) { - // Check to see if the HTML is ready for us. - if (HtmlReady()) - { - // Write to temporary file - ReadControlMeta(); + // Write to temporary file + ReadControlMeta(); - // Navigate to temp file - _webBrowser.Navigate(_filePath); - } - else - { - RefreshFromXmds(); - } + // Navigate to temp file + _webBrowser.Navigate(_filePath); + } + else + { + Debug.WriteLine("HTML Resource is not ready to be shown (meaning the file doesn't exist at all) - wait for the download the occur and then show"); } Controls.Add(_webBrowser); @@ -97,47 +94,85 @@ public IeWebMedia(RegionOptions options) Show(); } + /// + /// Web Browser finished loading document + /// + /// + /// void _webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { _documentCompletedCount++; + // Prevent double document completions if (_documentCompletedCount > 1) return; // Start the timer base.RestartTimer(); + // Don't do anything if we are already disposed if (_disposed) return; + // Show the browser _webBrowser.Visible = true; } + /// + /// Is the cached HTML ready + /// + /// true if there is something to show, false if nothing private bool HtmlReady() { // Check for cached resource files in the library // We want to check the file exists first - if (!File.Exists(_filePath) || _options.updateInterval == 0) + if (!File.Exists(_filePath)) + { + // File doesn't exist at all. + _reloadOnXmdsRefresh = true; + + // Refresh + RefreshFromXmds(); + + // Return false return false; + } // It exists - therefore we want to get the last time it was updated DateTime lastWriteDate = File.GetLastWriteTime(_filePath); + // Does it update every time? + if (_options.updateInterval == 0) + { + // Comment in to force a re-request with each reload of the widget + //_reloadOnXmdsRefresh = true; + + // File exists but needs updating + RefreshFromXmds(); + + // Comment in to force a re-request with each reload of the widget + //return false; + } // Compare the last time it was updated to the layout modified time (always refresh when the layout has been modified) // Also compare to the update interval (refresh if it has not been updated for longer than the update interval) - if (_options.LayoutModifiedDate.CompareTo(lastWriteDate) > 0 || DateTime.Now.CompareTo(lastWriteDate.AddMinutes(_options.updateInterval)) > 0) + else if (_options.LayoutModifiedDate.CompareTo(lastWriteDate) > 0 || DateTime.Now.CompareTo(lastWriteDate.AddMinutes(_options.updateInterval)) > 0) { - return false; + // File exists but needs updating. + RefreshFromXmds(); } else { - UpdateCacheIfNecessary(); - return true; + // File exists and is in-date - nothing to do } + + // Refresh the local file cache with any new dimensions, etc. + UpdateCacheIfNecessary(); + + return true; } /// - /// Updates the position of the background and saves to a temporary file + /// Pulls the duration out of the temporary file and sets the media Duration to the same /// private void ReadControlMeta() { @@ -159,7 +194,7 @@ private void ReadControlMeta() } catch { - Trace.WriteLine(new LogMessage("Html - SaveToTemporaryFile", "Unable to pull duration using RegEx").ToString()); + Trace.WriteLine(new LogMessage("Html - ReadControlMeta", "Unable to pull duration using RegEx").ToString()); } } } @@ -188,21 +223,30 @@ private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourc // Success / Failure if (e.Error != null) { - Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Info.ToString()); - // We have failed to update from XMDS, do we have a cached file we can revert to - if (File.Exists(_filePath)) + // We have failed to update from XMDS + // id we have been asked to reload on XmdsRefresh, check to see if we have a file to load, + // if not expire on a short timer. + if (_reloadOnXmdsRefresh) { - // Cached file to revert to - UpdateCacheIfNecessary(); - - _webBrowser.Navigate(_filePath); - } - else - { - // No cache to revert to - // Start the timer so that we expire - base.RenderMedia(); + if (File.Exists(_filePath)) + { + // Cached file to revert to + UpdateCacheIfNecessary(); + + // Navigate to the file + _webBrowser.Navigate(_filePath); + } + else + { + // No cache to revert to + Trace.WriteLine(new LogMessage("xmds_GetResource", "We haven't been able to download this widget and there isn't a pre-cached one to use. Skipping."), LogType.Info.ToString()); + + // Start the timer so that we expire + Duration = 2; + base.RenderMedia(); + } } } else @@ -225,6 +269,10 @@ private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourc string html = cachedFile.Replace("", ""); html = html.Replace("[[ViewPortWidth]]", _width.ToString()); + // Comment in to write out the update date at the end of the file (in the body) + // This is useful if you want to check how frequently the file is updating + //html = html.Replace("", "

" + DateTime.Now.ToString() + "

"); + // Write to the library using (StreamWriter sw = new StreamWriter(File.Open(_filePath, FileMode.Create, FileAccess.Write, FileShare.Read))) { @@ -232,11 +280,14 @@ private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourc sw.Close(); } - // Read the control meta back out - ReadControlMeta(); + if (_reloadOnXmdsRefresh) + { + // Read the control meta back out + ReadControlMeta(); - // Handle Navigate in here because we will not have done it during first load - _webBrowser.Navigate(_filePath); + // Handle Navigate in here because we will not have done it during first load + _webBrowser.Navigate(_filePath); + } } } catch (ObjectDisposedException) diff --git a/Media/Media.cs b/Media/Media.cs index 7788b53c..dfdae7ff 100644 --- a/Media/Media.cs +++ b/Media/Media.cs @@ -229,7 +229,8 @@ public void SignalElapsedEvent() Trace.WriteLine(new LogMessage("Media - SignalElapsedEvent", "Media Complete"), LogType.Audit.ToString()); - DurationElapsedEvent(_filesPlayed); + if (DurationElapsedEvent != null) + DurationElapsedEvent(_filesPlayed); } /// diff --git a/XiboClient.v11.suo b/XiboClient.v11.suo index fe515b6a..414f33f6 100644 Binary files a/XiboClient.v11.suo and b/XiboClient.v11.suo differ diff --git a/XmdsAgents/FileAgent.cs b/XmdsAgents/FileAgent.cs index 5ceb746a..059c75c1 100644 --- a/XmdsAgents/FileAgent.cs +++ b/XmdsAgents/FileAgent.cs @@ -123,7 +123,7 @@ public FileAgent() /// public void Run() { - Trace.WriteLine(new LogMessage("FileAgent - Run", "Thread Started"), LogType.Info.ToString()); + Trace.WriteLine(new LogMessage("FileAgent - Run", "Thread Started"), LogType.Audit.ToString()); // Get the required file id from the list of required files. RequiredFile file = _requiredFiles.GetRequiredFile(_requiredFileId, _requiredFileType); @@ -136,7 +136,7 @@ public void Run() try { - Trace.WriteLine(new LogMessage("FileAgent - Run", "Thread alive and Lock Obtained"), LogType.Info.ToString()); + Trace.WriteLine(new LogMessage("FileAgent - Run", "Thread alive and Lock Obtained"), LogType.Audit.ToString()); if (file.FileType == "resource") { @@ -187,7 +187,7 @@ public void Run() else { // Just error - we will pick it up again the next time we download - Trace.WriteLine(new LogMessage("FileAgent - Run", "Downloaded file failed MD5 check. Calculated [" + md5 + "] & XMDS [ " + file.Md5 + "] . " + file.SaveAs), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("FileAgent - Run", "Downloaded file failed MD5 check. Calculated [" + md5 + "] & XMDS [ " + file.Md5 + "] . " + file.SaveAs), LogType.Info.ToString()); } } else @@ -280,13 +280,21 @@ public void Run() else { // Just error - we will pick it up again the next time we download - Trace.WriteLine(new LogMessage("FileAgent - Run", "Downloaded file failed MD5 check. Calculated [" + md5 + "] & XMDS [ " + file.Md5 + "] . " + file.SaveAs), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("FileAgent - Run", "Downloaded file failed MD5 check. Calculated [" + md5 + "] & XMDS [ " + file.Md5 + "] . " + file.SaveAs), LogType.Info.ToString()); } } // Inform the Player thread that a file has been modified. OnComplete(file.Id, file.FileType); } + catch (WebException webEx) + { + // Log this message, but dont abort the thread + Trace.WriteLine(new LogMessage("FileAgent - Run", "Web Exception in Run: " + webEx.Message), LogType.Info.ToString()); + + // Mark as not downloading + file.Downloading = false; + } catch (Exception ex) { // Log this message, but dont abort the thread @@ -297,7 +305,7 @@ public void Run() } // Release the Semaphore - Trace.WriteLine(new LogMessage("FileAgent - Run", "Releasing Lock"), LogType.Info.ToString()); + Trace.WriteLine(new LogMessage("FileAgent - Run", "Releasing Lock"), LogType.Audit.ToString()); _fileDownloadLimit.Release(); } diff --git a/XmdsAgents/LibraryAgent.cs b/XmdsAgents/LibraryAgent.cs index b8fcf5c9..80ea75bd 100644 --- a/XmdsAgents/LibraryAgent.cs +++ b/XmdsAgents/LibraryAgent.cs @@ -92,7 +92,7 @@ public void Run() // Only do something if enabled if (!ApplicationSettings.Default.EnableExpiredFileDeletion) { - Trace.WriteLine(new LogMessage("LibraryAgent - Run", "Expired File Deletion Disabled"), LogType.Info.ToString()); + Trace.WriteLine(new LogMessage("LibraryAgent - Run", "Expired File Deletion Disabled"), LogType.Audit.ToString()); return; } diff --git a/XmdsAgents/LogAgent.cs b/XmdsAgents/LogAgent.cs index 46daf08f..9a3dc84a 100644 --- a/XmdsAgents/LogAgent.cs +++ b/XmdsAgents/LogAgent.cs @@ -63,7 +63,7 @@ public void Run() HardwareKey key = new HardwareKey(); - Trace.WriteLine(new LogMessage("RegisterAgent - Run", "Thread Woken and Lock Obtained"), LogType.Info.ToString()); + Trace.WriteLine(new LogMessage("RegisterAgent - Run", "Thread Woken and Lock Obtained"), LogType.Audit.ToString()); using (xmds.xmds xmds = new xmds.xmds()) { @@ -84,7 +84,7 @@ public void Run() ApplicationSettings.Default.IncrementXmdsErrorCount(); // Log this message, but dont abort the thread - Trace.WriteLine(new LogMessage("LogAgent - Run", "WebException in Run: " + webEx.Message), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("LogAgent - Run", "WebException in Run: " + webEx.Message), LogType.Info.ToString()); } catch (Exception ex) { diff --git a/XmdsAgents/RegisterAgent.cs b/XmdsAgents/RegisterAgent.cs index 622a0b21..7c14ce6c 100644 --- a/XmdsAgents/RegisterAgent.cs +++ b/XmdsAgents/RegisterAgent.cs @@ -91,12 +91,12 @@ public void Run() ApplicationSettings.Default.IncrementXmdsErrorCount(); // Log this message, but dont abort the thread - Trace.WriteLine(new LogMessage("RegisterAgent - Run", "WebException in Run: " + webEx.Message), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("RegisterAgent - Run", "WebException in Run: " + webEx.Message), LogType.Info.ToString()); } catch (Exception ex) { // Log this message, but dont abort the thread - Trace.WriteLine(new LogMessage("RegisterAgent - Run", "Exception in Run: " + ex.Message), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("RegisterAgent - Run", "Exception in Run: " + ex.Message), LogType.Info.ToString()); } } @@ -112,19 +112,12 @@ public static string ProcessRegisterXml(string xml) string message = ""; bool error = false; - // Work out if we need to do anything (have the settings changed since the last time) - string md5 = Hashes.MD5(xml); - try { // Load the result into an XML document XmlDocument result = new XmlDocument(); result.LoadXml(xml); - // If the XML we received has not changed, then go no further. - if (ApplicationSettings.Default.Hash == md5) - return result.DocumentElement.Attributes["message"].Value; - // Test the XML if (result.DocumentElement.Attributes["code"].Value == "READY") { @@ -143,6 +136,21 @@ public static string ProcessRegisterXml(string xml) if (result.DocumentElement.ChildNodes.Count <= 0) throw new Exception("Configuration not set for this display"); + // Hash after removing the date + try + { + result.DocumentElement.Attributes["date"].Value = ""; + } + catch + { + // No date, no need to remove + } + + string md5 = Hashes.MD5(result.OuterXml); + + if (md5 == ApplicationSettings.Default.Hash) + return result.DocumentElement.Attributes["message"].Value; + foreach (XmlNode node in result.DocumentElement.ChildNodes) { Object value = node.InnerText; diff --git a/XmdsAgents/RequiredFilesAgent.cs b/XmdsAgents/RequiredFilesAgent.cs index 63a8d9af..31715055 100644 --- a/XmdsAgents/RequiredFilesAgent.cs +++ b/XmdsAgents/RequiredFilesAgent.cs @@ -130,7 +130,7 @@ public void Run() { _clientInfoForm.RequiredFilesStatus = string.Format("Waiting: {0} Active Downloads", filesToDownload.ToString()); - Trace.WriteLine(new LogMessage("RequiredFilesAgent - Run", "Currently Downloading Files, skipping collect"), LogType.Info.ToString()); + Trace.WriteLine(new LogMessage("RequiredFilesAgent - Run", "Currently Downloading Files, skipping collect"), LogType.Audit.ToString()); } else { @@ -219,7 +219,7 @@ public void Run() ApplicationSettings.Default.IncrementXmdsErrorCount(); // Log this message, but dont abort the thread - Trace.WriteLine(new LogMessage("RequiredFilesAgent - Run", "WebException in Run: " + webEx.Message), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("RequiredFilesAgent - Run", "WebException in Run: " + webEx.Message), LogType.Info.ToString()); _clientInfoForm.RequiredFilesStatus = "Error: " + webEx.Message; } diff --git a/XmdsAgents/ScheduleAgent.cs b/XmdsAgents/ScheduleAgent.cs index 20998677..c825286c 100644 --- a/XmdsAgents/ScheduleAgent.cs +++ b/XmdsAgents/ScheduleAgent.cs @@ -112,7 +112,7 @@ public void Run() // If we are restarting, reset _manualReset.Reset(); - Trace.WriteLine(new LogMessage("ScheduleAgent - Run", "Thread Woken and Lock Obtained"), LogType.Info.ToString()); + Trace.WriteLine(new LogMessage("ScheduleAgent - Run", "Thread Woken and Lock Obtained"), LogType.Audit.ToString()); _clientInfoForm.ScheduleStatus = "Running: Get Data from Xibo Server"; @@ -156,7 +156,7 @@ public void Run() ApplicationSettings.Default.IncrementXmdsErrorCount(); // Log this message, but dont abort the thread - Trace.WriteLine(new LogMessage("ScheduleAgent - Run", "WebException in Run: " + webEx.Message), LogType.Error.ToString()); + Trace.WriteLine(new LogMessage("ScheduleAgent - Run", "WebException in Run: " + webEx.Message), LogType.Info.ToString()); _clientInfoForm.ScheduleStatus = "Error: " + webEx.Message; }