Design Patterns for all – Chapter III (Factory Pattern)

Tuesday, June 30, 2009

Design Patterns for all – Chapter III (Factory Pattern)


This is a series of articles which explain Design Patterns in detail with C# examples. In the previous chapter we saw the Singleton Design pattern. In this chapter we are going to see the Factory Pattern in detail with c# coding. Factory pattern is one of the widely used Design Patterns in the Object oriented programming world.



Definition:

A Factory Patterns creates an Interface for creating object and lets subclass do the instantiation. A Factory Pattern lets a class to defer instantiation to the subclasses. Simply saying it abstracts the instance creation.



Overview:

It lets the developer create an interface and retains which class needs to be instantiated. The Factory pattern comes under the category of Creational Patterns.

Generally when we create a class, we will provide constructors to the users of the class so they can create instances for the classes. But on some situations we need or should not give them the ability to create instances with the available classes. On such situations we can create Factory Pattern. That is rather than calling the constructors for creating objects, you are calling the Factory to create objects.

Its primary purpose is to create objects like a real work Factory.



Logical Model:

The prime actors of the Factory Pattern are:

· Client

· Factory

· Product



Product:

A product can be anything you produce in the factory. In programmatic angle it will the actual object which needs to be created.

Factory:

A Factory is the one who creates object of the product.

Client:

A client instead of directly creating objects of the product uses the Factory to create objects for it. The client is not aware about how the objects are created.





Factory Pattern in .net Framework:

Some of the areas where Factory Pattern is used are given below,



· IClassFactory is an interface used to create instances of COM classes.

· System.Web.IHttpHandlerFactory class

· System.Convert



Example in C#:

In this example we are going to create we use Abstract classes instead of Interfaces as Abstract classes has the benefits like versioning, etc., over Interfaces.



using System;

using System.Collections.Generic;

using System.Text;



namespace FactoryDemo

{



abstract class Car

{

public abstract int Speed { get; }

}



abstract class CarFactory

{

public abstract Car ShowCar();

}



//Concrete is nothing but the implementaion for the absract classes

class ConcreteCar : Car

{

int _speed = 300;



public override int Speed

{



get { return _speed; }



}

}



class ConcreteCarFactory : CarFactory

{



public override Car ShowCar()

{



return new ConcreteCar();



}



}



class CarCompany

{



public void ProduceCar(CarFactory objfac)

{



Car mycar = objfac.ShowCar();

Console.Write("Car Produced with speed: " + mycar.Speed);

Console.Read();





}



}



class Program

{

static void Main(string[] args)

{

CarFactory mycarfactory = new ConcreteCarFactory();



new CarCompany().ProduceCar(mycarfactory);

}

}





}



Here the abstract classes Car and CarFactory provides the interface and the classes ConcreteCar and ConcreteCarFactory provides the implementation for the abstract classes. The CarCompany class uses all these to make the factory work.

In the simillar way you can create as many of Cars with different model like RollsRoye, Honda and there by creating classes for them by inheriting the classes Car and CarFactory.

But remember that the CarCompany class is abstracted from other classes.
www.codecollege.NET

What is an Index and its Types and Differences between them ?

What is an Index and its Types and Differences between them ?


What is an Index?


Indexing is a mechanism which makes record
fetching faster. It does this by having pre-sorted the rows of the table.


Types of Indexes:




  1. Clustered.


  2. Non-Clustered.




















Sno Clustered Non - Clustered
1 It reorders the physical storage of records in the table. It sorts and maintain a separate storage.
2 There can be only one Clustered index per table. More than one.
3 The leaf nodes contain data The leaf node contains pointer to data

Win Rs 70000 by participating in DesignChef.com Contest





Win Rs 70000 by participating in DesignChef.com Contest


for more details,


www.designchef.com



Win prizes worth $3000 by participating in CodeChef's Contest





CodeChef July Contest - Win prizes worth $3000




http://www.codechef.com/JULY09



Daily Tips- Tip #3 - Automatically closing a connection after datareader finishes execution





To automatically close a connection after datareader finishes execution, you need to specify the CommandBehaviour.CloseConnection parameter to the command object, as


drEmployees = cmdEmployees.ExecuteReader(CommandBehaviour.CloseConnection);



What are the uses of Views?





1. Views are virtual tables (they dont store data physically) which gives a result
of data by joining tables. So you are not storing redundant data.


2. Views are used to produce reports from data


3. Views can be used to provide security to data by giving access only to views.



Daily Tips- Tip #2 - How to prevent .DLL Decompilation?

Monday, June 29, 2009





How to prevent .DLL Decompilation?


If have written some worthful code and if you dont want it to be decompiled by anybody, then you have to make it secure.


Obfuscation:
The process by which you make your assembly not decompilable is called as Obfuscation.


Popular Tools available are :
XenoCode, Demeanor


Websites:  


htt://www.xenocode.com

 
http://www.wiseowl.com

 
remotesoft 


>rustemsoft 



Differences between Dataset and DataReader

Sunday, June 28, 2009



























Sno Dataset DataReader
1 Disconnected Mode Connected Mode
2 Can navigate back and forth Can navigate forward only
3 Data is editable Data is Readonly
4 Can contain more than one table and relationships Can contain only one row at a time.
5 Slower as having more overhead Faster when compared with dataset.

What is the name of the class used to read and get details of the files uploaded to asp.net?





System.Web.HttpPostedFile

Daily Tips- Tip #1 - How can we force all the validation controls in a page to run?



For that call this code,


Page.Validate();

Links for Asp.net Http Modules and Http Handlers



Http Modules and Http Handler
========================

http://support.microsoft.com/kb/307985





How To Create an ASP.NET HTTP Handler by Using Visual C# .NET


================================================

http://support.microsoft.com/kb/308001/EN-US/



Intercept, Monitor, and Modify Web Requests with HTTP Filters in ISAPI and ASP.NET

==================================================================

http://msdn.microsoft.com/hi-in/magazine/cc301704(en-us).aspx




Some more samples
================

http://www.informit.com/articles/article.aspx?p=25339&seqNum=3

How to force Garbage Collector?

System.GC.Collect() forces garbage collector, but it is not recommended.

What is assemblyInfo.cs file? Where can I find it? What is it for?

What
It consists of all build options for the project,including verison,company name,etc.
Where
It is located in the Properties folder.
Use
It is used to manage the build settings.

Oslo - The Microsoft's Modeling platform



Oslo is the code name for Microsoft's Modeling platform .


"Oslo" was first announced by Robert Wahbe in October 2007.


Microsoft says that oslo consists of the following:



*A tool that helps people define and interact with models in a rich and visual manner
*A language that helps people create and use textual domain-specific languages and data models
*A relational repository that makes models available to both tools and platform components



For more information about oslo, read the following:


http://www.microsoft.com/NET/Oslo.aspx




Watch videos about oslo,



mms://msstudios.wmod.llnwd.net/a2294/o21/presspass/modeling9_10_MBR.wmv


http://msstudios.vo.llnwd.net/o21/presspass/zune/Looking_Ahead_Zune.wmv

What is Serialization ? What are the Types of Serialization and their differences?

Serialization:
It is the process of converting an object to a form suitable for either making it persistent or tranportable.
Deserialization is the reverse of this and it converts the object from the serialized state to its original state.

Types:
1. Binary
2. XML

Differences:













Sno Binary XML
1

It preserves type fidelity , which is useful for preserving


the state of the object between transportation and invocation.


It doesnt preserves type fidelity and hence state cant be


maintained.

2 As it is the open standard its widely used Not that much compared to
Binary.

What is an application domain?

Saturday, June 27, 2009

The following is the definition given by Microsoft.

An application domain (often AppDomain) is a virtual process that serves to isolate an application. All objects created within the same application scope (in other words, anywhere along the sequence of object activations beginning with the application entry point) are created within the same application domain. Multiple application domains can exist in a single operating system process, making them a lightweight means of application isolation.

An OS process provides isolation by having a distinct memory address space. While this is effective, it is also expensive, and does not scale to the numbers required for large web servers. The Common Language Runtime, on the other hand, enforces application isolation by managing the memory use of code running within the application domain. This ensures that it does not access memory outside the boundaries of the domain. It is important to note that only type-safe code can be managed in this way (the runtime cannot guarantee isolation when unsafe code is loaded in an application domain).

What is the difference between CCW and RCW ?













Sno

CCW

RCW

1

COM to .NET communication happens through COM Callable Wrapper

.NET to COM Communication happens through Remote Callable Wrappter

How to invoke a method at runtime using Reflection in c#?



You need to call “InvokeMember” method of Reflection to do this.

Let us see this in detail with an example,

1. Create a Class library program and paste the code below,

Reflection Source Program
=========================

using System;
using System.Collections.Generic;
using System.Text;

namespace Employee
{
public class EmployeeDetails
{
private int empid=1;
private string empname="Ram";
private float salary=100000;

public string displayEmployeeDetails()
{
return "Empoyee Id:" + empid + "
" + "Empoyee Name:" + empname + "
" + "Empoyee salary:" + salary + "
";
}
}
}

2. compile it.

3. then create a windows application project and paste the following code

Reflection Program to invoke the method
==================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Employee;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}



private void button1_Click(object sender, EventArgs e)
{
Assembly assembly = Assembly.LoadFrom("E:\\WebExperiments\\Employee\\Employee\\bin\\Debug\\Employee.dll");
foreach (Type type in assembly.GetTypes())
{
// Pick up a class
if (type.IsClass == true)
{
Console.WriteLine("...Found Class : {0}", type.FullName);

}


object ibaseObject = Activator.CreateInstance(type);

object result = null;

result = type.InvokeMember("displayEmployeeDetails",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
ibaseObject, null);
MessageBox.Show(result.ToString() );
}
}
}
}

4. add reference to the Employee dll

5. run the program and see the method invoked.

Cystal Report Links





www.codeproject.com/KB/cs/CreatingCrystalReports.aspx



http://www.c-sharpcorner.com/Articles/ArticleListing.aspx?SectionID=1&SubSectionID=61



http://www.programmersheaven.com/download/44243/download.aspx



http://www.crystalreportsbook.com/Crystal_Reports_Net_Ch14_4.asp

What is the difference between a custom control and a user control ?

Friday, June 26, 2009







































Sno

User Control

Custom Control



Is a file with the .ascx extension

Is a file with the .dll extension

2

Can be
only used with the application

Can be
used in any number of applications

3

Language
dependent.

They are
language independent, a control
created in c# can be used in vb.net

4

Can’t be
added to Visual studio Toolbox

Can be added to Visual studio Toolbox

5

Inherits
from Server controls and easy to create.

You have
to develop from scratch ,
so comparatively
difficult.

6

Generally
used for static content

Used when
dynamic content is required

What are the differences between Trace and Debug?



















Sno

Trace

Debug



Works in both Debug and Release mode

Works
only in Debug mode.

2

Trace is enabled by default in visual studio

Debug is not enabled. You can manually do that.




How to call a user controls method from its parent?

For example the name of your control be a SecureLoginControl and the solution be MyControls and the method you are going to call is SecuredAuthentication(), then the coding you need to do is ,

Control declaration:
Public MyControls.SecureLoginControl objSecureLoginControl ;

When calling:
boolean b;
b=objSecureLoginControl.SecuredAuthentication();

or you can call like this also,

((SecureLoginControl)Panel1.FindControl("objSecureLoginControl")).SecuredAuthentication();

What are asynchronous callbacks in .net?

It means that a call is made from a Main Program to a .net Class’s method and the program continues execution. When the callback is made ( means the method has finished its work and returns value) , the Main program handles it.

What are the differences between machine.config and web.config files?





























Sno

Web.config

Machine.config



It is a config file for a single application.

It is a config file which is common for all the applications in a machine

2

It will be available in the application folder.

It is available in the Microsoft.NET\Framework\{version}\CONFIG Folder.

3

The settings in the web.config overrides that of Machine.config

Cant do.

4

Automatically installed when visual studio .net is installed

This is automatically created when you create an asp.ne website




What is web.config.? How many web.config files can be allowed to use in an application?


1.    
 

The Web.Config file is the configuration file for
asp.net web application or a web site. prefix="o" ?>



2.    
 

You can have as many Web.Config files as you want
, but there can be only one web.config file in a single folder.

What are the differences between value and reference types

























Sno


Value Types



Reference Types



They contain their data directly

They store a reference to their value’s memory

2

They are allocated for storage either in stack or inline in structure..

They are allocated for storage in heap

3

can be built-in (implemented by the runtime), user-defined, or enumerations

self-describing types, pointer types, or interface types.


How do you relate an aspx page with its code behind page ?



Using the Page Directive.


<@page .. codefile="yourcsfile.aspx.cs" ...

Can we throw exception from catch block?



Yes.

where does a sharepoint webpart inherit from?

To create a SharePoint Web Part, you should inherit from the


Microsoft.SharePoint.WebPartPages.WebPart


base class.


For creating a basic sharepoint webpart see this link,




http://msdn.microsoft.com/en-us/library/ms452873(loband).aspx

what is autoeventwireup?

It is an automatic way to associate Asp.net Page events and methods.


When the autoeventwireup page attribute is set to true page events are automatically called.


The disadvantage is that it expects page events in a predictable way , so you loose the flexibility of choosing your own event handler names.

UML tutorials

www.uml.org



www.sparxsystems.com.au/uml-tutorial.html




http://uml-tutorials.trireme.com/



www.tutorialspoint.com/uml/index.htm



www.freebookcentre.net/.../Free-Uml-Books-Download.html




http://courses.softlab.ntua.gr/softeng/Tutorials/UML-Use-Cases.pdf

.Net Tutorials


http://asp.net



www.w3schools.com/ASPNET/default.asp




http://aspalliance.com




www.dotnetspider.com



http://www.techtutorials.info/wbmsnet.html style="font-size: 11pt; font-family: Calibri">




www.learnvisualstudio.net/




www.15seconds.com




www.aspnettutorials.com




www.411asp.net/home/tutorial




www.startvbdotnet.com



www.programmingtutorials.com/vbnet.aspx




www.devarticles.com/c/b/VB.Net




www.internettutorials.net



www.xml.com/pub/rg/_NET_Tutorials

mcse tutorial



www.intelligentedu.com/newly.../MCSE_Windows2000.html



www.mcsetutorialsonline.com



apex.vtc.com/mcse-bundle.php


www.velocityreviews.com/.../t237762-online-mcse-tutorial.html

www.learnthat.com/.../learn-430-windows_cp_mcse_practice_exam.htm

www.self-certify.com/mcse-tutorial.asp


http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.skills_assessment&tid=bcee1d4b-e637-4ee6-989b-74acbe5efddb&cat=en_US_0d692642-c6e2-49ae-92c9-59a79e4fd247&lang=en&cr=US&sloc=&p=1



www.softwaretrainingtutorials.com/mcse-2003.php

microsoft tutorials



www.microsoft.com/education/tutorials.mspx


http://office.microsoft.com/en-us/training/default.aspx


www.officetutorials.com


http://databases.about.com/od/tutorials/Tutorials.htm


http://www.free-training-tutorial.com



http://www.learnthat.com


www.tutorialguide.net/microsoft

Free domain from Microsoft with lot of features




Free domain from Microsoft with lot of features. Get benefitted from it.

Free domain from Microsoft with lot of features


Code Green Contest - Try it for a chance to win $10K

Code Green Contest - Try it for a chance to win $10K

Code Green Contest

What should be done to make a session cookieless

Thursday, June 25, 2009

Change the web.config file with the following setting to create a ASP.NET cookieless session ,



set the cookieless attribute to 'false', as

<sessionstate timeout='20' cookieless='false' mode='InProc'>

how will u check whether the user is supportig cookies?

The only way to check whether a client accepts cookies or not is , to create a cookie and read it back.

If you are able to read it back then , its accepting else not.

what does '()' denote in the object creation statement

what does '()' denote in the object creation statement?

It denotes the constructor.

How to call a base class constructor from a derived class?

How to call a base class constructor from a derived class?

using System;
using System.Collections.Generic;
using System.Text;

namespace OOPTest7
{
class A
{
public A()
{
Console.Out.Write("base A");
}
public A(string s)
{
Console.Out.Write(s);
}

}

class B : A
{

public B() : base("base cons called from Derived")
{
Console.Out.Write("B");
}

}



class Program
{
static void Main(string[] args)
{
B b= new B();
Console.In.Read();
}
}
}

interface ,the class which implemented it and its object, with interface in left hand side during creation

If a class IA is implementing an interface I which is having a method a, then
can is the following allowed? Will that have all the methods of IA apart from that of interface I?

I a = new IA();

Yes. always the base class or interface can contain derived class, but it will have
only those of the base. So it will not have members of IA which are not from interface I.

using System;
using System.Collections.Generic;
using System.Text;

namespace OOPTest6
{
interface I
{
void a();
}

class IA : I
{
public void a()
{
Console.Out.Write("a");
}
public void nonintfacemeth()
{
Console.Out.Write("nonintfacemeth");
}


}


class Program
{
static void Main(string[] args)
{
I i = new IA();
i.a();

}
}
}

If A is the base class and B inherits B and C inherits B and an object is created for C , whats order of constructor

If A is the base class and B inherits B and C inherits B and an object is created for C , then what will be the order of
the constructor being called?

A then B then C.

using System;
using System.Collections.Generic;
using System.Text;

namespace OopTest5
{
class A
{
public A()
{
Console.Out.Write("A");
}

}

class B : A
{
public B()
{
Console.Out.Write("B");
}

}

class C : B
{
public C()
{
Console.Out.Write("C");
}

}


class Program
{
static void Main(string[] args)
{
C c = new C();
Console.In.Read();
}
}
}

Does C# (.NET) support partial implementation?

Does C# (.NET) support partial implementation?
No.

the following program will throw an error.

using System;
using System.Collections.Generic;
using System.Text;

namespace OPPTest3
{
interface IA
{
void x();
void y();
}

class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}

}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}

Can we leave a virtual function in an abstract class without implementing in the derived class

Does c# support pure virtual function?
No.
Instead you can use abstract function which is also called as a pure virtual function.
abstract class abTest
{
public abstract void a();

}

Can we leave a virtual function in an abstract class without implementing in the derived class ?
No. It will throw an error.

using System;
using System.Collections.Generic;
using System.Text;

namespace OppTest4
{
abstract class abTest
{
public abstract void a();

}

class UsesabTest : abTest
{
//public override void a()
//{
// Console.Out.Write("a");
//}

public void x()
{
Console.Out.Write("x");
}
}

class Program
{
static void Main(string[] args)
{
}
}
}

Can a base class contain its derived class?

Can a base class contain its derived class?
Yes. But the reverse is not possible.

using System;
using System.Collections.Generic;
using System.Text;

namespace OppsTest
{
class A
{
int i = 1;

public A()
{
}

public void testa()
{
Console.Out.Write(i);
}
}

class B : A
{
int j = 3;
public B()
{
}

public void testb()
{
Console.Out.Write(j);
}

}




class Program
{
static void Main(string[] args)
{
A a = new B();
a.testa();
Console.In.Read();
}
}
}

Class implementing Interface

using System;
using System.Collections.Generic;
using System.Text;

namespace OppTest2
{
interface IA
{
void x();
void y();
}

class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
public void y()
{
Console.Out.Write("test y");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}

how to implement a pure virtual function in c#?

how to implement a pure virtual function in c#?

using System;
using System.Collections.Generic;
using System.Text;

namespace OppTest4
{
abstract class abTest
{
public abstract void a();

}

class UsesabTest : abTest
{
public override void a()
{
Console.Out.Write("a");
}

public void x()
{
Console.Out.Write("x");
}
}

class Program
{
static void Main(string[] args)
{
UsesabTest mn = new UsesabTest();
mn.a();
}
}
}

FxCop – Part III (A detailed explanation over Project)

FxCop – Part III (A detailed explanation over Project and its functionalities)


In the Part I we saw the introduction to FxCop and in Part II we saw about the startup usage of FxCop. In this Part III we are going to see in detail about FxCop Project and its features.



Here we dived the explanations over the Project into 2, they are:

· Basics of Project

· Advanced features of Project



Basics of Project:

In this we will see the basics of FxCop Project which needs little explanation. The topics we are going to cover here are:

1. Creating a new project

2. Open an existing project

3. Saving project

4. Opening Recent Projects

5. Saving Reports

6. Importing Reports

7. Adding Targets

8. Adding Rules

9. Analyzing a Project

10. Viewing Analysis Summary



1. Creating a new Project:

To create a new project,

Click File > New Project.



2. Open an existing project

To open an exiting project,

· File > Open Project

· Select the project file you want to open from the location you stored it or the location in which it is available.

· Click Open button.



3. Saving project

You can save the project in 2 ways, as follows,

i) When you are saving it for the first time

ii) When you are saving one more copy of the project.



a) When you are saving it for the first time

· Click File > Save Project or Ctrl S

· Select the path where you want to save it

· Enter the name of the project you want to save in

· Click Save





b) When you are saving one more copy of the project

· Click File > Save Project as

· Select the path where you want to save it

· Enter the name of the project you want to save in

· Click Save



4. Opening Recent Projects

To open Opening Recent Projects,

a) Click File > Recent Projects

b) Select the desired project



5. Saving Reports

To save reports,

· Click File > Save Report as

· Select the path where you want to save it

· Enter the name of the Report you want to save in

· Click Save



6. Importing Reports

To Import Reports,

· Click File > Import Reports or Ctrl I

· Select the Report file you want to open from the location you stored it or the location in which it is available.

· Click Open button



7. Adding Targets

To add Target,

· Project > Add Targets.

· Select the desired assembly you want to analyze(it can either be a dll or an exe).



8. Adding Rules

To Add Rules,

· Project > Add Rules.

· Select the desired Rules dll from the location you are having the rules.



9. Analyzing a Project

To analyze a project, its given in detail in the earlier chapters. Anyhow its given here once more for continuity or completeness of the topic.

· Select the desired assembly you want to analyze (it can either be a .dll or an .exe).

· For example, I am selecting here a .net application (Which was downloaded from internet)

· If you have selected multiple assemblies then select any one of them (the one you want to analyze first) and then click Project > Analyze or press F5 or Click Analyze from toolbar.

· Analyzing with introspection Engine dialog box will appear when the analysis is under process.

· Then it will display list of messages in the right pane.



10. Viewing Analysis Summary

To view Analysis Summary report,

· Click Project > Analysis summary

· Analysis summary window will appear.

· Click ok to close the window.



Advanced features of Project:

In this we will Advanced features of FxCop Project which needs some explanation. The topics we are going to cover here are:

1. General Project settings

2. Saving and Compression settings

3. Spelling and Analysis settings

4. Preferences Settings

5. Font and colors settings

6. Analysis Engine settings



1. General Project settings
For doing General Project settings,

· Click Project > Options

· Select General tab



Here you can do the things like:

(1) Changing Project name

(2) Changing Report style sheet path

(3) Save messages settings for Project and Reports



2. Saving and Compression settings

For doing this,

· Click Project > Options

· Select Saving and Compression tab



Here you can do the things like:

(1) Project Save settings

(2) Project File name Rule settings

(3) Compression settings



3. Spelling and Analysis settings

For doing this,

· Click Project > Options

· Select Spelling and Analysis tab



Here you can do the things like:

(1) Multithreading settings

(2) GAC settings

(3) Spelling and analysis settings





4. Preferences Settings
For doing this,

· Click Tools > Settings

· Select Preferences tab



Here you can do the things like:

(1) General preference settings like checking for updates in startup,etc

(2) Filtering messages

(3) Launching in source code editor

(4) Command line settings



5. Font and colors settings

For doing this,

· Click Tools > Settings

· Select Font and colors tab



As the name implies, it does the font and color related settings.



6. Analysis Engine settings

For doing this,

· Click Tools > Settings

· Select Analysis Engine tab



Here you can do the things like:

(1) Engine related settings

(2) Some more advanced settings.

SharePoint for all – Chapter I (Introduction to the basics of SharePoint)

SharePoint for all – Chapter I (Introduction to the basics of SharePoint)
This will be a series of articles on SharePoint, which explains from the basics to advanced usage of SharePoint and its group of products. This article is the first of them which gives an introduction to SharePoint. In the coming chapters, we will see the features of SharePoint in depth.

SharePoint is said to be one of the fastest growing technologies from Microsoft.

Definition:
It is a browser-based Content Management System with collaboration features from Microsoft.
It can be configured to run intranet, extranet and internet sites.

Microsoft’s Definition:
Microsoft Office SharePoint Server 2007 is an integrated suite of server capabilities that can help improve organizational effectiveness by providing comprehensive content management and enterprise search, accelerating shared business processes, and facilitating information-sharing across boundaries for better business insight. Additionally, this collaboration and content management server provides IT professionals and developers with the platform and tools they need for server administration, application extensibility, and interoperability.

SharePoint Products:

Microsoft lists the following as the SharePoint Products and Technology family:
1. WSS (Windows SharePoint Services)
2. MSS (Microsoft Search Server)
3. Forms Server
4. MOSS (Microsoft Office SharePoint Server)

IDE’s for developing SharePoint Products:

1. Visual studio
2. Microsoft Office SharePoint Designer

1. WSS

Windows SharePoint Services is foundation for all SharePoint based products. It is an object model for creating web pages which does document management and collaboration and centralized document repository.

The latest version of WSS is 3.0. You can download WSS 3.0 from the following link,

http://msdn.microsoft.com/en-us/sharepoint/default.aspx

2. MSS

Microsoft Search Server is an enterprise search platform from Microsoft, based on the search capabilities of Microsoft Office SharePoint server. –Wiki.
You can download MSS from the following link,

http://msdn.microsoft.com/en-us/library/bb931107.aspx

3. Forms Server

It is a server which allows InfoPath forms to be used on a browser. It allows even database operations.

4. MOSS

Microsoft Office SharePoint Server (MOSS) 2007 is a portal-based platform built over Windows SharePoint Services (WSS) 3.0. It organizes and aggregates an organization's information in one central, web-based application. MOSS enables users to create portals, has enterprise-level services, such as business intelligence and business process integration, etc.

Used for:
It is primarily used for Content Management, Collaboration, organizing and aggregating an enterprise's data into web-based portal. For e.g. Knowledge Management Portal.

Advantages:
Many built-in features, Rich Security, Content Management, Integration with Office products, business process can be integrated with workflows, less effort to create basic sites with standard functionalities such as search etc.

Hierarchy:
Web Application -> Site Collection -> Sites->database (Content db, Config db, SSO db). An interesting point to note here is that the equivalent of .Net website here is Web Application and not the sites under site collection. Also the databases are encrypted hence developers can't view data.

Study Material from Microsoft:

http://office.microsoft.com/en-us/sharepointserver/FX100492001033.aspx

http://sharepoint.microsoft.com/Pages/Default.aspx

Study Material from Others:

http://www.fpweb.net/sharepoint-hosting/free-sharepoint-tutorials.asp

http://blog.sharepointhosting.com/Downloads/SharePoint-Tutorials.aspx

http://www.cudenver.edu/RESOURCES/WEBDEVELOPMENT/CMSRESOURCES/TUTORIALS/CREATESPSITE/Pages/CreateaSharePointsite.aspx

http://www.softwaretrainingtutorials.com/ms-sharepoint.php

System Requirements:

Hardware Requirements suggested by Microsoft:

Component Minimum Recommended
Processor 2.5 gigahertz (GHz) Dual processors that are each 3 GHz or faster
RAM 1 gigabyte (GB) 2 GB
Disk NTFS file system–formatted partition with a minimum of 3 GB of free space NTFS file system–formatted partition with 3 GB of free space plus adequate free space for your Web sites
Drive DVD drive DVD drive or the source copied to a local or network-accessible drive

Display 1024 × 768 1024 × 768 or higher resolution monitor
Network 56 kilobits per second (Kbps) connection between client computers and server 56 Kbps or faster connection between client computers and server


For detailed information on the System requirements for SharePoint, see the following link,

http://technet.microsoft.com/hi-in/library/cc288751(en-us).aspx

Design Patterns for all – Chapter II (Singleton Pattern)

Monday, June 22, 2009

Design Patterns for all – Chapter II (Singleton Pattern)

In the previous chapter we saw the basics of Design patterns and OOPs which will give the foundation for understanding Design patterns better. In this chapter we are going to see the Singleton Pattern in detail with c# coding.

Singleton Pattern:
It comes under the category of ‘Creational Pattern’.

Definition:

It allows a single instance of a class and provides global access to it.

Steps to implement a Singleton Pattern in C#:
1. Create a sealed class.
2. Declare a private variable for that class inside the class.
3. Make the constructor as private.
4. Create a public static property which only returns the instance
5. Inside that use lock() to handle the object instance for supporting multi-threading functionality.

Applicability:
1. Logger
It is primarily used in the areas where single access channel is needed. Logging is an area where it is primarily used.
2. Db Connection
For managing database connections also it is used as there should be only one connection at a time.
3. Configuration Manager
Then configuration managers, which read and write to configuration files, there also Singletons are used.

A Logger example in C#:
Steps to write it:
1. Select Visual studio > Project > C# & Windows Application.
2. Follow the steps given in the steps to write a Singleton class above
3. The complete code of the Singleton Pattern and its usage class are given below :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SingletonDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
MySingleton sg = MySingleton.Instance;
sg.LogMyError("test");
}
}


public sealed class MySingleton
{
private static volatile MySingleton instSingleton;
private static object objSynformultithread = new Object();

private MySingleton()
{
}

public void LogMyError(String msg)
{
TextWriter twLog = new StreamWriter("c:\\log.txt");

// write a line of text to the file
twLog.WriteLine("Start" + DateTime.Now);
twLog.WriteLine(msg);
twLog.WriteLine("End");
// close the stream
twLog.Close();
}


public static MySingleton Instance
{
get
{
if (instSingleton == null)
{
lock (objSynformultithread)
{
if (instSingleton == null)
instSingleton = new MySingleton();
}
}

return instSingleton;
}
}
}
}

Explanations over the Program:

Purpose of Sealed:
It prevents derivation which could add instances.

Purpose of Private Static Volatile:
Private, it makes the variable private and so not accessible from outside.
Static, without creating instance (only the instance created inside) we can call with name of the class as MySingleton.variable.
Volatile, makes the instance variable assignment completed before it is accessed.

Purpose of Lock:
It avoids deadlocks, enables multithreaded functionality.

The above program has the function LogMyError which does the logging to the file system. You can change the file name and path wherever you want it to get stored. Moreover it was written for a demo purpose only, so its not that much fuller. You need to add the append functionality to it such that it works as according to your need.

If you do the minor modifications based on your need of logging then it will be a good Logger for any kind of application.
Similarly it can be used for DB Connection, Configuration Management, etc.

Design Patterns for all – Chapter I (Introduction to Design patterns and OOPs)

Design Patterns for all – Chapter I (Introduction to Design patterns and OOPs)
In this chapter we will see the basics of Design patterns and OOPs which will give the foundation for understanding Design patterns better. In the coming chapters we will see the Design patterns in detail with practical examples and code.

Definition:

Design Patterns are best proven techniques for a common design problem.
It is only a design technique and not code. Though code is available for almost all design patterns in all popular languages, design patterns mean the design technique alone.
Each design pattern explains a repeated problem, gives standard solution to the problem.

History:
GoF Gang of four, a four member team (Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides) are said to be people who brought up this idea. They wrote some patterns which are considered the base for all other patterns.

Types of Patterns:
Design Patterns are generally classified into three categories, they are:
1. Creational
2. Structural
3. Behavioral

1. Creational
They deal with object creation. They provide you the best way to create objects based on the current situation.
Example:
Singleton, Factory method, Abstract factory, Builder

2. Structural
They deal with relationship between entities. They provide you the best way to relate entities on various scenarios.
Example:
Adapter, Aggregate, Bridge

3. Behavioral
They deal with communication between objects. They provide you the best way to communicate between objects.
Example:
Chain of responsibility, Command, Interpreter

Further Classification:
Though the above three are the major classification, one more category also exists which may be considered as a sub part of the above. It is:

Concurrency
They deal with multi-threaded programs. They provide solutions for multi-thread design problems.
Example:
Balking, Double checked locking, guarded suspension

OOP Techniques and Design Patterns:
Before going into design patterns, we need to know some of the OOP (Object Oriented Programming) features, which will in turn lead to a better understanding of Design patterns.
Let us now see the OOPs features one by one,

Class:
It defines characteristics of a thing and its behavior. It is blueprint from based on which objects are created.
Example: Employee (which will have all the details about the employee like name, id, salary, etc and the methods which describes his behavior like calcSalary(),displaydetails(),etc.

Object:
Is an instance of a class. It will be exactly the same as a class but can be assigned values and used whereas a class can’t be used without creating objects.

Inheritance:
A feature in which the base class’s characteristics and behavior are derived to the child class also.
Types:
Single
Multiple

Single:
A class inherits from a single class.
Multiple:
A class inherits from more than 1 class.

Abstraction:
“Abstraction is simplifying complex reality by modeling classes appropriate to the problem, and working at the most appropriate level of inheritance for a given aspect of the problem.” Is what the Wikipedia says.

Encapsulation:
It is a feature which hides data and functions from others classes.

Polymorphism:
A feature using which more than one definition is given to a single name. It can either be function polymorphism or operator overloading.

Association:
Association defines a relationship between classes of objects which allows one object to cause another to perform an action on its behalf.

Composition:
Composition is a way to combine simple objects or data types into more complex ones.

Aggregation:
Aggregation is a form of composition where one looks at the system as a whole rather than as parts.

Part II (A startup lesson on using FxCop)

Monday, June 15, 2009

Part II (A startup lesson on using FxCop)

In the previous article (FxCop Part I – Introduction), we saw the basics of FxCop , its definition, download path, comparison with other Code analysis tools, a simple demo for doing a analysis,etc.

In this article (Part II -A startup lesson on using FxCop), we are going to see the usage of FxCop at a beginner’s level.

As we saw in the previous article two things are required for doing any analysis in FxCop, they are:
· Assembly ( either a .exe or .dll)
· Rule

A brief explanation about the windows and menus in FxCop
Run FxCop by clicking , Start > All Programs > Microsoft FxCop > Microsoft FxCop 1.36
After the FxCop window was opened,
Click File > New Project.
The following Figure 1.0 shows the FxCop tool,
Fig 1.0


Panes in FxCop
There are 3 panes in the tool, they are:
· Main Pane
· Messages Pane
· Output Pane

Main Pane
Figure 1.1 shows the Main Pane,
Fig 1.1
It will have 2 tabs in it, they are
· Targets
· Rules
These two tabs serve the respective purpose of showing and managing targets and Rules in the current project.

Messages Pane
This Pane shows the messages that are generated by the FxCop tool after doing the Code analysis and it will be of various categories.
Figure 1.2 shows the Messages pane.
Fig 1.2
It will have 4 tabs in it they are,
· Active
· Exclude in Project
· Exclude in Source
· Absent
The usage of these we will see in the later articles.

Output Pane
This will show the properties in code format when an item is clicked on the Main Pane.
Figure 1.3 shows the Output Pane,
Fig 1.3

Menus
For the initial level, it is enough to know about the 3 menus in the tool. They are
1. File > New Project
It is used to create a new project.
2. Project > Add Targets
It is used to add assemblies from the Project on which you want to do the analysis.
3. Project > Analyze
To start the analysis, you need to click this or press F5 or click Analyze button on the toolbar.

A simple analysis:
1. Run FxCop.
Start > All Programs > Microsoft FxCop > Microsoft FxCop 1.36
2. File > New Project.
3. Project > Add Targets.
4. Select the desired assembly you want to analyze (it can either be a .dll or an .exe).
For example, I am selecting here a .net application (Which was downloaded from internet)
5. If you have selected multiple assemblies then select any one of them (the one you want to analyze first) and then click Project > Analyze or press F5 or Click Analyze from toolbar.
6. Analyzing with introspection Engine dialog box will appear when the analysis is under process.
7. Then it will display list of messages in the right pane.
The resultant window is what is shown in the Figure 1.0. The messages shown will be of the following categories, they are:
· Critical error
This means that it is an major issue and need to be corrected.
· Warning
This means it’s just a warning and not that much serious, but if corrected the it will be good.

More details about the messages:
Double click on the respective message, then Message Details window will appear, which gives a detailed explanation about the message along with other options.
That window will have 5 tabs in it which elaborates about he message and its dependencies.
Figure 2.0 shows the Message Details window,
Fig 2.0

Stopping the Analysis
Click the Cancel button on the Analyzing with introspection Engine dialog box to cancel the Analysis in the middle.
Viewing a summary of the Analysis
Click Project > Analysis Summary, it will display a summary of the analysis done.
Figure 2.1 shows the Analysis Summary window,
Fig 2.0

Saving the Project
After the analysis is over , save the project before saving the Message XML file otherwise it will throw an error.

Note:
Moreover save the Project file in the same directory of the Assembly for which the code analysis is done.
To save the project click,
File > Save Project.

Saving the Report
After saving the Project file, you a save the report file wherever you want.
To save the Report click,
File > Save Report
This might have given a basic idea about the usage and components of FxCop. We shall see more in the coming Chapters.

FxCop – Part I (Introduction)

FxCop – Part I (Introduction)

This will be a series of articles on FxCop, which explains from the basics to advanced usage of FxCop. This article is the first of them which gives an introduction to FxCop.

Definition
It is a code analysis tool which analyzes the code and gives suggestions to improve coding.

Overview
It analyzes programming elements in targets, and provides an informational report that contains messages about the targets;
It can analyze either a dll or an exe.

Target
They are nothing but managed assemblies.

Message
Messages include suggestions about how to improve the source code used to generate them.

Rule
A rule is a code which analyses and finds defects and informs about it.

For analysis 2 things are required,
1. Target assemblies
2. Rules

Running FxCop
· From GUI
After installation, you will have shortcut in Programs menu; you can start FxCop by clicking the link.
· Command Line
You can run FxCop.exe with respective command line arguments to start it from command line.

Using FxCop you can do the following:
· Manage Rules (decide which rules need to be applied to which assembly)
· Apply Styles to Reports.
· Filter and save messages.
· And also you can save and reuse application settings.

Download Link
www.microsoft.com/Downloads/details.aspx?FamilyID=9aeaa970-f281-4fb0-aba1-d59d7ed09772&displaylang=en

Similar Code Analysis tools:
StyleCop is another tool which does code analysis.

Difference between FxCop and StyleCop:
FxCop does code analysis over the binaries, whereas StyleCop does code analysis over the source code itself.

Latest Versions:
FxCop : ver. 1.36
StyleCop : ver. 4.3.1.3

Steps to do an analysis:
1. Run FxCop.
2. File > New Project.
3. Project > Add Targets.
4. Select the desired assembly you want to analyze(it can either be a dll or an exe).
5. If you have selected multiple assemblies then select any one of them ( the one you want to analyze first) and then click Project > Analyze or press F5.
6. Then it will display list of messages in the right pane.

LinkWithin

Blog Widget by LinkWithin

Recommended Books