Silverlight 4 Beta Announced

clock November 18, 2009 05:09 by author jamesstill

Just when I was getting used to SL 3, Scott Guthrie announced today at PDC that SL 4 Beta is now available at silverlight.net. Among the new features he demonstrated:

  • native printing support
  • system clipboard
  • rich-text formatting
  • right-click context menus
  • mousewheel support

He also mentioned that SL 4 "has" MVVM. Hm. Like a project template similar to RIA Services? Or they built it on that pattern? Not sure what he meant. Speaking of RIA it is now a first class citizen in TFS 2010. Also, they made improvements to it and made it a native WCF service. That's pretty sweet. It enables something I've been wanting, namely, the ability to employ service orientation for the middle tier and abstract that away from the caller. If RIA Services is a WCF service then SL can call it, an ASP.NET web page can call it, a mobile device, a portal page, and so on. I hate the idea of middle tier plumbing being compiled over and over again in local APPBASE dirs for each of these clients.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Windows 7 Development

clock November 18, 2009 03:11 by author jamesstill

"Building Windows is like building a movie theatre." Microsoft provides the seats, lobby, screen, and so on and we provide the movie. Windows 7 development: research showed that 55% of Windows 7 beta testers had 1024 x 768 screen resolutions. Really?

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Microsoft PDC09 Keynote Address

clock November 17, 2009 05:09 by author jamesstill

Microsoft announced the new bits at PDC keynote today. The theme? Cloud, cloud, and more cloud. The Azure platform goes into production on Jan 1. In beta through the next several months are new cloud platform tools: AppFabric (previously code named "Dublin") and Endpoint. From what I understand AppFabric provides a unified hosting environment for WCF and Workflow, SQL Azure database caching, and can be configured right in IIS. Endpoint seems to be a discovery service for web services all over the world. You can search it and get all the information you need to consume that data in your application. It probably uses the REST protocol. Microsoft showed a pretty cool demo with the NASA web service that involved showing 3D landscapes of pictures taken by the Mars Rover. You could do a serious mashup in a .NET app with Endpoint.

The CIO of the U.S. government gave a little pep talk about cloud computing. He said the Obama Administration is committed to the cloud and is actively migrating to it now. Honestly, will Multnomah County really spend $3.5 million to build a new DC? Next year, Azure will offer totally configurable VMs in any flavor you want. We could run all of the county DC virtualized on Azure. New apps would plug right in to the cloud environment and legacy stuff could be put on configurable virtual servers in WinOS 2003, 2008, whatever.

Oh and Visual Studio 2010 with .NET Framework 4.0 will be released sometime in Q1 or Q2. The beta is out now and there was some cool stuff in it. You can drag a code pane over to your other monitor, debugging is beefed up, and unit tests write themselves at run time. Other stuff but it went pretty fast.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


IIS 7 Non-HTTP Protocol Support

clock July 19, 2009 05:08 by author jamesstill

More fun with WCF. Out of the box IIS 7 supports the HTTP protocol only. To configure named pipes, TCP, or MSMQ you must use the IIS configuration tool appcmd.exe located in %windir%\system32\inetsrv. (The command-line tool updates the %windir%\system32\inetsrv\config\applicationHost.config file.) For example, if tcp runs over port 808 and my web server's windir is c:\windows then the command to enable tcp is:

c:\windows\system32\inetsrv\appcmd.exe set site "Default Web Site" -+bindings.[protocol='net.tcp',bindingInformation='808:*']

One last detail: each WCF service hosted in its own application (virtual) directory beneath the Default Web Site must also be explicitly enabled for non-HTTP protocol support:

c:\windows\system32\inetsrv\appcmd.exe set app "Default Web Site/[app dir]" /enabledProtocols:http,net.tcp

Now that the tcp protocol is supported in IIS 7 over port 808, a client endpoint is available for netTcpBinding.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Visual Studio 2008: Unable to create the Web site

clock July 4, 2009 08:04 by author jamesstill

After a brief foray into Windows 7 Beta just to check it out I took my laptop back to Vista 64-bit, wiping everything out in the process to get a clean slate. Many moons ago, when first installing Vista, it took me about 3 minutes before I disabled the UAC. This time I'm trying hard not to disable it. (You know, best practices about not developing as a sysadmin and all of that.) Now I'm running into security issues that I'm forced to address rather than bypass. In the end this is a good thing. Here's the latest: In VS2008 I right-clicked on the solution and chose Add > New Web Site. Then I picked the WCF Service template and changed the location to HTTP. This tells VS to create a new virtual application beneath the Default Web Site (in my case c:\inetpub\wwwroot) but I got the error: "Unable to creat the Web site 'http://localhost/Foo' because I was not running Visual Studio in an administrator context. The solution is to run VS as an administrator (you can create a shortcut of devenv.exe and under the Advanced tab toggle "Run as administrator") in order to add the web site. Then save and close and go back in under your logged in credentials.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Windows Vista Port 8000

