Archives

Archives / 2011 / February
  • ASP.NET Tips and Tricks on dnrTV

    I recently did a show with Carl Franklin on ASP.NET Tips and Tricks, recorded for dnrTV.com.  In it, I go through a bunch of ASP.NET tips, from the oldies but goodies like Tracing and Caching, to some new ones like optimizing the performance of your ASP.NET MVC 3 applications.  The samples from the presentation are available for download here. more

  • What are you working on?

    If you ask a newly-hired developer this question while they are busy coding away on something, you’ll usually get an answer like “the Acme project.”  If that’s too obvious (after all, maybe that’s the only project this dev works on), then the answer might be “the new xyz feature” or “that abc bug.”  All of these are more-or-less valid responses, and depending on the scope of the response, they might be sufficiently clear to narrow down exactly how far along the dev is in getting the overall feature, story, or bug complete.  However, what if you come back in a few hours, or the next day, and ask the same question, and you get the exact same answer?  How do you know what … more

  • How to Record a Screencast with Expression Encoder 4

    I’m a huge fan of TechSmith Camtasia and use it for pretty much all of my screencasts.  However, I’m currently recording some presentations for the Code Project Agile Virtual Tech Summit that’s taking place next week, and the preferred capture program for the platform is Expression Encoder 4.  So, I figured while I’m learning how to do it, I might as well share how it works and how I find it compares with Camtasia. To get started, you should download and install Expression Encoder 4.  It’s a free product with the features needed to record your screen (and audio). Next, set your screen resolution to whatever you want to use for the recording.  Typically, to keep the file … more

  • Building a CachedRepository via Strategy Pattern

    In part one of this series, I introduced the CachedRepository pattern, and demonstrated how it can be applied through the use of simple inheritance to an existing Repository class.  This allows us to easily configure whether or not we want to use caching at the repository level through the use of an IOC Container like Structuremap.  However, using inheritance to achieve the behavior isn’t always desirable, since generally it’s better to use object composition if possible (this tends to result in more flexible designs). One benefit of the inheritance-based approach is its simplicity.  Both in terms of the code require and in terms of wiring up the interfaces and … more

  • Introducing the CachedRepository Pattern

    In this first part of a series on adding support for caching to the Repository Pattern, I’d like to show how to very simply control whether or not caching is performed on a per-repository basis through the use of an Inversion of Control Container.  In this case, I’ll be using StructureMap with ASP.NET MVC 3.  One of the primary goals of this implementation is to follow principles of object oriented design, in particular the Single Responsibility Principle and the Don’t Repeat Yourself Principle. To start, take a look at the MVC Music Store sample application.  The Jan 13 2011 release doesn’t include any usage of the Repository pattern, so the first thing we will do is add a … more

  • Improving ASP.NET MVC Application Performance at MVCConf

    Yesterday I gave a presentation to a little over 300 attendees of MVCConf on Improving ASP.NET MVC Application Performance.  There were some great responses on twitter and generally the ratings on SpeakerRate were positive, which was great because I was a bit worried going into the presentation, since I’d only committed to giving a talk at the conference a few day earlier.  I’m uploading the recording of the session to the MVCConf team now, and will add a link here when it’s available. Since the session was less than an hour, I had a couple of small things that I had wanted to touch on but didn’t have a chance, so I’ll mention those now.  I mentioned that having Caching … more

  • Starting and Stopping Services on Remote Servers using PowerShell

    This wraps up my mini-series on using PowerShell to help manage services running on multiple remote servers.  In my case, these scripts exist to make it easy for me to globally start and stop services on a number of web servers that are part of Lake Quincy Media’s AdSignia ad platform – you can read more about the message-based architecture we’re using here. I learned the basics of starting and stopping services here.  I adapted this so that I could store all of my server’s names in one PowerShell script, and call into it with another to list all of the running servers on remote servers using another PowerShell script.  I also made sure to make the ListServices.ps1 script use … more

  • List Services Running on Remote Servers

    As I wrote earlier, Lake Quincy Media’s AdSignia ad platform is utilizing services and a message-based architecture to decouple the system from the database and improve performance and reliability of the servers.  It’s proven useful to quickly work with the services across multiple nodes in the web cluster, and PowerShell is the obvious choice for automating some of these tasks.  When building up a collection of PowerShell scripts to support an application, I recommend that you store them in source control with the application itself.  It’s also worth following the Don’t Repeat Yourself principle, which you can do by using PowerShell functions to return results from one … more

  • Pass Results from One PowerShell Script To Another

    If you’re using PowerShell but want to keep your scripts DRY, you may want to factor common functions into their own scripts, and then call these scripts from multiple other scripts.   This is pretty easy to do.  For instance, if you have an array of values that you want to use as inputs for several scripts, you could create a file like this one: Colors.ps1 function Colors { return "Red", "White", "Blue" }   Now, to use this in another PowerShell script, you simply need to load it by using a . and then assign the result to a variable after a semicolon (;).  Like so: ListColors.ps1 . … more

  • Message-Based Architecture Goodness

    Recently at Lake Quincy Media we upgraded our logging system for the AdSignia ad platform so that it uses messaging rather than direct SQL database access.  This allows us to log much more detailed data, which we can then analyze, and also improves the performance of every ad request, since it eliminates a database call and replaces it with a local queue operation, which is much faster and less likely to suffer from any kind of contention.  Prior to this, the logging information was stored in the application’s only database, which also included all of the reporting tables, user data, advertiser, site, and advertisement records, etc.  The new design sets logging aside as a … more

  • MSBuild Invalid Character in Connection String with dbproj

    If you get this error: error MSB5016: The name “Intitial Catalog” contains an invalid character “ “. or something similar when trying to specify a connection string within an MSBuild task, like this one: <MSBuild Projects="src\Databases\Northwind.dbproj" Targets="Build;Deploy" Properties="TargetDatabase=Northwind;TargetConnectionString=&quot;Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User Id=foo;password=bar;Enlist=False;&quot;" />     The issue is with the semicolons in the querystring.  If you replace them with %3B then the error goes away: … more

  • If Writing An Object That Is IDisposable, Don&rsquo;t Fail During Construction

    There’s a great pattern for ensuring that unmanaged resources are cleaned up in the .NET world.  It’s called the Disposable pattern and it applies to any resource that implements the IDisposable interface.  If you are writing an object that directly deals with unmanaged resources, such as files, database connections, network sockets, fonts, etc., then you are well advised to implement IDisposable and ensure your resources are cleaned up in your class’s Dispose() method.  Having followed this pattern, you’ll allow client code to clean up after itself by calling Dispose() as soon as they are finished with the resources your class uses, rather than waiting for the garbage … more

  • Getting Next Month in MSBuild

    I’m working on an application that needs to deploy a new database each month, in order to manage the large amount of data involved.  We’d like to automate this as much as possible, and since we already have the database schema in a Visual Studio 2010 database project, we figured the simplest thing would be to create an MSBuild task to do this, and then schedule it as part of our build server.  The format we want to use for the database name is simply “Databasename_201103” where the 201103 is next month’s year and month number (in this case, March 2011). So, to make the first part work is pretty simple.  You can pass in a parameter, TargetDatabase, to the Deploy task of a … more