Saturday, May 23, 2009

JetBrains ReSharper 4.5

JetBrains is providing the “best” productivity add-on around. Visual Studio is simply not the same without R#. There is a small penalty in performance of-course but it’s absolutely worth it. Bare in mind that the solution wide analysis feature should not be turned on all the time for large solutions (50+ projects) because it slows down studio a lot.

The is a 30 day fully functional trial available: http://www.jetbrains.com/resharper/download/index.html

Features: http://www.jetbrains.com/resharper/features/

Code Analysis
On-the-fly Error Detection
Multilevel Code Inspection
Quick-Fixes
Navigating Between Code Highlights
Solution-Wide Error Analysis
Value Analysis
Annotated Framework
Navigation & Search
Navigate from Here
'Go to' Features
Usage Search
CamelHumps
Type Hierarchy
File Structure
Find Referenced/Dependent Code
Collapse All in Solution Explorer
Locate in Solution Explorer
View Recent Items
Stack Trace Explorer
To-do Explorer
Refactorings
Using Code Refactorings
Change Signature
'Convert' Refactorings
Copy Type
Encapsulate Field
'Extract' Refactorings
'Inline' Refactorings
'Introduce' Refactorings
Make Method Static/Non-Static
'Move' Refactorings
Pull/Push Members Up/Down
Rename
Replace Constructor with Factory Method
Safe Delete
Use Base Type where Possible
Code Generation
Create from Usage
Generate Type Members
Implement/Override Methods
Configure Generation Options
Coding Assistance
Syntax Highlighting
Context Actions
Code Completion
Complete Statement
Extended Naming Style Configuration
Parameter Info
Highlight Matching Delimiters
Importing Namespaces
Auto-insertion of Delimiters
Code Reordering
Quick Documentation
Comment/Uncomment Code
Highlight Current Line
Extend/Shrink Selection
Duplicate Line or Selection
Multiple Entries Clipboard
Code Cleanup
Using Code Cleanup
Code Formatting
Optimizing Namespace Import Directives
Removing Code Redundancies
Migrating to C# 3.0
Reordering Type Members
Code Style Configuration and Sharing
Code Templates
Live Templates, Surround Templates, File Templates
Customizing, Configuring and Sharing Templates
Unit Testing
Running and Debugging Tests
Unit Test Explorer
Unit Test Sessions
Profiling Unit Tests with dotTrace Profiler
Cross-Language Functionality
Build Scripts

Visual Studio 2010 Beta 1 (MSDN Subscriptions)

Visual Studio 2010 Professional Beta 1 (x86) - DVD (English)
Includes: Professional; 05-18-2009
File Name: en_visual_studio_2010_professional_edition_beta_1_x86_dvd.iso
Date Posted (UTC): 5/18/2009 10:03:17 AM

Available to Levels: MSDN OS (VL); VS Pro with MSDN Pro (VL); VS Pro with MSDN Premium (Empower); MSDN OS (Retail); Developer AA; VS Pro with MSDN Pro (Retail); MSDN Enterprise; MSDN Universal (Retail); VSTS Team Suite (VL); VSTS Architecture (VL); VSTS Development (VL); VSTS Test (VL); VS Pro with MSDN Premium (VL); MSDN Universal (VL); VSTS Database (VL); VS Pro with MSDN Premium (Retail); VSTS Test (Retail); VSTS Development (Retail); VSTS Architecture (Retail); VSTS Team Suite (Retail); VSTS Database (Retail); BizSpark Admin; BizSpark;

Visual Studio Team Foundation Server 2010 Beta 1 (x86 and x64) - DVD (English)
Includes: Team Foundation Server; 05-18-2009
File Name: en_visual_studio_team_foundation_server_2010_beta_1_x86_x64_dvd.iso
Date Posted (UTC): 5/18/2009 10:02:33 AM

Available to Levels: MSDN OS (VL); VS Pro with MSDN Pro (VL); VS Pro with MSDN Premium (Empower); MSDN OS (Retail); Developer AA; VS Pro with MSDN Pro (Retail); MSDN Enterprise; MSDN Universal (Retail); VSTS Team Suite (VL); VSTS Architecture (VL); VSTS Development (VL); VSTS Test (VL); VS Pro with MSDN Premium (VL); MSDN Universal (VL); VSTS Database (VL); VS Pro with MSDN Premium (Retail); VSTS Test (Retail); VSTS Development (Retail); VSTS Architecture (Retail); VSTS Team Suite (Retail); VSTS Database (Retail); BizSpark Admin; BizSpark;