clock July 4, 2009 06:25 by author jamesstill

Port 8000 is not open in Windows Vista except when running as a system administrator. And so with User Account Control (UAC) enabled, you cannot navigate to http://localhost:8000 or run self-hosted WCF Services without opening the port. To open for your user account, open a command prompt (running as Administrator) and invoke the netsh utility:

      netsh http add urlacl url=http://+:8000/ user=MYMACHINE\UserName

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Cursorless Iteration in SQL

clock June 9, 2008 08:29 by author jamesstill

Knowing when to use cursors and when to avoid them is key to being a successful developer. Here's a very useful snippet to use when you want to use a cursorless iteration over a resultset. In the example I create a temp table of widgets and then enumerate each row to print them out:

   1:  set nocount on;
   2:   
   3:  declare @i int
   4:  declare @curr_widget nvarchar(20)
   5:   
   6:  declare @widget_table TABLE (
   7:      id smallint primary key identity(1,1)
   8:      , widget_color nvarchar(10)
   9:      , widget_type nvarchar(10)
  10:  )
  11:   
  12:  -- populate the widget table with records
  13:  insert @widget_table (widget_color, widget_type) values ('Red','Widget')
  14:  insert @widget_table (widget_color, widget_type) values ('Orange','Gear')
  15:  insert @widget_table (widget_color, widget_type) values ('Yellow','Rotor')
  16:  insert @widget_table (widget_color, widget_type) values ('Green','Crank')
  17:  insert @widget_table (widget_color, widget_type) values ('Blue','Cog')
  18:  insert @widget_table (widget_color, widget_type) values ('Indigo','Flywheel')
  19:  insert @widget_table (widget_color, widget_type) values ('Violet','Propeller')
  20:   
  21:  -- cursorless enumeration of the widget table 
  22:  SET @i = 1
  23:  WHILE (@i <= (SELECT MAX(id) FROM @widget_table))
  24:      BEGIN
  25:          -- get the widget color and type
  26:          SELECT 
  27:              @curr_widget = widget_color + ' ' + widget_type
  28:          FROM 
  29:              @widget_table WHERE id = @i
  30:   
  31:          PRINT @curr_widget
  32:          
  33:          -- increment counter for next row
  34:          SET @i = @i + 1
  35:      END

 

The key to making this work of course is to have an identity column to order the rows and the MAX function to know when you're done. It's a great little trick to try in your next project.

Looking for custom .NET solutions or help with an existing project? Give me a call at +1 (503) 475-3808 and let's talk about your situation.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


STORM! ORM Mapper Beta Launch

clock March 28, 2008 02:59 by author jamesstill

I'm happy to announce that SquareWidget in partnership with the good folks at FlishHorse have launched the Strongly-Typed Object Relational Mapper (STORM) Beta. Download it now and take it for a spin. What is STORM? It's an add-in into Visual Studio 2005. What does it do? It's an OR mapper. It's a code generator. And there are no third-party black box assemblies or other wackiness. We've used Subsonic, NHibernate, and many other ORM tools and we came to the conclusion that it's no fun writing and maintaining a bunch of XML scripts. And we also didn't like creating custom templates like in CodeSmith. We're lazy. So we made a tool that's trivial to use.

Here's how easy it would be to STORM an ASP.NET web application:

  1. fire up VS and create a new web app
  2. add a Web.config file to the project
  3. right-click anywhere in the code window or on the solution root and choose Storm To > Configure Storm
  4. Fill in the four required fields, notably the connection string to your SQL Server database and click Save
  5. right-click and choose Storm All! and it will do its thing. 

 

Let me know what you think!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


IComparer and Sorting Widgets

clock January 16, 2008 05:31 by author jamesstill

Back in the turn of the last century, the golden days of .NET 1.1, if you wanted to implement a type-safe custom collection your best bet was to derive from CollectionBase in the System.Collections namespace. CollectionBase was more than just an abstract base class. It was also a wrapper around an internal ArrayList. If you wanted to sort strongly-typed objects in the collection you would implement an IComparer class:

inner class AscendingWidgetSorter : IComparer {
    public int Compare(Object x, Object y) {
        Widget w1 = (Widget)x;
    IComparable ic1 = (IComparable)w1.Size;
    Widget w2 = (Widget)y;
    IComparable ic2 = (IComparable)w2.Size;
    return ic1.CompareTo(ic2);
    }
}

The IComparer implementation could then be passed into a Sort method in your custom collection:

public void Sort() {
    IComparer widgetSorter = new AscendingWidgetSorter();
    InnerList.Sort(widgetSorter);
} 

Fast forward to .NET 2.0/3.5 and we now have support for generics in IComparer which is in the System.Collections.Generic namespace. With the use of templates you no longer have to cast the type inside the Compare method, you can declare the type with the IComparer implementation. Let's say we want to compare square widgets and provide support for sorting them. They come in four sizes labelled A, B, C, and D. Further, if two widgets are of the same size then the larger of the two is the one with the most teeth. A square widget can have anywhere from 4 to 8 teeth. Here's the IComparer implementation:

