Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

More plugin examples

Nik Molnar edited this page Mar 1, 2013 · 1 revision

Sample plugin. Don't need this just yet


In many cases you need to display nested data on your tab where the value is not just a string but another set of data.

Say we have a remote server where some administrator keeps deleting our files. A simple plugin would show us all files in the same directory as the currently executing file:

[IMAGE - Screen shot]

Core Concepts

There are a few new things here; we have a nested set of data, some basic formatting and a help icon. To nest result sets, we create a separate List of objects arrays:

var files = new List<object[]> { new object[] { "Name", "Size", "Last Mod", "Created", "Readonly" } };

then populate it in a loop:

files.Add(new object[] { fileSpec, 
    "_" +file.Length.ToString() + "_",
   file.LastAccessTimeUtc.ToShortDateString(),
   file.CreationTimeUtc.ToShortDateString(),
   file.IsReadOnly });

and then add the List into our original List:

data.Add(new object[] { "Files", files });

You can also see that I used the known _foo_ syntax to underline a value, you can also use *bar* for bold text.

To get the help icon, we need to create a web page with some help information for our plugin somewhere and then add its Url to our plugin. We need to implement the IDocumentation interface with a single property: DocumentationUri.

Complete Example

Here's the complete code for this plugin:

using System.Collections.Generic;
using System.IO;
using System.Web;
using Glimpse.Core.Extensibility;

namespace Sample.Docs
{ 
    public class GlimpseFilesPlugin : TabBase, IDocumentation
    { 
        public override string Name
        {
            get { return "Files"; }
        }

        public override object GetData(ITabContext context)
        {
            var data = new List<object[]> { new object[] { "Key", "Value" } };

            string folderName = Path.GetDirectoryName(HttpContext.Current.Request.PhysicalPath);
            string execFileName = Path.GetFileName(HttpContext.Current.Request.PhysicalPath);

            data.Add(new object[] { "Directory", folderName });

            DirectoryInfo folder = new DirectoryInfo(folderName);

            var files = new List<object[]> { new object[] 
                  { "Name", "Size", "Last Mod", "Created", "Readonly" } };

            foreach (FileSystemInfo fsi in folder.GetFileSystemInfos())
            {
                if (fsi.GetType() == typeof(FileInfo))
                {
                    FileInfo file = (FileInfo)fsi;

                    string fileSpec = file.Name;
                    if (fileSpec == execFileName)
                    {
                        fileSpec = "*" + fileSpec + "*";
                    }

                    files.Add(new object[] { fileSpec, 
                         "_" +file.Length.ToString() + "_",
                        file.LastAccessTimeUtc.ToShortDateString(),
                        file.CreationTimeUtc.ToShortDateString(),
                        file.IsReadOnly });
                }
            }

            data.Add(new object[] { "Files", files });

            return data;
        }

        public string DocumentationUri
        {
            get { return "http://myCoolGlimpsePlugins.xyz/help/files"; }
        }
    }
}