Tuesday, February 02, 2010

More Fun with Fluent NHibernate Automapping

NHibernate is a flexible and adaptable framework; and when you understand the way it works and how to utilize its strengths, it can bring significant benefits to your projects. But being flexible and adaptable comes at a cost. Developers who are new to this ORM framework often claim that NHibernate has a steep learning curve, and they are correct –mastering NHibernate does require significant study.

Like any other tool, you need to get the facts and carefully consider where you'll invest your limited time. One of my personal 2010 goals is to become completely comfortable with both NHibernate and Fluent.NHibernate. I made this decision after a great deal of thought and study. My conclusions were that NHibernate is still years ahead of competing technologies and is likely to remain so for the foreseeable future for .NET developers. I could have decided to invest my time studying ASP.NET MVC, but I decided that NHibernate is much more important for me.

Fortunately, there are some new approaches including Fluent NHibernate, which is now in its 1.0 RTM iteration, that can make basic NHibernate projects very easy to implement and which can give you a taste of how powerful NHibernate really is, but with only a very modest investment of effort. That’s the purpose of this article.

To begin with, this tutorial focuses on the “Top Down” development paradigm. As Microsoft .NET Framework developers, most of what we have learned and most of the tools we have been given (LINQ To SQL, Entity Framework, DataSets, and so on) have been what we call “Data-centric” – meaning that you start with the database schema, and build everything around that. This is a methodology that can quickly create difficulties when one wants to approach business problem solutions in a true OOP – object oriented manner. With NHibernate and Fluent NHibernate, you do not need “Visual Designers” because you can start with your domain model and not have to worry about what the database will look like. And, you don't need to stab your fingers anymore with XML Mapping files!

Read more: eggcafe

Posted via email from jasper22's posterous

Creating a Simple IoC Container

Inversion of Control (IoC) is a software design principle that describes inverting the flow of control in a system, so execution flow is not controlled by a central piece of code. This means that components should only depend on abstractions of other components and are not be responsible for handling the creation of dependent objects. Instead, object instances are supplied at runtime by an IoC container through Dependency Injection (DI).

IoC enables better software design that facilitates reuse, loose coupling, and easy testing of software components.

At first IoC might seem complicated, but it’s actually a very simple concept. An IoC container is essentially a registry of abstract types and their concrete implementations. You request an abstract type from the container and it gives you back an instance of the concrete type. It’s a bit like an object factory, but the real benefits come when you use an IoC container in conjunction with dependency injection.

An IoC container is useful on all types of projects, both large and small. It’s true that large, complex applications benefit most from reduced coupling, but I think it’s still a good practice to adopt, even on a small project. Most small applications don’t stay small for long. As Jimmy Bogard recently stated on Twitter: “the threshold to where an IoC tool starts to show its value is usually around the 2nd hour in the life of a project”.


Read more: Tim Ross

Posted via email from jasper22's posterous

Phalanger

Phalanger is a new PHP  implementation introducing the PHP  language into the family of compiled .NET languages. It provides PHP applications an execution environment that is fast and extremely compatible with the vast array of existing PHP code. Phalanger gives web-application developers the ability to benefit from both the ease-of-use and effectiveness of the PHP language and the power and richness of the .NET platform taking profit from the best from both sides.

Developing .NET/Mono applications or libraries with PHP

Thanks to the full .NET/Mono support it is also possible to develop all kinds of .NET applications using PHP language. This includes applications with Windows Forms/Gtk# user interface, class libraries and web applications build using the ASP.NET infrastructure. This allows you to develop ASP.NET style applications which benefits from the ASP.NET features like code separation using code-behind, ASP.NET controls (including any third-party controls) and other. You can use this Phalanger project for smoothly porting PHP applications to the ASP.NET infrastructure, because you can make the original PHP application a part of a larger ASP.NET system, but still write all the source code in the PHP language.


Read more: Phalanger

Posted via email from jasper22's posterous

.Net Remoting Made Easy

   The subject of .net remoting can be very complex. There are several different ways you can do remoting; you can marshall by value or by reference, you can use server-side activation or client-side activation. You can choose SingleCall or Singleton instantiation, among others. You can use either of the default protocols (tcp or http) or you can use a custom protocol.

In this article I’m going to attempt to give you, the reader, the most “bang for your buck”. In other words, I’m going to use a configuration which I believe addresses the majority of situations you are likely to encounter, and I’m going to strip away everything that’s unnecessary for this configuration. (It’s sort of an 80/20 thing, if you change 80/20 to about 90/10.)

The scenario we’ll look at is one where we marshall by reference, use server-side activation, and Singleton instantiation. The implementation I use will work equally well for either TCP or HTTP protocols. In addition, I’ll show you how to make everything configurable so that you can change either the client implementation or the server implementation on the fly, without having to change any code or recompile.

This article is meant to be a quick tutorial to get you up and running quickly. I’m not going to go into any lengthy explanations about what remoting is, or when and why you should use it other than to say that its best used when you need to communicate internally behind your firewall, between applications/servers hosted on the same platform. In other words, you can’t use .net remoting to communicate between a .net application and a java application, or over the internet. If you want more in depth information in that regard, there’s a ton of it on Microsoft’s web site.

Read more: Murray Hill Technologies

Posted via email from jasper22's posterous

Global Windows Hooks

There are many articles of this type, but I didn't find any article discussing about how to hook the mouse and the keyboard using Visual Basic .NET. Since I have done this in VB.NET, I decided to post it here for people who will need it.

This project is a single component that contains various Windows hooks (I might add some other hook types in this component in future, if I have time).

  • Clipboard hook
  • Keyboard hook
  • Mouse hook

It is a library file WindowsHookLib.dll that can be referenced from various projects.

This component differs from what I have seen in other similar articles, by providing two more things:

  1. Preventing a message to be passed to other windows.
  2. Raising the MouseClick and MouseDoubleClick events. (I have never seen them in other low level hooks!)

Read more: CodeProject

Posted via email from jasper22's posterous

The Pain of deploying Primary Interop Assemblies

Alright, first of all, what are Primary Interop Assemblies (PIAs), and why am I devoting an entire post to the pains caused by deploying these things? And secondly, how do they relate with what we’ve been talking about thus far?

The answer to the second question is simple – we’ve been talking about COM Interop in C# lately, and we’ve just gotten through how C# 4.0 makes Indexed Properties accessible in a first class manner. Primary Interop Assemblies fit to the picture because they’re the way that COM interfaces are exposed into the managed world. In essence, they’re the bridge that allows you to use native COM “stuff” from your managed programming models. They are typically large API collections that must be deployed along with client applications.

What’s wrong with deploying PIAs?

Well, nothing’s wrong with it per se, but it certainly isn’t pleasant for developers who just want to write code against a COM API to have to worry about shipping the PIAs onto the client box, worry about whether or not it already exists on the client machine and what version lives there and all that. As I’ve mentioned before, you can think of the overarching theme of C# 4.0 as an interop release, one where we attempt to make interoping with different programming models and paradigms much simpler and much more first class.


Read more: Sam Ng's Blog

Posted via email from jasper22's posterous

AutoCompleteComboBox for Silverlight

The built-in ComboBox in Silverlight is not powerful enough to cater our requirements of enterprise applications. In LOB (Line of business) applications, sometimes we need type-ahead behavior for combo boxes so that the available choices are filtered as the user starts typing. The AutoCompleteBox (previously included in Silverlight Toolkit but now a part of Silverlight 3 native controls) is a very powerful and flexible control, and in this article, we will look how we can customize the AutoCompleteBox to be used as a replacement for Combo Box/Drop Down.

What will we cover?

To begin the article, let's first define what functionalities we need to add to the AutoCompleteBox to make it behave like a type-ahead customizable drop down combo box. Here are our requirements:

  1. There should be a down-arrow like button that pops up the drop down with the available choices. Currently, the AutoCompleteBox is a simple textbox in its original shape.
  2. When an item is selected, bringing the drop down should show ALL the available choices. Currently, it only displays the selected one.
  3. If an item is selected and the drop down is opened, the selected item should be highlighted.
  4. The custom AutoCompleteBox should be useable for concrete object-to-object relationships (e.g. SalesOrderDetail object containing a reference to the Project object, also called associations or navigational properties).
  5. The custom implementation should be useable in foreign key relationships (e.g. SalesOrderDetail object containing a field called ProductID).
To address all these, we will create an AutoCompleteComboBox control that inherits the AutoCompleteBox and start adding the above features to it.


Read more: CodeProject

Posted via email from jasper22's posterous

The Quick and Easy on Using NMCap to Create Circular Network Traces Based on File Size

I wanted to take a minute to show you a quick way to utilize Network Monitor to perform Sequential, or also called Circular, captures for troubleshooting issues.  This is particularly useful when you can’t dictate when the networking communications you are looking for are going to happen. This method of troubleshooting has been available via GUI configurations using other network traffic capture utilities but has been, and currently is, only available through the command line options provided with Network Monitor. 

(NMCap is a tool that is installed when you install Network Monitor 3.x.  This is a command line based tool that provides great a bit of functionality.  As time goes by you will find more postings on other uses this tool can provide.)

As said before, the goal of this discussion is to describe how to collect a sequential trace.  What I mean by that is that you set Netmon to create a trace that only grows so large… 200MB for example.  Once the capture has grown to 200MB it will close the current file and create a new one.  That file will grow up to 200MB and then create another file.  This will provide you the ability to go back and review your files and look to see if the date/time stamp matches the date/time of when your possible problem may have occurred.  Having this information helps because you can delete the trace files that you know do not meet your criteria.  If you were to just start a trace file and walk away it could easily fill your hard drive or become so large that it will become too much of a burden to be open or parsed in a timely fashion. 


Read more: Microsoft Enterprise Networking Team

Posted via email from jasper22's posterous

Yahoo YUI Compressor vs. Microsoft AJAX Minifier vs. Google Closure Compiler

A little more than a year and half ago I created a MSBuild Task for the YUI Compressor that was very well received, and even highlighted on the YUI Compressor site.  At the time of writing that article YUI Compressor was king of the hill, and for the most part the only game in town that was really designed for production level use.  Since then a number of new competitors have been released by Google and Microsoft, and I wanted to see how they stacked up against the YUI Compressor.

Setup

For these tests I wanted to test a pretty complex set of JavaScript to really stretch the limits of each of the optimizers. So I choose jQuery 1.4 as the subject for the tests.  I choose jQuery for many reasons, but the biggest is because it is very well known set of code for most developers, and it would be very easy for anybody to test in their applications.

The setup of my machine is as follows:

  • Windows 7 Pro (x64)
  • Java 6 Update 17
  • .NET 3.5 SP1

Each optimizer and the version:


Read more:  Nick Berardi's Coder Journal

Posted via email from jasper22's posterous

50 Brilliant CSS3/JavaScript Coding Techniques - Smashing Magazine

dynamic PNG shadow position & opacity
When the light is turned on, the position and opacity of the logo shadow will change dynamically, depending on the position and distance of the light bulb. Don’t forget to drag the logo and/or the light bulb around!


css3-new-00.jpg

Read more:  Smashing Magazine

Posted via email from jasper22's posterous

Sun.com is dead now

Just found that sun.com is now redirecting to oracle.com. Some days back I visited Sun’s original website. But it didn’t took long by Oracle to make it red. Well I am a regular visitor of Sun forums. And with this change, I am trying to adjust myself with this transition. As I am having some issue in finding contents.

Read more: pakzilla

Posted via email from jasper22's posterous

Did you know about db4o – a brilliant object oriented database

One of my habits is making utilities app with C#.Net. I made a lot of small apps and a lot of them will require some sort of local database. Normally I’m just using XML serialization. It’s a quick solution, easy to implement and you could read the XML file and change it with just the notepad. However, I’m planning on a middle-size project lately. It does not require a complex structure but the amount of data is kind of big so XML is not really suitable anymore. So I’m on the search for a easy to use local database. It’s when I found Open new tab “db4objects”.

Read more: HIEUUK

Posted via email from jasper22's posterous

Finding a Node in an XML String - Deborah's Developer MindScape

A common requirement with an XML file is to find a particular node. If you are targeting the .NET framework 3.5 or higher, you can find the node using Linq to XML or by using Lambda expressions.

As with many of my prior XML examples, the XML string is as follows:

<States>
  <State name="Wisconsin">
    <Regions>
      <Region name="Milwaukee">
        <Area name="Mukwanago"/>
        <Area name="Germantown"/>
      </Region>
      <Region name="Fox Valley">
        <Area name="Oshkosh" />
        <Area name="Appleton" />
      </Region>    
    </Regions>
  </State>
</States>

The code to find the node for the Milwaukee region is as follows:

In C#:

// Be sure to set a reference to System.Core and System.Xml.Linq
XElement states  = XElement.Load("testXML.xml");

// Using LINQ
XElement foundNode;
var query = from XElement r in states.Descendants("Region")
                   where r.Attribute("name").Value == "Milwaukee"
                   select r;
foundNode = query.FirstOrDefault();

// Using Lambda expressions
foundNode = states.Descendants("Region").
     Where(r => r.Attribute("name").Value ==
                         "Milwaukee").FirstOrDefault();

In VB:

' Be sure to set a reference to System.Core and System.Xml.Linq
Dim states As XElement = XElement.Load("testXML.xml")

' Using LINQ
Dim foundNode As XElement
Dim query = From r As XElement In states...<Region> _
                  Where r.@<name> = "Milwaukee"
foundNode = query.FirstOrDefault()

' Using Lambda expression
foundNode = states...<Region>.Where(Function(r) r.@<name> =  _ 
                                 "Milwaukee").FirstOrDefault

This code first loads the XML file containing the XML. The next set of code can be done using LINQ or using Lambda expressions. Use either one, but not both. :-)

The C# code uses the XElement properties and methods. The VB code uses XML literals.

NOTE: The XElement properties and methods work in VB as well.

Enjoy!

NOTE: This post was created based on a prior post that included both finding a node and adding new nodes. This post separates the first step to provide a more straightforward example.


Read more:  Deborah's Developer MindScape

Posted via email from jasper22's posterous

Visual Studio Tips and Tricks : Guidelines, a hidden feature for the Visual Studio Editor -- vstipEdit0015

Guidelines, a hidden feature for the Visual Studio Editor -- vstipEdit0015

 

image

 

So this is the first tip update I have done that has apparently been removed in VS2010.  At the time of this writing I am talking with the VS editor folks to find out if the registry hack is, in fact, gone or just needs to go somewhere else.  I will update this post if I discover any change. 

 

With that said, if you are using Visual Studio 2010 there is an extension, created by Paul Harrington, you can use to have the guidelines:

 

http://visualstudiogallery.msdn.microsoft.com/en-us/0fbf2878-e678-4577-9fdb-9030389b338c


Read more: Visual Studio Tips and Tricks

Posted via email from jasper22's posterous

User Account Control Step-by-Step Guide - Sent using Google Toolbar

This step-by-step guide provides the instructions necessary to use User Account Control (UAC) in a test environment.

This document is not intended to provide a comprehensive, detailed description of UAC. Additional resources include the following:

  • All users of this step-by-step guide will also be interested in Getting Started with User Account Control on Windows Vista (http://go.microsoft.com/fwlink/?LinkID=102562).

  • For additional information for IT professionals, see Understanding and Configuring User Account Control in Windows Vista (http://go.microsoft.com/fwlink/?LinkId=56402).

  • For information for developers and independent software vendors about how to develop applications for Windows Vista® or Windows Server® 2008, see The Windows Vista and Windows Server 2008 Developer Story: Windows Vista Application Development Requirements for User Account Control (UAC) (http://go.microsoft.com/fwlink/?LinkId=89654).

What is User Account Control?

User Account Control (UAC) is a new security component in Windows Vista. UAC enables users to perform common tasks as non-administrators, called standard users in Windows Vista, and as administrators without having to switch users, log off, or use Run As. A standard user account is synonymous with a user account in Windows XP. User accounts that are members of the local Administrators group will run most applications as a standard user. By separating user and administrator functions while enabling productivity, UAC is an important enhancement for Windows Vista.


Read more: Technet

Posted via email from jasper22's posterous