Application: EventsMonitor
Revit Platform: All
Revit Version: 2011.0
First Released For: 2010.0
Programming Language: C#
Skill Level: Medium
Category: Basics
Type: ExternalApplication 

Subject: Track Event.
Summary: 
This sample demonstrates how to subscribe to controlled application level Events. 

Classes: 
Autodesk.Revit.UI.IExternalCommand 
Autodesk.Revit.UI.IExternamApplication
Autodesk.Revit.DB.Events

Project Files: 
Command.cs
This file contains the class Command which implements IExternalCommand and used to retrieve the events setting to help user changing his choices.

ExternalApplication.cs
This file contains one class ExternalApplication which implements IExternalApplication interface and provides an entry of the sample.  This class controls other function class and plays the bridge role in this sample. It also creates a custom panel "Event Monitor" that contains a push button named “Set Events” in OnStartup method.

EventManager.cs
This file contains one class AppEventManager which implements all the events handler methods. This class is a manager for application events. In this class, you can subscribe and remove the events according to what you select.

LogManager.cs
This file contains one class LogManager which implements all operations about writing log file and generating event information for showing in the information windows.

EventInfoWindows.cs
This file contains a form class InformationWindows which consists of one DataGridView to show the user the Revit events history log. The event log includes the event time, the event name, and the event type.

EventSettingForm.cs
This file contains a form class which consists of CheckedList controls to provide the user with options about to which events they subscribe.

JournalProcessor.cs
This file contains one class JournalProcessor which can help to auto-test this sample.This class checks the external xml file before the UI pops up and help entrance method to control whether it is playing journal or operating in UI.This class also can help to dump the selected event list to external xml file or journal file and retrieve the event list from those files. If you are just interested in how to use event, you can skip over this class and other related sentence.

Description: 
The sample pop up a dialog named “Events Tracking Setting” when the Revit application starts. User makes his choice in this dialog and tracking the events he selected. And one custom panel with a push button is created at the same time. This button is used to retrieve the setting dialog shown at the beginning to let use change his last choice. All subscribed events are shown in InformationWindows including their names, types and the trigger times.
-	This sample will subscribe to events according to what the user chose in Events Setting Window.
-	This sample lists events information like time, name, and type and so on in a modeless window when corresponding events are raised.

Instructions: 
1.	Build this sample under Debug mode and register your .addin with .addin of this sample.
2.	Run Revit. An Events setting dialog box will appear.
3.	Choose any event that you would like to track. For example you might try to select DocumentSaving and DocumentsSaved events. Push OK button and go to Events information window. Open and save a document, then a log item will appear in the Events information window and be written into the EventsMonitor.log file. 
4.	And then, if you want to change another event to track, you can push the “Set Events” button in the "EventsMonitor" panel. The Events Setting dialog box will appear again.

Notes:
1.	Note that some condition compile directive(#if) were used in sample’s sources, they’re used for different purposes; please make sure you build this sample under Debug mode to let sample works as described above, building sample under Release mode is just for regression test purpose.