CurtisMitchell

IThinkTherefore, IBlog

Archive for the ‘Miscellaneous’ Category

Code Camp Report

2 comments

Name: Chicago Code Camp 2010
Where: Illinois Institute of Technology, Chicago, IL
When: May 1, 2010

My Talk

 

I had an opportunity to present at the Chicago Code Camp. My talk was titled, “Seven Habits of Highly Effective ASP.NET MVC Developers.” It is a long title derived from Stephen Covey’s best selling business book, “Seven Habits of Highly Effective People.”

Similarly, the content of my presentation was derived from the habits and principles that Stephen Covey introduces in his book. The difference is the technical spin that I apply to make these principles relate to the job of developing web applications using Microsoft’s ASP.NET MVC framework. I presented habits that we as developers should adopt in order to effectively begin and maintain our web applications over their respective lifecycle.

Surprisingly, this topic was very popular at the Chicago Code Camp. Initially, I was expected to present in a room that seated about thirty people. However, the room quickly exceeded capacity and I was asked to present in a larger room. The seats in the larger room were quickly taken, and some attendees sat along a window sill in the back of the room.

At the conclusion of the talk, I had some great discussions with a few people with questions ranging from organizational concerns to technical implementation. I was able to answer many of the questions or offer relevant suggestions.

Overall, I felt like the presentation was well received. The initial feedback available on Twitter gave me the feeling that the experience was a pleasant one. Here are some example tweets that I read shortly after the talk:

“Learned a lot from your MVC talk. Hopefully you can go to CVNUG code camp some day”@cksanjose

“Highly Effective Habits of MVC Developers by Curtis Mitchell. This guy is crazy awesome”@jonathanbaltz

“Liking the MVC presentation. The speaker is really up beat. Keeps you interested.”@itsff

Talks I attended

 

Ioke ( by Ola Bini )

Ioke is an experimental language written by the presenter of this talk. It runs atop the Java Virtual Machine and it is inspired by many of the features in languages like Ruby and Lisp. It is a very impressive programming language. However, it is not intended for use in production applications. Ola Bini did mention he is working on a newer programming language. I am hoping the new language implements many of the features in Ioke, and become a viable language to use in production scenarios.

Limelight ( by Micah Martin )

Limelight is a framework written and actively maintained by Micah Martin’s company, 8th Light Incorporated. The framework allows developers to create desktop applications in the popular Ruby scripting language. In addition, the development experience is simple yet powerful. Limelight employs a web development-like paradigm. And, it makes deployment of these applications over the web very easy.

Micah also explained that Limelight applications should be considered rich internet applications (RIA) as well. He demonstrated Limelight links – a hyperlink that can be used to download and launch Limelight applications from a server. This eases versioning and maintenance of desktop applications because the deployed software is hosted on a server like a web application. And, users automatically get the most recent version when they launch the application from a web-enabled computer.

Making the web “F#”unctional w/BistroMVC ( by Scott Parker )

This talk focused on two things of interest to me: Microsoft’s newest .NET language, F#, and an alternative Model-View-Controller web framework, BistroMVC. The presenter was entertaining and very comfortable throughout the talk. He did a good job at targeting the “F# newbies” like myself and many others in attendance. The talk included a good introduction to F#. Unfortunately, due to time constraints, we weren’t able to get a good introduction to BistroMVC.

However, I learned enough to pique my interest in both technologies. I am going to definitely learn more about F# and do some more investigation into BistroMVC.

Web Testing with Visual Studio 2010 ( by Richard Campbell )

Microsoft released Visual Studio 2010 on April 12th of this year. They have put a lot of work into improving the features related to testing. Richard Campbell gave a very entertaining and educated talk on how to leverage a small portion of these new features to stress test our web applications.

Personally, I have been looking into some of the web testing capabilities of VS2010 from an automated integration test perspective. It was great to learn about and see the stress-testing features.

