Пример #1
0
        public IEnumerable <JournalEntry> GetEntries(Usn currentUSN, ChangeReason reasonFilter, bool returnOnlyOnClose, TimeSpan timeout)
        {
            if (currentUSN < Data.FirstUSN || currentUSN > Data.MaximumUSN)
            {
                throw new ArgumentOutOfRangeException(nameof(currentUSN));
            }

            return(new ChangeJournalEntries(this, new ReadChangeJournalOptions(currentUSN, reasonFilter, returnOnlyOnClose, timeout)));
        }
Пример #2
0
            private bool Read()
            {
                const int CurrentUSNLength = sizeof(long);

                var readData = new READ_USN_JOURNAL_DATA_V0
                {
                    StartUsn          = _currentUSN,
                    ReasonMask        = Options.ReasonFilter,
                    UsnJournalID      = ChangeJournal.Data.ID,
                    ReturnOnlyOnClose = Options.ReturnOnlyOnClose ? (uint)1 : 0,
                    Timeout           = (ulong)Options.Timeout.TotalSeconds,
                };

                var handle    = ChangeJournal.ChangeJournalHandle;
                var entryData = Win32DeviceControl.ControlWithInput(handle, Win32ControlCode.ReadUsnJournal, ref readData, BufferSize);

                if (entryData.Length > CurrentUSNLength) // There are more data than just data currentUSN.
                {
                    var bufferHandle  = GCHandle.Alloc(entryData, GCHandleType.Pinned);
                    var bufferPointer = bufferHandle.AddrOfPinnedObject();

                    _currentUSN = Marshal.ReadInt64(entryData, 0);

                    // Enumerate entries
                    _entries.Clear();
                    var offset = CurrentUSNLength; // Skip currentUSN field
                    while (offset < entryData.Length)
                    {
                        var entry = GetBufferedEntry(bufferPointer, offset);
                        offset += entry.Length;
                        _entries.Add(entry);
                    }

                    bufferHandle.Free();
                    _currentIndex = 0;
                    return(true);
                }
                else
                {
                    _eof = true;
                    return(false);
                }
            }
Пример #3
0
 public void Reset()
 {
     _currentUSN   = Options.InitialUSN ?? ChangeJournal.Data.FirstUSN;
     _currentIndex = -1;
 }