Dan's Green Shoes

Got my green shoes on!

clip_image010_thumb.jpg


4 Comments

SignalR with Silverlight 5

SignalR is truly an amazing API. It’s ridiculously easy to use. The majority of SignalR client examples that I see on the web are for HTML/JS or WPF. There are examples for Silverlight but for older version of SignalR and Silverlight. What I was hoping to find was a step by step example using VS2k12, SL5 and latest greatest Nuget Packages. Since I could not find one, I thought I would create one and share. This step by step was highly inspired by the samples found here:

https://github.com/SignalR/SignalR/tree/master/samples

Setting up the Solution

Recommend you download the code and follow along. In Visual Studio 2012, create a new Silverlight 5 application called “SilverlightClientSignalR” as seen below. Continue reading


2 Comments

Calling into your database on Silverlight Application_Exit

My team has developed several Line of Business applications using Silverlight.  Most but not all have at least 3 if not all of the following feature requests:

  • Allow users to be signed into the LOB more than once. Users like having more than 1 browser tab or even more than 1 browser type with the LOB app loaded simultaneously.
  • Ability to differentiate between a user in Tab1 versus Tab2 for purposes of concurrency, etc.
  • Limit the number of simultaneous sessions a specific user can have. 1 is a valid constraint.
  • Automatically log out a user instance after X seconds a.k.a session time out
  • Gather user information such as browser type/version, screen resolution, IP, etc
  • # of concurrent distinct users logged in over time.
  • # of concurrent users logged in over time total.
  • Max or average simultaneous sessions by users.

All of these are good feature requests for any Line of Business Application. Thinking through it, these features share an implementation detail that requires the LOB to track each signed in user instance.

Implementation Plan

Here was the plan.

  1. Create a new database table called AppInstance. This table will contain a list of all the active users in the system.
  2. Create a new database table called ArchivedAppInstance. This table contains all previously logged in users.
  3. Whenever a user logs in, add a row to the AppInstance table that records the UserId, timestamp of when that user logged in and any other information your LOB might want to know.
  4. Whenever a user logs out, archive the #3 AppInstance row to ArchivedAppInstance table noting the logged out timestamp.

The information in these 2 new tables enable the implementation of the features above. Conceptually this is very simple. In fact, 1 through 3 above are easy. #4 it turns out, in Silverlight was not as straight forward as one might think. Why? First, there are multiple ways the application can be exited such as clicking the LOB “Log Out” button, closing the browser directly, navigating away from the LOB web page or, heaven forbid, a browser crash. Except for crashing, the Silverlight application’s Exit event is raised but if you try to perform some backend action like calling a web service it won’t go through since the thread required to make the service call itself is gone.

I worked on a team to solve this. My colleague Tammy McClellan recently documented our approach for other product owners internally and I thought I would share on my blog. In addition, Tammy created an extremely small and simple sample application with our implementation. You can find the code here.

Continue reading


1 Comment

Using your “User” table with MVC4 Internet Template

The MVC4 Internet template assumes that it will be adding a user table called “UserProfile” to your database.  What I think a high percentage of developers would want is to use their domain model’s “user” entity and have SimpleMembership just manage the passwords.  In this blog post I will demonstrate how I did this and welcome alternative suggestions.
I recommend you first understand the authentication process provided by the MVC 4 Internet template.  There are 2 fantastic posts you should read first.

  1. MVC 4 Authentication
  2. SimpleMembership, Membership Providers, Universal Providers and the new ASP.NET 4.5 Web Forms and ASP.NET MVC 4 templates

In addition, please check out Scott Allen’s excellent Pluralsight course called “Building Applications with ASP.NET MVC 4”.

MVC 4 Internet Template with pre-existing Domain Model

Create a new ASP.NET MVC 4 Internet Application and name it “SimpleMemberExample”

image

Custom Domain Model/Database

The first thing I want to do is create the custom domain model/database.  In the “Model” directory, lets add a class that represents our custom “User” table.  Lets call this custom user entity “Administrator” as seen here:

namespace SimpleMembershipExample.Models
{
    public class Administrator
    {
        public Administrator(){}
        #region Fields and Properties
        public int Id { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
        #endregion
    }
}

(I was unable to figure out how my user table’s unique identifier could use a Guid.  I think the unique identifier of your custom user entity/table must be an int to use SimpleMembership.  anyone know?)

Lets add a custom DbContext as shown here to the root of the project.

using System.Data.Entity;
using SimpleMembershipExample.Models;

namespace SimpleMembershipExample
{
    public class SomeAppDbContext: DbContext
    {
        public SomeAppDbContext(): base(nameOrConnectionString: "SomeAppName"){}
        public DbSet<Administrator> Administrators { get; set; }
    }
}

The DbContext only contains a single table called Administrators just to keep this super duper easy.  Yours would contain lots more. Notice in the custom constructor, I am telling the DbContext to use a specific connection string.  Lets add that connection string to the Web.Config.

image

This connection string could be anything you want it to be.

Just for demo purposes, I am naming the database “SomeAppName”.  As a final step, in “Global.asax.cs”, put the following code:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        SomeAppDbContext dbcontext = new SomeAppDbContext();
        dbcontext.Administrators.All(i => i.Name != "Dan");

Running the application, the magical EF Code First will create the following database.  We have a custom database with a custom user table called “Administrators”.

image

Customizing MVC 4 Internet Template

Remove InitializeSimpleMembershipAttribute

The Internet template contains an Action filter called “InitializeSimpleMembershipAttribute”.  I deleted that class and removed any references to it.

Replace UserProfile with your Custom User Entity

The Internet template assumes that it will be adding a user table called “UserProfile” to your database.  What I think a high percentage of developers would want is to use their domain model’s “user” entity and have SimpleMembership just manage the passwords.  Let me demonstrate how to do this.

In the “Model” folder, in the “AccountModel.cs” file, delete the “UserProfile” class.  We want to use our “Administrator” entity instead.  Wherever UserProfile is referenced elsewhere, replace with Administrator.   The original UserProfile had properties called “UserName” and “UserId”.  Administrator has properties “Name” and “Id”.  Make sure to sync those properties up.

I want to have only 1 DbContext and I want to use my DbContext.  In the “Model” folder, in the “AccountModel.cs” file, delete the “UsersContext” class.  Wherever UsersContext is referenced elsewhere, replace with SomeAppDbContext.

Call WebSecurity.InitializeDatabaseConnection

As a final step, in “Global.asax.cs”, put the following code:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        SomeAppDbContext dbcontext = new SomeAppDbContext();
        dbcontext.Administrators.All(i => i.Name != "Dan");
        WebSecurity.InitializeDatabaseConnection("SomeAppName", 
            "Administrators", "Id", "Name", autoCreateTables: true);

WebSecurity.InitializeDatabaseConnection takes the web.config connection string name, the name of your custom user table (“Administrators”), the unique identifier field name of your user table (“Id”) and the user name field.  Running the InitializeDatabaseConnection method does several things:

  1. Initializes the static Roles and WebSecurity classes.
  2. Adds the following tables to your database: webpages_Membership, webpages_OAuthMembership, webpages_Roles, webpages_UsersInRoles, UserProfile.

Running the Internet Application

When you run the code with those changes, the following database is created:

image

The home screen looks like this:

image

Click on the Register link in the upper right.

image

Fill out the form and click the “Register” button.  The MVC 4 Internet template application will navigate you back to the home page.

image

Notice it knows the name you registered with.  If you check for cookies, you will see the typical ASPXAUTH as shown below.

image

If you click the “Log off” link and check cookies, the ASPXAUTH cookie disappears.  The ASPXAUTH cookie is the key to the authentication.

When you look at the database you will see the following:

image

Notice with the code changes, the MVC Internet template knew to save to the custom user table “Administrators”.  The password was saved to the webpages_Membership table with a foreign key relationship to the Administrators table.

Please download the code here.

OfficeStore


Leave a comment

“Old School” Office Add-ins: Windows Store versus Office Store

I just completed ProModel’s end of year technology review with the product owners and Keith Vadas, the CEO of ProModel.  There was some reflection on the year past, but the primary focus was on the roadmap for next year for ProModel’s portfolio of decision support tools.

