Sunday, March 30, 2008

creating MSDN-style documentation from .NET assemblies - SandCastle

Introduction: Sandcastle is a command line based tool created by Microsoft, used for creating MSDN-style documentation from .NET assemblies and their associated XML comments files. Sandcastle Help File Builder is to provide graphical and command line based tools to build a help file in an automated fashion.

Simple steps to generate help files for your assemblies 
=====================================

I. Softwares to be installed:
SandCastle - http://www.codeplex.com/Sandcastle
SandCstle help file builder - http://www.codeplex.com/SHFB

II. Configuration in Visual studio
Configure Visual studio to generate XML comment file along with assemblies

Project properties -> Build tab -> check “XML documentation file”

III. Configure SandCastle Help Builder
Create a new project and add your assembly to the project. Once you added assemblyname it appears with xml comment file. It looks like ”MyAssembly.dll, MyAssembly.xml”.

IV. Finally build help file
In SandCastle Help Builder -> Goto “Documentation” menu -> Build Project

Once you build project, It saves help project file as well once it gets build you will have your html help file.

****END**** 

 

Posted by at 15:15:34 | Permalink | No Comments »

SubSonic step by step

  

SubSonic step by step

I. SubSonic is a toolset that helps to

  1. Generate DAL layer
  2. Maintains and Generates SQL Script for DB Versioning
  3. Dynamic Query tool helps to use SQL Server etc without knowing SQL
  4. OR Mapper that extends to views and stored procedures

II. Installation

  1. Download SubSonic @ http://www.codeplex.com/subsonic/Release/ProjectReleases.aspx?ReleaseId=5636
  2. Install SubSonic by walking through steps, by default it stores at “Program Files\SubSonic\SubSonic 2.1 Beta 2\SubSonic”

III. Configuring inside Visual Studio 2005/ 2008 to use SubSonic

  1. Create new Website project
  2. Create another new class library project say ‘NorthWindDAL’ and add to solution as shown below (this project is going to act as DAL layer for web project)

  1. Add application configuration file to ‘NorthWindDAL’ class library (app.config)
  2. Create folder in NorthWindDAL project to keep all Subsonic generated classes
  3. Add below configuration sections to app.config file of NorthWindDAL project
    1. Add configsection

<configSections>
                  <section name=SubSonicService
                         type=SubSonic.SubSonicSection,SubSonic
                         requirePermission=false/>

   </configSections> 

  1. add Connection strings section

<connectionStrings>
<add name=NorthWind               connectionString=Server=yourserverName;Database=dbName;UID=youruserName;PWD=yourPassword;/>

   </connectionStrings> 

  1. add Subsonic service provider

<SubSonicService defaultProvider=NorthWind>
            <providers>
                  <clear/>
                  <add name=NorthWind
                         type=SubSonic.SqlDataProvider, SubSonic
                         connectionStringName=NorthWind
                         generatedNamespace=NorthWind  />
            </providers>
   </SubSonicService>

  1. Goto Bin folder of NorthWindDAL project and give reference to ‘SubSonic.dll’ available at “Program Files\SubSonic\SubSonic 2.1 Beta 2\SubSonic”
  2. and add reference to System.Web and System.Configuration

IV. Adding SubSonic Commander as external tool in Visual studio

Now you are ready for generate code.

When you click on External tool ‘SubSonicDAL’ , it generates code in specified folder that is ‘NorthWind’

That’s it…..  so simple

Posted by at 11:45:46 | Permalink | No Comments »

Tuesday, March 25, 2008

.NET 3.5 Features - JSON Serialization

Serialization & Deserialization:
The process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created. Serialization/Deserialization is used to transport or to persist objects.

Types of Serialization :
1. Binary Serialization
2. SOAP Serialization
3. XML Serialization
4. Custom Serialization

.NET 3.5 has new object called DataContractJsonSerliaizer used to JSON serialization for Ajax calls / Javascript calls.

Here i am writing JSONHelper class to Serialize and Deserialize
Add Reference: System.Runtime.Serialization.dll(.NET 3.0), System.ServiceModel.Web.dll(.NET 3.5)

using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
public class JSONHelper
{
    public static string Serialize(T obj)
    {
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());   
    MemoryStream ms = new MemoryStream();
    serializer.WriteObject(ms, obj);
    string retVal = Encoding.Default.GetString(ms.ToArray());
    return retVal;
    }

    public static T Deserialize(string json)
    {

    T obj = Activator.CreateInstance();
    MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json));

    DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
    obj = (T)serializer.ReadObject(ms);
    ms.Close();

    return obj;
    }

}

Below class going to use for serialization and Deserialization


[DataContract]
public class Book
{

    private int _id;    private string _name;
    public Book() {}

    public Book(int id, string name)
    {
    _id = id;
    _name = name;
    }

   

    [DataMember]   
    public int Id
    {
    get { return _id; }

    set { _id = value; }
    }

    [DataMember]

    public string Name
    {
    get { return _name; }

    set { _name = value; }
    }
}

How to Use JSONHelper class to Serialize

Book b1 = new Book(1, “ASP.NET 3.5″);
string jsonOutput = JSONHelper.Serialize<Book>(b1);

Serialization output:
{”Id”:1,”Name”:”ASP.NET 3.5″}

How to Use JSONHelper class to Deserialize
Book b2 = JSONHelper.Deserialize<Book>(jsonOutput);

 

Posted by at 02:46:50 | Permalink | No Comments »