Tuesday, August 9, 2011

First N-Hibernate Application



Installing NHibernate
Download the NHibernate binaries and extract in a folder. That’s it. Create a project in visual studio and add NHibernate references in it.
Create a business project (class library) . Create the property classes in it as equal number of tables present in database.
Lets start by defining a very simple domain. For the moment it consists of one entity called Product. The product has 3 properties Name, Category and Discontinued.

Add a folder Domain to the FirstSample project of your solution. Add a new class Product.cs to this folder. The code is very simple and uses automatic properties (a feature of the new C# 3.0 compiler)
namespace FirstSolution.Domain
{
   
public class Product
    {
       
public string Name { get; set; }
       
public string Category { get; set; }
       
public bool Discontinued { get; set; }
    }
}

Define the Mapping

Create a folder Mappings in the FirstSample project. Add a new xml-document to this folder and call it Product.hbm.xml. "hbm" part of the file name. This is a convention used by NHibernate to automatically recognize the file as a mapping file. Define "Embedded Resource" as Build Action for this xml file.
In the Windows Explorer locate the nhibernate-mapping.xsd in the src folder of NHibernate and copy it to your SharedLibs folder. We can now use this xml schema definition file when defining our mapping files. VS will then provide intellisense and validation when editing an xml mapping document.
Back in VS add the schema to the Product.hbm.xml file
Let's start now. Each mapping file has to define a root node

xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 

                   assembly="FirstSolution" 

                   namespace="FirstSolution.Domain">

 

  

  

hibernate-mapping>
In a mapping file when referencing a domain class you always have to provide the fully qualified name of the class (e.g. FirstSample.Domain.Product, FirstSample). To make the xml less verbose you can define the assembly name (in which the domain classes are implemented and the namespace of the domain classes in the two attributes assembly and namespace of the root node. It's similar to the using statement in C#.

Now we have to first define a primary key for the product entity. Technically we could take the property Name of the product since this property must be defined and has to be unique. But it is common to use a surrogate key instead. For thus we add a property to our entity and call it Id. We use Guid as the type of the Id but it can as well be an int or a long.
using System;
 
namespace FirstSolution.Domain
{
   
public class Product
    {
       
public Guid Id { get; set; }
       
public string Name { get; set; }
       
public string Category { get; set; }
       
public bool Discontinued { get; set; }
    }
}
The complete mapping file
xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                  
assembly="FirstSolution"
                  
namespace="FirstSolution.Domain">
 
 
<class name="Product">
   
<id name="Id">
     
<generator class="guid" />
   
id>
   
<property name="Name" />
   
<property name="Category" />
   
<property name="Discontinued" />
 
class>
 
hibernate-mapping>

Monday, August 8, 2011

DNN SKIN IMPLEMENTATION


Whenever start dnn skin implementation on dnn website. In html design file change module names to under square braces:
Eg: If there is logo module in dnn.
Then replace that module in html in following format
Logo to [Logo].
After converting Logo to [Logo] it is understandable for dnn engine that [Logo] is a dnn module it will convert it into
All this coversion will be done only after Parsing the skin. After parsing DNN engine generate a user control for that html file. Which is called a skin that can be implemented on the dnn pages.
DNN Skin Installation:
To install a dnn skin go in extensions and select skin from dropdownlist.
Then follow the described steps of DNN installation. Dnn engine will install skin in portals folder. After that any one can implement that skin.

Skin need to be place in the same folder under same portal for which we have design it. If skin is in another folder then it will show you to implement the skin along with preview of correct images. But css will implement on that preview.

Friday, March 11, 2011

To Resize the image

To resize the image without croping and distorting it. Follow these steps for it:

System.Drawing.Bitmap OriginalBM = new System.Drawing.Bitmap(Server.MapPath("./SiteImages/FoodItems" + "/" + postingImage));
System.Drawing.Size newSize = new System.Drawing.Size(90, 90);
System.Drawing.Bitmap ResizedBM = new System.Drawing.Bitmap(OriginalBM, newSize);
ResizedBM.Save(Server.MapPath("./SiteImages/NewImages/" + postingImage));