Friday, March 27, 2009

Silverlight Web Part for Sharepoint

In this post, we are going to see integrating the webpart with Silverlight contents on SharePoint Site.

For that, we need to combine all required java script and Xaml files (used to display the Silverlight content) in to single assembly without any dependent files. It makes sense to embed the Xaml and java script file as a resource and reference it in programming using the WebResource.axd handler mechanism for extracting embedded resources.

1. Create a Webpart project and create or add the required java script and Xaml files to the project.
Include some files Silverlight.js, Scene.js and Scene.xaml

2. Set the BuildAction property to “Embedded Resource” in properties window for each java script and Xaml.
This will use to include the files as Resources in an assembly.

3. Add the assembly-level attribute System.Web.UI.WebResource to grant permission for these resources to be served by WebResource.axd and to associate MIME type for the response.

[assembly: WebResource("Arun.Silverlight.js", "text/javascript" )]
[assembly: WebResource("Arun.Scene.js", "text/javascript")]
[assembly: WebResource("Arun.Scene.xaml", "text/xml")]

Now JavaScript and Xaml files are compiled into my assembly as embedded resources.

4. Now, we can use the RegisterClientScriptresource() method of the Page.ClientScriptManager class to rendered the page with the referenced files.

this.Page.ClientScript.RegisterClientScriptResource(GetType(), "Arun.Silverlight.js"); this.Page.ClientScript.RegisterClientScriptResource(GetType(), "Arun.Scene.js");

Include the above lines in the PreRender method to register the javascript files for the webpart.

5. Add the following lines to the RenderWebPart method to host the < div > tag and call the Silverlight content to the webpart,

string strLoad = "Silverlight.createDelegate(scene, scene.handleLoad)";



The method GetWebResourceUrl(GetType(), "Arun.Scene.xaml") used to retrieve the Url of the Xaml file from WebResource.axd.

Tuesday, March 24, 2009

Code Contracts

Code Contracts provide a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of preconditions, postconditions, and object invariants. Contracts act as checked documentation of your external and internal APIs. The contracts are used to improve testing via runtime checking, enable static contract verification, and documentation generation.

Code Contracts bring the advantages of design-by-contract programming to all .NET programming languages.

The benefits of writing contracts are:

Improved testability
  • each contract acts as an oracle, giving a test run a pass/fail indication.
  • automatic testing tools, such as Pex, can take advantage of contracts to generate more meaningful unit tests by filtering out meaningless test arguments that don't satisfy the pre-conditions.

Static verification tools can takes advantage of contracts to reduce false positives and produce more meaningful errors.

API documentation Our API documentation often lacks useful information. The same contracts used for runtime testing and static verification can also be used to generate better API documentation, such as which parameters need to be non-null, etc.

Using a set of static library methods for writing preconditions, postconditions, and object invariants as well as two tools from Micrsosoft:

  • ccrewrite, for generating runtime checking from the contracts
  • cccheck, a static checker that verifies contracts at compile-time.

The plan from Microsoft is to add further tools for

  • Automatic API documentation generatio
  • Intellisense integration

The use of a library has the advantage that all .NET languages can immediately take advantage of contracts. There is no need to write a special parser or compiler. Furthermore, the respective language compilers naturally check the contracts for well-formedness (type checking and name resolution) and produce a compiled form of the contracts as MSIL. Authoring contracts in Visual Studio allows programmers to take advantage of the standard intellisense provided by the language services. Previous approaches based on .NET attributes fall far short as they neither provide an expressive enough medium, nor can they take advantage of compile-time checks.

Contracts are expressed using static method calls at method entries. Tools take care to interpret these declarative contracts in the right places. These methods are found in the System.Diagnostics.Contracts namespace.
• Contract.Requires takes a boolean condition and expresses a precondition of the method. A precondition must be true on entry to the method. It is the caller's responsibility to make sure the pre-condition is met.
• Contract.Ensures takes a boolean condition and expresses a postcondition of the method. A postcondition must be true at all normal exit points of the method. It is the implementation's responsibility that the postcondition is met.

Watch this space for more developments in this area.


Thursday, March 5, 2009

Cloud Computing through the lens of SOA

Cloud computing is a style of computing that defines the way IT functions are going to be delivered or acquired in the future. This can essentially be contributed due to the emergence of revolutionary technologies such as Virtualization, Service oriented Architecture and the Web.

I will attempt to explain the influence of these technologies on the formation of the "Cloud".Let me do this by first highlighting some key attributes that basically characterizes the “Cloud”. Followed by, describing how these emerging technologies meet to address them.

ABC's of the “Cloud”:
Adapt: Being scalable and elastic to meet fluctuating resource demands
Black-Boxed: Delivery of capabilities “as a service”
Focus is on the Results and Not on Components
Delivery Service Levels are Critical
Commune: Anyone Anywhere Anytime access
The amalgamation of Virtualization, Service oriented Architectures based on open standards along with the pervasive nature of the Internet has made IT services generally available at global scales. Now let’s look at how these technologies principally function to meet the ABC’s of the cloud:

Virtualization technologies such as Hyper-V, VMware, Citrix have de-coupled software from the hardware making it possible to run multiple software instances on a single hardware. The technology allows IT administrators to seamlessly Ramp up/down computational capabilities such as processor, storage, RAM in a matter of hours or even minutes. Virtualization has enabled efficient use of shared resources along with the de-coupling increasing the economies of scale of computing.

"Functionality being delivered through a platform independent contract" is the key design principle behind service oriented application. This makes service consumers consume information by being de-coupled from the technical implementation of the provider and focus only on the results. Also being self contained, services can be designed or managed at a unit level hence allowing for more granular control of service levels.

The global pervasiveness and the open standards of the Internet have made this technology as the de-facto mode of delivering IT-services on the public cloud. Although one may also argue that in case of private clouds, say within an enterprise, the use of private networks may enable cloud-style environments delivery capabilities without ever using Internet technologies. However from a universal accessibility stand-point the access over such channels may be confined to that within the enterprise boundaries limiting the openness otherwise observed on the cloud.