Richard is the founder of and Product Evangelist of StrangeLoop Networks. His company specializes in optimizing web applications. He demonstrated his expertise in the subject matter and delivered a great presentation on how to use VS2010 to make sure your web application can perform.

Conclusion

 

I am very happy I attended this event. There were approximately 550 registrants and slightly more than 300 attendees. The attendees, presenters, and organizers included notable leaders from the .NET community such as:

  • Scott Seely, co-author of "Effective REST Services via .NET: For .NET Framework 3.5", founder of Friseton, LLC
  • Micah Martin, founder of 8th Light Inc. and co-author of "Agile Principles, Patterns, and Practices in C#"
  • Robert “Uncle Bob” Martin, author of "Clean Code: A handbook of Agile Software Craftsmanship", co-aurthor of "Agile Principles, Patterns, and Practices in C#", and founder of Object Mentor
  • Rocky Lhotka, creator of the widely-used CSLA.NET framework
  • Carl Franklin, co-host of the popular .NET Rocks podcast
  • Richard Campbell, co-host of the popular .NET Rocks podcast

To name a few.

This code camp met my criteria of successful code camps. It was well-organized, supported by a great development community, consisted of diverse technological topics, and concluded with downright awesome giveaways. I hope I have an opportunity to attend future Chicago Code Camps.

Written by curtis

May 3rd, 2010 at 2:40 pm

Posted in Miscellaneous

Two ways to handle unauthorized requests to Ajax actions in ASP.NET MVC 2

leave a comment

Problem:  I have created a view that posts to an action via Ajax with the expectation that the action will return the requested data or an empty string.  Even better, I would like it to be configurable to return whatever value I see fit.

The problem arises when I decorate the called action with the [Authorize] attribute.  If the request is not authorized and I have a loginUrl configured in my web.config, my ajax request will return the html output of my loginUrl view.  That is undesirable.

Solution #1:  I need to implement a custom ActionFilterAttribute that I can use on the ajax action to handle the request appropriately.  Here is the code for my ActionFilterAttribute:

    public class AjaxAuthorizeAttribute : ActionFilterAttribute
    {
        public string View { get; set; }
        private bool renderView;

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!filterContext.HttpContext.Request.IsAuthenticated && filterContext.HttpContext.Request.IsAjaxRequest())
            {
                renderView = true;
            }

            base.OnActionExecuting(filterContext);
        }

        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (renderView)
            {
                filterContext.Result = new ViewResult { ViewName = View };
                filterContext.Result.ExecuteResult(filterContext.Controller.ControllerContext);
                return;
            }

            base.OnResultExecuting(filterContext);
        }
    }

And, here is how I would decorate my ajax action in my controller class:

	[AjaxAuthorize(View="AjaxAuthorizeError")]
public ActionResult AjaxRequest()
{
        return View();
}

That would handle the issue by checking whether the request is authenticated.  If it isn’t authenticated and the request is being submitted via ajax, a specified view will get called.  The content of that view determines what my ajax call will receive back when the request is not authenticated.

Note:  There is no default view page being rendered if one is not passed to the ActionFilterAttribute.  That’s room for improvement.

Solution #2:  I can extend the existing Authorize attribute by inheriting from the AuthorizeAttribute class.  Here is the code that extends the Authorize attribute:

    public class AjaxAuthorizeOverrideAttribute : AuthorizeAttribute
    {
        public string View { get; set; }

        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            if (!filterContext.HttpContext.Request.IsAjaxRequest())
            {
                base.HandleUnauthorizedRequest(filterContext);
                return;
            }

            filterContext.Result = new ViewResult { ViewName = View };
            filterContext.Result.ExecuteResult(filterContext.Controller.ControllerContext);
        }
    }

Here is the decorator for the ajax action in the controller class:

[AjaxAuthorizeOverride(View="AjaxAuthorizeError")]
public ActionResult AjaxRequest()
{
     return View();
}

Note:  Again, there is no default view page being rendered.

Written by curtis

March 22nd, 2010 at 4:10 pm

