Client side tab

28 views
Skip to first unread message

Steven Lauwers

unread,
Apr 6, 2016, 7:02:52 AM4/6/16
to GetGlimpse-dev
Hi Nik & Anthony,

Someone raised this issue on my SignalR plugin for Glimpse.
The invocations are being recorded, but the SignalR invocations tab does not refresh when new data is available.
To fix this, I need to change my SignalR invocation tab so it behaves more like the Ajax tab.

In the Glimpse documentation I cannot find any guidance on how to achieve this.
Is there any (3rd party) tab you know of that I can take as example?

Cheers,



Steven

Anthony van der Hoorn

unread,
Apr 6, 2016, 10:41:11 AM4/6/16
to getglim...@googlegroups.com
Besides the Ajax/History tab I'm not sure of any other client side plugin that has a "live" status maintained by the server. Hopefully the code from either of those tabs will help point you in the right direction.
Let me know how you get on.
Cheers
Anthony

--
You received this message because you are subscribed to the Google Groups "GetGlimpse-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to getglimpse-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven Lauwers

unread,
Apr 25, 2016, 9:36:53 AM4/25/16
to GetGlimpse-dev
Hey guys,

I was able to get it working, it wasn't even that hard :).
Basically what I needed to do, was the following:

Step 1 - Implement an IClientScript interface:

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
Reply all
Reply to author
Forward
0 new messages