Real-Time Visitor Count in Sitefinity with SignalR

In the previous post we looked at how to install and use SignalR in Sitefinity with a really simple popup notification sample. This time we’ll look at how we can leverage SignalR to create a real-time count of readers visiting a blog post. Be sure you’ve reviewed the previous post as we’ll be extending the existing Notify Hub and JavaScript for this example.

Read more at the Falafel Software Blog: Real-Time Visitor Count in Sitefinity with SignalR

Sitefinity Real-Time Notifications with SignalR

One of the more interesting technologies I discovered during my recent trip to Tech Ed 2014 is SignalR, which is a library for ASP.NET that allows real-time communication between the server and browser. This exciting platform enables bi-directional communication between a page and the server, allowing updates to be instantly pushed in either direction. Best of all, SignalR automatically detects the best option for communication based on the capabilities of the client ensuring maximum compatibility across different browsers.

To learn more about SignalR and see it in action, I highly recommend you check out this session from Tech Ed: Building Real-Time Applications with ASP.NET SignalR.

Today we’ll see how you can setup Sitefinity to use this library with a simple notification that fires when a user logs into the backend. Later we’ll build a more real-world scenario by building a real-time viewer count for a blog post.

Read more at the Falafel Software Blog: Sitefinity Real-Time Notifications with SignalR

Creating Individual Search Indexes for Multiple Sitefinity Blogs

Sitefinity provides the ability to index all of your content so that it is easily searchable by your visitors. You can also partition the contents of the search into separate indexes based on the different content types, such as News, Blogs, Events, etc.

However, what if you have multiple blogs but want your visitors to be able to limit their search to a single specific blog? That’s the focus of today’s post.

Read more at the Falafel Software Blogs: Creating Individual Search Indexes for Multiple Sitefinity Blogs

Querying the List of Sitefinity Dynamic Modules and Types

The Code Reference of the Sitefinity Module Builder makes it simple to get started building custom widgets and components to interact with your Dynamic Modules. However, the generated code is specific to each module and type, requiring that you pass in the full type as a string, resolving the type at runtime.

But what if you need to write generic code that could be used for multiple dynamic modules, where you won’t necessarily know in advance what the types are?

The answer is the ModuleBuilderManager, which exposes methods for retrieving both modules and their associated types. Let’s take a closer look at what you need to do to query modules and types..

For this example I’ve created a few sample dynamic modules, leaving one in a disabled state so you can see how the results differ.

Read more at the Falafel Software Blogs: Querying the List of Sitefinity Dynamic Modules and Types

Embedding Sitefinity Widget MVC Views in an External Assembly

As we saw in the previous post, you can override the default MVC Views of the Falafel Dashboard Widgets for Sitefinity that are served from the Embedded Resources of the assembly. But how did we get the views there in the first place, and how do we serve them to the Sitefinity widgets while allowing them to be overridden with the physical files?

That’s what we will be exploring today.

Read more at the Falafel Software Blog: Embedding Sitefinity Widget MVC Views in an External Assembly

Customizing the MVC Views of the Falafel Dashboard Widgets for Sitefinity

Last week, Falafel released the new Dashboard Widgets for Sitefinity, allowing you to easily add 11 new widgets to the administration dashboard for Sitefinity 6.2+. The widgets are easy to use and provide valuable information at a glance. But did you know they’re also highly customizable?

Because these widgets are built with ASP.NET MVC, you can modify the View templates of each individual widget to change the layout to suit the visual needs of your site. In this post we’ll take a look at how you can achieve this. In a later post, we’ll look at the technical details that make this possible.

Read more at the Falafel Software Blog: Customizing the MVC Views of the Falafel Dashboard Widgets for Sitefinity

Selecting Dynamic Content in Native Sitefinity Modules with Custom Fields

The Sitefinity Module builder allows you to create custom types on the fly for use as custom modules.

In the 5.0 release back in February, a two new field types were added to the module builder: Guid and Array of Guids. These allow you to “link” content items using their Id properties, adding support of one-to-many and many-to-many relationships between your content.

Radoslav posted a helpful sample of a custom dynamic content selector field control that allows you to select content for these relationships. While this sample is thorough, it is a lot of custom code to work with if you simply want to make a basic association.

Such a situation occurs with the recently released Sitefinity MVC Store sample project. In this project, there are two content types Artist and Genre that are referenced in a one-to-many relationship to the content type Album. Instead of implementing the full selector above, a simpler control was created by inheriting from the existing ChoiceField control.

This field already contains a lot of the functionality required, since it was designed to present a list of options to the user, in many forms. In this case, the field is defaulted to a dropdown list:


In this example, the name of the field (Artist and Genre exactly match the name of the Content Type being associated. This eliminates the need to create a separate field for each content type, and it can even be reused in other content modules.

Here is the full code for this custom field control, showing how this was achieved.

View Code Sample on Gist

Keeping the Default Behavior

Notice that not only does this control inherit from ChoiceField but the ScriptDescriptorType and ResourcesAssemblyInfo overrides also force this control to reuse the base behavior of that field. The reason for this is that by doing so, the control will reuse the native JavaScript file for the designer, so that it isn’t necessary rewrite a entirely new script from scratch just to accommodate our custom type. Instead, the default one for ChoiceField is compatible since this control inherits directly from it.

Defining the Desired Behavior

Also, you can see that the RenderChoicesAs property forces a list. This could be modified if you a different input type is required. However, using a custom field does not present the option to set this on the website when the field is added, so it is explicitly set here.

Populating the Choice Collection

Finally, the Configure method takes care of actually loading the choices and presenting them to the user. While you can certainly hard-code your custom module and content types into the control, the FieldDefinition that is passed to this method includes a lot of information that can be used to extract the data needed to load the content items.

The ControlDefinitionName contains the type of the current content type using dot notation (Example: Telerik.Sitefinity.DynamicTypes.Model.MusicStore.Album), so removing the last element results in the parent module type.

NOTE: This selector does not account for nested or child types, and should be modified if you are using such a content type.

The name of the field is stored in the FieldName property, and appending them together results in the full name of the dynamic content type.

This name can then be used to initialize the Content Type required by the Dynamic Module Manager to retrieve content items of that type. From there a simple use of the Sitefinity API retrieves the published items and binds them to the Choices collection so they can be shown in the dropdown list.


Retrieving Associated Items Using the API

Once your content items are added with these associations using the new custom field, you can easily retrieve them back using the API. This is demonstrated in the Browse method of the StoreController.cs class:
View Code Sample on Gist

Which reveals the albums which match the selected Genre: