0

I want a plug-in to detect when a case is created that falls under a certain custom category. When the case is created, I want to be able to execute some code instantly. How would I go about doing this? I am just starting with FogBugz and can think of potentially referencing the InterfaceEvents assembly or creating a custom workflow, but nothing has seemed right. Any solution? Thanks

Edit: I am trying to implement the IPlugInBugCommit interface, but am getting errors every time I try to build the project:

Error   1   'FogCreek.FogBugz.CBug' is inaccessible due to its protection level *************\Visual Studio 2008\Projects\HelloWorld\HelloWorld\HelloWorld.cs
Error   4   Inconsistent accessibility: parameter type 'FogCreek.FogBugz.CBug' is less accessible than method 'FogCreek.FogBugz.Plugins.Interfaces.HelloWorld.BugCommitAfter(FogCreek.FogBugz.CBug, FogCreek.FogBugz.BugAction, FogCreek.FogBugz.CBugEvent, bool)'  C:\Users\mxb\Documents\Visual Studio 2008\Projects\HelloWorld\HelloWorld\HelloWorld.cs  33  21  HelloWorld

Here is my code:

/* FogBugz namespaces-- make sure you add the neccesary assembly references to

* the following DLL files contained in C:\Program Files\FogBugz\Website\bin\ * FogBugz.dll, FogCreek.Plugins.dll, FogCreek.Plugins.InterfaceEvents.dll */

using FogCreek.FogBugz;
using FogCreek.FogBugz.UI;
using FogCreek.FogBugz.Plugins;
using FogCreek.FogBugz.Plugins.Api;
using FogCreek.FogBugz.Plugins.Interfaces;

    namespace FogCreek.FogBugz.Plugins.Interfaces
{
    /* Class Declaration: Inherit from Plugin, implement interfaces
     * IPluginPageDisplay, IPluginExtrasMenu, and IPluginCommit */
    public class HelloWorld : Plugin, IPluginPageDisplay, IPluginExtrasMenu, IPluginBugCommit
    {
        //CODE 1265 GO AND LOG ONTO APPDEV COMPUTER
        /* Constructor: We'll just initialize the inherited Plugin class, which 
         * takes the passed instance of CPluginApi and sets its "api" member variable. */
        public string hello;
        public HelloWorld(CPluginApi api)
            : base(api)
        {
            hello = "THIS IS A BIG TEST";
        }
    public string PageDisplay()
    {
        return "<h1>Hello, world!</h1><p>"+hello+"</p>";
    }
    #region IPluginBugCommit Members
    public void BugCommitAfter(CBug bug, BugAction nBugAction, CBugEvent bugevent, bool fPublic)
    {
        hello = "A bug was created.";
    }
    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()) };
    }

}

}

Edit2: Everything I have looked at says to add a reference to FogCreek.Plugins.InterfaceEvents.dll, but our local installation of fogbugz has no such file. Is this the reason?

flag
Take a look at IPluginBugCommit (fogcreek.com/FogBugz/library/70/?topic=/fogbugz/…). This interface lets you run code as soon as a bug is created or changed. – Daniel LeCheminant Jul 14 2010 at 20:40
I am trying to implement this, but am getting errors. Is there something simple I am missing? The question has been edited, thanks. – mbauer14 Jul 15 2010 at 14:40
I believe you only need to add a reference to FogBugz.dll and FogCreek.Plugins.dll. You shouldn't need to put your plugin in the FogCreek.FogBugz.Plugins.Interfaces namespace. Also, recall that the state of hello isn't going to be persisted between calls to the interfaces that you implement. Consider using api.Database.GetKeyValue and api.Database.SetKeyValue if you're trying to persist data. – Daniel LeCheminant Jul 15 2010 at 16:55
Thanks, the hello was just a test to see if the project was working properly when I added a case, but I'll definitely change it if I'm using something similar. – mbauer14 Jul 15 2010 at 17:50
@mbauer14: I was just warning you because the the example you provided never would have said "A bug was created" because the PageDisplay() would have been called an instance that was different from the one that BugCommitAfter was called on ... – Daniel LeCheminant Jul 15 2010 at 18:44
show 1 more comment

1 Answer

1

I think you were having trouble because the wrong CBug class was being referenced. Try this:

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 YourNamespace
{
    public class HelloWorld : Plugin, IPluginPageDisplay, IPluginBugCommit
    {
        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());
        }

        #region IPluginBugCommit Members
        public void BugCommitAfter(CBug bug, BugAction nBugAction, CBugEvent bugevent, bool fPublic)
        {
            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;
        }
    }
}
link|flag
Yup, using FogCreek.FogBugz.Plugins.Entity was the magic line. Thanks for the help! – mbauer14 Jul 15 2010 at 18:06

Your Answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.