Blog

SQL Saturday Baton Rouge 2014

First, SQL Saturday Baton Rouge 2014 has opened registration and placed the session list online. If you’re interested in development at all this is a must attend event. The sessions span all areas of development. The tracks include: .NET, Business Intelligence, Career Development, CIO/IT Manager, DBA, IT Pro, PowerShell, SharePoint, SQL Dev, and Web/Mobile dev. Please visit the website and sign up if you’re interested.

Secondly, I will be presenting “Testable WebForms with MVP”. This will be an intermediate topic and I’ll be assuming experience using ASP.NET WebForms and a basic understanding of unit testing. All code examples will be in C#. Here’s the description I sent in:

MVC is all the rage but what about all the code you already have written in ASP.NET WebForms? How can you make it maintainable and testable? In this session, I’ll show how you can make WebForms applications testable using Model-View-Presenter.

ASP.NET Forms Bootstrap Menu Control

UPDATE: I have closed the comments for this post. If you’d like to discuss the ASP.NET Forms Bootstrap Menu Control, please visit the GitHub repository located at: https://github.com/jeremyknight-me/aspnet-forms-bootstrap-menu


When I couldn’t find an ASP.NET Form menu control that was compatible with Bootstrap 3.1, I did what every other developer would do: I created one. Enjoy!

Here’s the HTML markup view:

<div class="navbar navbar-inverse navbar-static-top" role="navigation">
    <div class="container" style="padding: 0; margin: 0;">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="navbar-collapse collapse">
            <jk:BootstrapMenu ID="BootstrapMenu1" runat="server">
                <Items>
                    <asp:MenuItem Text="Home" NavigateUrl="#" />
                    <asp:MenuItem Text="About" NavigateUrl="#" />
                    <asp:MenuItem Text="Contact" NavigateUrl="#" />
                    <asp:MenuItem Text="Drop Down">
                        <asp:MenuItem Text="Action" NavigateUrl="#" />
                        <asp:MenuItem Text="Another action" NavigateUrl="#" />
                        <asp:MenuItem Text="Something else here" NavigateUrl="#" />
                    </asp:MenuItem>
                    <asp:MenuItem Text="Help" NavigateUrl="#" />
                    <asp:MenuItem Text="Nothing" />
                </Items>
            </jk:BootstrapMenu>
        </div><!--/.nav-collapse -->
    </div>
</div>

Here’s the HTML markup view for using with a SiteMapDataSource:

<div class="navbar navbar-inverse navbar-static-top" role="navigation">
    <div class="container" style="padding: 0; margin: 0;">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div class="navbar-collapse collapse">
            <jk:BootstrapMenu ID="BootstrapMenu2" runat="server" DataSourceId="SiteMapDataSource1" />
            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
        </div><!--/.nav-collapse -->
    </div>
</div>

In either case you’ll need a page directive

<%@ Register tagPrefix="jk" assembly="JK.Core.Web" namespace="JK.Core.Web.Controls" %>

Updates:

  • 2017 January 23: Closed comments to push conversation to GitHub repository.
  • 2015 January 19: Added zip file sample project for download to OneDrive.
  • 2014 August 15: Added page directive needed to use control in page markup
  • 2014 April 11: Updated to work with SiteMapDataSource

What Tools Do I Use?

At Houston TechFest 2013, Claudio Lassala presented “Want to Build Software? Get Your Act Together First!“. It got me thinking about how I work and what software I would recommend. The following tools fit into two categories. I either use it daily or it’s invaluable in specific situations (for example, taking screenshots or giving presentations).

The Data I Need When I Need It

I use a combination of three pieces of software to ensure that I always have all of the information I need at my fingertips. The three are: SkyDrive, OneNote, and KeePass.

SkyDrive is the Microsoft DropBox competitor. I use it for a 2 reasons. The first reason is it that it offers more storage for free. SkyDrive gives 7 GB while DropBox gives 2 GB. I actually have 25 GB due to an old SkyDrive promotion. The second reason is that I can view and edit all of my files directly through a browser. This has become extremely important to me. For example, I was recently in a meeting and a presentation that I was working on came up. I didn’t have my laptop but the meeting room had a computer connected to the screen. I was able to log into my SkyDrive and review the presentation directly from my SkyDrive.

OneNote is Microsoft’s note taking software. Evernote is a popular competitor and one that I have tried before. When OneNote was released for my mobile platform, I immediately switched back. Now I have access to my notes anywhere I have my phone or have access to an internet browser (I can view and edit my OneNote notebooks through SkyDrive).

KeePass is a password manager tool. We have passwords for everything now and they should all be unique and varied. How does it work? You create one password for your encrypted KeePass file and you place all of your other passwords into the file.

Collaboration

I currently work on a distributed team so having effective tools in place for collaboration and communication is a must.

For task and backlog tracking, we use Team Foundation Server. If TFS wouldn’t be available, I would be using Trello or a tool with similar features.

