Exemplo n.º 1
0
        public void TestAuditLogSerialization()
        {
            const int entryCount  = 20000;
            var       document    = new SrmDocument(SrmSettingsList.GetDefault());
            var       simpleEntry = AuditLogEntry.CreateSimpleEntry(document, MessageType.test_only, string.Empty);
            var       entries     = Enumerable.Range(0, entryCount).Select(index => simpleEntry).ToArray();

            Array.Reverse(entries);
            AuditLogEntry headEntry = null;

            foreach (var entry in entries)
            {
                if (headEntry == null)
                {
                    headEntry = entry;
                }
                else
                {
                    headEntry = entry.ChangeParent(headEntry);
                }
            }
            Assert.IsNotNull(headEntry);
            Assert.AreEqual(entryCount, headEntry.Count);
            Assert.AreEqual(headEntry.Count, headEntry.Enumerate().Count());
            var auditLogList       = new AuditLogList(headEntry);
            var serializedAuditLog = new StringWriter();
            var serializer         = new XmlSerializer(typeof(AuditLogList));

            serializer.Serialize(serializedAuditLog, auditLogList);
            var roundTrip = (AuditLogList)serializer.Deserialize(new StringReader(serializedAuditLog.ToString()));

            Assert.IsNotNull(roundTrip);
            Assert.AreEqual(auditLogList.AuditLogEntries.Count, roundTrip.AuditLogEntries.Count);
        }
