Taswar Bhatti
The synonyms of software simplicity
ASP.NET-MVC

To enable https on asp.net mvc, one can use the [RequireHttps] attribute on the base controller if you are using a base controller

But what if you want to give an option to the installer or the client to enable it in web.config, the easy way to do it for asp mvc2 is to create your own property like code below: (Please note: I am using protected virtual to override stuff for testing, its not one of the best things but it works in breaking dependency and its quick, so that I dont have to mock httpcontext, configuration manager etc etc, I could use an IoC but would make it more complicated for the reader but feel free to use one)

Here is the unit test for it, I am using a stub class to override the things I want for testing

Now in your web.config you can add a key value pair like

And last if you are using Asp.Net Mvc3 life is way easier, one can just use in their Global.ascx file to add the filter

Lastly you would add it to your BaseController

jquery

Was debugging some code that was broken due to jquery 1.6 update, and found this call for Jquery dropdown.val

Not working anymore but a simple fix of changing it to

This does the trick, for more on prop take a look at the api of jquery http://api.jquery.com/prop/

MSSQL

So was hacking a new installer and wanted to display the data link properties dialog, for building a connection string.
Here is what I have found out by playing with it.
One has to add the reference to ADODB.DLL (from .NET reference) and Microsoft OLE DB Service Component 1.0 Type Library from the COM tab in your visual studio reference tab.

Here is some sample code, assuming that you have a button and a textbox on the screen.

And here is how it looks like

Once a user clicks on build, the Data Link Properties Shows up.

Data Link Properties Dialog

Also note: that I am providing some default into the connection, since if you do not provide “Provider=SQLOLEDB.1” then the default is just OLE database not the MSSQL database option.

Rubymine

In order to run Rubymine under a 64bit jvm one needs to run the IDE from the bat file.

In the bat file which is located at C:\Program Files (x86)\JetBrains\RubyMine 3.1.1\bin add this line

SET RUBYMINE_JDK=%ProgramFiles%/Java/jdk1.6.0_25

and remove the IF statements
::IF “%RUBYMINE_JDK%” == “” SET RUBYMINE_JDK=%JDK_HOME%
::IF “%RUBYMINE_JDK%” == “” goto error

Run the rubymine.bat file voila 64bit jvm.

Mocking

Thanks to everyone who came to Unit Testing with Mocking Framework at the code camp today, I will get those Typemock license to the 2 winners.

Here is the code if anyone is interested
https://github.com/taswar/Ottawa-IT-Code-Camp-Unit-Testing-with-Mocking-Framework

Here is the presentation.

VisualStudio

So I had this issue at work had to install on xp machine, dont ask why but just had to 🙂 and the error was NET 4, Visual Studio 2010 install fails on XP SP3 machine “Fatal error during installation”

Thus I was stuck installing Visual Studio 2010, I went and downloaded .net 4 standalone

And was having the same issues.

And went through the logs and found the error message was due a registry key (aren’t they always)

Product: Microsoft .NET Framework 4 Client Profile — Error 1402. Could not open key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Security\ServiceModel 4.0.0.0. System error 5. Verify that you have sufficient access to that key, or contact your support personnel.

So I went to regedit, went to that key and added Administrators rights to it and run the installer again and everything was fine and installed vs2010 and .net 4 finally…………….

Anywayz just in case anyone runs into this issue again, this was the solution.

browser testing

Thanks to everyone who came out for the Ottawa .Net Community talk yesterday on WatiN , SpecFlow, BDD, WebDriver, I had a blast. I would like to thank everyone who came out for the talk.

Here is my presentation

You can find the code on github
https://github.com/taswar/ODNC-WatiN-And-SpecFlow-Demo-Code

Additional Resources

Here are some additional information for people who wish to learn more Gherkin style of BDD. Cuke4Nuke provides a free pdf file on learning cucumber BDD although not specflow but gives you a good idea of learning it.

http://www.cuke4ninja.com/

Steve Sanderson has a blog post where he explains BDD style with WatiN and specflow
http://blog.stevensanderson.com/2010/03/03/behavior-driven-development-bdd-with-specflow-and-aspnet-mvc/

Brandon Satrom also has a series of video which shows how to use specflow with WatiN
http://userinexperience.com/?tag=/aspnet-mvc

lg-p500-optimus-one

So Koodoo is having a deal on android phone LG Optimus One LGP500H and I couldnt resist and picked one up and unlocked it and wanted to start development on it. So here are some steps on LG Optimus One LGP500H installing usb driver.

So my first step is to get the USB driver working on my win7 machine.
I went to LG and downloaded their Mobile Support Tool to PC from http://www.lg.com/ca_en/support/product/support-product-profile-mobile-redux.jsp?customerModelCode=LGP500H&initialTab=drivers&targetPage=support-product-profile-mobile-redux

Once downloaded I launched the app.
Here is a step by step instructions of it.

One has to click on the Install USB Driver (yeah I know it looks grey out but one can click on it)

Next select the model of your phone and double click, which is LGP500H for us.

Then it will launch the install of the driver and select English

Click Next

And you will next see that the install is successful.

Now you can plug in your phone and it should try to update it but since its update to date there is nothing to install optionally one can install the mobile sync app and manual.

Hope this helps 🙂

automapper

In this last part of the series I wanted to talk about how to register automapper at startup of your web application, in doing so it would help speed things up with automapper.

There are many ways to do it, the easiest way is to just have a method inside Global.asax.cs file in your Application_Start like below

And if you are using an IoC container, than one can use the Command Pattern for a StartupTask, below is an example of using ServiceLocator for startup.

Note: one will need to remove all the CreateMap code in their controller to here, you do not need to call CreateMap anymore since the startup task takes care of it.

This concludes our final segment on Automapper, hopefully you will find this helpful 😛

Previous Post:
Part 1 (NullSubsitution)
Part 2 (Flattening by Convention)
Part 3 (Nested Mapping)
Part 4 (Projection)
Part 5 (CustomResolver)
Part 6 (CustomFormatter)

automapper

In this part I will show how we can use a customer value formatter (CustomFormatter) to format our mapped data into single “Number of Order:” and plural “Number of Orders:”.

First the Domain and Dto (data transfer object)

Now we will introduce a CustomResolver and Formatter, for the Formatter we are inheriting from IValueFormatter

For our mapping code we will use a block for options, so that after resolving the value, it would format it.

From the view we can see that the first order is displaying Order rather than Orders.

In the last part of the series I will show how to move all your mapping code to startup, so that it would speed things up.

Previous Post
Part 1 (NullSubsitution)
Part 2 (Flattening by Convention)
Part 3 (Nested Mapping)
Part 4 (Projection)
Part 5 (CustomResolver)

UA-4524639-2