sharing about .NET and technology RSS 2.0
# Wednesday, August 06, 2008

SQL Server 2008 is now available on MSDN and TechNet, see the announcement here. To have an overview of the new features, you can have a look here and you may download the SQL Server 2008 Books Online. Apparently has SQL Server 2008 powershell support!

Wednesday, August 06, 2008 9:40:44 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [1] -
Links | SQL Server
# Friday, June 20, 2008

Version 0.28 of SyntaxColor4Writer has been compiled with the latest bits of Windows Live Writer 2008 (12.0.1370.325). You can download it from here.

Friday, June 20, 2008 10:20:31 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [5] -
.NET | SyntaxColor4Writer | Windows Live Writer
# Monday, May 19, 2008
# Wednesday, April 30, 2008
# Tuesday, April 01, 2008
# Sunday, March 23, 2008

The unity application block is a dependency injection container with support for constructor, property and method call injection. It simplifies the Inversion of Control (IoC) pattern and the Dependency Injection (DI) pattern. The Unity application block can be found on CodePlex.

The unity application block has two important methods for registering types and mappings into the container, namely RegisterType and RegisterInstance.

Method Default Lifetime Explanation
RegisterType Transient lifetime Container will create a new instance on each call to Resolve
RegisterInstance Container-controller lifetime Instance has the lifetime of the container

 

Below you find an example where we map the ILogger interface to ConsoleLogger (implements ILogger).

UnityContainer container = new UnityContainer();
container.RegisterType<ILogger, ConsoleLogger>();
ILogger logger = container.Resolve<ILogger>();

Assume you have the following class that contains a dependency to ILogger as a parameter on the constructor.

public class MyClass
{
   ILogger _logger;

   public MyClass(ILogger logger)
   {
      _logger = logger;
   }
}

If we use the Resolve method of UnityContainer it will automatically inject the ILogger (ConsoleLogger) object. This is called constructor injection.

UnityContainer container = new UnityContainer();
container.RegisterType<ILogger, ConsoleLogger>();
MyClass myClass = container.Resolve<MyClass>();

You can also map multiple types for the same interface. In that case you can use a key as a parameter.

UnityContainer container = new UnityContainer();
container.RegisterType<ILogger, ConsoleLogger>("console");
container.RegisterType<ILogger, EventLogger>("event");

If you now try to resolve MyClass you will get an exception, because it cannot resolve which type (ConsoleLogger or EventLogger) to use. Therefore you can use the Dependency attribute where you can denote a key. For example:

public class MyClass
{
   ILogger _logger;

   public MyClass([Dependency("console")] ILogger logger)
   {
      _logger = logger;
   }
}

Below you find an example of property injection:

public class AnotherClass
{
   ILogger _consoleLogger;
   ILogger _eventLogger;

   [Dependency("console")]
   public ILogger ConsoleLogger
   {
      get { return _consoleLogger; }
      set { _consoleLogger = value; }
   }

   [Dependency("event")]
   public ILogger EventLogger
   {
      get { return _eventLogger; }
      set { _eventLogger = value; }
   }
}

Note that you can also map and register your types through a configuration file.

<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
  <configSections>
    <section name="unity"
            type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
                 Microsoft.Practices.Unity.Configuration" />
  </configSections>
  <unity>
    <containers>
      <container>
        <types>
          <type name="console" 
                type="IStaySharp.UnitySample.ILogger, IStaySharp.UnitySample" 
                mapTo="IStaySharp.UnitySample.ConsoleLogger, IStaySharp.UnitySample" />
          <type name="event"   
                type="IStaySharp.UnitySample.ILogger, IStaySharp.UnitySample" 
                mapTo="IStaySharp.UnitySample.EventLogger, IStaySharp.UnitySample" />
        </types>
      </container>
  </containers>
  </unity>
</configuration>

The following code shows you how to use a configuration file with UnityContainer.

UnityContainer container = new UnityContainer();
UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
section.Containers.Default.GetConfigCommand().Configure(container);

ILogger logger = container.Resolve<ILogger>("console");
Sunday, March 23, 2008 2:38:43 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [2] -
.NET | Unity
# Tuesday, March 18, 2008

When trying to edit some code during debug, I received the following dialog of Visual Studio:

EditContinue64

It appears that the edit and continue feature is not supported when the target is a 64-bit application. On this page you find a nice overview of the scenarios where the edit and continue features are not supported. To resolve the problem, you have to set the target to x86, which can be found in the project properties.

BuildSettingsPlatform

Tuesday, March 18, 2008 1:50:14 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [1] -
.NET | Visual Studio
# Friday, March 14, 2008

In my current sample project when the runtime tried to access the MyMeta library (see following post) I always get the following FatalExecutingEngineError exception:

FatalExecutionEngineError

It turns out that the problem is that the MyMeta library is compiled under a x86 platform whereas the application is running on a x64 platform. In the properties settings of your visual studio project you have to set the platform target to x86! It was set to 'Any CPU', but now everything works fine.

BuildSettingsPlatform

Friday, March 14, 2008 9:11:47 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [1] -
.NET | Visual Studio
# Thursday, March 13, 2008
# Tuesday, March 04, 2008

Component Dropper is a component that resides in the toolbox of VS.NET and enables you to choose a component (controls, datasets, providers, components, etc.) from the assemblies that are referenced in the current project.

In Visual Studio .NET you can auto populate the controls in the toolbox by setting the AutoToolboxPopulate property to true in menu Tools -> Options -> Windows Forms Designer.

AutoToolboxPopulate

Component Dropper is an alternative way for dropping a component on the designer surface. It gives you a dialog with all the components that reside in the assemblies that are referenced in the current project. This means that it is not limited to the assemblies that reside in the current solution. This way you can easily browse and search throughout the assemblies and controls, this is very handy if you have bunch of assemblies and controls. There is never a need to refresh the toolbox, because it dynamically searches throughout the references in the current project.

ComponentDropper09

Download: ComponentDropper v0.9 (35.04 KB)

There is also a demo (1.11 Mb) that illustrates the use of Component Dropper. Note that the demo uses an older version of Component Dropper, namely version 0.5, and it's not an VS add-in anymore.

If after installation you don't see the component dropper appearing in the toolbox, you can simply drag-and-drop the IStaySharp.RazorToolbox.dll to the toolbox.
Any suggestions or remarks are welcome!

Tuesday, March 04, 2008 5:28:38 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [4] -
.NET | Component Dropper | Visual Studio
# Monday, March 03, 2008

PowerCommands is a set of useful extensions for the Visual Studio 2008 adding functionality to various area of the IDE.
The features I found very useful are:

  • Copy/Paste References
  • Edit Project File
  • Remove and Sort Usings

PowerCommands can be downloaded here and below you find the complete list of features:

  • Collapse Projects
    This command collapses a hierarchy in the solution explorer starting from the root selected node. It can be executed from three different places: solution, solution folders and project nodes respectively.
  • Copy Class
    This command copies a selected class entire content to the clipboard. It can be executed from a single project item or a project item with dependent sub items.
  • Paste Class
    This command pastes a class entire content from the clipboard. It can be executed from a project or folder node.
  • Copy References
    This command copies a reference or set of references to the clipboard. It can be executed from the references node, a single reference node or set of reference nodes.
  • Paste References
    This command pastes a reference or set of references from the clipboard. It can be executed from different places depending on the type of project. For CSharp projects it can be executed from the references node. For Visual Basic and Website projects it can be executed from the project node.
  • Copy As Project Reference
    This command copies a project as a project reference to the clipboard. It can be executed from a project node.
  • Edit Project File
    This command opens the MSBuild project file for a selected project inside Visual Studio. It can be executed from a project node.
  • Open Containing Folder
    This command opens a Windows Explorer window pointing to the physical path of a selected item. It can be executed from a project item node
  • Open Command Prompt
    This command opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively.
  • Unload Projects
    This command unloads all projects in a solution. It can be executed from the solution node.
  • Reload Projects
    This command reloads all unloaded projects in a solution. It can be executed from the solution node.
  • Remove and Sort Usings
    This command removes and sort using statements for all classes given a project. It can be executed from a solution node or a single project node.
    Note: The Remove and Sort Usings feature is only available for C# projects since the C# editor implements this feature as a command in the C# editor (which this command calls for each .cs file in the project). The Visual Basic IDE implements this functionality for Imports in an interactive way: Project properties, go to the References tab, then click the Unused References... button, then select which references you want removed via a listbox.
  • Extract Constant
    This command creates a constant definition statement for a selected text. It can be executed from the code window over a selected text.
  • Clear Recent File List
    This command clears the Visual Studio recent file list.
  • Clear Recent Project List
    This command clears the Visual Studio recent project list.
  • Transform Templates
    This command executes the associated custom tool with text templates items. It can be executed from a DSL project node or a folder node.
  • Close All
    This command closes all documents. It can be executed from a document tab.
