Andrew Matthews describes another interesting pattern in [1], which he called Ambient Content Pattern :

"Provide a place to store scope or context related information or functionality that automatically follows the flow of execution between execution scopes or domains."

[1] http://aabs.wordpress.com/2007/12/31/the-ambient-context-design-pattern-in-net/

Posted at Wednesday, January 02, 2008 2:38:13 PM (W. Europe Standard Time, UTC+01:00) 
Comments [0] #      | 

Microsoft offers free copies of the following books at [1]:

Introducing Microsoft LINQ by Paolo Pialorsi
Introducing Microsoft ASP.NET AJAX by Dino Esposito
Introducing Microsoft Silverlight 1.0 by Laurence Moroney


[1] http://csna01.libredigital.com/

Posted at Wednesday, January 02, 2008 8:39:36 AM (W. Europe Standard Time, UTC+01:00) 
Comments [0] #      | 

Since I read "Design Patterns. Elements of Reusable Object-Oriented Software" by the GoF the very first time in 1999, I am a big fan of patterns at all. Making heavy use of factory patterns such as the Factory Method or Abstract Factory I came along with a useful pattern we call a Declarative Factory. A Declarative Factory is based especially on the Attribute construct in the .NET Framework and allows you to extend new classes with factory capabilities in a zero-effort manner. The idea behind this pattern is to extend your application with new constructs in form of extensions without touching already existing code. This is possible when your extensions are provided by container objects. The key element here is about the new elements which you are not aware in your code yet.

This pattern is much like a Abstract Factory, however, there is no need  to create a concrete Factory class.
Also you add factory capabilities to  a new class by only adding the corresponding attribute.

Declarative Factory Pattern

First we have a look at the actual container object. Here we tell the container object to provide factory capabilities to create ConcretePrototype instances. The FactoryContainer can be any class we are using within our application, as example this could be a sub-class of ListViewItem in a WPF-based application.

[DeclarativeFactory(typeof(ConcretePrototype))]
public class FactoryContainer { }

The declaration of the ConcretePrototype is also straightforward. The IPrototype is the common interface for all prototypes that can be created by the Declarative Factory. If this pattern is applied to a WPF-based object this could also something like a DependencyObject or a FrameworkElement. In this case the DeclarativeFactory cold provide factory capabilities for the corresponding types.

public class ConcretePrototype : IPrototype

The attribute itself looks as following:

DeclarativeFactory Attribute

The magic now, lies in the way how to invoke the factory method provided by the Declarative Factory.

FactoryContainer container = new FactoryContainer();

DeclarativeFactoryAttribute[] a_attrib =
   (DeclarativeFactoryAttribute[]) container.GetType().GetCustomAttributes(
typeof(DeclarativeFactoryAttribute), true); IPrototype prototype = a_attrib[0].Create() as IPrototype;

You just resolve the factory attribute and call the factory method. Very easy, isn't it? However, you have to keep a few things in mind about this pattern.  First of all, it makes no sense if you already know about the class you want to instantiate. So, there is absolutely no reason to apply the Declarative Factory to the class itself. In this case you should definitely stay with common patterns such as the Factory Method. If you are going to make you project extensible where new types are provided through container objects this pattern appears to be very handy .

You can download the example source code for this pattern (under MS-Pl) at CodePlex [1].

 

[1] http://www.codeplex.com/declarativefactory

Posted at Tuesday, January 01, 2008 12:33:33 PM (W. Europe Standard Time, UTC+01:00) 
Comments [0] #      | 

After reading about dzone [1] in Matthias' blog [2], I signed up an account there and published my first article [3]. Having only a very quick look on this portal, it looks to me like one of those few, providing additional value.

dzone

[1] http://www.dzone.com/
[2] http://unmaintainable.wordpress.com/2007/12/22/one-year-of-blogging/
[3] http://www.dzone.com/links/wcf_net_35_and_http_request_content.html

Posted at Monday, December 31, 2007 12:31:07 PM (W. Europe Standard Time, UTC+01:00) 
Comments [1] #      | 

web.config files can be easily extended using the configSection tags.

A brief overview is given by Aaron Johnson on his blog [1], referring the original MSDN documentation [2].

[Update 12/31/2007]

Also another brief summary by Dieder Tierman [3] and a very good How-to on MSDN [4] how to write own section handlers.

[1] http://cephas.net/blog/2003/09/26/extending-webconfig-in-aspnet/
[2] http://msdn2.microsoft.com/en-us/library/0hyxd0xc(vs.71).aspx
[3] http://ms-dotnet.blogspot.com/2007/01/create-custom-configuration-section-in.html
[4] http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx

Posted at Monday, December 31, 2007 9:42:34 AM (W. Europe Standard Time, UTC+01:00) 
Comments [0] #      | 

This update [1] finally supports the new file formats of Office 2007 on your mobile device:

