public static FileErrorMessage ( |
||
ex | ||
title | string | |
fileName | string | |
return | bool |
// Adding attached screenshot have dedicated functions that deal with the visual // clues as well private void AddScreenshot2Note(Bitmap bitmap) { Logger.record("[AddScreenshot2Note]: Saving screen to file", "SMWidget", "info"); bool exDrRetry = false; // Name the screenshot, save to disk screenshotName = currentScreenshot++.ToString() + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".jpg"; do { exDrRetry = false; try { bitmap.Save(currentSession.workingDir + screenshotName, ImageFormat.Jpeg); AutoSaveScrenshot(screenshotName); } catch (Exception ex) { Logger.record("[AddScreenshot2Note]: EXCEPTION reached - Session Note file could not be saved (" + screenshotName + ")", "SMWidget", "error"); exDrRetry = Logger.FileErrorMessage(ex, "SaveToSessionNotes", screenshotName); } } while (exDrRetry); // Put a visual effect to remember the tester there's an image on the attachment barrel BevelBitmapEffect effect = new BevelBitmapEffect(); effect.BevelWidth = 2; effect.EdgeProfile = EdgeProfile.BulgedUp; ScreenShot.BitmapEffect = effect; }
private void LoadCsvIntoSession(string csvFile) { Logger.Record("[LoadCsvIntoSession]: Grabbing CSV file variables", "Session", "info"); bool exDrRetry; do { exDrRetry = false; try { foreach (var line in File.ReadAllLines(csvFile, Encoding.UTF8)) { if ("" == line) { continue; } var thisLine = line.Split(','); if (thisLine.Length <= 2) { continue; } var note = thisLine[2].Replace("\"", ""); switch (thisLine[1]) { case @"Session Reporter": Tester = note; StartingTime = DateTime.Parse(thisLine[0]); break; case @"Scenario ID": ScenarioId = note; break; case @"Session Charter": Charter = note; break; case @"Environment": Environment = note; break; case @"Versions": Versions = note; break; } } } catch (Exception ex) { Logger.Record("[LoadCsvIntoSession]: EXCEPTION reached - Session Report file could not be read (" + csvFile + ")", "Session", "error"); exDrRetry = Logger.FileErrorMessage(ex, "LoadCsvIntoSession", csvFile); } } while (exDrRetry); Logger.Record("[LoadCsvIntoSession]: Grabbing CSV file variables done.", "Session", "info"); }
/** Reporting **/ /***************/ // General note on writign the reports to disk: // Some bug reports seem to indicate that we are holding the file while trying to write to it. // This is the reason of adding 150 milliseconds of delay between writes. // I'll only know how dumb an idea is it after continuing (or not) to receive exception reports from users. // When a report collection is requested: public void CollectReport() { Logger.record("[CollectReport]: Report building", "Session", "info"); bool exDrRetry = false; string report_prefix = "report_"; string reportFile = report_prefix + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv"; string reportFileFull = workingDir + reportFile; String[] files = Directory.GetFiles(workingDir, "*.csv"); Array.Sort(files); do { exDrRetry = false; try { File.AppendAllText(reportFileFull, columnHeaders + "\n"); Thread.Sleep(150); foreach (string file in files) { // Skip over other report files if (file.Contains(report_prefix)) { continue; } // Skip over files that don't end like ########_######.csv. if (!(System.Text.RegularExpressions.Regex.IsMatch(file, ".*\\d{8}_\\d{6}.csv$", System.Text.RegularExpressions.RegexOptions.IgnoreCase))) { continue; } StreamReader sr = new StreamReader(file); sr.ReadLine(); // We skip the first line (with the headers); string oneFile = sr.ReadToEnd(); File.AppendAllText(reportFileFull, oneFile); Thread.Sleep(150); Logger.record("\t[CollectReport]: Another file concatenated into a report: " + file, "Session", "info"); // TODO: Remove the Thread.Sleep(150) parts? } } catch (Exception ex) { Logger.record("[CollectReport]: EXCEPTION reached - Session Report file could not be saved (" + reportFile + ")", "Session", "error"); exDrRetry = Logger.FileErrorMessage(ex, "CollectReport", reportFile); } } while (exDrRetry); Logger.record("[CollectReport]: Report built, done.", "Session", "info"); MessageBox.Show("Rapid Reporter has finished the report consolidation process.\nFile generated: " + reportFile, "Rapid Reporter -report consolidation", MessageBoxButton.OK, MessageBoxImage.Information); }
// When the note is 'saved', it get's saved into an RTF file, and marked for being attached to a session note. private void save_Click(object sender, RoutedEventArgs e) { Logger.record("[save_Click]: RTF Note to be saved", "RTFNote", "info"); bool exDrRetry = false; TextRange tr = new TextRange(richTextNote.Document.ContentStart, richTextNote.Document.ContentEnd); // How do we kow the '3' minimum? By trial and error. Any character entered in the area makes it go 3+. Empty area is 0<=x<=2 if (3 <= tr.Text.Length) { Logger.record("\t[save_Click]: RTF Note not empty, will save", "RTFNote", "info"); // Name the note, save to file sm.rtfNoteName = currentRTFNote++.ToString() + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".rtf"; do { exDrRetry = false; try { // Process is: // 1. Save the file // 2. Change the visual cue // 3. Add an autogenerated line to the session CSV // Saves the file FileStream fs = new FileStream(workingDir + sm.rtfNoteName, FileMode.OpenOrCreate, FileAccess.Write); TextRange RTF = new TextRange(richTextNote.Document.ContentStart, richTextNote.Document.ContentEnd); RTF.Save(fs, System.Windows.DataFormats.Rtf); // Set the visual effect to clue the tester there's a note attached BevelBitmapEffect effect = new BevelBitmapEffect(); effect.BevelWidth = 2; effect.EdgeProfile = EdgeProfile.BulgedUp; sm.RTFNoteBtn.BitmapEffect = effect; // Adds an 'autogenerated' line to the session CSV sm.AutoSaveNote(sm.rtfNoteName); Logger.record("\t\t[save_Click]: RTF Note saved: " + sm.rtfNoteName, "RTFNote", "info"); } catch (Exception ex) { Logger.record("\t\t[save_Click]: EXCEPTION reached - RTF Note file could not be saved (" + sm.rtfNoteName + ")", "RTFNote", "error"); exDrRetry = Logger.FileErrorMessage(ex, "save_Click", sm.rtfNoteName); } } while (exDrRetry); } Logger.record("[save_Click]: RTF Note saving mechanism done. Will close (hide).", "RTFNote", "info"); // We not really 'close' the window. Close function deals with whether hiding or closing it. this.Close(); Logger.record("[save_Click]: RTF Note saving mechanism done. Closed (hidden).", "RTFNote", "info"); }
// Save all notes on file, after every single note private void SaveToSessionNotes(string note) { Logger.record("[SaveToSessionNotes]: File will be updated and saved to " + sessionFile, "Session", "info"); bool exDrRetry = false; do { exDrRetry = false; try { File.AppendAllText(sessionFileFull, note); } catch (Exception ex) { Logger.record("\t[SaveToSessionNotes]: EXCEPTION reached - Session Note file could not be saved (" + sessionFile + ")", "Session", "error"); exDrRetry = Logger.FileErrorMessage(ex, "SaveToSessionNotes", sessionFile); } } while (exDrRetry); }
// Transforming a CSV into a .HTML public void CSV2HTML(string CSVFile) { Logger.record("[CSV2HTML]: HTML Report building", "Session", "info"); bool exDrRetry = false; string htmlFile = CSVFile; htmlFile = htmlFile.Replace(".csv", ".htm"); string htmlFileFull = workingDir + htmlFile; string[] thisLine = new string[columnHeaders.Split(',').Length]; do { exDrRetry = false; try { string t = "th"; string tableLine = ""; string noteImage = ""; string noteRtf = ""; longstrings.htmlstrings.html_title = sessionFile; File.Delete(htmlFileFull); File.WriteAllText(htmlFileFull, longstrings.htmlstrings.a_html_header); Thread.Sleep(150); File.AppendAllText(htmlFileFull, longstrings.htmlstrings.c_javascript); Thread.Sleep(150); File.AppendAllText(htmlFileFull, longstrings.htmlstrings.d_style); Thread.Sleep(150); File.AppendAllText(htmlFileFull, longstrings.htmlstrings.g_html_body1); Thread.Sleep(150); File.AppendAllText(htmlFileFull, "<h1>Session Report | Powered by <a href=\"http://testing.gershon.info/reporter/\">Rapid Reporter</a></h1><br />"); Thread.Sleep(150); File.AppendAllText(htmlFileFull, longstrings.htmlstrings.i_toggle_auto); Thread.Sleep(150); File.AppendAllText(htmlFileFull, longstrings.htmlstrings.j_html_bodytable1); Thread.Sleep(150); foreach (string line in File.ReadAllLines(workingDir + CSVFile)) { if ("" == line) { continue; // Some files have empty lines in it, we don't want to process these lines. } noteImage = ""; noteRtf = ""; // We clean this variables in order not to carry the last ones from the last iteration thisLine = line.Split(','); // Dealing with screenshot attachments (if they exist). if (thisLine.Length > 4) { if (File.Exists(workingDir + thisLine[4])) { noteImage = "<a href=\"" + thisLine[4] + "\" target=\"_blank\"><img src=\"" + thisLine[4] + "\"></a>"; } else { noteImage = thisLine[4]; } } noteImage += " "; // Dealing with the RTF note attachments (if they exist). if (thisLine.Length > 5) { if (File.Exists(workingDir + thisLine[5])) { noteRtf = "<a href=\"" + thisLine[5] + "\" target=\"_blank\">" + thisLine[5] + "</a>"; } else { noteRtf = thisLine[5]; } } noteRtf += " "; tableLine = "<tr class=\"" + thisLine[2] + "\"> <" + t + ">" + thisLine[0] + "</" + t + "><" + t + ">" + thisLine[1] + "</" + t + "><" + t + " class=\"notetype\">" + thisLine[2] + "</" + t + "><" + t + ">" + thisLine[3].Replace("\"", "") + "</" + t + "><" + t + ">" + noteImage + "</" + t + "><" + t + ">" + noteRtf + "</" + t + "></tr>\n"; File.AppendAllText(htmlFileFull, tableLine); Thread.Sleep(150); t = "td"; } File.AppendAllText(htmlFileFull, longstrings.htmlstrings.m_html_bodytable2); Thread.Sleep(150); File.AppendAllText(htmlFileFull, longstrings.htmlstrings.p_html_footer); Thread.Sleep(150); } catch (Exception ex) { Logger.record("[CSV2HTML]: EXCEPTION reached - Session Report file could not be saved (" + htmlFile + ")", "Session", "error"); exDrRetry = Logger.FileErrorMessage(ex, "CSV to HTML", htmlFile); } } while (exDrRetry); Logger.record("[CSV2HTML]: HTML Report built, done.", "Session", "info"); MessageBox.Show("Rapid Reporter has finished the process of transformation to HTML.\nFile created: " + htmlFile, "Rapid Reporter -tohtml transformation", MessageBoxButton.OK, MessageBoxImage.Information); }
// Adding attached screenshot have dedicated functions that deal with the visual // clues as well private void AddScreenshot2Note(Bitmap bitmap) { Logger.record("[AddScreenshot2Note]: Saving screen to file", "SMWidget", "info"); bool exDrRetry = false; // Name the screenshot, save to disk screenshotName = currentScreenshot++.ToString() + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + "_" + FlickrAddon.hashcode + ".jpg"; // HASCODE ADDED!!!___<-----######### do { exDrRetry = false; try { string strReportFileName = currentSession.GetCurrentSessionFile(); Graphics graphicImage = Graphics.FromImage(bitmap); graphicImage.SmoothingMode = SmoothingMode.AntiAlias; StringFormat format = new System.Drawing.StringFormat(StringFormatFlags.DirectionRightToLeft); graphicImage.DrawString(strReportFileName, new Font("Arial", 14, System.Drawing.FontStyle.Bold), System.Drawing.Brushes.Red, new System.Drawing.Point(50, 50)); bitmap.Save(currentSession.workingDir + screenshotName, ImageFormat.Jpeg); AutoSaveScrenshot(screenshotName); string strFileTag = "#Session File: " + strReportFileName; string URL = ""; if (ToggleUpload2) { if (m_flickrLoggedIn) { URL = m_flickr.GetUrl(m_flickr.Upload(screenshotName, "", "", currentSession.GetTags() + strFileTag)); currentSession.UpdateNotes("WebUrl: ", URL); FlickrInlogg.Text = "Account: " + m_flickr.GetCurrentUser(); //currentSession.noteTypes[ReporterNoteName] } else { m_flickr.Login(); FlickrInlogg.Text = "Account: " + m_flickr.GetCurrentUser(); URL = m_flickr.GetUrl(m_flickr.Upload(screenshotName, "", "", currentSession.GetTags() + strFileTag)); currentSession.UpdateNotes("WebUrl: ", URL); m_flickrLoggedIn = true; } } } catch (Exception ex) { Logger.record("[AddScreenshot2Note]: EXCEPTION reached - Session Note file could not be saved (" + screenshotName + ")", "SMWidget", "error"); exDrRetry = Logger.FileErrorMessage(ex, "SaveToSessionNotes", screenshotName); } } while (exDrRetry); // Put a visual effect to remember the tester there's an image on the attachment barrel BevelBitmapEffect effect = new BevelBitmapEffect(); effect.BevelWidth = 2; effect.EdgeProfile = EdgeProfile.BulgedUp; ScreenShot.BitmapEffect = effect; }
public void Csv2Html(string csvFile, bool relativePath) { Logger.Record("[CSV2HTML]: HTML Report building", "Session", "info"); var csvFileFull = relativePath ? WorkingDir + csvFile : csvFile; var htmlFileFull = DiscoverSavePath(csvFile); bool exDrRetry; do { exDrRetry = false; var htmlFileBufferPopups = ""; try { var imgCount = 0; var ptnCount = 0; var t = "th"; var title = string.Format("{0}{1}", ScenarioId, Htmlstrings.HtmlTitle); File.Delete(htmlFileFull); var htmlTop = string.Format("{0}{1}{2}{3}{4}{5}{1}{6}", (object)Htmlstrings.AHtmlHead, (object)title, (object)Htmlstrings.BTitleOut, (object)Htmlstrings.CStyle, (object)Htmlstrings.DJavascript, (object)Htmlstrings.EBody, (object)Htmlstrings.GTable); var topNotes = ""; var bottomNotes = ""; foreach (var line in File.ReadAllLines(csvFileFull, Encoding.UTF8)) { if ("" == line) { continue; } var note = ""; var thisLine = line.Split(','); if (thisLine.Length > 2) { note = thisLine[2].Replace("\"", ""); switch (thisLine[1]) { case @"Screenshot": if (!File.Exists(WorkingDir + note)) { note += " not found."; break; } note = HtmlEmbedder.BuildSessionRow_Img(imgCount, WorkingDir + note); htmlFileBufferPopups += HtmlEmbedder.BuildPopUp_Img(imgCount); imgCount++; break; case @"PlainText Note": if (!File.Exists(WorkingDir + note)) { note += " not found."; break; } htmlFileBufferPopups += HtmlEmbedder.BuildPopUp_PTNote(ptnCount, WorkingDir + note); note = HtmlEmbedder.BuildSessionRow_PTNote(ptnCount); ptnCount++; break; } } if (thisLine[1] == "Type" || thisLine[1] == "Session Reporter" || (thisLine[1] == "Scenario ID" || thisLine[1] == "Session Charter") || (thisLine[1] == "Environment" || thisLine[1] == "Versions" || thisLine[1] == "Summary")) { topNotes += BuildTableRow(t, thisLine[1], thisLine[0], note); } else { bottomNotes += BuildTableRow(t, thisLine[1], thisLine[0], note); } t = "td"; } topNotes = topNotes + BuildTableRow("td", "", "", ""); var output = htmlTop + string.Format("{0}{1}{2}{3}{4}", topNotes, bottomNotes, Htmlstrings.JTableEnd, htmlFileBufferPopups, Htmlstrings.MHtmlEnd); File.WriteAllText(htmlFileFull, output, Encoding.UTF8); MessageBox.Show("The HTML was created successfully!\nFile created: " + htmlFileFull, "HTML Conversion Successful!", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { Logger.Record("[CSV2HTML]: EXCEPTION reached - Session Report file could not be saved (" + htmlFileFull + ")", "Session", "error"); exDrRetry = Logger.FileErrorMessage(ex, "CSV to HTML", htmlFileFull); } } while (exDrRetry); Logger.Record("[CSV2HTML]: HTML Report built, done.", "Session", "info"); }