Monday, March 03, 2008 11:42:58 AM (Romance Standard Time, UTC+01:00) -  # -  Comments [0] -
Links | Visual Studio
# Tuesday, February 12, 2008

Version 0.27 of SyntaxColor4Writer has been released. It has been updated with the newest release of Windows Live Writer v12.0.1367.1128 and CodeHighlighter 4.0.0051.

Tuesday, February 12, 2008 10:31:44 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [5] -
.NET | SyntaxColor4Writer | Windows Live Writer
# Monday, December 31, 2007

SMO (SQL Server Management Objects) is a .NET based object library for programming all aspects of managing Microsoft SQL Server. Replication Management Objects (RMO) is another library that encapsulates SQL Server replication management.

SMO assemblies are shipped with SQL Server 2005 and can be used to connect with SQL Server 7, 2000 or 2005. The assemblies are located in the following folder C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies.

  • Microsoft.SqlServer.Smo.dll
  • Microsoft.SqlServer.ConnectionInfo.dll
  • Microsoft.SqlServer.SmoEnum.dll
  • Microsoft.SqlServer.SqlEnum.dll

With SMO you can do all kind of management on a SQL Server, namely: tables, columns, indexes, stored procedures, service broker, backup and restore, managing users/roles and logins, scheduling, etc. Here you can find some specific tasks that can be done with SMO.

Below you find an example how you can create a table with SMO:

using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

public class Sample
{
    public void Create(string connectionstring)
    { 
        SqlConnection connection = new SqlConnection(connectionstring);
        Server server = new Server(new ServerConnection(connection));
        
        Database database = server.Databases["MyDatabase"];
        
        // Create table, called Customer
        Table table = new Table(database, "Customer");
        
        // Add 'ID' column which is the primary key
        Column idColumn = new Column(table, "ID");
        idColumn.DataType = DataType.Int;
        idColumn.Identity = true;
        idColumn.IdentitySeed = 1;
        idColumn.IdentityIncrement = 1;
        
        // Create a primary key index
        Index index = new Index(table, string.Format("PK_{0}", table.Name));
        index.IndexKeyType = IndexKeyType.DriPrimaryKey;
        index.IndexedColumns.Add(new IndexedColumn(index, "ID"));
        table.Indexes.Add(index);                        
        
        // Add 'Name' column
        Column nameColumn = new Column(table, "Name");
        nameColumn.DataType = DataType.VarChar(50);
        
        // Add colums to table
        table.Columns.Add(idColumn);
        table.Columns.Add(nameColumn);
        
        table.Create();
    }
}
Monday, December 31, 2007 3:04:11 AM (Romance Standard Time, UTC+01:00) -  # -  Comments [2] -
.NET | Database | SQL Server
# Friday, December 28, 2007

MyMeta is an open-source API that allows you to get meta-data from your database. MyMeta is part of MyGeneration, a free code generator hosted on Sourceforge. The MyMeta API can be downloaded separately here (filename is called 'mymeta_installer.exe').

