I am running a simple plugin, yet when I build the file and add a new case, the displayed counter increases by 2 each time, not one. When I create a new case via an email account with pop3 access, the counter increases by 3. In the BugCommitAfter method, I am testing if the method is in the correct project, and only update the count if it is. Is there any reason this method is called several times? Thanks
using System;
using FogCreek.FogBugz;
using FogCreek.FogBugz.Plugins;
using FogCreek.FogBugz.Plugins.Api;
using FogCreek.FogBugz.Plugins.Entity;
using FogCreek.FogBugz.Plugins.Interfaces;
using FogCreek.FogBugz.UI;
namespace FogCreek.Plugins.HelloWorld
{
public class HelloWorld : Plugin, IPluginPageDisplay, IPluginBugCommit, IPluginExtrasMenu
{
public string hello;
public HelloWorld(CPluginApi api)
: base(api)
{
}
private int GetCommitCount()
{
int cCommits = 0;
return Int32.TryParse(api.Database.GetKeyValue("cCommits"), out cCommits) ? cCommits : 0;
}
private void IncrementCommitCount()
{
int cCommits = GetCommitCount();
api.Database.SetKeyValue("cCommits", (cCommits + 1).ToString());
}
public string PageDisplay()
{
return string.Format("Commits: {0}", GetCommitCount()) + api.Database.GetKeyValue("Hello");
}
#region IPluginBugCommit Members
public void BugCommitAfter(CBug bug, BugAction nBugAction, CBugEvent bugevent, bool fPublic)
{
if (bug.ixProject.ToString().Equals("1"))
{
api.Database.SetKeyValue("Hello", bug.sTitle);
IncrementCommitCount();
}
}
public void BugCommitBefore(CBug bug, BugAction nBugAction, CBugEvent bugevent, bool fPublic)
{
}
public void BugCommitRollback(CBug bug, BugAction nBugAction, bool fPublic){}
#endregion
public PermissionLevel PageVisibility()
{
return PermissionLevel.Normal;
}
public CNavMenuLink[] ExtrasMenuLinks()
{
return new CNavMenuLink[] { new CNavMenuLink("Say Hello", api.Url.PluginPageUrl()) };
}
}
}