Visual Studio Team System 2010 Team Suite Beta 1 (x86) - DVD (English)
Includes: Team System; 05-18-2009
File Name: en_visual_studio_team_system_2010_team_suite_beta_1_x86_dvd.iso
Date Posted (UTC): 5/18/2009 10:02:03 AM

Available to Levels: MSDN OS (VL); VS Pro with MSDN Pro (VL); VS Pro with MSDN Premium (Empower); MSDN OS (Retail); Developer AA; VS Pro with MSDN Pro (Retail); MSDN Enterprise; MSDN Universal (Retail); VSTS Team Suite (VL); VSTS Architecture (VL); VSTS Development (VL); VSTS Test (VL); VS Pro with MSDN Premium (VL); MSDN Universal (VL); VSTS Database (VL); VS Pro with MSDN Premium (Retail); VSTS Test (Retail); VSTS Development (Retail); VSTS Architecture (Retail); VSTS Team Suite (Retail); VSTS Database (Retail); BizSpark Admin; BizSpark;

Friday, May 22, 2009

ASP.NET Portal Starter Kit

The ASP.NET Portal Starter Kit demonstrates how you can use ASP.NET and the .NET Framework to build a dynamic portal application. The ASP.NET Portal Starter Kit offers all the functionality of typical portal applications.
It's developed in c# 3.0 \ .NET 3.5.
Portal_Big.bmp Logoneg.gif
http://www.codeplex.com/ASPNETPortal

Project Scope

Re-engineering the original project using up-to-date technologies

Features

  • Dynamic Portal Infrastructure
  • 10 basic portal modules for common types of content
  • 2 extra portal modules: RSS Feed and Wiki (postponed)
  • A "pluggable" framework that is simple to extend with custom portal modules
  • Online administration of portal layout, content and security
  • XML based definition of portal layout
  • Database based definition of portal layout new.jpg
  • Roles-based security for viewing content, editing content, and administering the portal
  • Full mobile support using the ASP.NET Mobile Controls
  • Multiple database support easily extensible to support more databases new.jpg
  • Web service layer ASMX and WCF new.jpg
  • Smart Client to support Admins and power users new.jpg

Technologies and Design Approaches Demonstrated

  • .NET 2.0 \ .NET 3.5 new.jpg
  • Web Client Software Factory new.jpg
  • Object Builder new.jpg
  • Smart Client Software Factory new.jpg
  • ASP.NET Mobile Controls
  • Three-tier architecture with ASP.NET
  • Role Based Security
  • Layered architecture new.jpg
    • Vertical: Data\Business\Presentation
    • Horizontal: Services, Framework
  • Design Patterns new.jpg
  • NUnit Tests new.jpg
  • Master Pages, SiteMaps & Themes new.jpg

Thursday, May 21, 2009

Design Pattern: Factory Method

The factory method pattern deals with the problem of creating objects without specifying the exact class of object that will be created. The factory method design pattern handles this problem by defining a separate method for creating the objects, whose subclasses can then override to specify the derived type of object that will be created.
More generally, the term factory method is often used to refer to any method whose main purpose is creation of objects.

This sample requires the following to be installed: Visual Studio 2008. You can checkout a read-only copy of this sample using tortoise from:
http://bakopanos.googlecode.com/svn/trunk/designpatterns/GangOfFour.FactoryMethod

A very simple example: we’ll create a DataFactory class that will be able to map a IDataReader to an Object. The DataFactory is abstract since the subclasses will override the Map method implementation.   
    

public abstract class DataFactory<T>
where T : class, new()
{
public abstract List<T> List();

protected List<T> List(string cmd)
{
var items = new List<T>();

using (var conn = new SqlCeConnection(@"Data Source=Database1.sdf"))
{
conn.Open();
using (var command = new SqlCeCommand(cmd, conn))
{
var reader=command.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
items.Add(Map(reader));
}
}
}
return items;
}

public abstract T Map(IDataRecord reader);
}


We need to map the database Table Titles to the object Title.



 
public classTitle
{
    public int Id { get; set; }
    public stringName { get; set; }
}
The TitleDataFactory class subclasses the DataFactory and overrides the Map method.


public class TitleDataFactory : DataFactory<Title>
{
public override List<Title> List()
{
return List("select * from titles");
}

public override Title Map(IDataRecord reader)
{
int id = (int) reader["id"];
string name = reader["name"] as string;
var item = new Title {Id = id, Name = name};

return item;
}
}



