Today, I went to Tools – Folder Options and saw a tab that was unfamiliar to me.  I am using Windows 2008 and saw the Search tab.  One of the options was the ability to include natural language search. 

image

After a little research, I turned this on and WOW!  It will search everything from outlook emails to mp3 metadata in a natural language format.  This is extremely useful.

Some examples of searches I have done with success:

  • Emails from Fred on NUnit
  • 1980 pop music
  • SOW for Company XYZ

 

Technorati Tags: ,

For the last several months, I have had several changes in my environment that has caused me to take a look at how I collect information.  I am now doing more research than ever, my job has changed, and I am working to become a more organized person (although I will never reach GTD nirvana).  Lately the questions for me have been:

  • Where did I see that sample?
  • Which email account did I get that information in?
  • Do you mean I have to retype all of these meeting notes?
  • What are my next priorities?

Sound familiar?  After playing around with OneNote for a couple of years, it took an aha moment for me.  I learned about sharing notebooks across computers.  This concept has now become invaluable.  Below are a few tips and tricks that I am starting to use with OneNote:

  1. Poor mans Tablet PC.  Last Christmas, I was given a Digimemo L20 for a gift.  This is a pretty ingenious piece of equipment and one I take with me whenever I go to meetings.  The software now includes a way to transport my notes (even in digital ink) to OneNote very quickly.
  2. Use a command line argument to start OneNote on a specific page/section (/hyperlink).  I usually take a little bit of time to discover command line arguments. This time I was a little late in looking at these, but what a time saver.  Every OneNote section or page has a hyperlink that is associated with it, which can be discovered by right-clicking on the page tab/section tab and selecting copy hyperlink to this page.  Combined with SlickRun, this is truly invaluable. OneNote Command Line Switches
  3. Using a notebook on multiple computers. Here is a link.
  4. Using it as a ToDo list manager.  I combine a Slickrun magic word with Todo to go to a specific page in my notebook that is shared across computers.  Get this, the tasks even integrate well with Outlook 2007.

 

Technorati Tags: ,

I stumbled across this article on Lifehacker today.  It demonstrates how to add a custom search on Vista’s Start menu.  I customized one for going to Dan Appleman’s SearchDotNet site.  Here is the text I used for the URL

 

http://www.searchdotnet.com/results.aspx?cx=002213837942349435108%3Ajki1okx03jq&q=%w&cof=FORID%3A9#1121

 

Notice, I put in the %w where my search text would go.  Now I won’t use slick run for custom searching on this site.

Last night I created an Excel spreadsheet that captured all of the basic information for my family, addresses and such.  I figured I would import it into Outlook.  I am currently running Outlook 2007.  What a pain that turned out to be.

  • There is no support for importing Excel 2007 spreadsheets.  Guess that was just an oversight from the Outlook Team.
  • After saving down to Excel 2003, no big deal, the import asked me to specify a specific range in the spreadsheet to import the contacts from.  I do know how to do this, however, once I created the range and resaved the spreadsheet in 2003 format, I kept getting errors
  • I ended up converting to a CSV format.  So during the import process, I could have just went through the wizard steps and imported the contacts giving me not a very good experience because my field names did not match those in Outlook.  Fortunately, I did mapped the fields and completed the import.

 

The bottom line in this for me was that the customer experience was not too good.  Here are a number of things that I would have improved upon:

  1. Ensure that a user was able to import with the same Office Version.  Not too much to ask I think.
  2. Give more explicit instructions on what was needed to successfully import an Excel file up front in step one of the wizard.  I would have canceled, created the named range, and voila, complete.  Even better, have Outlook inspect the Excel file and help determine the range.
  3. When mapping the fields, it was not intuitive to drag the column names of the the import file to the Outlook field names, unless I missed some instructions.

 

My rant for the day.

 

Technorati Tags: ,

Those of you that use RhinoMocks probably know how to do this already, however, I spent about twenty minutes getting this right.  I was writing a test that was looking to ensure that a call to a mocked object doesn’t happen.  As I created the test, it passed right away which was a bad sign, even though the mocked object was being called.

