CurtisMitchell

IThinkTherefore, IBlog

Archive for the ‘.net’ tag

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 Curt

February 11th, 2010 at 9:59 pm

Posted in .net, CSharp, Javascript, web

Tagged with , , , , ,

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

Debug an IE Add-On in Visual Studio 2008

leave a comment

I’m working on a project that involves creating an IE Add-On in C#.  It is an inherited project that was created in Visual Studio 2005 targeting the .NET Framework 2.0.

Well, times have changed.  I am now doing most of my development in Visual Studio 2008, and (when lucky) I am using the features of the .NET Framework 3.0 or higher.  When I first made the switch, I tried to use 2008 to continue my work on the toolbar, but I failed miserably.  I was shocked to find out that my process of registering my assembly in a post-build action and launching IE as a Start Action did not work in 2008.  At the time, I quickly got over it, and preserved 2005 just for that project.

Luckily, in a more recent attempt to use 2008 for this type of development, I was able to solve the problem.  Check it out.

Problem:

Whenever I tried to debug my IE Toolbar project in Visual Studio 2008, I would get a nasty exception that says, “Error while trying to run project.  Unable to start debugging

image

My project is configured to register the assembly using regasm in a Post-build step.  Then, as you can see below, the VS Debugger is configured to start Internet Explorer (and subsequently attach to the process).

image1

Well, that was the wrong way of doing it.  I was able to get it to work successfully by modifying the Start Action like such:

image

And it worked!

UPDATE:  I still had issues on a separate computer.  Adding “about:blank” to the command line arguments fixed the issue.

Written by curtis

May 6th, 2009 at 3:25 pm

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 , ,

(Reminder) How to reset my environment settings in Visual Studio 2008

leave a comment

A co-worker once asked me how to reset his environment settings. His environment was set to Visual Basic, but he wanted to change it to C#. Both of us are very experienced .NET programmers, but neither of us could remember how to do it. Here is a reminder to us all:

Goto Tools > Import and Export Settings > Reset all settings

Goto Tools > Import and Export Settings > Reset all settings

Written by curtis

January 30th, 2009 at 8:16 am

Posted in .net, CSharp

Tagged with , ,

Not really a Fan, but still kind of Groovy

2 comments

Fan is a very young programming language with some promise.  The features of the language are more pragmatic than theoretical.  This means, Fan, like Python and Ruby, should allow you to be productive in a concise manner.  The syntax of Fan left a lot to be desired.  It is not the prettiest language, but hopefully, syntactic sugar will be added in the future to facilitate Fan’s adoption.The killer feature that Fan promises to deliver is the interoperability with both the Java Virtual Machine and the .NET Runtime.  Currently, one or the other are required to compile Fan source code.  However, Fan currently does not offer much in terms of interoperability with Java and/or any of the CLR languages.  That is disappointing for now, but the language is extremely young.  Powerful features like that take time.

While a more developed Fan will find its niche audience of developers, I wonder about the true utility of such a language.  The JVM already has the well-known scriptingly awesome language known as Groovy.  I do not qualify as a Java developer, but I hold Groovy in high regard because of its performance, language features, and *gulp* use of the JVM.  Java reservations aside, Groovy is a language I look forward to learning.

.NET is not absent of nice scripting languages either.  Boo is one such language, noted for its Python-like syntax. Oh, and did I mention IronPython?  It is also noted for its Python-like syntax, but .NET-like performance.  Perhaps, the most awaited .NET language is IronRuby, a dynamic language with the features of ruby and the power of the .NET Framework.  It is going to be great.

There is one other .NET language that I think deserves mention.  It is called Nemerle.  Nemerle is a static language, much like C#.  However, Nemerle implemented features like type inference long before the release of C# 3.0.  Since the latest release of C#, Nemerles advantages have become less pronounced.  But, it still differentiates itself from C# with features like Macros that allow you to customize the syntax of Nemerle (think domain specific language).

Nemerle is a pretty mature language.  It has some integration with Visual Studio 2005.  Also, the Nemerle compiler is written in Nemerle.  That could be a sign of a pretty usable language.

Nemerle is open-source.  I don’t know if it is actively developed today.  However, I recently came across a blog post that sums up some of the features of Nemerle.  That post was the inspiration for this post actually.  Onur went as far as to call Nemerle “C# glorified.”  I’m not sure I agree with that.

