Topic: C#

Tiling a 2-D Polygon using C# GDI+

Tiling a Polygon

Tiling a Polygon

One of the most challenging problems I came across working on a .NET PDF Annotator and Editor application was to tile a 2-D polygon and also accurately determine the number of tiles that fill the surface of the polygon.  The tiling part was not as much of a challenge as the counting part. The tiled polygon was to be rendered on a PDF document since the application in question is a PDF Annotating and Editing tool. We looked for anything the third party .NET PDF rendering/manipulation API that was used could provide for the tile rendering but there was nothing unfortunately.
Continue reading »

More on Pure MVC for C#

puremvc

Last week, Karega Scott made a nice post on how Pure MVC makes development of Windows applications using C# simple. I thought I ll piggyback on this post and share some of my thoughts regarding this popular framework. I think the framework, if understood completely and adopted intelligently, has to offer some really cool benefits like :

  • Light-weight messaging mechanism (using Notification/Observer patterns) between different parts of the application without having to create custom events/hooks all over the place.
  • Highly Decoupled Components allowing abstraction and seperation of logic.
  • The application's testability is enhanced greatly because of the reason stated above.
  • A Centralized singleton Facade component that mediates between the different components in the application.
  • The use of commands in the framework can help in building complex applications that need to perform several different UI-driven functions.

Continue reading »

WinForms Development Made Simple with PureMVC

PureMVC is open source framework that allows creation of application using Model, View and Controller pattern, and was original designed for Flex, Air and Flash application. It has since been port to various languages include the .NET C# language. So when I first heard about it, several months ago, I was working on a pretty large WinForm application design around the MVP - Model, View and Presenter pattern.

Our presenters were responsible for handling the user interaction coming from the views by subscribing to events published by the views, and coordinating these actions with changes needs from the models such that these changes are then reflected back in the views themselves.

Although this approached work, it requires a lot of wiring and unwiring of events from the various presenters to views, presenters to model, and presenters to presenters. So the code quickly begins to look like the following:

public class presenter1

{

public event EventHandler<EventArgs> SomethingHappened;

public presenter1()

{

_model = new Model();

_model.StateChanged += OnModelChange;

_model.DocumentSaved += OnModelSaved;

_view = new View();

_view.OnMouseDown += OnMouseDown;

_view.OnMouseUp += OnMouseUp;

_view.OnMouseMove += OnMouseMove;

_view.OnMouseEnter += OnMouseEnter;

}

As you can see, for every user interaction on the view or model change a particular presenter is interested in, you must subscribe to an event, and if other presenters are interested in particular actions from views they are not responsible for, well, I’m sure you can get the picture. So act II, introduction of PureMVC framework for WinForms.

So exploring the capabilities of PureMVC framework, uncovered a simplification of our code. At its core, it consists of four singleton objects Model, View, Controller and Façade. The Model, View and Controller contain literal string references to Proxies which are data model, Mediators which provide and manage the user interface, and Commands which interact with the Proxies and Mediators or other commands.

But the simplification revolves around the Façade which is responsible to provide messaging throughout the core framework using an Observer notification scheme. So now our code quickly begins to look like the following:

public class presenter1 : Mediator

{

public presenter1()

{

}

public override void ListNotificationOfInterest()

{

return new List<string> { Nofication.ViewMouseClick, Notification.ModelChange,};

}

public override void HandleNofication(INofication notification)

{

switch(nofication.Name)

{

case Notification.ViewMouseClick:

Dosomething();

break;

}

}

public class presenter2 : Mediator

{

public presenter2()

{

}

public override void ListNotificationOfInterest()

{

return new List<string> { Nofication.ViewMouseClick,};

}

public override void HandleNofication(INofication notification)

{

switch(nofication.Name)

{

case Notification.ViewMouseClick:

DoSomethingFun();

break;

}

}

public partial class view1 : Page

{

protected void view_mouseclicked(object sender, MouseEventArgs e)

{

Façade.NotifyObserver(new PureMVC.Pattern.Notification(Notification.Name));

}

Both presenter1 and presenter2 state they are interested in Notication.MouseClick event, and view1 uses the Façade to notify both presenters that the user has clicked the mouse button. No need to publish and subscribe to any events outside what’s naturally needed in the view.

The only thing I dislike is the name references, but as long as we are using constants you should be fine.

Related Services: .Net Application Development, Custom Software Development

.NET Web Browser Control Gotchas

How many of you folks out there have used the .NET Web browser control for Windows applications? I bet most of you, at some point, must have done some head-scratching as to why Microsoft did not make this control as powerful as it should have been. This control does offer all of the navigation functions and basic browser capabilities but there is lot more that could have been done to enchance it's utility value. After some persistent fighting with this control in our current project, here are some gotchas that I have to offer.

Continue reading »

Microsoft Eats Its Young: AjaxPro is no more

Ajaxnet
Back when .NET didn't have an Ajax pot to piss in, I voraciously read Michael Schwarz's blog and followed his Ajax.NET framework. He eventually released a companion "Pro" version. Now, several Microsoft MVP awards later, he is packing it in. I, for one, will miss the competition in the .NET world. That leaves two major alternatives that I'm aware of:

  1. Anthem.NET
  2. Gaia Ajax Widgets

Since the concepts around how Ajax apps should be built are still in flux, it would be nice to have a few alternatives in the .NET world (especially ones that don't produce the XHR salad that ASP.NET Ajax does).

Technorati Tags: , , , ,

MS Volta: GWT for .NET

I missed this yesterday as I was immersed in the GWT conference. Over at MS Labs, you can see Volta, Microsoft's take on compiling to JavaScript, sort of like a GWT for the .NET platform.

You architect and build your application as a .NET client application,
assigning the portions of the application that run on the server tier
and client tier late in the development process. You can target either
web browsers or the CLR as clients and Volta handles the complexities
of tier-splitting. The compiler creates cross-browser JavaScript for
the client tier, web services for the server tier, and all
communication, serialization, synchronization, security, and other
boilerplate code to tie the tiers together. In effect, Volta offers a
best-effort experience in multiple environments without requiring
tailoring of the application.

Supposedly it compiles from MSIL (Microsoft Intermediate Language) to JavaScript, which allows you to compile from all of the .NET supported languages. Also, you can debug in VisualStudio.

There was a project call Script# that compiled C# to JavaScript, but this is a lot more substantial. Lots of docs and demos, too. I haven't kicked the tires on this yet, but I'll ask one of my .NET guys to check it out.

As for how it works under the covers:

In essence Volta is a recompiler. Volta works on MSIL rather than on a textual source language. Volta rewrites MSIL into any number of target languages, including, today JavaScript and MSIL itself. Rewriting, as a general technology, lets us delay permanent decisions about architecture, execution platform and browser until after our code is basically working. Furthermore, it frees us from having to express all these irreversible decisions in your source code. The result is a programming model that enables us to easily reshape a working application, and finally realizes the promise of one application running anywhere.

If you think about it, this is really not a threat to GWT, but a validation. If GWT is good for Java developers and Java projects, the same holds true for .NET. If you have C# developers, have them write C# for both the client and server side. Check as much as you can at compile time. Let the compiler deal with optimization, etc.

This, combined with the announcement on IE8 makes me more optimistic about MS's support for Ajax in the browser.

Topics: , ,

Framework Watch – Jayrock

Nice and simple, that's what I like in my dotnet frameworks. Jayrock certainly fits the bill there. It's somewhat similar to the Java-based DWR, in that it automatically generates a Javascript proxy class from your ASP.NET HTTP Handler. From the project page:

Jayrock is a modest and an open source (LGPL) implementation of JSON and JSON-RPC for the Microsoft .NET Framework, including ASP.NET. What can you do with Jayrock? In a few words, Jayrock allows clients, typically JavaScript in web pages, to be able to call into server-side methods using JSON as the wire format and JSON-RPC as the procedure invocation protocol. The methods can be called synchronously or asynchronously.

This framework could be used as the basis for a more full featured framework (like WebWork on top of DWR and Dojo). I'd like to see them follow DWR's lead and add Comet support.


Technorati : , ,

Topics: , ,

Eight Javascript Code Generators

Javascript code generation seems to be here to stay, with GWT taking roots and Ruby providing it's RJS Templates. It seems like it's time for a roundup of the little critters.

  • RJS Templates for Ruby on Rails - Not quite a true Ruby->Javascript compiler as it seems to me, but cuts down on lots of coding.
  • GWT - Java->Javascript. Everyone has heard of this beast. It's the 800 pound gorilla sucking the air out of the room for many other frameworks. Unique in that it provides a "hosted" mode that lets you debug in Java rather than Javascript.
  • pyjamas - Python->Javascript. Open Source project inspired by GWT from which it borrows some ideas. Fairly active.
  • Morfik - Java, Basic, C#, Object Pascal -> Javascript. Commercial offering from down under (Tazmania, dontcha know). Comes as an IDE that also provides server side development capability.
  • Script# - C#->Javascript. No "hosted mode," so you are stuck debugging the generated Javascript. Runs out of Visual Studio. One man's effort right now, though that man apparently works for Microsoft. Unclear what the future of this project might be.
  • Java2Script - Java->Javascript. Eclipse plugin. Predates GWT. Has a set of widgets based on SWT. Claims to allow you to convert your SWT based desktop apps into Javascript-based web apps. The demos (see screenshot of one of them) look promising.
  • j2s.jpg
  • Scheme2Js - Scheme->Javascipt. If you feel the need to get that LISP-like syntax when you write code, here is the compiler for you. There's an article describing the inner workings for those interested.
  • Haxe - Haxe->Javascript. Haxe is an OO language used to write web applications, among other things. You can also use it to write Flash and server side apps. All in one language. Didn't I just see a resume for a Haxe developer here somewhere?

I'd only feel comfortable using RJS and GWT at this point, since RJS doesn't really "hide" the Javascript all that much, and GWT provides the hosted mode. If you are debugging a complex, generated hunk of Javascript, you'd better be able to either make sense of the code (RJS) or go back to the source language (Java in GWT). I'm surprised the other tools don't think to provide some sort of high-level language debugging capability. I guess too few developers these days remember what it was like to debug assembly language generated from a compiler.

There's also the ParenScript LISP->Javascript compiler, but it, alas, seems to have gone the way of all single developer open source projects. Last, there is this article from Microsoft Research about the implementation of an Oberon to Javascript compiler. An interesting how-to of how such a thing can be built. Sorry, just the article, no download.



Technorati : , , , , , , , , ,

Launch: Pathfinder Newsletter

    Get a monthly update on best practices for delivering successful software.

    Subscribe via email


    Subscribe via RSS      RSS icon

Topics

Search

WordPress

Comments about this site: info@pathf.com