public void loadReport(string xml) { try { if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } progressBar1.Value = 0; progressBar1.Style = ProgressBarStyle.Continuous; images.Clear(); // Check the file exists if (!File.Exists(xml)) { throw new Exception("The file does not exist."); } try { XmlReaderSettings settings = new XmlReaderSettings(); settings.CheckCharacters = false; // Load the file contents into the XML document using (var reader = XmlReader.Create(File.OpenRead(xml), settings)) { _reoprtXml.Load(reader); } } catch (XmlException ex) { MessageBox.Show("The XML report " + xml + " is corrupted."); pictureBox1.Image = null; return; } // Populate the UI var experiment = _reoprtXml.DocumentElement.SelectSingleNode("Experiment"); var result = _reoprtXml.DocumentElement.SelectSingleNode("Result"); var appLog = _reoprtXml.DocumentElement.SelectSingleNode("AppLog"); var screens = _reoprtXml.DocumentElement.SelectSingleNode("InteractionScreenshots"); var fileAccess = _reoprtXml.SelectNodes("InstallerAnalyzerReport/Result/FileAccess")[0]; var newFilesLeftOver = fileAccess.SelectNodes("NewFiles/File[@LeftOver='True']"); fileBtn.Text = ("Files (" + newFilesLeftOver.Count + ")"); fileBtn.Tag = fileAccess; fileName.Text = Path.GetFileName(experiment.SelectSingleNode("InstallerName").InnerText); //jobId.Text = experiment.SelectSingleNode("JobId").InnerText; duration.Text = experiment.SelectSingleNode("Duration").InnerText; vmResult.Text = "TODO"; injectorResult.Text = result.SelectSingleNode("Injector/RetCode").InnerText; injectorResult.ForeColor = injectorResult.Text == "0" ? Color.DarkGreen : Color.Red; Out.Tag = result.SelectSingleNode("Injector/StdOut").InnerText; err.Tag = result.SelectSingleNode("Injector/StdErr").InnerText; uibotLog.Tag = _reoprtXml.DocumentElement.SelectSingleNode("AppLog").InnerText; uiBot.Text = result.SelectSingleNode("UiBot/Description").InnerText; Color c = Color.DarkRed; switch (uiBot.Text) { case "Finished": case "PartiallyFinished": c = Color.Green; break; case "UIStuck": c = Color.Blue; break; case "TimeOut": c = Color.Blue; break; } uiBot.BackColor = c; uiBot.ForeColor = Color.White; // New Apps var newAppsNode = result.SelectSingleNode("NewApplications"); newApps.Text = newAppsNode.Attributes["count"].InnerText; List <String> apps = new List <string>(); applist.Clear(); foreach (XmlNode node in newAppsNode.SelectNodes("Application")) { apps.Add(node.InnerText); var lvi = new ListViewItem(); lvi.Text = node.InnerText; lvi.ImageIndex = 0; applist.Items.Add(lvi); } newApps.Tag = apps; // Extract the zip file into a temporary directory File.WriteAllBytes(ZIP_FILE, Convert.FromBase64String(screens.InnerText)); // Empty the previous screen dir if (Directory.Exists(SCREEN_DIR)) { Directory.Delete(SCREEN_DIR, true); } Directory.CreateDirectory(SCREEN_DIR); // Extract the images using (var zipfile = ZipFile.Read(ZIP_FILE)) { zipfile.ExtractAll(SCREEN_DIR); // Load the images info var sp = new Regex(@"^\d+\.bmp$", RegexOptions.IgnoreCase); var files = Directory.GetFiles(SCREEN_DIR).Where(f => sp.IsMatch(Path.GetFileName(f))).OrderBy(x => int.Parse(Path.GetFileNameWithoutExtension(x))); foreach (var f in files) { ScreenInfo si = new ScreenInfo(); si.rendered_image = f; int seq = int.Parse(Path.GetFileNameWithoutExtension(f)); // Check we have the clean image as well string clean = Path.Combine(SCREEN_DIR, "clean_" + seq + ".bmp"); if (File.Exists(clean)) { si.clean_image = clean; } // Check we have xml data about that string xmldata = Path.Combine(SCREEN_DIR, "" + seq + ".xml"); if (File.Exists(xmldata)) { XmlSerializer s = new XmlSerializer(typeof(CandidateSet)); using (var fr = File.OpenRead(xmldata)) using (XmlReader r = XmlReader.Create(fr)) { si.cs = s.Deserialize(r) as CandidateSet; } } images.AddLast(si); } } File.Delete(ZIP_FILE); totScreens.Text = "" + images.Count; node = images.Last; UpdateScreenshot(); } catch (Exception e) { MessageBox.Show("Error occurred: " + e.Message); pictureBox1.Image = null; } }
public void SetScreenData(ScreenInfo item) { this.screenData = item; this.Image = Image.FromFile(item.clean_image); _best = findBestItem(item.cs); }