MyMeta supports the following databases. Note that the API is extensible and that you can provide your own plug-ins

  • Advantage
  • Delimited Text
  • Firebird
  • IBM DB2
  • IBM iSeries (AS400)
  • Interbase
  • Microsoft Access
  • Microsoft SQL CE
  • Microsoft SQL Server
  • MySQL
  • MySQL2
  • Oracle
  • Pervasive
  • PostgreSQL
  • PostgreSQL 8+
  • SQLite
  • VistaDB
  • Xsd3b (xml,xsd,uml,er)

Below you find a code snippet that will iterate, for a SQLite database, all tables, columns and indexes.

string connectionstring = @"data source=SQLiteDatabase.DB";

MyMeta.dbRoot myMeta = new MyMeta.dbRoot();
myMeta.Connect(MyMeta.dbDriver.SQLite, connectionstring);

IDatabase db = myMeta.DefaultDatabase;

foreach (MyMeta.ITable table in db.Tables)
{
    Console.WriteLine("{0} ({1})", table.Name, table.Columns.Count);
    Console.WriteLine("\tCOLUMNS");

    foreach (MyMeta.IColumn column in table.Columns)
    {
        Console.WriteLine("\t\t{0} ({1}), Nullable:{2}", 
                 column.Name, column.DataTypeName, column.IsNullable);
    }

    Console.WriteLine("\tINDEXES");

    foreach (MyMeta.IIndex index in table.Indexes)
    {
        Console.WriteLine("\t\t{0}, Unique:{1}", index.Name, index.Unique);
    }
}