There are a couple of methods a person can use to create mock objects.  Be sure to use the right one for your test.

  • MockRepository.CreateMock – This creates a mock object where errors will be thrown for any method that is called and not recorded
  • MockRepository.DynamicMock – This creates a mock object where errors will not be thrown by unrecorded methods.

 

In brief, I first used the DynamicMock<T> method which of course swallowed the call and didn’t throw the error.  So after changing to CreateMock<T>, here is how my final test ended up:

 

image

 

A couple things to note:

Notice that the using for the record has no Expect calls

 

Technorati Tags: ,
  • What are my cookie values? 
  • What are all the items I have in a current session? 
  • How can I know how much ViewState is on a page? 
  • For the last request I made, how many times did I call a particular method?

As an ASP.Net developer, these are constant questions that I run into while developing.  In a conversation with a co-worker, he suggested that the application should have a “developer’s toolbar”, that could get displayed as needed on a page to answer some of these questions? What a great idea.  But how do I go about it, so that it isn’t part of my production code? What are my options?

  • Use compilation constants to remove the code as it is released.  I try to stay as far away from compilation constants as possible.  Too many bad experiences.
  • Use a configuration setting.  This might be an option.  However, this feels like putting development code into production.
  • Create a HttpModule or HttpHandler.  I have never written one of these, but some reading indicates that it might be possible.

In the end, I chose the HttpModule / Handler route.  Here is the story for it.

Creating the HttpModule

First I started by creating a new class library and adding a new class that implements IHttpModule.  I then hooked into the following events:

 

image

PreRequestHandlerExecute

I used this event to tackle the issue of deciding whether or not to show the toolbar.  This was challenging for me because I used a Session and a QueryString to determine this for me.  The reason for this is I wanted the toolbar to be off by default, in case the web.config file included the HttpModule and went to production.  Second, I wanted a way that the developer at any time could show the toolbar or hide it.

This event is the first time that the developer gets access to Session data in the pipeline for an HttpModule.  For the longest time, I was getting errors and couldn’t understand why I couldn’t read or write to the session.  I added the following interface IRequiresSessionState to the class and this solved my problems.

Here is the code that I used to check if the toolbar should be available.

image

 

If the toolbar should be visible, the code to create the toolbar is implemented.

image

 

Notice a couple of things with this code.  First I created custom handler classes for items like cookies, logs, and sessions.  I placed them in the same assembly as the HttpModule so that I could create kind of a package deal.  After the standard web.config entries for handlers and modules, this code is in a working state, but not where I want it to be.  That is where the BeginRequest and a custom Filter came in.

Here is the result of the toolbar at the bottom of the page

image

 

BeginRequest Event

I used the BeginRequest event to set the Response.Filter equal to a custom filter.  The reason for this only became evident when I looked at the view source on a page. 

This is what it looked like before the filter:

image

Here is after the filter.

 

image

 

Notice how the toolbar itself was originally after the end html tag.  This is because I am writing to the Response.Output method the toolbar.  In the HttpModule when making Response.Write calls, they are placed at the end of the stream of the page. In another post, I will look at the Response.Filter and how I used that.

 

One of the challenges I am currently facing is how to manage Resources in a web farm.  I have written a custom provider, that uses a database as it’s main storage mechanism.  Thanks to Michèle Leroux Bustamante for writing a wonderful article on steps that need to be taken to do this. So far, it has been working wonderfully except for one issue.

I want to be able to make a change to a value in the database and be able to see that value in “real time” on the website.  So far, I have only found two ways to accomplish feat.

  1. Recycle the application – This of course is not acceptable, due to the fact I may have more than twenty servers to reset, among other obvious things like screwing up the user experience on the site.
  2. Modify the web.config, which basically does the same thing as #1.

