/* Copyright 2009 Fog Creek Software, Inc. */ using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Web; /* FogBugz namespaces-- make sure you add the neccesary assembly references to * DLL files contained in C:\Program Files\FogBugz\website\bin\ */ using FogCreek.FogBugz; using FogCreek.FogBugz.Plugins; using FogCreek.FogBugz.Plugins.Api; using FogCreek.FogBugz.Plugins.Interfaces; using FogCreek.FogBugz.UI; using FogCreek.FogBugz.Database; namespace IPluginBinaryPageDisplay_Example { /* Class Declaration: Inherit from Plugin, implement IPluginBinaryPageDisplay, etc. */ public class IPluginBinaryPageDisplay_Example : Plugin, IPluginBinaryPageDisplay, IPluginPageDisplay, IPluginExtrasMenu { /* Constructor: We'll just initialize the inherited Plugin class, which * takes the passed instance of CPluginApi and sets its "api" member variable. */ public IPluginBinaryPageDisplay_Example(CPluginApi api) : base(api) { } #region IPluginBinaryPageDisplay Members public byte[] BinaryPageDisplay() { /* Use the FogBugz API to create a select query that gives us the plugin's * assembly binary (which is stored in zipped format) */ CSelectQuery sq = api.Database.NewSelectQuery("Plugin"); /* All direct SQL queries are considered unsafe. Use IgnorePermissions * to override */ sq.IgnorePermissions = true; sq.AddSelect("rgbFile"); sq.AddSelect("sFilename"); sq.SetParamString("sPluginId", "IPluginBinaryPageDisplay_Example@fogcreek.com"); sq.AddWhere("sPluginId = @sPluginId"); DataSet ds = sq.GetDataSet(); /* Restore default permissions mode */ sq.IgnorePermissions = false; /* Now we can get an array of bytes to return, and set the response header * so that the browser knows how to interpret the data. */ byte[] dllImage = (byte[])ds.Tables[0].Rows[0]["rgbFile"]; api.Response.ContentType = "binary/octet-stream"; api.Response.AddHeader( "Content-Disposition", string.Format("attachment; filename={0}", ds.Tables[0].Rows[0]["sFilename"].ToString() ) ); ds.Dispose(); return dllImage; } public PermissionLevel BinaryPageVisibility() { /* We'll let all logged-in users with "normal" and "admin" permissions access * this page. */ return PermissionLevel.Normal; } #endregion #region IPluginPageDisplay Members public string PageDisplay() { /* Generate a page that includes a link to the DLL */ return String.Format( @"
{0}
...so I put a plugin in your plugin. This page (generated by IPluginPageDisplay) uses the IPluginBinaryPageDisplay interface to allow users to download this plugin's DLL file in zipped-up format.
The Plugin API tells me this page's URL is: {1}
And that the URL of this plugin's binary page is: {2}
", FogCreek.FogBugz.UI.PageDisplay.Headline("I Heard You Liked Plugins..."), HttpUtility.HtmlEncode(api.Url.PluginPageUrl()), HttpUtility.HtmlEncode(api.Url.PluginBinaryPageUrl())); } public PermissionLevel PageVisibility() { return PermissionLevel.Normal; } #endregion #region IPluginExtrasMenu Members public CNavMenuLink[] ExtrasMenuLinks() { /* Create a link to this plugin's page in the "Extras" menu */ return new CNavMenuLink[] { new CNavMenuLink("Download a plugin binary!", api.Url.PluginPageUrl()) }; } #endregion } }