Professional Programmer Notes

or just call this my soapbox

WPF’ing around with Boo and external xaml files

leave a comment »

Here is a snippet of Boo code (formatted with Python syntax highlighter) that will load a xaml file into a WPF Window:

import System
import System.Windows from PresentationFramework
import System.Windows.Markup from PresentationFramework
import System.IO

class XamlWindow(Window):
	def constructor(name):
		load_xaml(name)

	def load_xaml(name):
		xaml_file = File.OpenRead(Path.GetFullPath(name))
		self.Content = XamlReader.Load(xaml_file)

Application().Run(XamlWindow("mainui.xaml"))</pre>

See http://devpinoy.org/blogs/smash/archive/2006/10/04/XAMl-meets-Boo.aspx for reference.

Alternatively, here is the equivalent IronPython code:

import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore")

from System.Windows import Window, Application
from System.Windows.Markup import XamlReader
from System.IO import File, Path

class XamlWindow(Window):
	def __init__(self, name):
		self.load_xaml(name)

	def load_xaml(self, name):
		xaml_file = File.OpenRead(Path.GetFullPath(name))
		self.Content = XamlReader.Load(xaml_file)

Application().Run(XamlWindow("mainui.xaml"))

Lastly, here is an example xaml file

<StackPanel
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Label Content="Hello World" />
    <Button Content="Clickable" />
</StackPanel>
Note: There is no UserControl or Window element and the namespaces are defined on the root container, the StackPanel.
Results:
screenshot of very simple wpf app

Written by curtismitchell

May 22, 2011 at 5:39 pm

Posted in .net

Tagged with , , , , ,

HP Mini with Ubuntu needs Firmware upgrade for Wireless

with 2 comments

I recently installed Ubuntu Netbook Remix on my HP Mini 311.  The OS is beautiful.  It is a great fit for what I use my netbook to do: web development, view videos, and surf the net.

Unfortunately, I realized my wireless adapter was not working after installation.  It had a message that said something about needing a firmware upgrade.

I did some soul searching and internet surfing and found an answer to the problem! 

Open a terminal and execute the following command:

sudo apt-get install –reinstall bcmwl-kernel-source

After a restart, my problem was solved. 

I found this answer here:  http://myhpmini.com/forum/viewtopic.php?t=2604

 

Oh yeah – I’m also selling the netbook to make room for my next toy.  Info is here: http://raleigh.craigslist.org/sys/2093241344.html

Make me an offer.

Written by curtismitchell

December 3, 2010 at 5:23 pm

Posted in Linux

Tagged with , ,

VMWare VMDebugger “unable to detect current startup project”

leave a comment »

 

I spent many small packets of time trying to find a solution to this problem over about two months.  Luckily, I stumbled across an answer that actually worked for me.

Problem: Visual Studio 2008 with VMWare VMDebugger integration does not work.  When I try to launch debugging in a VM, I get a message that says “Unable to detect current startup project”.

Solution:  Remove any installer projects that are in the solution.

Source: Read MartinMoesby comment here.

Written by curtismitchell

November 9, 2010 at 5:48 pm

Code Camp Report

with 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 curtismitchell

May 3, 2010 at 2:40 pm

Posted in Uncategorized

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 curtismitchell

March 22, 2010 at 4:10 pm

Posted in Uncategorized

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

with 2 comments

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 curtismitchell

February 19, 2010 at 12:14 pm

Posted in Uncategorized

Gestalt = Low-Lying Awesome

leave a comment »

Microsoft appears to be betting big on Silverlight.  When the Silverlight 1.0 bits were released in 2007, my initial thoughts were, “Yay, Flash for .NET developers.”  As Microsoft pushed forward with version 2, version 3, and now version 4 of Silverlight, those sarcastic thoughts have subsided to make way for more genuine curiosity.  How did that happen?

Well, for starters, Microsoft delivered real features.  Initially, Silverlight demos were all about media (music and video).  In addition, Microsoft touted the interopability between dynamic languages like vbx, c#, python, ruby, and javascript.  Then, that interopability was sidelined and Silverlight applications started to emerge.  Which was interesting.  In fact, Silverlight 2 had enough features to stir up debates in the enterprise over which RIA technology was best suited for enterprise applications: Flash 8 with Flex or Silverlight 2.   Then, Microsoft played their wildcard.  They made Silverlight play nicely with … ugh … Mac OSX.  Out-of-browser Silverlight applications made me raise my eyebrows for a technology that I had quickly written off as a “fad”.

That might still be the case.  I won’t make a claim either way.  But, Silverlight and RIA are spaces where Microsoft continue to innovate.  Gestalt is a very good example of that last statement.  Gestalt is built atop a foundation consisting of XAML, Silverlight, and dynamic languages.  It enables web developers to script their way to rich internet applications in a way that both Flash and Silverlight seemingly missed. 

With that said, it is difficult to pinpoint exactly what value Gestalt adds, but you feel it when you’re molding some python, ruby, or javascript hackery into a magical Silverlight-powered application that just works.

The technology appears to still be more of a proof-of-concept than a supported product.  But, it makes a strong case for embracing XAML and Silverlight. 

Checkout the website and the samples at http://visitmix.com/labs/gestalt/.

Written by curtismitchell

February 11, 2010 at 9:59 pm

Posted in .net, CSharp, Javascript, web

Tagged with , , , , ,