After a lot of research, I have concluded that the resources are cached.  I read in an article that these cache values were not accessible and that was by design because resources are static.  I am looking for a way to just reset these cached resources without affecting the rest of the application.  Any help would be appreciated.

 

 

Technorati Tags: , ,

As I was creating a few properties in the Application settings class in Visual Studio 2008, I noticed a new dropdown as part of the screen.  It allows for the changing of the access modifier for the Settings Class, it can now be either internal or Public.  Now there is a way to expose these settings externally.  By default they are Internal, but I made this one public.

image

 

For more information on using the settings class, http://msdn2.microsoft.com/en-us/library/cftf714c(VS.90).aspx

 

As an avid fan of CodeRush, I am awed at the extensibility that this product provides.  One area is in the extensibility of creating custom plugins.  I took the time this weekend to understand how to build a custom metric after seeing a training video up at the DevExpress site.  The metric I chose to build was one that counted the number of returns in a method.  This metric will be useful in code reviews to see if a method may be too complex based upon the number of returns.

Here are my high level steps:

 

1.  Create a new plugin project.

image

 

2.  Drag and drop a CodeMetricProvider from the toolbox and set the following properties

image

3.  Implement the method for getting the metric value, it should look something like this:

        private void metricReturnsCounter_GetMetricValue(object sender, DevExpress.CodeRush.Extensions.GetMetricValueEventArgs e)

        {

            if (e.LanguageElement is Member)

            {

                Member member = (Member)e.LanguageElement;

                int counter = 0;

                foreach (LanguageElement element in member.AllFlowBreaks)

                {

                    if (element.ElementType == LanguageElementType.Return)

                        counter++;

                }

                e.Value = counter;

            }

 

        }

That’s it, the final result looks like this in the metrics window of CodeRush:

image

As you can see, it looks like there is a lot of work that can be done on a couple of these methods, to clean the number of returns up.

 

Technorati Tags: , , ,

  Update:  removed my mock object from the new test for clarity.

I have reevaluated my approach to how to write a test to catch exceptions.  NUnit has an attribute for ExpectedException which I have been using to test exceptions in my code.  I ran across an instance of a specialized Exception the other day, that had custom parameters as part of the exception.  Using the ExpectedException attribute, I was able to test that the Exception was thrown, but not the custom parameters that were part of the Exception. For example of an Exception with custom parameters, check out the framework MembershipCreateUserException.

 

Here is the setup code to put the tests in context.

 

        DynamicMock mockService;

        IAuthenticationContract agent;

        CustomMembershipProvider provider;

 

 

        [SetUp]

        public void Setup()

        {

            mockService = new DynamicMock(typeof(IAuthenticationContract));

            agent = (IAuthenticationContract)mockService.MockInstance;

            provider = new CustomMembershipProvider(agent);

 

        }

 

My original Test looked as follows:

 

        [Test]

        [ExpectedException(typeof(MembershipCreateUserException))]

        public void ValidateUserReturnsFalseWithBlankPassword()

        {

 

            mockService.ExpectNoCall(“ValidateCredentials”);

 

            provider.ValidateUser(“Someone”, “”);

            mockService.Verify();

 

        }

 

What I am expecting is that the provider.ValidateUser() call will throw the exception.  This does work as expected, but at this point I only get that a type of MembershipCreateUserException was called. I cannot inspect any properties of the exception at this point, but the test passes.

 

Here is my new test:

 

        [Test]

        public void ValidateUserReturnsFalseWithBlankPassword()

        {

 

            try

            {

                provider.ValidateUser(“Someone”, “”);

                Assert.Fail(“The Blank Password should have thrown an Error”);

 

            }

            catch (MembershipCreateUserException ex)

            {

                Assert.AreEqual(MembershipCreateStatus.InvalidPassword, ex.StatusCode);

            }

 

 

        }

 

Notice that my intent is also to just ensure the the provider.ValidateUser() call is going to fail.  I am catching this exception that is expected and validating the Exception status.  This last test more explicitly states my intent of the test.

 

Technorati Tags: , ,

« Previous PageNext Page »