private void xmds1_BlackListCompleted(object sender, XiboClient.xmds.BlackListCompletedEventArgs e) { if (e.Error != null) { System.Diagnostics.Trace.WriteLine("Error sending blacklist", "BlackList - BlackListCompleted"); } else { System.Diagnostics.Trace.WriteLine("Blacklist sending complete", "BlackList - BlackListCompleted"); } return; }
/// <summary> /// Register display completed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void xmds1_RegisterDisplayCompleted(object sender, XiboClient.xmds.RegisterDisplayCompletedEventArgs e) { tbStatus.ResetText(); if (e.Error != null) { tbStatus.AppendText("Status" + Environment.NewLine); tbStatus.AppendText(e.Error.Message); Debug.WriteLine("Error returned from Call to XMDS Register Display.", "xmds1_RegisterDisplayCompleted"); Debug.WriteLine(e.Error.Message, "xmds1_RegisterDisplayCompleted"); Debug.WriteLine(e.Error.StackTrace, "xmds1_RegisterDisplayCompleted"); } else { tbStatus.AppendText(RegisterAgent.ProcessRegisterXml(e.Result)); } }
void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourceCompletedEventArgs e) { // Success / Failure if (e.Error != null) { Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Error.ToString()); } else { // Handle the background String bodyStyle; if (_backgroundImage == null || _backgroundImage == "") { bodyStyle = "background-color:" + _backgroundColor + " ;"; } else { bodyStyle = "background-image: url('" + _backgroundImage + "'); background-attachment:fixed; background-color:" + _backgroundColor + " background-repeat: no-repeat; background-position: " + _backgroundLeft + " " + _backgroundTop + ";"; } string html = e.Result.Replace("</head>", "<style type='text/css'>body {" + bodyStyle + " font-size:" + _scaleFactor.ToString() + "em; }</style></head>"); string fullPath = Settings.Default.LibraryPath + @"\" + _mediaId + ".htm"; using (StreamWriter sw = new StreamWriter(File.Open(fullPath, FileMode.Create, FileAccess.Write, FileShare.Read))) { sw.Write(html); sw.Close(); } _webBrowser.Navigate(fullPath); } }
/// <summary> /// Refresh Complete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourceCompletedEventArgs e) { try { // Success / Failure if (e.Error != null) { Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Error.ToString()); // We have failed to update from XMDS, do we have a cached file we can revert to if (File.Exists(_filePath)) { // Cached file to revert to UpdateCacheIfNecessary(); _webView.Browser.GetMainFrame().LoadUrl(_filePath); } else { // No cache to revert to // Start the timer so that we expire base.RenderMedia(); } } else { // Ammend the resource file so that we can open it directly from the library (this is better than using a tempoary file) string cachedFile = e.Result; // Handle the background String bodyStyle; if (_options.backgroundImage == null || _options.backgroundImage == "") { bodyStyle = "background-color:" + _options.backgroundColor + " ;"; } else { bodyStyle = "background-image: url('" + _options.backgroundImage.Replace('\\', '/') + "'); background-attachment:fixed; background-color:" + _options.backgroundColor + "; background-repeat: no-repeat; background-position: " + _options.backgroundLeft + "px " + _options.backgroundTop + "px;"; } string html = cachedFile.Replace("</head>", "<style type='text/css'>body {" + bodyStyle + " }</style></head>"); html = html.Replace("[[ViewPortWidth]]", _width.ToString()); // Write to the library using (StreamWriter sw = new StreamWriter(File.Open(_filePath, FileMode.Create, FileAccess.Write, FileShare.Read))) { sw.Write(html); sw.Close(); } // Read the control meta back out ReadControlMeta(); // Handle Navigate in here because we will not have done it during first load _webView.Browser.GetMainFrame().LoadUrl(_filePath); } } catch (ObjectDisposedException) { Trace.WriteLine(new LogMessage("WebMedia", "Retrived the data set, stored the document but the media has already expired."), LogType.Error.ToString()); } catch (Exception ex) { Trace.WriteLine(new LogMessage("WebMedia", "Unknown exception " + ex.Message), LogType.Error.ToString()); // This should exipre the media Duration = 5; base.RenderMedia(); } }
/// <summary> /// Register display completed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void xmds1_RegisterDisplayCompleted(object sender, XiboClient.xmds.RegisterDisplayCompletedEventArgs e) { if (e.Error != null) { textBoxResults.Text = e.Error.Message; System.Diagnostics.Debug.WriteLine("Error returned from Call to XMDS Register Display.", "xmds1_RegisterDisplayCompleted"); System.Diagnostics.Debug.WriteLine(e.Error.Message, "xmds1_RegisterDisplayCompleted"); System.Diagnostics.Debug.WriteLine(e.Error.StackTrace, "xmds1_RegisterDisplayCompleted"); } else { textBoxResults.Text = e.Result; } }
/// <summary> /// Schedule XMDS call completed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void xmds2_ScheduleCompleted(object sender, XiboClient.xmds.ScheduleCompletedEventArgs e) { System.Diagnostics.Debug.WriteLine("Schedule Retrival Complete."); // Set XMDS to no longer be processing _xmdsProcessing = false; // Expect new schedule XML if (e.Error != null) { // There was an error - what do we do? System.Diagnostics.Trace.WriteLine(e.Error.Message); } else { // Only update the schedule if its changed. String md5CurrentSchedule = ""; // Set the flag to indicate we have a connection to XMDS Properties.Settings.Default.XmdsLastConnection = DateTime.Now; // Hash of the result String md5NewSchedule = Hashes.MD5(e.Result); try { StreamReader sr = new StreamReader(File.Open(_scheduleLocation, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)); // Yes - get the MD5 of it, and compare to the MD5 of the file in the XML md5CurrentSchedule = Hashes.MD5(sr.ReadToEnd()); sr.Close(); // Compare the existing to the new if (md5CurrentSchedule == md5NewSchedule) return; } catch (Exception ex) { // Failed to get the MD5 of the existing schedule - just continue and overwrite it Debug.WriteLine(ex.Message); } System.Diagnostics.Debug.WriteLine("Different Schedules Detected, writing new schedule.", "Schedule - ScheduleCompleted"); // Write the result to the schedule xml location StreamWriter sw = new StreamWriter(_scheduleLocation, false, Encoding.UTF8); sw.Write(e.Result); sw.Close(); Debug.WriteLine("New Schedule Recieved", "xmds_ScheduleCompleted"); // Indicate to the schedule manager that it should read the XML file _scheduleManager.RefreshSchedule = true; } }
/// <summary> /// Event Handler for required files being complete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void xmds2_RequiredFilesCompleted(object sender, XiboClient.xmds.RequiredFilesCompletedEventArgs e) { System.Diagnostics.Debug.WriteLine("RequiredFilesAsync complete.", "Schedule - RequiredFilesCompleted"); //Dont let this effect the rendering //Application.DoEvents(); if (e.Error != null) { // There was an error - what do we do? System.Diagnostics.Trace.WriteLine(new LogMessage("Schedule - RequiredFilesCompleted", e.Error.Message), LogType.Error.ToString()); // Is it a "not licensed" error if (e.Error.Message == "This display client is not licensed") { Properties.Settings.Default.licensed = 0; } _xmdsProcessing = false; } else { // Set the flag to indicate we have a connection to XMDS Properties.Settings.Default.XmdsLastConnection = DateTime.Now; // Firstly we know we are licensed if we get this far if (Properties.Settings.Default.licensed == 0) { Properties.Settings.Default.licensed = 1; } try { // Load the result into XML FileCollector fileCollector = new FileCollector(_cacheManager, e.Result); // Bind some events that the fileCollector will raise fileCollector.LayoutFileChanged += new FileCollector.LayoutFileChangedDelegate(fileCollector_LayoutFileChanged); fileCollector.CollectionComplete += new FileCollector.CollectionCompleteDelegate(fileCollector_CollectionComplete); fileCollector.MediaFileChanged += new FileCollector.MediaFileChangedDelegate(fileCollector_MediaFileChanged); fileCollector.CompareAndCollect(); } catch (Exception ex) { _xmdsProcessing = false; // Log and move on System.Diagnostics.Trace.WriteLine(new LogMessage("Schedule - RequiredFilesCompleted", "Error Comparing and Collecting: " + ex.Message), LogType.Error.ToString()); } _cacheManager.WriteCacheManager(); } }
/// <summary> /// Capture the XMDS call and see if it went well /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _xmds_SubmitLogCompleted(object sender, XiboClient.xmds.SubmitLogCompletedEventArgs e) { _xmdsProcessing = false; // Test if we succeeded or not if (e.Error != null) { // We had an error, log it. System.Diagnostics.Trace.WriteLine(new LogMessage("_xmds_SubmitLogCompleted", String.Format("Error during Submit to XMDS {0}", e.Error.Message)), LogType.Error.ToString()); // Dump the stats to a file instead if (_lastSubmit != "") { try { // Open the Text Writer StreamWriter tw = new StreamWriter(File.Open(_logPath, FileMode.Append, FileAccess.Write, FileShare.Read), Encoding.UTF8); try { tw.Write(_lastSubmit); } catch {} finally { tw.Close(); tw.Dispose(); } } catch {} } } // Clear the last sumbit _lastSubmit = ""; }
/// <summary> /// Refresh Complete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void xmds_GetResourceCompleted(object sender, XiboClient.xmds.GetResourceCompletedEventArgs e) { try { // Success / Failure if (e.Error != null) { Trace.WriteLine(new LogMessage("xmds_GetResource", "Unable to get Resource: " + e.Error.Message), LogType.Error.ToString()); // Start the timer so that we expire base.RenderMedia(); } else { // Write to the library using (StreamWriter sw = new StreamWriter(File.Open(_filePath, FileMode.Create, FileAccess.Write, FileShare.Read))) { sw.Write(e.Result); sw.Close(); } // Write to temporary file SaveToTemporaryFile(); // Handle Navigate in here because we will not have done it during first load _webBrowser.Navigate(_temporaryFile.Path); } } catch (ObjectDisposedException) { Trace.WriteLine(new LogMessage("Rss", "Retrived the data set, stored the document but the media has already expired."), LogType.Error.ToString()); } catch (Exception ex) { Trace.WriteLine(new LogMessage("Rss", "Unknown exception " + ex.Message), LogType.Error.ToString()); } }
void xmdsFile_GetFileCompleted(object sender, XiboClient.xmds.GetFileCompletedEventArgs e) { Debug.WriteLine("Get File Completed"); try { // Success / Failure if (e.Error != null) { // There was an error - what do we do? if (e.Cancelled) { Debug.WriteLine("The GetFile Request has been cancelled."); } else { Debug.WriteLine("The GetFile Request is still active, cancelling."); // Make sure we cancel the request xmdsFile.CancelAsync(e.UserState); } // Log it Trace.WriteLine(String.Format("Error From WebService Get File. File=[{1}], Error=[{0}], Try No [{2}]", e.Error.Message, _currentFileList.path, _currentFileList.retrys)); // Retry? //TODO: What if we are disconnected from XMDS? if (_currentFileList.retrys < 5) { // Increment the Retrys _currentFileList.retrys++; // Try again GetFile(); } else { // Delete the file try { if (_currentFileList.type == "layout") File.Delete(Properties.Settings.Default.LibraryPath + @"\" + _currentFileList.path + ".xlf"); else File.Delete(Properties.Settings.Default.LibraryPath + @"\" + _currentFileList.path); } catch (Exception ex) { Trace.WriteLine(new LogMessage("xmdsFile_GetFileCompleted", "Unable to delete the failed file: " + _currentFileList.path + " Message: " + ex.Message)); } // Removed this blacklist code. Files that are not in the cachemanager will not be played on the client (and therefore // we wont try to play a corrupt / partial file). // If we blacklist here we will never try to get this file again, until the blacklist is cleared in XMDS // Better to just skip it for now, and retry it once we have the required files list again /*// Blacklist this file? string[] mediaPath = _currentFileList.path.Split('.'); string mediaId = mediaPath[0]; BlackList blackList = new BlackList(); blackList.Add(mediaId, BlackListType.Single, String.Format("Max number of retrys failed. BlackListing for this display. Error: {0}", e.Error.Message)); */ // Move on _currentFileList.complete = true; _currentFile++; } } else { // Set the flag to indicate we have a connection to XMDS Properties.Settings.Default.XmdsLastConnection = DateTime.Now; // What file type were we getting if (_currentFileList.type == "layout") { // Decode this byte[] into a string and stick it in the file. string layoutXml = Encoding.UTF8.GetString(e.Result); // We know it is finished and that we need to write to a file try { string fullPath = Properties.Settings.Default.LibraryPath + @"\" + _currentFileList.path + ".xlf"; StreamWriter sw = new StreamWriter(File.Open(fullPath, FileMode.Create, FileAccess.Write, FileShare.Read)); sw.Write(layoutXml); sw.Close(); // This file is complete _currentFileList.complete = true; } catch (IOException ex) { //What do we do if we cant open the file stream? System.Diagnostics.Debug.WriteLine(ex.Message, "FileCollector - GetFileCompleted"); } // Check it String md5sum = _cacheManager.GetMD5(_currentFileList.path + ".xlf"); System.Diagnostics.Debug.WriteLine(String.Format("Comparing MD5 of completed download [{0}] with given MD5 [{1}]", md5sum, _currentFileList.md5)); // TODO: What if the MD5 is different? if (md5sum != _currentFileList.md5) { // Error System.Diagnostics.Trace.WriteLine(new LogMessage("xmdsFile_GetFileCompleted", String.Format("Incorrect MD5 for file: {0}", _currentFileList.path))); } else { // Add to the CacheManager _cacheManager.Add(_currentFileList.path + ".xlf", md5sum); // Report this completion back to XMDS _requiredFiles.MarkComplete(int.Parse(_currentFileList.path), md5sum); _requiredFiles.ReportInventory(); } // Fire a layout complete event LayoutFileChanged(_currentFileList.path + ".xlf"); System.Diagnostics.Trace.WriteLine(String.Format("File downloaded: {0}", _currentFileList.path), "xmdsFile_GetFileCompleted"); _currentFile++; } else { // Need to write to the file - in append mode FileStream fs = new FileStream(Properties.Settings.Default.LibraryPath + @"\" + _currentFileList.path, FileMode.Append, FileAccess.Write); fs.Write(e.Result, 0, e.Result.Length); fs.Close(); fs.Dispose(); // Increment the chunkOffset by the amount we just asked for _currentFileList.chunkOffset = _currentFileList.chunkOffset + _currentFileList.chunkSize; // Has the offset reached the total size? if (_currentFileList.size > _currentFileList.chunkOffset) { int remaining = _currentFileList.size - _currentFileList.chunkOffset; // There is still more to come if (remaining < _currentFileList.chunkSize) { // Get the remaining _currentFileList.chunkSize = remaining; } } else { String md5sum = _cacheManager.GetMD5(_currentFileList.path); System.Diagnostics.Debug.WriteLine(String.Format("Comparing MD5 of completed download [{0}] with given MD5 [{1}]", md5sum, _currentFileList.md5)); if (md5sum != _currentFileList.md5) { // We need to get this file again try { File.Delete(Properties.Settings.Default.LibraryPath + @"\" + _currentFileList.path); } catch (Exception ex) { // Unable to delete incorrect file //TODO: Should we black list this file? System.Diagnostics.Debug.WriteLine(ex.Message); } // Reset the chunk offset (otherwise we will try to get this file again - but from the beginning (no so good) _currentFileList.chunkOffset = 0; System.Diagnostics.Trace.WriteLine(String.Format("Error getting file {0}, HASH failed. Starting again", _currentFileList.path)); } else { // Add the MD5 to the CacheManager _cacheManager.Add(_currentFileList.path, md5sum); // This file is complete _currentFileList.complete = true; // Fire the File Complete event MediaFileChanged(_currentFileList.path); System.Diagnostics.Debug.WriteLine(string.Format("File downloaded: {0}", _currentFileList.path)); // Report this completion back to XMDS string[] filePart = _currentFileList.path.Split('.'); _requiredFiles.MarkComplete(int.Parse(filePart[0]), md5sum); _requiredFiles.ReportInventory(); // All the file has been recieved. Move on to the next file. _currentFile++; } } } // Before we get the next file render any waiting events System.Windows.Forms.Application.DoEvents(); } } catch (Exception ex) { Trace.WriteLine(new LogMessage("xmdsFile_GetFileCompleted", "Unhanded Exception when processing getFile response: " + ex.Message)); // TODO: Blacklist the file? // Consider this file complete because we couldn't write it.... _currentFileList.complete = true; _currentFile++; } // Get the next file GetFile(); }
/// <summary> /// Capture the XMDS call and see if it went well /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _xmds_SubmitStatsCompleted(object sender, XiboClient.xmds.SubmitStatsCompletedEventArgs e) { System.Diagnostics.Debug.WriteLine(new LogMessage("_xmds_SubmitStatsCompleted", String.Format("IN")), LogType.Audit.ToString()); _xmdsProcessing = false; // Test if we succeeded or not if (e.Error != null) { // We had an error, log it. System.Diagnostics.Trace.WriteLine(new LogMessage("_xmds_SubmitStatsCompleted", String.Format("Error during Submit to XMDS {0}", e.Error.Message)), LogType.Error.ToString()); // Dump the stats to a file instead if (_lastSubmit != "") { try { // Open the Text Writer StreamWriter tw = new StreamWriter(File.Open(Application.UserAppDataPath + "//" + Properties.Settings.Default.StatsLogFile, FileMode.Append, FileAccess.Write, FileShare.Read), Encoding.UTF8); try { tw.Write(_lastSubmit); } catch (Exception ex) { // Log this exception System.Diagnostics.Trace.WriteLine(new LogMessage("_xmds_SubmitStatsCompleted", String.Format("Error writing stats to file with exception {0}", ex.Message)), LogType.Error.ToString()); } finally { tw.Close(); tw.Dispose(); } } catch (Exception ex) { // Log this exception System.Diagnostics.Trace.WriteLine(new LogMessage("_xmds_SubmitStatsCompleted", String.Format("Could not open the file with exception {0}", ex.Message)), LogType.Error.ToString()); } } } // Clear the last sumbit _lastSubmit = ""; System.Diagnostics.Debug.WriteLine(new LogMessage("_xmds_SubmitStatsCompleted", String.Format("OUT")), LogType.Audit.ToString()); }