However, I believe Groovy is definitely “Java glorified.”   Maybe Nemerle is a little Groovy.

Written by curtis

August 3rd, 2008 at 4:14 pm

SnippetCompiler is great, but…

2 comments

…we don’t have to use it for quick compilable chunks of .NET goodness.  As detailed on marlongrech.wordpress.com, we can use TestDriven.Net to run small parts of code in the Visual Studio.NET debugger.

The code is not required to be a test case for use in a unit testing framework.  It can be an arbitrary method that just does some processing.  The key to using this technique, is to make sure you set a breakpoint.  That way you can manipulate parameters and actually get feedback about what the method is doing when it executes.

This is yet another reason we should buy TestDriven.Net.  It can pay for itself within a day or two.

In addition to SnippetCompiler and TestDriven.Net, Powershell is very useful for this kind of snippet testing as well.  But I’ll have to defer that post for another time.

Written by curtis

July 2nd, 2008 at 6:04 pm

Fix Visual Style of Tab Control in .NET

one comment

I was having an issue with my tab contols looking very ugly:

Ugly Tab

These controls did not look anything like other fancy tab controls that I have seen recently in XP and Vista.    My tab control sucked.  Looking at it took away my desire to use my application.

I made several attempts at remedying the issue.  I tried one combination of property changes after another to no avail.  I was on the verge of creating a new owner-drawn tab control ( I had created a new project in Visual C# Express and everything) when I stumbled upon a CodeProject article.

I didn’t follow the article all the way through because it seemed to be written for an older version of the Framework and IDE.  But, it reminded me that there is an Application.EnableVisualStyles() method*.

I swiftly made sure I called that method before any controls were drawn, saved my hard work, and clicked the VS “Play” button with the excitement and anticipation of a child in line at Chuck E. Cheese.  That all died quickly when I received a screen containing the same ugly tabs staring back at me.

I checked the return value of the Application.RenderWithVisualStyles property and discovered my application was not using visual styles.  Thanks to the MSDN documentation, I quickly found the problem.  I had XP’s Appearance set to Windows Classic style.  Doh!!!

After changing XP’s Appearance back to Windows XP style, I had beautiful tabs:

Beautiful Tabs

To recap the solution:

  1. Call Application.EnableVisualStyles() before any controls get rendered.  In Program.cs just before Application.Run is a good place.
  2. Make sure you are allowing your OS to use visual styles.
  3. Don’t judge me for being absent-minded most of the time.  I’m trying to get it out of the way so that I won’t be absent-minded when I’m older.

* I probably saved over that memory with a Mitch Hedberg joke or my wedding anniversary date.

Written by curtis

May 17th, 2008 at 9:38 am

Posted in .net, CSharp, vb.net

Tagged with , , , ,

BDD in .NET the way the big kids are doing it

2 comments

This is an introductory article about using test/unit and test/spec for behavior driven development (BDD) in .NET.

Target audience:

This article is for you if:
1. You are a programmer/developer that uses Microsoft’s .NET Framework
2. You are interested in doing behavior driven development
3. You realize that while .NET has some nice up and coming BDD Frameworks, they still lag behind test/spec and rspec in features and usability.

Assumptions:

This article assumes that the target platform is Windows XP or greater (or lesser, depending on your experiences with Vista). These steps were not tested on Mono (by me), nor did I test on any OS not previously mentioned. I also assume that you are familiar with Ruby and gems. Also, I assume that you are comfortable with changing environment variables within Windows, which may require elevated privileges.

Required software/tools:

1. Ruby programming language
2. DiffUtils
3. RubyCLR (gem)
4. test/spec (gem)
5. zentest (gem)

Installation:

Download the One-Click Installer for Ruby from here. Double-click the executable and follow the wizard. Installation is a breeze with the One-Click Installer.

Second, download the DiffUtils from here. I suggest you download the installer instead of the zipped binaries. I tried the binaries initially, but found a missing dependency (try figuring that out). After downloading the installer, run it and remember the installation path for later use.

To complete the installation, we need to add the installation path to the PATH environment variable. We can do this by hitting the Left Windows key + Page Break. Select the “Advance” tab and click on the “Environment Variables” button. Select the variable named Path in the System Variables list. Click the “Edit” button under the list to bring up the edit dialog. Append a semi-colon and the installation path to the end of the “Variable Value” text box. BEFORE you exit out of the dialogs, click the “New…” button under the User Variables list. Create a variable named “HOME” and set its value to your user directory that has your “My Documents” folder e.g. “C:\Documents And Settings\Curtis”. Press the “Ok” buttons to exit all of the dialogs, and reboot your computer. The last step is very important, so try not to skip it.

Now that we have Ruby and DiffUtils installed, we can install the requisite ruby gems. Installation of the gems is straight-forward. At the command prompt, use a variation of the following command to install each gem:

gem install [gem name] --include-dependencies

I suggest you add the –include-dependencies flag to the gem commands in order to save a few prompts. Once the gems are installed, you’re all set. You don’t need me.

Usage:

I’ll add a few notes about how to use your new setup. This is where all your hard work pays off.

First, create a new C# Class Library solution in Visual Studio. I suggest you change the output directory to “../bin” in order to have MSBuild output your assembly to a “bin” directory in the root path of the solution.

Open your text editor and create a new file called “.autotest” in the root path of your solution. Note: This may be difficult to accomplish in Notepad since the filename is essentially an extension in Windows. I suggest using Notepad++ or Scite (installed with the one-click Ruby installer) instead.

This file is really just a Ruby source file used by the ZenTest gem. Copy the following code into the file and save it:

class Autotest
  #This method tells autotest to run all of the Ruby source files in the 'test'
  #directory whenever a file changes; namely a test file.
  def tests_for_file(filename)
    return Dir["/test/**/*.rb"]
  end
end

#This block tells autotest to run any file in the 'test' folder that starts with
#'test_' and ends with 'rb' whenever a 'dll' file changes in the 'bin' directory
Autotest.add_hook :initialize do |at|
  at.add_mapping(/^bin.*\/.*dll$/) do |filename, _|
    puts "This file changed: " + filename
    at.files_matching(/^test.*\/test_.*rb$/)
  end
end

This assumes the only .rb files in the solution’s path will be files intended to test the .NET assembly that is being created.

Next, create a new file in your text editor. Call it “test_mydotnetlib.rb” or something cheesier. But, be sure to prefix it with “test_” and save it into a folder called “test” under your solution’s path. The following steps will detail how to actually create a file to test your code.

All test files will require a few standard declarations in order to work properly:

require 'rubyclr'
require 'test/unit'
require 'test/spec'

include Test::Unit

#includes the .NET assembly intended for testing
reference_file 'C:\Dotnet\src\MySolution\bin\MyCustomLibrary.dll'

There are two points to note about the above line: First, the whole path to the output of your class library project should be specified. Secondly, this line points to a ‘bin’ directory located under the Solution’s path. This isn’t the default path of output for Visual Studio, so if you skipped the step above where I suggested you change the output path of your class library project, now is the time to correct that.

Now, we can begin writing our actual tests. Add the following to your test file and save it:

describe "MyCustomLibrary" do
  before(:each) do
    @speaker = MyCustomLibrary::Speaker.new
  end  

  it "should say hello" do
    @speaker.sayHello.should.equal 'hello'
  end
end

At this point, we can start up Autotest. Open a command window and change directories to the root of your Visual Studio solution. Type “.autotest” and hit enter. Autotest will run the test that you just saved. It should show that you have 1 failed test. That’s great!

Create a Speaker class in your .NET project. Implement the sayHello method so that it returns the string “hello”. Build your project, and watch Autotest re-test your code again. This time the test should pass.

Sweet! This is just the tip of the iceberg of what can be done with RubyCLR.

This solution works because of the creativity and hard work of some great developers. I’m going to run the credits before the end, just to make sure you stick around to acknowledge their efforts:

Credits:
John Lam (RubyCLR) and the person or people continuing to develop it
Christian Neukirchen (test/spec)
Nathaniel Talbott (test/unit) and the person or people that continue to develop it
ZenSpider (ZenTest)
Paul Eggert (DiffUtils)
Venkat Subramaniam (for his inspiring presentation on DNRTV.com)
And, of course, Matz and the rest of the Ruby team

I also appreciate the efforts of all others involved whether directly or indirectly.

Now, back to the code…

Written by Curt

May 5th, 2008 at 7:37 pm

Posted in CSharp, Ruby, Testing

Tagged with , , , , , ,