Posted in Miscellaneous

Changing the default Virtual Directory/[TARGETVDIR] name in a Visual Studio Setup Project

one comment

While working on a Visual Studio Setup Project for an ASP.NET MVC application, I ran into an interesting dilemma. The installer automatically uses the Title of your setup project as the default virtual directory value. From a user experience standpoint, it can serve as a visual indicator that this "virtual directory" is specifically for the application that you (the user) are installing.

However, it isn’t ideal. See, usually the title of an installer is human readable e.g. "My Application". However, I don’t think user would want their virtual directory to contain spaces since spaces typically get escaped to a hex value, making your site’s address http://someserver/My%20Application. Visual Studio Setup Projects do not offer a straight-forward way of editing this default value, except to edit your title to read "MyApplication".

There are a handful of solutions that have been conceived by various people that include passing command line arguments or using custom dialog windows that set the TARGETVDIR parameter explicitly – to name a couple.

For different reasons, none of the proposed solutions satisfied my dilemma.

So, here is what I did:

I opened the deployment project in notepad++ (a very handy text editor), found the line that says, "VirtualDirectory" = "My Application" and changed it to "VirtualDirectory" = "MyApplication". After saving the file, reloading it in Visual Studio, and building my installers, my dilemma was solved. I hope this is helpful to you as well.

Written by curtis

February 19th, 2010 at 12:14 pm

Posted in Miscellaneous

Richmond Code Camp 2009.2

3 comments

Wow! What an event!

This weekend, I joined ~400 others for the Richmond Code Camp and a good time was had. As others have noted, the hardest part of the day was choosing which talks to attend due to a schedule full of excellent topics and speakers.

I started off with Justin Etheredge’s talk on Linq Expressions. This was 75 minutes of great slides and polished demos of basic to advanced Linq concepts. I left that talk more educated and less scared of the power of Linq Expressions. Justin has an unbelievable understanding of how Linq works and an amazing ability to convey that to the layman with nothing more than a stock photo of a cat and a VM with Win 7 and VS 2010.

Second, I attended a talk that was missed from Raleigh’s Code Camp two weeks earlier. I went to John Feminella’s talk on Ruby for C# developers. John gave .NET developers a great introduction to the Ruby language using IronRuby (I thought that was brave at this point). To my surprise, John held up his end with great content and examples, and IronRuby held up its end with stability and support for most of the features of Matz Ruby (the original implementation of Ruby).

Next, I decided to checkout Open Spaces. The evening before, I jokingly suggested that the audience would convince Kevin Hazzard to present something on the DLR at Open Spaces since he was not officially presenting. Well, I guess they did! Kevin led a discussion on IronPython and the DLR that included some very nice demos. He also discussed C# 4.0’s new “Dynamic” type and how it actually works. I gained a lot of insight on when and where the DLR and Dynamic Languages on .NET are useful. And, while I love Ruby, IronPython is making the Python language very attractive to me.

Another talk that I was able to attend was by Chris Love. He talked about building quality ASP.NET applications faster. I know Chris to be a very experienced developer. He just completed an updated version of a book I found to be very practical when I was getting into more advanced ASP.NET concepts, ASP.NET 3.5 Website Programming: Problem – Design – Solution. His talk drew off of his experiences building applications and sites for his clients. He talked about architecture as well as development practices. I recommend his talk to anyone doing ASP.NET development that is looking for practical advice on how to manage it all from start to finish.

In the last time slot of the day, I presented Spark, an ASP.NET MVC View Engine, to a great audience. This was essentially the same talk that I gave a couple of weeks earlier at Raleigh’s Code Camp, but I made some modifications for the Richmond crowd. Here are the slides from that talk:

Enjoy!

Written by curtis

October 5th, 2009 at 3:04 pm

Posted in .net, CSharp, Miscellaneous

Tagged with , , , , ,

Slides from Raleigh Code Camp 2009

leave a comment