To allow Windows Mobile users to work with Office documents created in the Open XML formats, Microsoft has developed an upgrade for Word Mobile, Excel Mobile, and PowerPoint Mobile applications. This upgrade to the Office Mobile applications allows viewing and editing of Word documents and Excel workbooks and viewing of PowerPoint slideshows created by using Microsoft Office 2007.


Other improvements include:
• Enhanced viewing experience for charts in Excel Mobile.
• Ability to view SmartArt in PowerPoint Mobile.
• Ability to view and extract files from compressed (.zip) folders.

The update need approximately 7 Mb on your device so I would recommend using a memory card for the installation.

[1] http://www.microsoft.com/downloads/...

Posted at Saturday, December 29, 2007 11:53:46 AM (W. Europe Standard Time, UTC+01:00) 
Comments [0] #      | 

Looks like it enables import and live preview of RAW files in Vista without any further third-party tool. Can be downloaded at [1].

[1] http://www.olympus.co.jp/...

Posted at Friday, December 28, 2007 11:41:50 AM (W. Europe Standard Time, UTC+01:00) 
Comments [0] #      | 

Sometimes, simple things end up as epic battles. If you try to MSN Search and Google for the nasty "You have create a Service" page for IIS hosted WCF services, you will and up with a lot of pre-release information and noise in the search results. Actually, you might spend days in finding some relevant information.

You have created a service.

Yesterday, I was finally pointed to the right place in the MSDN documentation [1] where you can find this specific information:

<serviceDebug httpHelpPageEnabled="Boolean"
    httpHelpPageUrl="Uri"
    httpsHelpPageEnabled="Boolean"
    httpsHelpPageUrl="Uri"
    includeExceptionDetailInFaults="Boolean" />

With the serviceDebug tag it should be possible to get rid of the page. It is easy to find as long as you know you have to search for HTML help page.

[1] http://msdn2.microsoft.com/en-us/library/ms788993.aspx

Posted at Friday, December 21, 2007 9:18:05 AM (W. Europe Standard Time, UTC+01:00) 
Comments [1] #      | 
XLINQ Summary
Posted in .NET | Coding

I just found this nice LINQ to XML summary [1] on The Code Project.

[1] http://www.codeproject.com/KB/vista/LINQ_3.aspx#LoadingXML

Posted at Sunday, December 09, 2007 11:58:39 PM (W. Europe Standard Time, UTC+01:00) 
Comments [1] #      | 

The new Web Programming Model [1] of WCF and the .NET Framework brings some very useful features such as the WebGet and the WebInvoke Attribute and the capability to deal directly with HTTP requests. But how do we access the HTTP request in these methods? Dealing with HTTP requests and responses using the System.Net namespace is quite straight forward. Therefore, we have a look in sending and receiving a simple HTTP request:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(myUrl);
byte[] a_dataBytes = Encoding.UTF8.GetBytes(data);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = a_dataBytes.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(a_dataBytes, 0, a_dataBytes.Length);

WebResponse
response = request.GetResponse(); StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
var content = responseReader.ReadToEnd();

Now we want to access the HTTP context within a operation with the following signature:

[OperationContract]
[WebInvoke(Method = "PUT", UriTemplate = "{uri}")]
bool Put(string uri);

Accessing the context of the incoming request is straightforward using the WebOperationContext class.

IncomingWebRequestContext context =
    WebOperationContext.Current.IncomingRequest;

var length = context.ContentLength;
var type = context.ContentType;
var headers = context.Headers;

Since the documentation does not provide many example code, and the ORCAS samples do not cover this yet, I had to figure out how to access the content of the incoming request. After spending hours on MSN Search, Google and the MSDN Library I finally tried out something. In some general examples, either a Message or a Stream is passed over as single parameter to the operation. Hence, I changed the contract as follows:

[OperationContract]
[WebInvoke(Method = "PUT", UriTemplate = "{uri}")]
bool Put(string uri, Stream stream);

Reading the content then is easy:

var reader = new StreamReader(stream);
string content = reader.ReadToEnd();

This solution however comes up with one major drawback: If you try to access your foo.svc via browser you will end up some error telling you "For request in operation Post to be a stream the operation must have a single parameter whose type is Stream.". Also calling foo.svc?wsdl will end up in some exception in the WSDL export extension.

 

[1] http://msdn2.microsoft.com/en-us/library/bb412169(VS.90).aspx

Posted at Sunday, December 09, 2007 9:22:53 AM (W. Europe Standard Time, UTC+01:00) 
Comments [0] #      | 
Copyright © 1995-2009 by Andreas Heil. aheil is a registered trademark of Andreas Heil. All rights reserved.
The opinions expressed herein are my own personal opinions and do not represent my employers' views in any way. Content and thoughts expressed on these pages and the weblog are subject to be changed. Out of date posts should not be considererd as my current thoughts and opinions.