Fabrice Kauffmann has started a series of posts on using a physics engine with WPF, with some good code samples to get you on the right track. You can read part 1 here, or in the original French here
More WPF Physics
May 15, 2008 · No Comments
→ No CommentsCategories: .NET
Dead ringer
May 5, 2008 · 1 Comment
→ 1 CommentCategories: .NET
.NET is crap?
May 5, 2008 · 2 Comments
Wow, I can’t believe I still enjoy writing .NET apps on Windows when it’s this bad. How naive of me… Maybe I’m just old and get a kick from dumbed-down languages (btw I turned 100011 (0×23) yesterday; yay me!
).
→ 2 CommentsCategories: .NET
System.Web.Routing with WebForms sample
April 25, 2008 · 1 Comment
UPDATE: You can see a sample site running here. As it’s using IIS6 I needed to add a Wildcard Application Mapping. Note this passes every request through ASP.NET; you might prefer some alternative options, or use IIS 7 where you get it for free.
Since my earlier post on using the System.Web.Routing assembly with traditional WebForms (here), I’ve had some requests for a sample project to show it in action. You can get the source right here.
This sample shows a way of getting the route information from the RouteHandler to the page, with minimal changes to existing pages (good if you’re migrating from a 3rd party URL rewriter). Basically the WebFormRouteHandler copies relevant routing values into the HttpContext.Items collection (so they’ll only exist for the lifetime of the current request). You can then grab these values in your WebForm.
For another example of passing routing details to a WebForm, see Phil Haack’s great post here.
→ 1 CommentCategories: .NET
Batch Updates and Deletes with LINQ to SQL
April 14, 2008 · No Comments
My co-worker / colleague Terry Aney has posted a kick-ass article about coaxing LINQ to SQL into generating more efficient SQL batch UPDATE and DELETE commands (in the current LINQ to SQL release, separate UPDATE / DELETE commands are executed for each row). It’s an interesting read and the end result is pretty sweet too
→ No CommentsCategories: .NET
Excel add-ins in C#
April 13, 2008 · 1 Comment
My colleague Terry Aney has posted a detailed article on the “fun” he’s had creating Excel add-ins in C# (after migrating from XLAs + VBA). If you need to make several thousand calls between add-ins and Excel and want to use .NET, you should definitely run some performance comparisons first
In a related post he discusses source control strategies / workarounds for XLA files.
→ 1 CommentCategories: .NET · COM Interop · Excel · VB
ASP.NET Routing… Goodbye URL rewriting?
March 11, 2008 · 5 Comments
UPDATE 2: You can find a sample project and more details here.
UPDATE: Be sure to check out Phil Haack’s post covering some of the security implications of this. I’ve also added a related comment to the end of this post
The recent ASP.NET MVC Preview 2 release brought some interesting stuff for “traditional” ASP.NET developers. The new System.Web.Routing and System.Web.Abstractions assemblies have no dependency on MVC and can be leveraged pretty easily. Check out this post by Phil Haack (and be sure to keep up with his upcoming posts that will go into more detail).
One of the obvious uses for the new routing mechanism is as a “clean” alternative to URL rewriting (and possibly custom VirtualPathProviders for simple scenarios) for traditional / postback-based ASP.NET sites. After a little experimentation I found some minimal steps that work pretty well:
- Create a custom IRouteHandler that instantiates your pages
- Register new Routes associated with your IRouteHandler
- That’s it!
The IRouteHandler implementation can be as simple or elaborate as you like. Just implement the GetHttpHandler method and return a new instance of an ASP.NET page (if you want to use an ASPX you can instantiate it with BuildManager.CreateInstanceFromVirtualPath).
Here’s a very simple IRouteHandler implementation that instantiates a single page (compiled or ASPX) for any request sent to it:
public class WebFormRouteHandler<T> : IRouteHandler where T : IHttpHandler, new() { public string VirtualPath { get; set; } public WebFormRouteHandler( string virtualPath ) { this.VirtualPath = virtualPath; } #region IRouteHandler Members public IHttpHandler GetHttpHandler( RequestContext requestContext ) { return ( VirtualPath != null ) ? (IHttpHandler)BuildManager.CreateInstanceFromVirtualPath( VirtualPath, typeof( T ) ) : new T(); } #endregion }
This example could be useful in a site with a single ASPX that hosts multiple ASCXs as its “pages” (maybe one that uses the inbuilt SiteMap as a mapping mechanism between public URLs and ASCXs). For more traditional sites, your GetHttpHandler would return separate page instances based on the RequestContext it’s provided with (RequestContext includes the routing details extracted from the URL; MVC would create a Controller at this point).
Routes are usually registered in the Application_Start handler in Global.asax. Here’s a simple example based on the “single ASPX / multiple ASCX” approach that passes several routes to a single page (MyPage.aspx):
protected void Application_Start( object sender, EventArgs e ) { RegisterRoutes( RouteTable.Routes ); } public static void RegisterRoutes( RouteCollection routes ) { // Note: Change the URL to “{controller}.mvc/{action}/{id}” to enable // automatic support on IIS6 and IIS7 classic mode var routeHandler = new WebFormRouteHandler<Page>( “~/MyPage.aspx” ); routes.Add( new Route( “{page}”, routeHandler ) ); routes.Add( new Route( “AccountServices/{page}”, routeHandler ) ); routes.Add( new Route( “Default.aspx”, routeHandler ) ); }
Phil Haack has a post that covers some security implications of this approach. Like Phil suggests, the ‘insecure’ behavior might be exactly what you want. You could prevent direct URL access to your ASPX’s (using ASP.NET’s existing mechanisms) and consider them just resources to be used by your IRouteHandler.
Also note that Phil includes a mechanism for passing the RequestContext to your page (just define and implement the IRoutablePage interface).
→ 5 CommentsCategories: .NET
Silverlight 2 - 2D Physics revisited
March 6, 2008 · 11 Comments
It’s awesome that Silverlight 2 [beta 1] is now with us; the world just became a far cooler place :) It can’t all be good of course; sadly my earlier Silverlight 1.1 demos no longer work
Fortunately it took almost no effort to get things moving again. If you’ve got Silverlight 2, you can try the updated demo here (or click the image). There’s also a new “heads will roll” feature for your viewing pleasure. Source code coming soon…
You might notice objects occasionally roll behind each other (BulletX is a 3D physics engine; I’m probably missing a constraint), or you might get kicked to a blank page… They’re my bugs, not Silverlight’s :) I’ll update here when they’re fixed.
→ 11 CommentsCategories: .NET
WPF animated GIF and Javascript filmroll
February 29, 2008 · 2 Comments
I made a few improvements to my SkinBuilder utility (I’m using it daily and it’s great!). You can now add these attributes to a <Snapshot>:
- Top, Left, Right, Bottom - Snapshot position relative to container edges (otherwise defaults to top left).
- Width, Height - Snapshot width and height (defaults to container size if known).
- RenderDpi - The DPI (Dots Per Inch) to render at.
- Dpi - The DPI of the snapshot (this may influence the final width and height; defaults to 96 if omitted).
- Quality - Compression quality level for JPEGs (0 to 100; defaults to 100).
Additionally the <Group> element supports position attributes (Top, Left, Right, Bottom) and a new OutputPath attribute, which lets you set a relative base path for all contained Snapshots.
The most interesting new attributes are RenderDpi and Dpi. The following examples show a rotating 3D Kaxaml logo as an animated GIF and a Javascript-driven “filmstrip”, both rendered at 300 dpi and scaled down to 96 dpi (effectively anti-aliasing the result - something WPF 3D can’t otherwise do when rendering to a bitmap):
Javascript-driven filmstrip (and here’s the image it’s using).
Note - I passed the animated GIF through a freeware utility called Beneton Movie GIF so I could enable the “repeat forever” flag. The Javascript example just manipulates the CSS backgroundPosition property on a timer event…
Let me know if you generate any cool WPF 3D animation GIFs or filmstrips! :) If they’re really REALLY cool I’ll post them here!
→ 2 CommentsCategories: .NET
WordPress "Snap Preview"
February 20, 2008 · No Comments
You’ll be pleased to know I’ve finally switched off my annoying “Snap Preview” that WordPress.com enables by default. FYI here’s how you do it.
→ No CommentsCategories: .NET
