Example #1
0
        public void TestAuditLogRef()
        {
            const string TEST_PREFIX      = "test";
            const int    TEST_ENTRY_COUNT = 3;
            var          document         = new SrmDocument(SrmSettingsList.GetDefault());

            Assert.IsTrue(document.AuditLog.AuditLogEntries.IsRoot);
            Assert.AreEqual(0, AuditLogEntryRef.PROTOTYPE.ListChildrenOfParent(document).Count());
            AuditLogEntry headEntry = document.AuditLog.AuditLogEntries;

            for (int i = 0; i < TEST_ENTRY_COUNT; i++)
            {
                var auditLogEntry = AuditLogEntry.CreateTestOnlyEntry(DateTime.UtcNow, SrmDocument.DOCUMENT_TYPE.mixed, TEST_PREFIX + i);
                headEntry = auditLogEntry.ChangeParent(headEntry);
            }
            Assert.IsNotNull(headEntry);
            Assert.AreEqual(TEST_ENTRY_COUNT, headEntry.Count);
            document = document.ChangeAuditLog(headEntry);
            var auditLogRefs = AuditLogEntryRef.PROTOTYPE.ListChildrenOfParent(document).Cast <AuditLogEntryRef>().ToList();

            Assert.AreEqual(TEST_ENTRY_COUNT, auditLogRefs.Count);
            var extraLogEntry = AuditLogEntry
                                .CreateTestOnlyEntry(DateTime.UtcNow, SrmDocument.DOCUMENT_TYPE.mixed, "extra entry")
                                .ChangeParent(document.AuditLog.AuditLogEntries);
            var document2 = document.ChangeAuditLog(extraLogEntry);

            Assert.AreEqual(TEST_ENTRY_COUNT + 1, AuditLogEntryRef.PROTOTYPE.ListChildrenOfParent(document2).Count());
            foreach (var auditLogRef in auditLogRefs)
            {
                var entry1 = auditLogRef.FindAuditLogEntry(document);
                var entry2 = auditLogRef.FindAuditLogEntry(document2);
                Assert.AreEqual(entry1, entry2);
            }
        }
Example #2
0
        public SrmDocument ChangeEntry(SrmDocument document, AuditLogEntry auditLogEntry)
        {
            var copy  = new List <AuditLogEntry>(document.AuditLog.AuditLogEntries);
            var index = copy.FindIndex(e => e.LogIndex == Entry.LogIndex);

            if (index >= 0)
            {
                copy[index] = auditLogEntry;
                return(document.ChangeAuditLog(ImmutableList.ValueOf(copy)));
            }

            return(document);
        }
Example #3
0
        public SrmDocument ChangeEntry(SrmDocument document, AuditLogEntry auditLogEntry)
        {
            var entries = new Stack <AuditLogEntry>();

            foreach (var entry in document.AuditLog.AuditLogEntries.Enumerate())
            {
                if (entry.LogIndex == Entry.LogIndex)
                {
                    var newEntry = auditLogEntry.ChangeParent(entry.Parent);
                    foreach (var e in entries)
                    {
                        newEntry = e.ChangeParent(newEntry);
                    }
                    return(document.ChangeAuditLog(newEntry));
                }
                else
                {
                    entries.Push(entry);
                }
            }

            return(document);
        }
Example #4
0
 public SrmDocument AppendEntryToDocument(SrmDocument doc, bool raiseEvent = true)
 {
     doc = doc.ChangeAuditLog(ChangeParent(doc.AuditLog.AuditLogEntries));
     OnAuditLogEntryAdded?.Invoke(this, new AuditLogEntryAddedEventArgs(doc.AuditLog.AuditLogEntries));
     return(doc);
 }
Example #5
0
 public SrmDocument AppendEntryToDocument(SrmDocument doc)
 {
     return(doc.ChangeAuditLog(ChangeParent(doc.AuditLog.AuditLogEntries)));
 }
Example #6
0
 public static bool EqualExceptAuditLog(SrmDocument document1, SrmDocument document2)
 {
     return(document1.ChangeAuditLog(AuditLogEntry.ROOT).Equals(document2.ChangeAuditLog(AuditLogEntry.ROOT)));
 }