Esempio n. 1
0
        private void NotifyEventThread()
        {
            while (true)
            {
                _notifyResetEvent.WaitOne();
                lock (this) {
                    // after a clear, we something get notified
                    // twice for the same entry
                    if (_notifying)
                    {
                        return;
                    }
                    _notifying = true;
                }

                try {
                    int oldest_entry = OldestEventLogEntry;
                    if (_lastEntryWritten < oldest_entry)
                    {
                        _lastEntryWritten = oldest_entry;
                    }
                    int current_entry = _lastEntryWritten - oldest_entry;
                    int last_entry    = EntryCount + oldest_entry;
                    for (int i = current_entry; i < (last_entry - 1); i++)
                    {
                        EventLogEntry entry = GetEntry(i);
                        CoreEventLog.OnEntryWritten(entry);
                    }
                    _lastEntryWritten = last_entry;
                } finally {
                    lock (this)
                        _notifying = false;
                }
            }
        }
Esempio n. 2
0
        public override void EnableNotification()
        {
            if (file_watcher == null)
            {
                string logDir = FindLogStore(CoreEventLog.Log);
                if (!Directory.Exists(logDir))
                {
                    Directory.CreateDirectory(logDir);
                }

                file_watcher          = new FileSystemWatcher();
                file_watcher.Path     = logDir;
                file_watcher.Created += delegate(object o, FileSystemEventArgs e)
                {
                    lock (this)
                    {
                        if (_notifying)
                        {
                            return;
                        }
                        _notifying = true;
                    }

                    // allow for file to be finished writing
                    Thread.Sleep(100);

                    // Process every new entry in one notification event.
                    try
                    {
                        while (GetLatestIndex() > last_notification_index)
                        {
                            try
                            {
                                CoreEventLog.OnEntryWritten(GetEntry(last_notification_index++));
                            }
                            catch (Exception ex)
                            {
                                // FIXME: find some proper way to output this error
                                Debug.WriteLine(ex);
                            }
                        }
                    }
                    finally
                    {
                        lock (this)
                            _notifying = false;
                    }
                };
            }
            last_notification_index          = GetLatestIndex();
            file_watcher.EnableRaisingEvents = true;
        }
Esempio n. 3
0
        private void NotifyEventThread(ManualResetEvent resetEvent)
        {
            if (resetEvent == null)
            {
                return;
            }

            while (true)
            {
                try {
                    resetEvent.WaitOne();
                } catch (ObjectDisposedException) {
                    // Notifications have been disabled and event
                    // has been closed but not yet nulled. End thread.
                    break;
                }

                lock (_eventLock) {
                    if (resetEvent != _notifyResetEvent)
                    {
                        // A new thread has started with another reset event instance
                        // or DisableNotifications has been called, setting
                        // _notifyResetEvent to null. In both cases end this thread.
                        break;
                    }

                    if (_readHandle == IntPtr.Zero)
                    {
                        break;
                    }

                    int oldest_entry = OldestEventLogEntry;
                    if (_lastEntryWritten < oldest_entry)
                    {
                        _lastEntryWritten = oldest_entry;
                    }
                    int current_entry = _lastEntryWritten - oldest_entry;
                    int last_entry    = EntryCount + oldest_entry;
                    for (int i = current_entry; i < (last_entry - 1); i++)
                    {
                        EventLogEntry entry = GetEntry(i);
                        CoreEventLog.OnEntryWritten(entry);
                    }
                    _lastEntryWritten = last_entry;
                }
            }
        }