For voice, we use Skype. It’s simple, effective, and proven. Its screen sharing feature comes in handy if it’s just a quick discussion. For more complex screen sharing, we use TeamViewer. TeamViewer allows users to pass control around. This comes in extremely handy when working through code with another developer. Another plus is that TeamViewer has official apps for Android, Windows 8, Windows Phone 8, and iOS.

Let’s Develop Something Already!

I have already mentioned that I work in a Microsoft development team so Visual Studio is a must. I currently have 2010 and 2012 installed on my machine but we will be moving everything to 2013 on its release. If you’d like to know which plugins I’m using for Visual Studio, see my post “Visual Studio Add-ons“.

Everyone has their own favorite text editor and mine is Notepad++. It’s always the first thing that I install on a new machine and I immediately set it as my default text viewer. I’ve recommended it to every developer friend that I know. It has lots of goodies throughout the program including plugins. For example, the Compare plugin has taken the place of WinMerge on my machines and ToolBucket let’s me easily generate GUIDs and lorem ipsum, encode/decode to base 64, and more.

A great tool for testing .NET code snippets, LINQ statements, etc. is LINQPad. This little application is extremely feature packed and you’ll find more ways to use it every time you open it. One of my favorites is the ability to generate the SQL for a LINQ statement.

IETester by DebugBar is a must have for web developers wanting to test their website’s rendering in multiple IE versions.

Greenshot is my go to application for screenshots. It has multiple capture modes and a built in image editor which allows you to edit an image before saving the final version.

Presentation Must Haves

If you’re giving presentations or sharing screens often, I have a couple of recommendations.

The first suggestion is Key Jedi. Presenters tend to forget that the viewers don’t know when you press Alt, Ctrl, etc. This is a little application displays those special combination keystrokes so that your audience doesn’t get lost when you’re flying around Visual Studio using only the keyboard.

The second is ZoomIt. This application allows you to Zoom in and out of any application running in Windows. It also has some markup features which are quite nice once you get used to the keyboard shortcuts.

Lazy Strategy Pattern

The following are some code samples that show how to use Lazy to clean up how your objects are initialized when using the Strategy pattern in .NET. The following code is taken from the DimeCast.Net Strategy pattern video. It uses an enum to select the correct logging strategy and logs the given message. The original code from the video before Lazy is applied looks like (by the way, I’m only posting the sections relevant to strategy and lazy):

public class LoggingService : ILoggingService
{
    private readonly Dictionary<LoggingStrategy, Logger> strategies;

    public LoggingService()
    {
        this.strategies = new Dictionary<LoggingStrategy, Logger>();
        this.DefineStrategies();
    }

    private void DefineStrategies()
    {
        this.strategies.Add(LoggingStrategy.Event, new EventLogger());
        this.strategies.Add(LoggingStrategy.Repository, new RepositoryLogger());
        this.strategies.Add(LoggingStrategy.Trace, new TraceLogger());
    }
}

Here is the same code using the Lazy<T> class in the System namespace.

public class LazyLoggingService : ILoggingService
{
    private readonly Dictionary<LoggingStrategy, Lazy<Logger>> strategies;

    public LazyLoggingService()
    {
        this.strategies = new Dictionary<LoggingStrategy, Lazy<Logger>>();
        this.DefineStrategies();
    }

    private void DefineStrategies()
    {
        this.strategies.Add(LoggingStrategy.Event, new Lazy<Logger>(() => new EventLogger()));
        this.strategies.Add(LoggingStrategy.Repository, new Lazy<Logger>(() => new RepositoryLogger()));
        this.strategies.Add(LoggingStrategy.Trace, new Lazy<Logger>(() => new TraceLogger()));
    }
}

And one final time just in case you don’t have access to Lazy<T>. This uses delegates to accomplish the same thing as the Lazy<T> class. I’ll be using the Func<TResult> delegate.

public class DelegateLoggingService : ILoggingService
{
    private readonly Dictionary<LoggingStrategy, Func<Logger>> strategies;

    public DelegateLoggingService()
    {
        this.strategies = new Dictionary<LoggingStrategy, Func<Logger>>();
        this.DefineStrategies();
    }

    private void DefineStrategies()
    {
        this.strategies.Add(LoggingStrategy.Event, () => new EventLogger());
        this.strategies.Add(LoggingStrategy.Repository, () => new RepositoryLogger());
        this.strategies.Add(LoggingStrategy.Trace, () => new TraceLogger());
    }
}

Now that all the code is out of the way, let’s talk a little about why you would want to use this. Let’s look at the original code sample. The DefineStrategies function initializes a Logger object and adds it to the Dictionary. Every single Dictionary.Add call in the original code is initializing an object. That’s additional memory and processing time for every object. By using Lazy(or the delegate method shown above), you postpone the initialization of the object until you actually ask for it.

Lazy initialization may not work well for everything but I’ve found that it makes strategy implementations much more lean and efficient in terms of machine resources.