示例#1
0
        public EventIdentificationStore(IFilterConfiguration configuration)
        {
            _store             = GetIsolatedStorageFile();
            _configurationHash = HashBuilder.BuildFilterConfigHash(configuration);

            _store.CreateRadonDirectoryIfNotExists();
        }
示例#2
0
 public void SaveAlreadyReportedEventIdentification(LogEvent logEvent)
 {
     lock (_fileAccessLock)
     {
         using (var stream = new IsolatedStorageFileStream(Path.Combine("Radon", _configurationHash), FileMode.Create, _store))
             using (var writer = new StreamWriter(stream))
             {
                 var id = HashBuilder.BuildEventIdentification(logEvent);
                 writer.WriteLine(id.TimeStampUtc.ToString("u"));
                 writer.WriteLine(id.Hash);
             }
     }
 }
        public IEnumerable <LogEvent> ReadEvents()
        {
            var oldEventIdentification = _identificationStore.GetAlreadyReportedEventIdentification();
            var events = _eventReader.ReadEvents();

            if (oldEventIdentification == null)
            {
                return(events);
            }

            var filteredEvents =
                events.TakeWhile(
                    e =>
            {
                var newerThan = e.TimeGenerated.ToUniversalTime() > oldEventIdentification.TimeStampUtc;

                if (newerThan)
                {
                    // The event is newer than the old event
                    return(true);
                }
                else
                {
                    if (e.TimeGenerated.ToUniversalTime() == oldEventIdentification.TimeStampUtc)
                    {
                        var eventHash = HashBuilder.BuildEventIdentification(e).Hash;
                        if (eventHash != oldEventIdentification.Hash)
                        {
                            // The event is the same age as the old event but has a different hash
                            return(true);
                        }
                    }
                }
                return(false);        // The event wasn't newer than than the old event or the same age and hash -> stop returning older events
            });

            return(filteredEvents);
        }