This weekend, I had the pleasure of presenting a talk on Spark View Engine at Raleigh Code Camp (#rducc).  It was a well organized event with a schedule full of great topics and presenters.  The Triangle .NET User Group (TriNUG) did a wonderful job at organizing and running the event.  Thanks, TriNUG!

As promised, I am posting the slides that I used in the Spark talk.  Although the true context of the talk is not present on the slides, I hope these are helpful to someone using the Spark View Engine or considering it.

Stay tuned, or subscribe to the rss. I am planning to post a series of short to-the-point screencasts that demonstrate how to practically use Spark in your ASP.NET MVC application.

In the meantime, checkout http://www.dimecasts.net for some great videos on Spark.

Written by curtis

September 21st, 2009 at 10:01 am

Ruby-like Times method for Ints in C#

leave a comment

Yesterday, @mccartsc did a presentation on Linq for a group of us at work. As part of his presentation, he demonstrated an extension method he threw together to give .NET Integers the Times method that Ruby programmers have enjoyed for years.

Basically, the n.Times methods is passed a block that it will execute n number of times. In Ruby, you could do something like this:

5.times {|x| puts x }

That trivial line of code would output integers 0 through 4.

With such a trivial use case, you may be wondering “Why would anyone want to do that?” Well, @mccartsc and I had a discussion about coding without traditional For Loops. Foreach Loops are great for enumerating IEnumerable objects, but it is not a replacement for the traditional For Loop. We thought, “Wouldn’t it be great if you could use a Ruby-like Time method to execute a block of code an arbitrary number of times?” So, @mccartsc built it as part of his Linq demonstration.

Here’s how he did it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinqDemo
{
    static class Extensions
    {
        public static void Each<T>(this IEnumerable<T> collection, Action<T> action)
        {
            foreach (var item in collection)
                action(item);
        }

        public static IEnumerable<int> Range(this int max)
        {
            for (int i = 0; i < max; i++)
                yield return i;
        }

        public static void Times(this int i, Action<int> action)
        {
            i.Range().Each(action);
        }
    }
}

@mccartsc created three extension methods to implement the Times method. “Each” is an extension method for IEnumerable types. It passes each member of a collection into an Action delegate.

“Range” is an extension method for Int types. It creates a zero-based IEnumerable collection out of an integer. For instance, 5.Range();, would return a collection consisting of integers 0,1,2,3,4.

Finally, “Times” is another extension method for Int types that allows a user to execute an action an arbitrary number of times by using the aforementioned Range and Each methods. Once I have these extension methods in my C# project, I can execute code like this:

5.Times(i => Console.WriteLine(i.ToString()));

The above would output:
0
1
2
3
4

I think that’s pretty cool.
Thanks @mccartsc for the code and the demonstration.

Update: @mccartsc got a blog! Check him out at http://scmccart.wordpress.com/.

Written by Curt

May 1st, 2009 at 9:13 pm

Posted in Miscellaneous

Tagged with , ,

Handling mscorlib.dll System.Threading.ThreadAbortException issue in an ASP.NET application

leave a comment

I discovered an unhandled System.Threading.ThreadAbortException was being thrown in my ASP.NET application. I was only able to see this issue when running the application in the Visual Studio debugger. The offending code was a seemingly trivial call to Response.Redirect.

When I called Response.Redirect, the thread handling the current response would be aborted. The thread didn’t like being aborted out of the blue like that. The fix is to pass the second parameter to the Response.Redirect method which tells Response.Redirect whether or not it should end the response. Passing in false will cause the Redirect method to fire, but allow the original response thread to execute the code after the call to Response.Redirect. I use a Return statement to avoid unnecessary processing.

Microsoft explains it here: http://support.microsoft.com/default.aspx?scid=kb;en-us;312629

Written by Curt

April 8th, 2009 at 9:20 am

Posted in .net, Miscellaneous

Tagged with

Microsoft.WebApplication.targets not found

one comment

While setting up a non-Microsoft CI environment for an ASP.NET MVC project, I came across an interesting problem.  My build agent was unable to compile my project because it could not find the Microsoft.WebApplication.targets file, which, on the development computer is located under the C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications directory.

I wanted a quick solution, so I Googled it.  The top two sites resolved the issue by creating the path on the build server and copying the file over.  That is A solution to the problem.  I suppose another solution would be to install Visual Studio on the build agent.  But, that (borderline) defeats the purpose.

I decided to make a copy of the Microsoft.WebApplication.targets file in the folder of the solution.  Then, I opened the web project file and edited the line that points to the file.  I changed:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />

to

<Import Project="$(SolutionDir)\Microsoft.WebApplication.targets" />

The project builds successfully in both environments now!

Written by Curt

February 1st, 2009 at 12:35 pm

BarCampRDU 2008

one comment

I had the pleasure of attending BarCampRDU yesterday; that is BarCamp in the Raleigh/Durham N.C. region. On the BarCamp wiki, the event is described as “an ad-hoc gathering born from the desire for people to share and learn in an open environment. It is an intense event with discussions, demos and interaction from participants.”

Opening BarCampRDU 2008

Yup, that is correct.  The attendees decide on what to discuss.  There are no formal presenters, only facilitators to lead the discussions.  Once the topics have been determined, a schedule is posted and individuals decide for themselves which topics to attend.

I attended the following discussions:

  1. How to sell free software
  2. Twitter, Patterns and Anti-Patterns
  3. Fan Programming Language
  4. Bootstrapping a business in the RTP area
  5. Git

I am still gathering my thoughts on some of the discussions.  I will add links to my posts about the topics as I deem necessary.

Overall, the event was very well done.  The organizers and the sponsors took great care of us and I hope to be in attendance at the next BarCampRDU.

Written by curtis

August 3rd, 2008 at 4:12 pm

Developer vs. Coder

leave a comment

Are you a developer or a coder?  Before you answer that question, I urge you to consider several characteristics about yourself that you may be taking for granted.

First, let me start by saying this:  If you do not write code of any sort, then you are neither developer or coder.  But, you’re still invited to read the rest of my rant and share your $.02 via comments.

Why do you do it?  Why do you write code?  Is it a lucrative career choice you made based on the short-term earning potential?  Or, do you simply like building things because it’s neat?  A developer leans more toward the money.   The diplomat in me wants to point out that developers may also feel rewarded by just building things.  But, the distinction I want to make is that developers give the financial reward priority over the alternative.  On the other hand, a coder does it for the “love of the game” and not JUST for the money.

When do you think about your code the most?  Writing code can be a very stressful job.  Many people that do it pride themselves on being able to leave work (and the subsequent stress) at the office and focus purely on their personal lives.  Those people are developers.  Developers work from eight to five, nine to six, or whatever time they are paid to work.  Alternatively, coders may be in the office for eight to nine hours, but they are very likely to come up with the next killer app while doing something recreational like sleeping or gaming.  Coders may change environments, but they never stop working.  They write code for fun.

How did you write your last great project?  Did you use Google to overcome your programming challenges?  Did you copy code from some coder’s blog, or from an open source project without FULLY understanding what it does and why it does it that way?  Or, did you reach out to friends that write code; or better yet, did you figure it out for yourself?  If you reached out to friends or figured it out for yourself (even if Google pointed you in the right direction), you are a coder.

It is important to distinguish yourself between developers and coders.  As coders continue churning out great tools that are intuitive and fun to use, and our general population continue to become more computer savvy, the number of developers will grow much faster than the number of coders.  Developers will be the commodity while the value of coders make a sharp upwards turn.

In fact, what I am describing is already the reality.  Developers are happy to collect seemingly generous salaries and contract rates that allow them to sustain the status quo.  Meanwhile, coders have automated the collection, sorting, distribution, and storage of their funds in the interest of minimizing distractions while they innovate (for fun).

Written by Curt

October 11th, 2007 at 8:57 pm