I was able to get it working, it wasn't even that hard :).
This interface is discovered by Glimpse at startup.
Glimpse gets the URI and writes a script tag to the browser which makes a request to the server to load up my client plugin javascript file (see step 2).
public class PluginClientScript : IStaticClientScript
{
public ScriptOrder Order
{
get { return ScriptOrder.IncludeAfterClientInterfaceScript; }
}
public string GetUri(string version)
{
return string.Format("/Glimpse.axd?n={0}&v={1}", PluginClientResource.InternalName, version);
}
}
Step 2 - Implement an IResource to serve the client plugin javascript file to the browser
The client plugin javascript file is an embedded resource of my plugin assembly.
I subclassed the FileResource implementation since it already did everything I needed.
public class PluginClientResource : FileResource, IKey
{
internal const string InternalName = "glimpse_signalr_invocations_client";
private EmbeddedResourceInfo GlimpseSignalREmbeddedResourceInfo { get; set; }
public PluginClientResource()
{
Name = InternalName;
GlimpseSignalREmbeddedResourceInfo = new EmbeddedResourceInfo(
GetType().Assembly,
"Glimpse.SignalR.Invocations.plugin.js",
"application/x-javascript");
}
public string Key
{
get { return Name; }
}
protected override EmbeddedResourceInfo GetEmbeddedResourceInfo(IResourceContext context)
{
return GlimpseSignalREmbeddedResourceInfo;
}
}
Step 3 - Create the client plugin
I took the glimpse ajax plugin as example.
Step 4 Implement an IResource to serve data to the client plugin
The client plugin polls every second or so to the server to get new data.
The resource below accepts these requests and returns data as a json result
public class PluginDataResource : IResource, IKey
{
internal const string InternalName = "glimpse_signalr_invocations_data";
public string Name
{
get { return InternalName; }
}
public IEnumerable<ResourceParameterMetadata> Parameters
{
get { return new[] { ResourceParameter.Hash, ResourceParameter.Callback }; }
}
public string Key
{
get { return Name; }
}
public IResourceResult Execute(IResourceContext context)
{
if (context == null)
throw new ArgumentNullException("context");
var getInvocationsHandler = new GetInvocationsHandler();
var getInvocationsRequest = new GetInvocationsRequest();
var getInvocationsResult = getInvocationsHandler.Handle(getInvocationsRequest);
var data = FormatInvocations(getInvocationsResult.Invocations);
return new CacheControlDecorator(0, CacheSetting.NoCache, new JsonResourceResult(data, context.Parameters.GetValueOrDefault(
ResourceParameter.Callback.Name)));
}
}
By the way @Nik, see you next week at Techorama? :)
Cheers,
Steven