Tuesday, September 23, 2014

How setup SharePoint web application to write SignalR based application pages?

There are few steps to enable SignalR into a web application. But how do this for a SharePoint based web application? 

The goal of this post is provide you a SharePoint deployment package to is automate such steps for a SharePoint web application.

The only thing you have to do is:

2) Install the SignalR distributed assemblies the web application bin directory from Powershell console:

>Add-PSSnapin Microsoft.SharePoint.PowerShell
>Add-SPSolution (Resolve-Path .\SignalR.SharePoint.wsp)
>Install-SPSolution SignalR.SharePoint.wsp -WebApplication $WebAppUrl -GACDeployment -FullTrustBinDeployment -Force

3) Enable [SignalR SharePoint Configuration Feature] - in the web application scope - in order to modify the web.config for run-time assembly binding redirection, set legacyCasModel to false (allow dynamic calls) and set the owin:AutomaticAppStartup application setting key to false.

...
   <trust level="Full" originUrl="" legacyCasModel="false" />
...
  <runtime>
    <assemblyBinding>
...
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
...
  <appSettings>
...
    <add key="owin:AutomaticAppStartup" value="false" />
  </appSettings>

4) Create and deploy your hub based assembly into the web application. The easy way to do this is by writing the hub in a SharePoint based project and set the “Assembly Deployment Target” to WebApplication. You can also try with this simple chat example by deploying it into your web application.

5) Enable the [SignalR SharePoint Enable AutomaticAppStartup Feature] - in the web application scope - in order turn the owin:AutomaticAppStartup application setting key to true.

  <appSettings>
...
    <add key="owin:AutomaticAppStartup" value="true" />
  </appSettings>

6) Just open your browser and navigates to the application page. If you deployed the chat example, you can try with %WebApplicationUrl%/_layouts/15/_layouts/15/SignalR.SharePoint.Demo/Chat.aspx application page.

Monday, August 11, 2014

What about Catel.Fody and computed read-only properties change notifications?


In my last post, I covered the implementation of INotifyPropertyChanged interface when using SheepAspect as an AOP library. In the end, I also implemented an approach to notify changes of computed read-only properties. This approach has a downside, the dependent properties discovering process must be done in run-time.

Such a journey recalls us that Catel.Fody didn’t have support for notifying property changes of computed read-only properties. How could such a thing ever be possible? Obvious, “the shoemaker's son always goes barefoot” ;). But don’t worry: the feature is here, moving the dependent properties discovering process to build-time, thanks to Fody.

As you probably know by now, Catel.Fody will rewrite all properties on the DataObjectBase and ViewModelBase. So, if a property is written like this:

public string FirstName { get; set; }

will be weaved into

public string FirstName
{
    get { return GetValue<string>(FirstNameProperty); }
    set { SetValue(FirstNameProperty, value); }
}

public static readonly PropertyData FirstNameProperty = RegisterProperty("FirstName", typeof(string));


But now we added a new feature to Catel.Fody. If a read-only computed property like this one exists:

public string FullName
{
    get { return string.Format("{0} {1}", FirstName, LastName).Trim(); }
}

the OnPropertyChanged method will be also weaved into

protected override void OnPropertyChanged(AdvancedPropertyChangedEventArgs e)
{
    base.OnPropertyChanged(e);
    if (e.PropertyName.Equals("FirstName"))
    {
        base.RaisePropertyChanged("FullName");
    }
    if (e.PropertyName.Equals("LastName"))
    {
        base.RaisePropertyChanged("FullName");
    }
}


This feature is already available in the latest beta package of Catel.Fody.

Try yourself and let us know.

X-ray StoneAssemblies.MassAuth with NDepend

Introduction A long time ago, I wrote this post  Why should you start using NDepend?  which I consider as the best post I have ever...