Although the sample is far from a proper ORM implementation it demonstrates well the Factory Method design pattern. 
If you are looking for your next ORM tool then this is the wrong place, consider:
EntLib, Spring, ActiveRecord, NHibernate
LinqToSql, EntityFramework, DataSet
any of the many commercial frameworks such as IdeaBlade, DevExpress XPO and so on…
Some sample client code to demonstrate how to use the DataFactory


/// <summary>
///
Entry point into console application.
/// </summary>
static void Main()
{
List<Title> list = new TitleDataFactory().List();

foreach (var title in list)
{
Console.WriteLine(title.Name);
}

// Wait for user
Console.ReadKey();
}

Wednesday, May 20, 2009

C# Generics and Extension methods to build a simple iterator

In this example we focus on the type safe collection classes and show how to build a simple iterator.

This sample requires the following to be installed: Visual Studio 2008. You can checkout a read-only copy of this sample using tortoise from:
http://bakopanos.googlecode.com/svn/trunk/csharpsamples/GenericSamples/ForEachIteratoren
using System;

namespace ForEachIterators
{
interface IAction
{
void Action();
}

static class Program
{
public static void ForEachI<T>(this T[] array) where T : IAction
{
foreach (T elem in array)
{
elem.Action();
}
}

public class MyString : IAction
{
readonly string _s;
public MyString(string s) { _s = s; }

public void Action()
{
Console.WriteLine("I'm a string with {0}", _s);
}
}

public delegate void Action<T>(T obj);

public static void ForEach<T>(this T[] array, Action<T> action)
{
if (action != null)
foreach (T elem in array)
{
action(elem);
}
}
//leave private
static void StringAction(this string s)
{
Console.WriteLine("a String {0}", s);
}
//leave private
static void IntAction(this int i)
{
Console.WriteLine("an Integer {0}", i);
}

static void Main()
{
var arr0 = new MyString[2];
arr0[0] = new MyString("Hallo");
arr0[1] = new MyString("value");
arr0.ForEachI();

var arr1 = new [] { "Hello", "World" };
arr1.ForEach(StringAction);
var arr2 = new [] { 2, 6, 3, 9 };
arr2.ForEach(IntAction);
arr2.ForEach(IntAction); //Delegate inference
arr2.ForEach(i => Console.WriteLine("lambda: {0}", i));

Console.ReadLine();
}
}
}

C# Generics Sample

Generics provide the tool to create flexible reusable code by allowing classes, structures, interfaces, methods and delegates to be declared as a generic type instead of an actual type; the actual type is specified later. The System.Collections.Generic namespace provides generic collection classes that make creating type safe collections very easy.

In this example we focus on the type safe collection classes and show how their type safety works and what the speed benefit is of using a generic collection over a standard collection.

This sample requires the following to be installed: Visual Studio 2008. You can checkout a read-only copy of this sample using tortoise from:
http://bakopanos.googlecode.com/svn/trunk/csharpsamples/GenericSamples/ComparableConstraint

using System;
using System.Collections.Generic;

namespace ComparableConstraint
{
interface IPriorityQueue<TE, TP> where TP : IComparable<TP>
{
//
void Put(TE element, TP priority);
//
TE Get();
//
int Count { get;}
}

class PriorityQueue<TE, TP> : IPriorityQueue<TE, TP>
where TP : IComparable<TP>
{
struct KeyValuePair<TK, TV>
{
public readonly TK Key;
public readonly TV Value;

public KeyValuePair(TK key, TV value)
{
Key = key;
Value = value;
}
}

readonly List<KeyValuePair<TP, TE>> _list = new List<KeyValuePair<TP, TE>>();

public void Put(TE element, TP priority) {
_list.Add(new KeyValuePair<TP,TE>(priority, element));
}

public TE Get()
{
int maxInd = 0;
for (int i = 0; i < _list.Count; i++)
{
if (_list[i].Key.CompareTo(_list[maxInd].Key) > 0)
maxInd = i;
}
TE val = _list[maxInd].Value;
_list.RemoveAt(maxInd);
return val ;
}

public int Count { get { return _list.Count; }}
}

class Program
{
static void Main()
{
IPriorityQueue<String, int> pq1 = new PriorityQueue<String, int>(); //ok
pq1.Put("String 1 mit Prio 7", 7);
pq1.Put("String 2 mit Prio 4", 4);
pq1.Put("String 3 mit Prio 1", 1);
pq1.Put("String 4 mit Prio 5", 5);

while (pq1.Count > 0)
{
string s = pq1.Get();
Console.WriteLine(s);
}
Console.ReadLine();
}
}
}