Wiki

Case Status Kiln
Register Log In

Wiki

 
"How To" Guides»Event-Handling Approach
  • RSS Feed

Last modified on 12/16/2014 1:55 PM by User.

Tags:

Event-Handling Approach

Implementing interfaces allows a plugin to perform actions upon commit of a Bug, CSV checkin, Wiki, etc, but what if you want to get more granular and only do something when a case is opened, or resolved, or when a wiki page is first created? Plugin interface events allow you to achieve this specificity.

There are five classes in the FogCreek.FogBugz.Plugins.InterfaceEvents namespace. To handle any of the events below, a plugin must do the following. Examples are all for handling events fired when a case (CBug) is commited.

  1. Reference the InterfaceEvents assembly
    In Microsoft Visual Studio, right-click References in the Solution Explorer and select Add Reference...
    Navigate to your fogbugz directory and choose PluginUtils\bin\FogCreek.Plugins.InterfaceEvents.dll
     
  2. Add the InterfaceEvents namespace

    using FogCreek.Plugins.InterfaceEvents;
     
  3. In the class, declare an instance of the event API your plugin will use

    CPluginBugCommitEvents oPluginBugCommitEvents;
     
  4. In the plugin class's constructor:
    1. Instantiate the event API the plugin uses

      oPluginBugCommitEvents = new CPluginBugCommitEvents();
       
    2. Add your event-handlers (Hint: in Visual Studio, type "oPluginBugCommitEvents.OnCaseEdited +=" then hit tab. It will fill in the rest. Leave the method name highlighted for the next step)

      oPluginBugCommitEvents.OnCaseEdited +=new EventHandler<CPluginBugCommitEvents.BugEventArgs>(oPluginBugCommitEvents_OnCaseEdited);
       
  5. Define the method specified above (Hint: in Visual Studio, just hit tab if after leaving the method name highlighed from step 5.2 above to start) and dispatch to the InterfaceEvents library object for each method in the interface

    void oPluginBugCommitEvents_OnCaseEdited(object sender, CPluginBugCommitEvents.BugEventArgs e) {
         /* put the good stuff in here */
    }
     
  6. Implement the interface(s) corresponding to the events handled (e.g. for OnCaseEdited, the plugin must implement IPluginBugCommit)

    You need to call the same event in the oPluginBugCommitEvents that you are handling.

    oPluginBugCommitEvents.CaseEdited( bug, bugevent );

    See FogBugz Plugin Interfaces for more information on plugin interfaces.

Bug Commit Events
(CPluginBugCommitEvents)

The BugEventArgs passed to the delegate function on each of the following events consists of the CBug and CBugEvent objects.

OnCaseAssigned: Fired when a case is assigned to a FogBugz user. (Example)

OnCaseClosed:

OnCaseEdited:

OnCaseOpened:

OnCaseReactivated:

OnCaseReopened:

OnCaseResolved:

OnEmailReceived:

OnEmailReplied:

OnEmailSent:

OnEmailSorted:

 

Source Control Events
(CPluginCVSCommitEvents)

The DiscussTopicEventArgs passed to the delegate function on each of the following events consists of the CCVS object.

OnSourceControlCommit: Fired when files are commited to a configured source control repository. (Example)

Discussion Topic Events
(CPluginDiscussTopicCommitEvents)

The CVSEventArgs passed to the delegate function on each of the following events consists of the CDiscussTopic object.

OnDiscussPostCreated:

OnDiscussThreadCreated:

 

Time Interval Events
(CPluginTimeIntervalCommitEvents)

The TimeIntervalEventArgs passed to the delegate function on each of the following events consists of the CTimeInterval object.

OnTimeIntervalAdded:

OnTimeIntervalDeleted:

OnTimeIntervalEdited:

OnTimeIntervalEnded:

 

Wiki Page Events
(CPluginWikiPageCommitEvents)

The WikiPageEventArgs passed to the delegate function on each of the following events consists of the CWikiPage object.

OnWikiPageCreated:

OnWikiPageEdited: