Monday, January 28, 2008

TOOLS : What's use of CruiseControl.Net

CruiseControl.NET (CCNet) consists of a suite of applications, but at its core is the CruiseControl.NET Server which is an automated integration server.

The Server automates the integration process by monitoring the team's source control repository directly. Every time a developer commits a new set of modifications, the server will automatically launch an integration build to validate the changes. When the build is complete, the server notifies the developer whether the changes that they committed integrated successfully or not.

Effectively, integration becomes as easy as checking in code. Using an automated integration server not only makes integration easy, it also guarantees that an integration build will happen. There is no danger of developers forgetting to validate their changes after checking in.

The CCNet Server offers several key features:
  • Integration with a variety of Source Control systems
  • Can build multiple projects on one server
  • Integration with other external tools, such as NAnt and Visual Studio
  • Remote management and reporting
  • It should provide notification of build for any monitored project
  • Create Failed email notification group
  • Pass through more properties to the Builder
  • Can view project configuration through the WebDashboard
  • 'Always Get Latest' option for VSS plugin
  • MsTest Report stylesheet (and summary report improvements)
  • Show server log for a specific project
  • You can choose which project to monitor on each server
  • You can specify the refresh interval
  • You can choose to see only the projects that are failing or all the projects

CruiseControl.NET Tools

The other applications in the CruiseControl.NET suite are:

  • Web Dashboard: A .NET web application that gives you a status and detailed view of the CruiseControl.NET projects and servers in your organisation.
  • CCTray: A client System Tray application that enables you to see 'at a glance' the state of your projects from any machine on your network.

Share your thoughts with me !!!
- Rangoli

Thursday, January 17, 2008

LINQ : Why need LINQ?

  1. LINQ syntax beats SQL syntax. SQL is flawed in that queries become exponentially difficult to write as their complexity grows. LINQ scales much better in this regard. Once you get used to it, it's hard to go back.
  2. Database queries are easily composable. You can conditionally add an ORDER BY or WHERE predicate without discovering at run-time that a certain string combination generates a syntax error.
  3. More bugs are picked up at compile-time.
  4. Parameterization is automatic and type-safe.
  5. LINQ queries can directly populate an object hierarchy.
  6. LINQ to SQL provides a model for provider independence that might really work.
  7. LINQ significantly cuts plumbing code and clutter. Without sweeping stuff under the carpet, like Workflow or Datasets. This is a credit to the design team.
  8. C# hasn't suffered in the process (in fact, it's gained).

Share your thoughts with me !!!
- Rangoli

Thursday, January 10, 2008

C# : Partial Methods

In C# 3.0, partial classes allow you to split the definition of a class across multiple files. In the same way we can split the definition of a code unit separated over multiple files by Partial Method.

The following are some rules that apply to partial methods.

• Partial methods must only be defined and implemented in partial classes
• Partial methods must specify the partial modifier
• Partial methods are private but must not specify as private modifier
• Partial methods must return void
• Partial methods may be unimplemented
• Parital methods may be static
• Partial methods may have arguments

Example :

public partial class MyClass
{
partial void MyMethodStart(int count);
partial void MyMethodEnd(int count);
public MyClass()
{
int count = 0;
MyMethodStart(++count);
Console.WriteLine("Calling constructor.");
MyMethodEnd(++count);
Console.WriteLine("Count is {0} after calling partial methods. ", count);
}
}


public partial class MyClass
{
partial void MyMethodStart(int count)
{
Console.WriteLine(" MyMethodStart(Count is {0}) .", count);
}
partial void MyMethodEnd(int count)
{
Console.WriteLine("MyMethodEnd(Count is {0}) ", count);
}
}


OUTPUT :

MyMethodStart(Count is 1)
Calling constructor.
MyMethodEnd(Count is 2)
Count is 2 after calling partial methods.

Share your thoughts with me !!!
- Rangoli

LINQ : Converting an Array of Strings to Integers & Sorting

LINQ is just for queries because it stands for Language Integrated Query. But please don’t think of it only in that context. Normally we use to write a loop to iterate through the array of strings and populate a newly constructed array of integers. But LINQ makes much easier by writing a single line code for the same.

The following example helps us to convert an array of string to integer array with sorted result.

. Declare an array of strings

string[] numbers = { "0042", "010", "9", "27" };

.Convert the array of strings to an array of integer

int[] nums = numbers.Select(s => Int32.Parse(s)).ToArray();

.Sorting the converted array of interger

int[] nums = numbers.Select(s => Int32.Parse(s)).OrderBy(s => s).ToArray();

. To display the resulting array of integers

foreach(int num in nums)
Console.WriteLine(num);

OUTPUT :
9
10
27
42

Share your thoughts with me !!!
- Rangoli

Wednesday, January 9, 2008

LINQ : Introduction to LINQ

LINQ is Microsoft’s technology to provide a language-level support mechanism for querying data of all types. These types include in-memory arrays and collections, databases, XML documents, and more.

LINQ is all about queries, whether they are queries returning a set of matching objects, a single object, or a subset of fields from an object or set of objects. In LINQ, this returned set of objects is called a sequence. Most LINQ sequences are of type IEnumerable<T>, where T is the data type of the objects stored in the sequence.

For example, if you have a sequence of integers, they would be stored in a variable of type IEnumerable.

Example 1 : Collections (By adding using directive for the System.Linq namespace.)

using System;
using System.Linq;

string[] greetings = {"hello world", "hello LINQ", "hello Apress"};

var items =

from s in greetings
where s.EndsWith("LINQ")

select s;

foreach (var item in items)

Console.WriteLine(item);

OUTPUT:

hello LINQ

----------------------------------------------------------------------------------------------

Example 2 : XML (By adding using directive for the System.Xml.Linq namespace.)

using System;
using System.Linq;
using System.Xml.Linq;