Exemplo n.º 2
0
        public void EnableAuditLogging(bool enable)
        {
            if (!enable && !_skylineWindow.DocumentUI.AuditLog.AuditLogEntries.IsRoot)
            {
                using (var dlg = new AlertDlg(
                           AuditLogStrings.AuditLogForm_EnableAuditLogging_This_will_clear_the_audit_log_and_delete_it_permanently_once_the_document_gets_saved__Do_you_want_to_proceed_,
                           MessageBoxButtons.YesNo))
                {
                    if (dlg.ShowDialog(this) != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }

            _skylineWindow.ModifyDocumentNoUndo(oldDoc => AuditLogList.ToggleAuditLogging(oldDoc, enable));
            _enableAuditLogging.Checked = enable;
        }
Exemplo n.º 3
0
        public void EnableAuditLogging(bool enable)
        {
            if (!enable && !_skylineWindow.DocumentUI.AuditLog.AuditLogEntries.IsRoot)
            {
                using (var dlg = new AlertDlg(
                           AuditLogStrings.AuditLogForm_EnableAuditLogging_This_will_clear_the_audit_log_and_delete_it_permanently_once_the_document_gets_saved__Do_you_want_to_proceed_,
                           MessageBoxButtons.YesNo))
                {
                    if (dlg.ShowDialog(this) != DialogResult.Yes)
                    {
                        return;
                    }
                }
            }

            _skylineWindow.ModifyDocument(string.Empty, // Audit logging takes care of this now
                                          doc => AuditLogList.ToggleAuditLogging(doc, enable),
                                          AuditLogEntry.SettingsLogFunction);
            _skylineWindow.StoreNewSettings(_skylineWindow.DocumentUI.Settings);
            _enableAuditLogging.Checked = enable;
        }
Exemplo n.º 4
0
        public void TestAuditLogSerialization()
        {
            var datetime = AuditLogEntry.ParseSerializedTimeStamp("2019-01-01T05:02:03+04", out var tzoffset); // Accept ISO format, which may omit minutes in offset

            Assume.AreEqual(DateTimeKind.Utc, datetime.Kind);
            Assume.AreEqual(1, datetime.Hour); // Local time was 5AM, 4 hour offset to GMT.
            Assume.AreEqual(new TimeSpan(4, 0, 0), tzoffset);
            var xsd = AuditLogEntry.FormatSerializationString(datetime, tzoffset);

            Assume.AreEqual("2019-01-01T05:02:03+04:00", xsd);

            var zulu = AuditLogEntry.ParseSerializedTimeStamp("2019-01-01T01:02:03Z", out tzoffset);

            Assume.AreEqual(tzoffset, TimeSpan.Zero);
            Assume.AreEqual(datetime, zulu);

            AuditLogEntry.ParseSerializedTimeStamp("2019-01-01T01:02:03-04:30", out tzoffset);
            Assume.AreEqual(new TimeSpan(-4, -30, 0), tzoffset);

            datetime = AuditLogEntry.ParseSerializedTimeStamp("2018-12-31T23:02:03-04", out tzoffset);
            Assume.AreEqual(datetime, AuditLogEntry.ParseSerializedTimeStamp("2019-01-01T03:02:03Z", out tzoffset));

            // Test backward compatibility - this file with 4.2 log should load without any problems
            Assume.IsTrue(AuditLogList.ReadFromXmlTextReader(new XmlTextReader(new StringReader(Test42FormatSkyl)), out var loggedSkylineDocumentHash, out var old));
            Assume.AreEqual("tgnQ8fDiKLMIS236kpdJIXNR+fw=", old.RootHash.ActualHash.HashString);
            Assume.AreEqual("AjigWTmQeAO94/jAlwubVMp4FRg=", loggedSkylineDocumentHash);                                                                        // Note that this is a base64 representation of the 4.2 hex representation "<document_hash>0238A05939907803BDE3F8C0970B9B54CA781518</document_hash>

            var           then       = DateTime.Parse("2019-03-08 00:02:03Z", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); // Just before DST
            const int     entryCount = 20000;                                                                                                                  // Enough to ensure stack overflow in case of some design error per Nick
            var           timestep   = new TimeSpan(1, 0, 1);                                                                                                  // 20000 hours should be sufficient to take us into and out of daylight savings twice
            AuditLogEntry headEntry  = null;

            for (var index = 0; index++ < entryCount;)
            {
                var documentType = (SrmDocument.DOCUMENT_TYPE)(index % ((int)SrmDocument.DOCUMENT_TYPE.none + 1));
                var entry        = AuditLogEntry.CreateTestOnlyEntry(then, documentType, string.Empty);
                then += timestep;
                if (headEntry == null)
                {
                    headEntry = entry;
                }
                else
                {
                    headEntry = entry.ChangeParent(headEntry);
                }
            }
            Assert.IsNotNull(headEntry);
            Assert.AreEqual(entryCount, headEntry.Count);
            Assert.AreEqual(headEntry.Count, headEntry.Enumerate().Count());
            var auditLogList       = new AuditLogList(headEntry);
            var serializedAuditLog = new StringWriter();
            var serializer         = new XmlSerializer(typeof(AuditLogList));

            serializer.Serialize(serializedAuditLog, auditLogList);
            var currentCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; // Logs are meant to be culture invariant
            var roundTrip = (AuditLogList)serializer.Deserialize(new StringReader(serializedAuditLog.ToString()));

            Assert.IsNotNull(roundTrip);
            Assert.AreEqual(auditLogList.AuditLogEntries.Count, roundTrip.AuditLogEntries.Count);
            var entries          = auditLogList.AuditLogEntries.Enumerate().ToArray();
            var roundtripEntries = roundTrip.AuditLogEntries.Enumerate().ToArray();

            for (var i = 0; i < auditLogList.AuditLogEntries.Count; i++)
            {
                Assert.AreEqual(entries[i].TimeStampUTC, roundtripEntries[i].TimeStampUTC);
                Assert.AreEqual(entries[i].TimeZoneOffset, roundtripEntries[i].TimeZoneOffset);
                Assert.AreEqual(entries[i].SkylineVersion, roundtripEntries[i].SkylineVersion);
                Assert.AreEqual(entries[i].User, roundtripEntries[i].User);
                Assert.AreEqual(entries[i].DocumentType == SrmDocument.DOCUMENT_TYPE.proteomic ? SrmDocument.DOCUMENT_TYPE.none : entries[i].DocumentType, roundtripEntries[i].DocumentType);
                Assert.AreEqual(entries[i].Hash.ActualHash, roundtripEntries[i].Hash.ActualHash);
                // No Skyl hash until sserialized, so can't compare here
            }
            Thread.CurrentThread.CurrentCulture = currentCulture;

            // Make sure current system timezone isn't messing with us
            Assert.AreEqual(14, roundtripEntries[100].TimeStampUTC.Day);
            Assert.AreEqual(8, roundtripEntries[100].TimeStampUTC.Hour);
            Assert.AreEqual(27, roundtripEntries[10000].TimeStampUTC.Day);
            Assert.AreEqual(17, roundtripEntries[10000].TimeStampUTC.Hour);
        }