  Web Based Office Add-In Custom COTS
Portfolio Simulator X
Enterprise Portfolio Simulator X X
Process Simulator Visio X
ProModel X
Enterprise ProModel X X
Clinical Trial Simulator X
Project Simulator MS Project X
Army Synchronization Toolset X X
Lead Materiel Integrator – Decision Support Tool X X
Custom DOD Application3 X X

Notice that 2 of the products are Microsoft Office Add-ins.  During the end of year meeting, I found myself struggling to communicate the impact the release of Windows 8 RT and Pro have on the 2 add-ins, specifically the introduction of “App” stores.   Unlike Apple and Google’s model of a single App Store, Microsoft has many stores.  For Office Add-ins, the 2 primary stores of interest are the Windows Store and the Office Store.

Continue reading


4 Comments

HTML JavaScript Gantt libraries

I am working on a project at ProModel that requires a Gantt visualization of data using open web standards.   I thought it would be valuable to share my list of HTML JavaScript controls.  If I am missing anything, please reply and let my team know!

Gantt Component Name Online Example
Teamwork Gantt http://gantt.twproject.com/distrib/gantt.html
Ext Gantt http://www.bryntum.com/examples/gantt-latest/examples/advanced/advanced.html
dhtmlxGantt http://dhtmlx.com/docs/products/dhtmlxGantt/index.shtml
dojox.gantt http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/gantt/tests/test_Gantt.html
DevExpress MVC Extensions http://mvc.devexpress.com/Chart/GanttViews
jQuery.Gantt http://taitems.github.com/jQuery.Gantt/
http://www.maro-z.com/examples/jquery.gantt/
VARCHART Xgantt http://www.netronic.com/gantt/gantt-software.html?gclid=CPX5t_jI77MCFc5cMgodHxsAdg
JS Gantt http://www.jsgantt.com/
RadiantQ http://demos.radiantq.com/jQueryGanttDemo/Demo.htm
DlhSoft Gantt Chart Web Library http://dlhsoft.com/GanttChartWebLibrary/Demo/MainWebForm.aspx
DayPilot.org www.DayPilot.org
EJS TreeGrid http://www.tgantt.com/treegrid/www/Gantt.html#’RunExample
Fusion Charts http://www.fusioncharts.com/goodies/fusioncharts-free/chart-gallery/show.asp?id=44
PlexityHide GTP.NET http://plexityhide.com/?page_id=33
Rgraph http://hacksaw.mmto.arizona.edu/src/RGraph_2010-03-27-stable/RGraph/examples/gantt.html
Sunflower http://www.51diaodu.cn/sfgantt/examples/SFProject/track.htm


5 Comments

Remembering the Fabios of Technology Book Covers

This weekend, my wife finally convinced me to donate my old technology books to the local library.  I called the library to make sure it was open and discuss the donation process.  To my surprise and insult, I had to beg the librarian to take my books :-).   The feeling I got was “Sir, I don’t want your overly large and no longer relevant books”.  How dare she!

Continue reading


1 Comment

How to Unblock Multiple Files

I have been busy learning new technology around HTML 5, JavaScript, ASP.NET MVC, etc.  I find myself downloading sample code from the web to learn from.  Inevitable, I cannot get somethings to run due to the file being blocked.  Files downloaded from the web retain Internet Zone permission level and hence are “Blocked” by default on Windows 7 machines.

With code downloads, there can be LOTS of files.  There is not a built in way that i know of to unblock multiple files at once.   A couple of websites allowed me to easily batch unblock the downloaded files:

http://geekswithblogs.net/wildturtle/archive/2011/11/08/all-in-a-days-work-unblocking-multiple-downloaded-files-with.aspx

http://www.elijahmanor.com/2009/09/recursively-unblock-assemblies-with.html

 

Follow

Get every new post delivered to your Inbox.

Join 446 other followers