October 2008 - Posts
Lot's of good stuff today but first here's the new .NET logo and VS2010 & .NET CLR CTP!
Alot interesting posts this week - I collected the ones that I liked (and read their blog) the most.
Hope you'll enjoy this weekend reading.
DSL Tools / T4 /Modeling
Architecture /Enterprise Architecture /SOA
This is really cool - Photosynth, just click the link and you will be able to explore and create new worlds that were created by synthesizing all the picuters in to a single stunning virtual 3D memory.
I came across this cool thing:
The Forbidden City: Beyond Space and Time is a partnership between the
Palace Museum and IBM. The goal of the project is to provide the means
for a world-wide audience to celebrate and explore aspects of Chinese
culture and history
I came across this project at codeplex here's the project summery:
The MSBuild Extension Pack is the successor to the FreeToDev MSBuild Tasks Suite and provides a collection of over 170 MSBuild tasks designed for the .net 3.5 Framework. A high level summary of what the tasks currently cover includes the following:
• System Items: Certificates, COM+, Console, Date and Time, Drives, Environment Variables, Event Logs, Files and Folders, GAC, Network, Performance Counters, Registry, Services, Sound
• Code: Assemblies, CAB Files, Code Signing, File Detokenisation, GUID’s, Mathematics, Strings, Threads, Zip
• Applications: BizTalk 2006, Email, IIS7, MSBuild, SourceSafe, StyleCop, Team Foundation Server, Visual Basic 6, WMI
It implements a TaskAction based design which improves usability and maintenance whilst reducing the code base, e.g. to start or stop a website, typically two task files would be created to perform each task, whereas the pack accomplishes this in a single task files using TaskAction=”Stop” and TaskAction=”Start”.
Each task is documented and provided with an example in the help file. Where applicable, tasks are remote enabled, simply specify a MachineName and the task will target the remote machine.
Additional tasks and improvements to the documentation will be released frequently. I would encourage users to make use of the Issues and Discussions features on CodePlex and to contribute code to help drive this project forward."
When dealing with unmanaged resources (or in more general – when finalize is required) you need to use a certain pattern in order to get it right.
According to MSDN (brought here for convinience):
When to use finalize:
· Implement Finalize only on objects that require finalization. There are performance costs associated with Finalize methods.
· If you require a Finalize method, consider implementing IDisposable to allow users of your class to avoid the cost of invoking the Finalize method.
· Do not make the Finalize method more visible. It should be protected, not public.
· An object's Finalize method should free any external resources that the object owns. Moreover, a Finalize method should release only resources that the object has held onto. The Finalize method should not reference any other objects.
· Do not directly call a Finalize method on an object other than the object's base class. This is not a valid operation in the C# programming language.
· Call the base class's Finalize method from an object's Finalize method.
When to use Dispose method:
· Implement the dispose design pattern on a type that encapsulates resources that explicitly need to be freed. Users can free external resources by calling the public Dispose method.
· Implement the dispose design pattern on a base type that commonly has derived types that hold onto resources, even if the base type does not. If the base type has a Close method, often this indicates the need to implement Dispose. In such cases, do not implement a Finalize method on the base type. Finalize should be implemented in any derived types that introduce resources that require cleanup.
· Free any disposable resources a type owns in its Dispose method.
· After Dispose has been called on an instance, prevent the Finalize method from running by calling the GC..::.SuppressFinalize. The exception to this rule is the rare situation in which work must be done in Finalize that is not covered by Dispose.
· Call the base class's Dispose method if it implements IDisposable.
· Do not assume that Dispose will be called. Unmanaged resources owned by a type should also be released in a Finalize method in the event that Dispose is not called.
· Throw an ObjectDisposedException from instance methods on this type (other than Dispose) when resources are already disposed. This rule does not apply to the Dispose method because it should be callable multiple times without throwing an exception.
· Propagate the calls to Dispose through the hierarchy of base types. The Dispose method should free all resources held by this object and any object owned by this object. For example, you can create an object such as a TextReader that holds onto a Stream and an Encoding, both of which are created by the TextReader without the user's knowledge. Furthermore, both the Stream and the Encoding can acquire external resources. When you call the Dispose method on the TextReader, it should in turn call Dispose on the Stream and the Encoding, causing them to release their external resources.
· Consider not allowing an object to be usable after its Dispose method has been called. Re-creating an object that has already been disposed is a difficult pattern to implement.
· Allow a Dispose method to be called more than once without throwing an exception. The method should do nothing after the first call.
To combine all this info into code we will get the following:
1: // Design pattern for a base class.
2: public class Base : IDisposable
4: private bool isDisposed = false;
6: //Implement IDisposable.
7: public void Dispose()
13: protected virtual void Dispose(bool disposing)
15: if (!isDisposed)
17: if (disposing)
19: // Free other state (managed objects).
21: isDisposed = true;
24: // Free your own state (unmanaged objects).
25: // Set large fields to null.
26: /* Example: (note that dispose should throw errors)
27: if (obj != null)
30: obj = null;
35: // Use C# destructor syntax for finalization code.
38: // Simply call Dispose(false).
42: // Design pattern for a derived class.
43: public class Derived : Base
45: protected override void Dispose(bool disposing)
47: if (disposing)
49: // Release managed resources.
51: // Release unmanaged resources.
52: // Set large fields to null.
53: // Call Dispose on your base class.
56: // The derived class does not have a Finalize method
57: // or a Dispose method without parameters because it inherits
58: // them from the base class.
I’ve created a snippet that that will enable you to reuse this code:
Just unzip and throw the file in to “My documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets” – download it here
Mono 2.0 is a portable and open source implementation of the .NET framework for Unix, Windows, MacOS and other operating systems.
Microsoft Compatible APIs
- ADO.NET 2.0 API for accessing databases.
- ASP.NET 2.0 API for developing Web-based applications.
- Windows.Forms 2.0 API to create desktop applications.
- System.XML 2.0: An API to manipulate XML documents.
- System.Core: Provides support for the Language Integrated Query (LINQ).
- System.Xml.Linq: Provides a LINQ provider for XML.
- System.Drawing 2.0 API: A portable graphics rendering API.
- Gtk# 2.12: A binding to the Gtk+ 2.12 and GNOME libraries for creating desktop applications on Linux, Windows and MacOS X.
- Mono.Cecil: A library to manipulate ECMA CLI files (the native format used for executables and libraries).
- Mono.Cairo: A binding to the Cairo Graphics library to produce 2D graphics and render them into a variety of forms (images, windows, postscript and PDF).
- Mono's SQLite support: a library to create and consume databases created with SQLite.
- Mono.Posix: a library to access Linux and Unix specific functionality from your managed application. With both a low-level interface as well as higher level interfaces.
Third Party APIs bundled with Mono
- Extensive support for databases: PostgreSQL, DB2, Oracle, Sybase, SQL server, SQLite and Firebird.
- C5 Generics Library: we are bundling the C5 generics collection class library as part of Mono.
For cross-platform graphics, Mono also offers Mono.Cairo.
For database access, Mono provides bindings to SQLite
If you are looking to manipulate compiled assemblies, Mono.Cecil does just that.
Although the author writes about java applications the concepts are the same for .NET and supported to some extent by Visual Studio Test Edition
Here's the summery:
"Performance tuning was once more “art” than “science”, but after a combination of abstract analysis and trial-and-error, wait-based tuning has proven to make the exercise far more scientific and far more effective. Wait-based tuning begins by performing a wait-point analysis of an application’s architecture in order to identify technologies employed by the architecture that can potentially cause a request to wait. Wait-points come in two flavors: tier-based wait-points, which are indicative of any transition between application tiers, and technology-based wait-points, which are technology features such as caches, pools, and messaging infrastructures that can improve or hinder performance. With a set of wait-points identified, the tuning process is implemented by opening all tier-based wait-points and external dependency pools, generating balanced and representative load against the application, and tuning backwards, or tightening wait-points to maximize the performance of a request’s weakest link, but without saturating it.
Wait-based tuning has proven itself time and time again in real-world production environments to not only be effective, but to allow a performance engineer to realize measurable performance improvements very quickly."
That's it for now
Well I accidently click delete on my recycle bin and whoops it’s done after a quick search here’s the solution:
Start->Control Panel->Appearance and Personalization->Personalization and then click "change desktop icons" from the left-hand column.
From there just check Recycle Bin and click OK.
There's a nice switch in MSBuild:
The available verbosity levels are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. /v is also acceptable.
This way there's a lot of extra info that is generated for you and hopefully should help your debugging.
However there's another way - you can create a task that will just output the stuff you wan't to debug. I used it when I had to check why our custom code analysis wasn't working as we expect it to work:
First of all you need to make sure that you build is depends on something (this case BuildDependsOn) :
<Target Name="Build" DependsOnTargets="$(BuildDependsOn)"/>
Now we can add custom actions:
And here's the actual custom action (will print out all the rules):
<Message Condition="$(RunCodeAnalysis)'=='true'" Text="Rules: $(CodeAnalysisRules)"/>
Now you can search the output for "EyalDebugMessage and see all the rules
A friend at work pointed out this post by Oleg.
Here's the beginning of the post:
Here is how MSDN documentation defines the assembly directive.
The assembly directive identifies an assembly to be referenced so that you can use types within that assembly from code in the text template. Using the assembly directive is equivalent to using the Add Reference feature in Visual Studio.
This directive does not affect the source code of the compiled template. Instead it affects compiler options T4 uses to compile GeneratedTextTransformation into a .NET assembly. Here is an example of a T4 template and C# compiler T4 uses to compile it.
<#@ template language="C#" debug="True" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Data" #>
DataSet dataSet = new DataSet();
/t:library /utf8output /D:DEBUG /debug+ /optimize- /w:4
For the rest of the post
This blog carnival will be entirely dedicated to web development in MS platform.
Scott has published a whole list of links in his blog
· Amazon EC2 Support for Windows and ASP.NET: Big news announced this week: Amazon will be offering Windows Server 2008 as an option in their EC2 service. This enables you to use ASP.NET, IIS7 and SQL Server in the cloud.
· Using ASP.NET WebForms, MVC and Dynamic Data in a Single Application: Scott Hanselman has a nice post that demonstrates how you can have a single ASP.NET application that uses ASP.NET WebForms, MVC, WebServices and Dynamic Data. You have the flexibility to mix and match them however you want, which allows you to always use the right tool depending on the specific job.
· Modifying Data with the ListView's EditItemTemplate: Matt Berseth has a great post that talks about how to use the ASP.NET 3.5 ListView control to enable in-place editing scenarios - with total html markup control.
· 4 New Grouping Grid Skins: Vista, Bold, Win2k3 and Soft: Matt Berseth has another nice post that demonstrates how to skin the ASP.NET ListView control to enable some sweet data grouping scenarios.
· Unlocking and Approving User Accounts: Scott Mitchell posts another in his great series of articles on ASP.NET security (click here for all the articles in the series). This article talks about how you can setup administration pages that allow admins to lock out and approve user accounts using the ASP.NET Membership system.
· Adding OpenID to you website in conjunction to ASP.NET Membership: Dan Hounshell has a nice article that discusses how to add OpenID authentication support to your web-site, and use it in conjunction to ASP.NET's built-in membership system.
· MVC Membership with Preview 5: Troy Goode posts an update of his popular MVC Membership template that works with ASP.NET MVC Preview 5. It provides a set of administration pages you can use for user/role management, as well as adds support for OpenID and Windows LiveID.
· MVC Flickr Xplorer: Mehfuz Hossain has a cool ASP.NET MVC sample application posted that enables a nice picture explorer for FlickR photos.
ASP.NET Dynamic Data
· Simple 5 Table Northwind Example: Matt Berseth kicks off his ASP.NET Dynamic Data tutorial series with a nice post that shows how to build a simple 5 table application using ASP.NET Dynamic Data with .NET 3.5 SP1.
· Dynamic Data And Custom Metadata Providers: Matt continues the series and covers the MetadataType attribute, and how you can use it to annotate your entities with additional metadata.
· Dynamic Menu for your Dynamic Data: Matt continues and covers how to add a data-driven menu to the site.
· Customizing the Delete Confirmation Dialog: Matt continues and demonstrates how to build a nice UI experience when deleting records in a dynamic data application.
· Experimenting with YUI's DataTable and DataSource Controls: Matt experiments with how to use client-side AJAX components together with dynamic data.
Scott Hanselman has posted Plug-In Hybrids: ASP.NET WebForms and ASP.MVC and ASP.NET Dynamic Data Side By Side
Sam Gentile has a posted about his Thoughts on Web Development with ASP.NET Dynamic Data, Castle Active Record, jQuery
Tomorrow I'll compile more general Blog Carnival for you...