/// <summary>
/// Widget sizes range from the smallest A through the largest D and teeth 
/// on any particular widget can be as few as 4 and as many as 8. The sort 
/// algorithm must sort from smallest to largest first by size then by the
/// tooth count.
/// </summary>
internal class WidgetSorter : IComparer<SquareWidget> {
    /// <summary>
    /// Returns the smaller of the two widgets where:
    ///     less than 0    - sw1 is smaller than sw2
    ///     0              - sw1 is equal in size to sw2
    ///     greater than 0 - sw1 is greater than sw2 or sw2 is null
    /// </summary>
    /// <param name="sw1"></param>
    /// <param name="sw2"></param>
    /// <returns></returns>
    public int Compare(SquareWidget sw1, SquareWidget sw2) {
        if (sw1.Size.Equals(sw2.Size)) {
            return sw1.Teeth.CompareTo(sw2.Teeth);
        }
        else {
            return sw1.Size.CompareTo(sw2.Size);
        }
    }
}

And of course we need to describe a SquareWidget in our system:

public class SquareWidget {
    private int _id;
    private string _size;
    private int _teeth;
 
    public SquareWidget(int id, string size, int teeth) {
        this._id = id;
        this._size = size;
        this._teeth = teeth;
    }
       
    public int ID {
        get { return this._id; }
    }
 
    public string Size {
        get { return this._size; }
    }
 
    public int Teeth {
        get { return this._teeth; }
    }
}

From there the behavior is the same as before. You create an instance of the WidgetSorter and pass that into the List.Sort method. Here's a sample console app that exercises the code above with a List<T> thrown in for good measure:

class Program {
    static void Main(string[] args) {
 
        List<SquareWidget> widgetList = new List<SquareWidget>();
           
        // load widgets
        widgetList.Add(new SquareWidget(1, "C", 5));
        widgetList.Add(new SquareWidget(2, "A", 4));
        widgetList.Add(new SquareWidget(3, "D", 8));
        widgetList.Add(new SquareWidget(4, "A", 8));
        widgetList.Add(new SquareWidget(5, "D", 7));
        widgetList.Add(new SquareWidget(6, "C", 4));
        widgetList.Add(new SquareWidget(7, "A", 5));
       
        // instantiate our custom widget sorter and do the sort
        IComparer<SquareWidget> widgetSorter = new WidgetSorter();
        widgetList.Sort(widgetSorter);
 
        foreach (SquareWidget sw in widgetList) {
            Console.WriteLine(string.Format(
                "ID: {0} Size: {1} Teeth: {2}", sw.ID, sw.Size, sw.Teeth));
        }
        Console.ReadLine();
    }
}

If you run the app you'll get the list sorted according to our specifications:

ID: 2 Size: A Teeth: 4
ID: 7 Size: A Teeth: 5
ID: 4 Size: A Teeth: 8
ID: 6 Size: C Teeth: 4
ID: 1 Size: C Teeth: 5
ID: 5 Size: D Teeth: 7
ID: 3 Size: D Teeth: 8

Enjoy!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Fetching Connection Strings

clock December 27, 2007 04:49 by author jamesstill

Let's assume you wish to store your database connection string in the <connectionStrings> configuration section of Web.config. This is the best practice in my opinion because you can (and should) encrypt the section in production. Now you have two basic options:

(1) fetch the connection string at the UI level and pass it back to the data layer.

(2) remove the dependency altogether and let the data layer fetch it from Web.config

I've done it both ways. With option (1) you have a simple call to the ConfigurationManager:

string connectionString = ConfigurationManager.ConnectionStrings["FooBar"].ConnectionString;

 

Most people do this and it's quick and simple. If you don't want the coupling or you don't feel like parameter passing or you want your unit test assembly to be able to get a connection string without needing to reflect over the UI assembly, then option (2) involves creating a helper method that any assembly in your solution can call. Here's one that opens a config file from an explicit virtual root location and returns a string value that matches the passed in key:

public static string GetConnectionString(string connectionName) {
    string connectionString = string.Empty;
    // reading from explicit IIS virtual root alias name rather than "~"
    Configuration c = WebConfigurationManager.OpenWebConfiguration(@"\Widget");
    if (c != null) {
        ConnectionStringsSection section = c.GetSection("connectionStrings") as ConnectionStringsSection;
        foreach (ConnectionStringSettings css in section.ConnectionStrings) {
            if (css.Name.ToUpper().CompareTo(connectionName.ToUpper()) == 0) {
                connectionString = css.ConnectionString;
                break;
            }
        }
    }
    return connectionString;
} 

 

Then it's pretty simple to fetch a connection string from your DAL layer: 

string connectionString = GetConnectionString("FooBar");
SqlConnection cn = new SqlConnection(connectionString);

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


About

SquareWidget LLC is an Oregon-based software development company that specializes in handcrafted .NET software solutions.

Search

Archive

Categories


Sign in