MyMeta can map database types to specific ADO.NET data types and language types (C#, VB.NET, etc.). MyMeta has a set of XML files (included in the setup) that contains these mappings. Namely the 'Languages.xml' and 'DbTargets.xml'. Below you find a snippet of the two XML files:

<Languages>
    ...
    <Language From="SQL" To="C#">
        <Type From="bigint" To="long" />
        <Type From="binary" To="object" />
        <Type From="bit" To="bool" />
        <Type From="char" To="string" />
        <Type From="datetime" To="DateTime" />
        <Type From="decimal" To="decimal" />
        <Type From="float" To="double" />
        <Type From="image" To="byte[]" />
        <Type From="int" To="int" />
        <Type From="money" To="decimal" />
        <Type From="nchar" To="string" />
        <Type From="ntext" To="string" />
        <Type From="numeric" To="decimal" />
        <Type From="nvarchar" To="string" />
        <Type From="real" To="float" />
        <Type From="smalldatetime" To="DateTime" />
        <Type From="smallint" To="short" />
        <Type From="smallmoney" To="decimal" />
        <Type From="text" To="string" />
        <Type From="timestamp" To="byte[]" />
        <Type From="tinyint" To="byte" />
        <Type From="uniqueidentifier" To="Guid" />
        <Type From="varbinary" To="byte[]" />
        <Type From="varchar" To="string" />
        <Type From="xml" To="string" />
        <Type From="sql_variant" To="object" />
    </Language>
    ...
    <Language From="SQLITE" To="C# (SQLite v3.x)">
        <Type From="CHAR" To="string" />
        <Type From="DATETIME" To="DateTime" />
        <Type From="DATE" To="DateTime" />
        <Type From="TIMESTAMP" To="DateTime" />
        <Type From="TIME" To="TimeSpan" />
        <Type From="DECIMAL" To="decimal" />
        <Type From="VARCHAR" To="string" />
        <Type From="NVARCHAR" To="string" />
        <Type From="TEXT" To="string" />
        <Type From="INTEGER" To="long" />
        <Type From="INT" To="long" />
        <Type From="FLOAT" To="float" />
        <Type From="BOOLEAN" To="bool" />
        <Type From="CLOB" To="string" />
        <Type From="BLOB" To="byte[]" />
        <Type From="NUMERIC" To="decimal" />
        <Type From="VARYINGCHARACTER" To="string" />
        <Type From="NATIONALVARYINGCHARACTER" To="string" />
    </Language>
    ...
</Languages>
<DbTargets>
    ...
    <DbTarget From="SQL" To="SqlClient">
        <Type From="bigint" To="SqlDbType.BigInt" />
        <Type From="binary" To="SqlDbType.Binary" />
        <Type From="bit" To="SqlDbType.Bit" />
        <Type From="char" To="SqlDbType.Char" />
        <Type From="datetime" To="SqlDbType.DateTime" />
        <Type From="decimal" To="SqlDbType.Decimal" />
        <Type From="float" To="SqlDbType.Float" />
        <Type From="image" To="SqlDbType.Image" />
        <Type From="int" To="SqlDbType.Int" />
        <Type From="money" To="SqlDbType.Money" />
        <Type From="nchar" To="SqlDbType.NChar" />
        <Type From="ntext" To="SqlDbType.NText" />
        <Type From="numeric" To="SqlDbType.Decimal" />
        <Type From="nvarchar" To="SqlDbType.NVarChar" />
        <Type From="real" To="SqlDbType.Real" />
        <Type From="smalldatetime" To="SqlDbType.SmallDateTime" />
        <Type From="smallint" To="SqlDbType.SmallInt" />
        <Type From="smallmoney" To="SqlDbType.SmallMoney" />
        <Type From="text" To="SqlDbType.Text" />
        <Type From="timestamp" To="SqlDbType.Timestamp" />
        <Type From="tinyint" To="SqlDbType.TinyInt" />
        <Type From="uniqueidentifier" To="SqlDbType.UniqueIdentifier" />
        <Type From="varbinary" To="SqlDbType.VarBinary" />
        <Type From="varchar" To="SqlDbType.VarChar" />
        <Type From="xml" To="SqlDbType.Xml" />
        <Type From="sql_variant" To="SqlDbType.Variant" />
    </DbTarget>
    ...
    <DbTarget From="SQLITE" To="SQLite.NET v3.x">
        <Type From="CHAR" To="DbType.String" />
        <Type From="DATETIME" To="DbType.DateTime" />
        <Type From="DATE" To="DbType.DateTime" />
        <Type From="TIMESTAMP" To="DbType.DateTime" />
        <Type From="TIME" To="DbType.Time" />
        <Type From="DECIMAL" To="DbType.Decimal" />
        <Type From="VARCHAR" To="DbType.String" />
        <Type From="NVARCHAR" To="DbType.String" />
        <Type From="TEXT" To="DbType.String" />
        <Type From="INTEGER" To="DbType.Int64" />
        <Type From="INT" To="DbType.Int32" />
        <Type From="FLOAT" To="DbType.Single" />
        <Type From="BOOLEAN" To="DbType.Boolean" />
        <Type From="CLOB" To="DbType.String" />
        <Type From="BLOB" To="DbType.Binary" />
        <Type From="NUMERIC" To="DbType.Decimal" />
        <Type From="VARYINGCHARACTER" To="DbType.String" />
        <Type From="NATIONALVARYINGCHARACTER" To="DbType.String" />
    </DbTarget>
    ...
</DbTargets>

The xml files can be loaded by setting the LanguageMappingFilename and DbTargetMappingFilename. Setting the right target can be done by the properties Language and DbTarget.

string connectionstring = @"data source=SQLiteDatabase.DB";

MyMeta.dbRoot myMeta = new MyMeta.dbRoot();
myMeta.Connect(MyMeta.dbDriver.SQLite, connectionstring);

myMeta.LanguageMappingFileName = @"C:\Program Files\MyGenerations\Settings\Languages.xml";
myMeta.DbTargetMappingFileName = @"C:\Program Files\MyGenerations\Settings\DbTargets.xml";            

myMeta.Language = "C# (SQLite v3.x)";            
myMeta.DbTarget = "SQLite.NET v3.x";

IDatabase db = myMeta.DefaultDatabase;

foreach (MyMeta.ITable table in db.Tables)
{
    Console.WriteLine("{0} ({1})", table.Name, table.Columns.Count);
    Console.WriteLine("\tCOLUMNS");

    foreach (MyMeta.IColumn column in table.Columns)
    {
        Console.WriteLine("\t\t{0} ({1}), DBTargetType:{2}, LanguageType:{3}", 
            column.Name, column.DataTypeName, column.DbTargetType, column.LanguageType);
    }                
}

The mapped types can be found in the properties DbTargetType and LanguageType on the IColumn interface.

Friday, December 28, 2007 5:52:34 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [2] -
.NET | Database
# Friday, November 23, 2007

Jihaaa, Visual Studio 2008 has been released on MSDN. If you want to have a nice overview of the new features in VS2008, take a look at this post from ScottGu.

Take a look at the following downloads available for VS2008

Friday, November 23, 2007 12:24:13 AM (Romance Standard Time, UTC+01:00) -  # -  Comments [1] -
Links | Visual Studio
# Sunday, November 11, 2007

Finally Microsoft has released a final version of Windows Live Writer, namely Windows Live Writer 2008. This means also a new version of SyntaxColor4Writer that has been updated with the latest bit of Windows Live Writer and CodeHighlighter from Actipro, more info here.

Sunday, November 11, 2007 5:00:48 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [0] -
.NET | SyntaxColor4Writer | Windows Live Writer
# Tuesday, November 06, 2007

I has been a while that I released a new version of ComponentDropper and I am going to release a new update very soon. I received positive feedback, and I am planning to add some new features and certainly to provide an installer for the add-in. Please leave a comment if you have any suggestions about ComponentDropper. 

Tuesday, November 06, 2007 3:10:31 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [1] -
.NET | Component Dropper | Visual Studio
Yesterday I arrived in Barcelona for TechEd 2007. I followed already some interesting sessions about LINQ, it brings you closer how you can access data in a more intuitive and more object-oriented way (data = objects). I really like LINQ to SQL, one of the drawbacks, is that it can only be used against a SQL Server database. If you need to target another database and program against a conceptual model (not a 1-1 mapping with your datatable structure and objects) you can have a look at LINQ to Entities.
Tuesday, November 06, 2007 2:54:50 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [1] -
Events | TechEd
# Sunday, October 14, 2007

On my current project I had the need to iterate through the properties of an object with reflection and to check if one of the properties is a generic List type, e.g. IList<int>, IList<Customer>, etc. To check through reflection on a generic type, you need to use the GetGenericTypeDefinition method.

foreach (PropertyInfo propertyInfo in entity.GetType().GetProperties())
{
   if (propertyInfo.PropertyType.IsGenericType &&
       typeof(List<>).IsAssignableFrom(propertyInfo.PropertyType.GetGenericTypeDefinition()))
   {
      IEnumerable enumerable = propertyInfo.GetValue(entity, null) as IEnumerable;
      IEnumerator enumerator = enumerable.GetEnumerator();

      while (enumerator.MoveNext())
      {
         // do something
      }
   }
}
Sunday, October 14, 2007 11:49:11 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [3] -
.NET
# Monday, October 01, 2007

Last week, I purchased a Linksys WRT54GL at RouterShop.nl. The service at Routershop.nl was really fast: at around 1:00pm I created the order and it was delivered the very next day!

The big advantage of WRT54GL is that you can upgrade the firmware of the device. Some popular firmware's are DD-WRT, OpenWRT and Tomato. I am using Tomato, of which today a new version has been released, i.e. Tomato 1.09. Tomato has a very nice interface, many interesting features and great-looking graphs. Below you will find a nice graph concerning the bandwidth:

linksysbandwidthmonitor

Note that you need to install the Adobe SVG Viewer in order to view the graphs.

Monday, October 01, 2007 9:19:23 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [0] -
Hardware | Linksys WRT54
Navigation
Archive
<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Christoph De Baene
Sign In
Statistics
Total Posts: 176
This Year: 2
This Month: 0
This Week: 0
Comments: 249
All Content © 2010, Christoph De Baene
DasBlog theme 'Business' created by Christoph De Baene