Client Pay Portal
 kentico cms 8.1

Kentico CMS 8.1 – Displaying Data on Live Tiles

A few weeks ago Kentico released a beta of the upcoming Kentico 8.1 update (due out 8/22/2014). Not a major overhaul like v7 to v8, 8.1 is a refinement of the platform with some nice touches in several areas. Once of the most noticeable ones being the changes to the Dashboard for the admin portal.


Note

This blog contains totally reversed-engineered code and information. I’m sure the Kentico documentation will be filled with great examples and info to do this within your applications.


A little background

With v8, Kentico refocused the administration area of the site and allowed administrators to tailor the experience for specific roles. Marketing directors can log in and just see the Web Analytics and Campaign reports. Developers can quickly get to the Web Parts and Modules section right from the dashboard. These changes were geared at improving how users interact with the system by putting what’s important to them right in front.
 


Insert Live Tiles

Inspired (I’m assuming) by Windows 8, the new dashboard is now powered with “live” information in the form of constantly updating “Live Tiles.” These new squares of awesomeness can be empowered to display contextual information to user at certain intervals. This is a great way to get even more information in front of the user without having to drill down into a module or utility.
 

 


Creating an ILivetileModelProvider Class

To get started, I installed 8.1 and started digging into some of the Kentico modules. After looking at the code, it seems the real magic is in the ILiveTileModelProvider class creation. This class gets the RegisterLiveTimeModelProvider attribute, which hooks everything up behind the scenes.
 
[assemblyRegisterLiveTileModelProvider("BitWizardsSQLExecution""BitWizardsSQLExecution"typeof(BitWizardsSQLExecutionLiveTileModelProvider))]

The class looks to have a single method called GetModel which gets called to get the Live Tile info. Adding in some custom code to this method will get the data we want to show on the Live Tile.
Here is the code for the GetModel method that gets how many times the BW SQL Execution Module has been executed:
 
public LiveTileModel GetModel(LiveTileContext liveTileContext)
        {
            try
            {
                if (liveTileContext == null)
                {
                    throw new ArgumentNullException("liveTileContext");
                }
 
                DataSet ds = EventLogProvider.GetAllEvents("Source='BitWizards SQL Execution' AND EventCode='INFORMATION'"null);
 
                return new LiveTileModel
                {
                    Value = ds.Tables[0].Rows.Count,
                    Description = "Number of executions",
                };
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("BitWizardsSQLExecutionLiveTileModelProvider""EXCEPTION"ex);
                return null;
            }
        }

After we have that code in place we can start streaming live data to our dashboard.
 


Making it a little smarter

With the base code in place, we can get a little more creative (smarter) with how the code should run. In the following code I am doing the same thing, but caching the data for 10 minutes so we have a few less calls on our database.
 
public LiveTileModel GetModel(LiveTileContext liveTileContext)
        {
            try
            {
                if (liveTileContext == null)
                {
                    throw new ArgumentNullException("liveTileContext");
                }
 
                return CacheHelper.Cache(() =>
                {
                    DataSet ds = EventLogProvider.GetAllEvents("Source='BitWizards SQL Execution' AND EventCode='INFORMATION'"null);
 
                    if (ds.Tables[0].Rows.Count != 0)
                    {
                        return new LiveTileModel
                        {
                            Value = ds.Tables[0].Rows.Count,
                            Description = "Number of executions",
                        };
                    }
                    else return null;
 
                }, new CacheSettings(10"BitWizardsSQLExecutionLiveTileModelProvider"liveTileContext.SiteInfo.SiteID));
            }
            catch (Exception ex)
            {
                EventLogProvider.LogException("BitWizardsSQLExecutionLiveTileModelProvider""EXCEPTION"ex);
                return null;
            }
        }


Things I don’t Know

Given that I found all of this out by digging though the Kentico code, I’m sure there is plenty it does that I don’t know.  The main things are:
 
  • How often does it query for new data? From my calculations it appears to run a task that hits about every 20 seconds.
  • Does a single task run for every module with the “RegisterLiveTileModelProvider”?
  • What is the performance hit from running a lot of Live Tiles?

I’m sure a lot of these answers will be in the documentation so look for some updates when that comes out.


Looking forward

I’m sure this functionality can do a lot more than what I have learned so far. Specifically, I’d like to be able to pull different information and have it cycle. A way around that I thought is to have a “Random” at the beginning of the method and have it grab different data each time it refreshes. That way when the task calls the GetModel method it would probably get different information to show some different Live Tile data each time.

I’m really excited about Kentico’s new Agile-based approach to releases. I think it will make for a great product that will continue to evolve with the industry. And that means a better platform for your projects. So keep the suggestions coming to them and let’s build something awesome together!


Tip

Fellow MVP Brian McKeiver has a good blog on his first thoughts on Kentico 8.1 here.
 
 

Author

Wiz E. Wig, Mascot & Director of Magic
Wiz E. Wig

Director of Magic