XElement books = XElement.Parse(
@"<employees>
<employee>
<name>Arjun Kannan</name>
<dept>IT</dept>
</employee>
<employee>
<name>Nivas Nair</name>
<dept>IT</dept>
</employee>
<employee>
<name>Pandiaya Gopi Babu</name>
<dept>Fianace</dept>
</employee>
<employees>
");

var depts=
from e in employees.Elements("employee")
where (string) employee.Element("dept") == "IT"
select e.Element("name");

foreach(var dept in depts)
Console.WriteLine(dept.Value);

OUTPUT :

Arjun Kannan
Nivas Nair

----------------------------------------------------------------------------------------------

Example 3 : SQL (By adding using directive for the System.Data.Linq namespace.)

using System;
using System.Linq;
using System.Data.Linq;
using nwind;

Northwind db = new Northwind(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind");

var custs =
from c in db.Customers
where c.City == "Rio de Janeiro"
select c;

foreach (var cust in custs)
Console.WriteLine("{0}", cust.CompanyName);

OUTPUT :

Hanari Carnes
Que Delícia
Ricardo Adocicados


Hope you like this!!! Share your thoughts with me !!!
- Rangoli

Monday, January 7, 2008

C# : Extension Methods

For an example where you have a nullable value in the database and you represent this as a Nullable on your C# object (e.g., JoinDate). When you go to save this value back to the database, you want to save a DateTime value, otherwise you want to save a null to the database - specifically a DBNull.Value.

In C# 2.0 you'd have to write a static method like this:

public static class Util
{
public static object ToDBValue(Nullable nullable) where T : struct
{
if (nullable.HasValue)
{
return nullable.Value;
}
else
{
return DBNull.Value;
}
}
}
and use it like

db.SetParameterValue(cmd, Params.JoinDate, Util.ToDBValue( employee.JoinDate ));

In C# 3.0 you can convert the static method to an extension method by simply adding the this modifier to the first parameter like this:

public static class Util
{
public static object ToDBValue(this Nullable nullable) where T : struct
{
if (nullable.HasValue)
{
return nullable.Value;
}
else
{
return DBNull.Value;
}
}
}
Which allows you to call the method like this:
db.SetParameterValue(cmd, Params.JoinDate, employee.JoinDate.ToDBValue() );

Hope you like this!!! Share your thoughts with me !!!
- Rangoli

Thursday, January 3, 2008

C# : Collection Initialization

In C#3.0, a collection initializer specifies the elements of a collection. A collection initializer is made up of the following way,
  • A sequence of object initializers, enclosed by "{" and "}" tokens and separated by "," .
  • Element initializers, each of which specifies an element to be added to the collection object being added.
Note: A collection initializer invokes the ICollection.Add(T) method for each specified element in order. All the initialization values are of type string. Otherwise, you'd get a compiler error.

Example:

Suppose you want to represent a class and its enrolled Employees. You can do this through collection initializers as follows:

using System.Collections.Generic;

namespace VS2008New
{
public class Employee
{
public int ID { get; private set; }
public string Name { get; set; }
public string Destination { get; set; }
public int Experiance { get; set; }
public Employee(int id)
{
ID = id;
}
public override string ToString()
{
return Name + "\t" + Destination + "\t" + Experiance + "\t" + ID;
}
}
class Program
{
static void Main(string[] args)
{
List employees = CreateEmployeeList();
Console.WriteLine("Employee Lists:\n");
foreach (Employee c in employees)
Console.WriteLine(c);
}
static List CreateEmployeeList()
{
return new List
{
new Employee(1) { Name = "Tony Robert", Destination = "Saleman", Experiance = 5 },
new Employee(2) { Name = "Rangoli Kannan", Destination = "Jr Manager", Experiance = 3 },
new Employee(3) { Name = "Naren", Destination = "Sr Manager", Experiance = 7 }
};
}
}
}

Run the sample given above, you get the following result.

Hope this helps!!! Share your thoughts with me !!!
- Rangoli

C# : Object Initializers

In C#, when declaring an object or collection, you may include an initializer that specifies the initial values of the members of the newly created object or collection.

In C# 3.0, the new syntax for object creation and initialization in a single step. An object initializer consists of a sequence of member initializers, contained in '{ } 'braces and separated by commas. Each member initializer assigns a value to a field or property of the object.

For example,

using System.Collections.Generic;

namespace VS2008New
{
public class Employee
{
public int ID { get; private set; }
public string Name { get; set; }
public string Destination { get; set; }
public int Experiance { get; set; }

public Employee(int id)
{
ID = id;
}
public override string ToString()
{
return Name + "\t" + Destination + "\t" + Experiance + "\t" + ID;
}
}

class Program
{
static void Main(string[] args)
{
// In C# 2.0
Employee emp = new Employee(1000)
emp.Name = "Tony";
emp.Destination = "Salesman";
emp.Experiance = 5;
Console.WriteLine(c);

// In C# 3.0
Employee emp1 = new Employee(1001)
{ Name = "Rangoli Kannan", Destination = "Developer", Experiance = 4 };
Console.WriteLine(emp1);
}
}
}
Now build and run this application, we get the result like this,


Share your thoughts with me !!!
- Rangoli

Frameworks: Comparison between VS Frameworks

The comparison between Frameworks in Visual Studio
The core assemblies installed from the .NET Framework version 2.0 are still used by the 3.0 and 3.5 versions. In ASP.NET 3.5 doesn't change or take away or break any functionality, concepts, or code present in 2.0 - it simply adds new types and features and capabilities to the framework.

The VS 2008 is multi-targeted, meaning that you choose from a drop-down list whether to have Visual Studio 2008 build applications against the ASP.NET 2.0, 3.0, or 3.5 frameworks.

VS 2008 also includes an improved Designer experience, JavaScript debugging and IntelliSense features, and the ability to view and even step into the core .NET Framework code during debugging.

The following picture highlights the features in .NET 2.0 and the features added in .NET 3.0 and then in .NET 3.5:

For more background on how .NET 3.5 is mere additional assemblies and functionality added atop the existing .NET 2.0 base, refer to Daniel Moth's blog entry, .NET Framework 3.5. Also from Daniel's blog, the Visual Studio 2008 Stack helps paint a clear picture with regards to the changes in Visual Studio, the programming languages, the framework libraries, and the CLR over time:

New Visual Studio 2008 Features
Visual Studio 2008 offers an improved developer experience through a number of new features, including an improved Designer, more modern CSS editing options, and enhanced JavaScript debugging and development support. Visual Studio 2008 can target web applications to the .NET 2.0, .NET 3.0, or .NET 3.5 environments, meaning you can start using Visual Studio 2008 today to work on your ASP.NET 2.0 websites. I hope you got some basic idea about the Visual Studio 2008.Enjoy!

Share your thoughts with me !!!
Rangoli

C# : Auto-Implemented Properties

Auto-Implemented Properties :

Auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors.

When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field can only be accessed through the property’s get and set accessors.

The following example shows a simple class that has some auto-implemented properties:
class Emplyee
{
public int ID { get; private set; } // read-only

public string Name { get; private set; } // read-only

public string Destination { get; set; }
}
Auto-implemented properties must declare both a get and a set accessor. To create a readonly auto-implemented property, give it a private set accessor.

Attributes are not permitted on auto-implemented properties. If you must use an attribute on the backing field of a property, just create a regular property.

Share your thoughts with me !!!
- Rangoli