private void SafeAuditLog(ZipFileShare zip, string docPath) { if (ShouldShareAuditLog(Document, ShareType)) { var path = SrmDocument.GetAuditLogPath(docPath); if (File.Exists(path)) { zip.AddFile(path); } } }
protected override void DoTest() { OpenDocument("Rat_plasma.sky"); RunUI(SkylineWindow.ShowAuditLog); var auditLogForm = WaitForOpenForm <AuditLogForm>(); Assert.IsFalse(SkylineWindow.Document.Settings.DataSettings.AuditLogging); RunUI(() => auditLogForm.EnableAuditLogging(true)); // Test that initial hash is correct var expectedHash = BlockHash.SafeToBase64(new byte[] { 0xFE, 0x0F, 0x0C, 0x54, 0xA0, 0x77, 0xE5, 0x8F, 0x77, 0xDC, 0x8B, 0xEE, 0x44, 0xB6, 0x65, 0x6D, 0x98, 0x31, 0xAA, 0x35 }); var actualHash = GetDocumentHash(); Assert.AreEqual(expectedHash, actualHash); // Test that the hash is the same as if the document was simply read and hashed // The document is really small (<20KB) so it's fine to read it all into memory var bytes = File.ReadAllBytes(SkylineWindow.DocumentFilePath); var hash = Hash(bytes); Assert.AreEqual(expectedHash, hash); // Make sure that there's an entry describing 1) number of nodes and 2) settings changes from default settings Assert.AreEqual(1, SkylineWindow.Document.AuditLog.AuditLogEntries.Count); if (!RecordNewestEntry()) { RunUI(() => { LOG_ENTRY_MESSAGES[0].AssertEquals(SkylineWindow.Document.AuditLog.AuditLogEntries); }); } // Modify and save the document so that the audit log gets saved ChangeSettings(settings => settings.ChangePeptideFilter(filter => filter.ChangeExcludeNTermAAs(3))); // Change from 2 to 3 RunUI(() => SkylineWindow.SaveDocument()); RecordNewestEntry(); Assert.IsTrue(File.Exists(SrmDocument.GetAuditLogPath(SkylineWindow.DocumentFilePath)), "Audit log does not exist after saving document"); AssertEx.ValidateAuditLogAgainstSchema(File.ReadAllText(SrmDocument.GetAuditLogPath(SkylineWindow.DocumentFilePath))); // Also validate an old document AssertEx.ValidateAuditLogAgainstSchema(File.ReadAllText(TestFilesDir.GetTestPath("old_rat_plasma.skyl"))); // Modify document outside of skyline var docPath = SkylineWindow.DocumentFilePath; RunUI(() => SkylineWindow.NewDocument(true)); // Audit logging should be enabled since the previous settings will be used Assert.IsTrue(SkylineWindow.Document.Settings.DataSettings.AuditLogging); // Perform the following action manually: // Settings > Peptide Settings -- Filter > Exclude N-Terminal AA's changed from "3" to "4" var text = File.ReadAllText(docPath); var match = Regex.Match(text, "<peptide_filter .*start=\"3\""); Assert.IsTrue(match.Success); Assert.IsFalse(match.NextMatch().Success); var sb = new StringBuilder(text); sb[match.Index + match.Length - 2] = '4'; File.WriteAllText(docPath, sb.ToString()); var oldRef = SkylineWindow.Document; // Add an entry describing this change OpenDocumentNoWait("Rat_plasma.sky"); var alert = WaitForOpenForm <AlertDlg>(); OkDialog(alert, alert.ClickYes); var logForm = WaitForOpenForm <DocumentChangeLogEntryDlg>(); RunUI(() => { logForm.LogMessage = "Changed Exlude N-Terminal AA's from 3 to 4 manually"; }); OkDialog(logForm, logForm.OkDialog); // Wait until document gets switched, otherwise WaitForDocumentLoaded will think that the document is already loaded // since we're not waiting for the document to open (OpenDocumentNoWait) WaitForCondition(() => !ReferenceEquals(oldRef, SkylineWindow.Document)); Assert.AreNotEqual(expectedHash, SkylineWindow.Document.DocumentHash); // If this wasn't the case the dialogs would never show up, but check anyways WaitForDocumentLoaded(); RunUI(() => SkylineWindow.SaveDocument()); // Save so that hash in audit log matches document now // Now audit logging should be enabled Assert.IsTrue(SkylineWindow.Document.Settings.DataSettings.AuditLogging); // Make sure the entry was actually added Assert.AreEqual(3, SkylineWindow.Document.AuditLog.AuditLogEntries.Count); // Check that this entry got saved and read correctly, we don't record here if (!IsRecordMode) { RunUI(() => { LOG_ENTRY_MESSAGES[1].AssertEquals(SkylineWindow.Document.AuditLog.AuditLogEntries.Parent); }); } if (!RecordNewestEntry()) { RunUI(() => { LOG_ENTRY_MESSAGES[2].AssertEquals(SkylineWindow.Document.AuditLog.AuditLogEntries); }); } var fasta = FastaImporter.ToFasta(PROTEINLIST_CLIPBOARD_TEXT, TextUtil.SEPARATOR_TSV); RunDlg <EmptyProteinsDlg>(() => SkylineWindow.Paste(fasta), dlg => dlg.KeepEmptyProteins()); if (!RecordNewestEntry()) { RunUI(() => { LOG_ENTRY_MESSAGES[3].AssertEquals(SkylineWindow.Document.AuditLog.AuditLogEntries); }); } RunUI(SkylineWindow.ShowAuditLog); var auditLogForm1 = WaitForOpenForm <AuditLogForm>(); RunUI(() => auditLogForm1.ChooseView(AuditLogStrings.AuditLogForm_MakeAuditLogForm_Undo_Redo)); AuditLogUtil.WaitForAuditLogForm(auditLogForm1); // Show extra info for this entry RunDlg <AuditLogExtraInfoForm>(() => { Assert.AreEqual(4, auditLogForm1.DataGridView.RowCount); var fastaRow = auditLogForm1.DataGridView.Rows[0]; var undoRedoCol = auditLogForm1.FindColumn(nameof(AuditLogRow.UndoRedoMessage)); Assert.IsNotNull(undoRedoCol); var auditLogRowText = fastaRow.Cells[undoRedoCol.Index].Value as AuditLogRow.AuditLogRowText; Assert.IsNotNull(auditLogRowText); var col = auditLogForm1.DataGridView.Columns[undoRedoCol.Index] as AuditLogColumn; Assert.IsNotNull(col); Assert.IsTrue(col.ShouldDisplay(auditLogRowText, (int)AuditLogColumn.ImageIndex.extra_info)); col.Click(auditLogRowText, (int)AuditLogColumn.ImageIndex.extra_info); }, form => { var entry = SkylineWindow.DocumentUI.AuditLog.AuditLogEntries; Assert.AreEqual(form.Message, entry.UndoRedo.ToString()); Assert.AreEqual(form.ExtraInfo, entry.ExtraInfo); form.OkDialog(); }); // Disable audit logging, this should warn the user RunDlg <AlertDlg>(() => { auditLogForm1.EnableAuditLogging(false); }, alertDlg => { alertDlg.ClickYes(); }); AuditLogUtil.WaitForAuditLogForm(auditLogForm1); Assert.AreEqual(0, SkylineWindow.Document.AuditLog.AuditLogEntries.Count); Assert.IsFalse(SkylineWindow.Document.Settings.DataSettings.AuditLogging); // Re-open document without saving RunUI(() => SkylineWindow.NewDocument(true)); OpenDocument("Rat_plasma.sky"); RunUI(SkylineWindow.ShowAuditLog); var auditLogForm2 = WaitForOpenForm <AuditLogForm>(); RunUI(() => auditLogForm2.ChooseView(AuditLogStrings.AuditLogForm_MakeAuditLogForm_Undo_Redo)); AuditLogUtil.WaitForAuditLogForm(auditLogForm2); RunUI(() => { // Audit logging shold be back on and the entries should still be there Assert.IsTrue(SkylineWindow.DocumentUI.Settings.DataSettings.AuditLogging); Assert.AreEqual(3, SkylineWindow.DocumentUI.AuditLog.AuditLogEntries.Count); }); // Disable again, this time save RunDlg <AlertDlg>(() => { auditLogForm2.EnableAuditLogging(false); }, alertDlg => { alertDlg.ClickYes(); }); RunUI(() => SkylineWindow.SaveDocument()); // audit log should be gone Assert.IsFalse(File.Exists(SrmDocument.GetAuditLogPath(SkylineWindow.DocumentFilePath))); }