DCSIMG
September 2007 - Posts - Maor's Blog

September 2007 - Posts

Moving Team Foundation Server Databases To New Destination

Last week I installed Team Foundation Server (single server mode) for one of our customers. Due to hardware problem, I installed TFS on default drive C which has low capacity: ~50GB space.

After couple of days the customer installed another hard disk (160GB). He asked me to move TFS databases to the new hard disk.

These are the steps I used to move the TFS databases from drive C to the new hard disk.

Preparations

  1. Ask the users (and make sure...) to stop working against TFS.
  2. Backup TFS database or make sure you have access to the daily backups. (you won't use it; just in case...)

Workaround

  1. Stop TFSServerScheduler, SharePoint Timer Service & SQL Server Reporting services.
  2. Stop the TFS-related Application Pools:  ReportServer, TFS AppPool, TFSWSS, and TFSWSSADMIN. (You can also stop IIS if it isn't being used for anything else).
  3. Open Microsoft SQL Server Management Studio and connect to the Database Engine for your Team Foundation Server.
  4. Locate and Detach the TFS databases:
    • ReportServer
    • ReportServerTempDB
    • STS_Config_TFS
    • STS_Content_TFS
    • TfsActivityLogging
    • TfsBuild
    • TfsIntegration
    • TfsVersionControl
    • TFSWarehouse
    • TfsWorkItemTracking
    • TfsWorkItemTrackingAttachements
  5. Locate the database data files and transaction logs that were detached.  By default they are in the following directory: [C]:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data.  The following database files should be moved:
    • ReportServer.mdf and ReportServer_log.LDF
    • ReportServerTempDB.mdf and ReportServerTempDB_log.LDF
    • STS_Config_TFS.mdf and STS_Config_TFS_log.LDF
    • STS_Content_TFS.mdf and STS_Content_TFS_log.LDF
    • TfsActivityLogging.mdf and TfsActivityLogging_log.LDF
    • TfsBuild.mdf and TfsBuild_log.LDF
    • TfsIntegration.mdf and TfsIntegration_log.LDF
    • TfsVersionControl.mdf and TfsVersionControl_log.LDF
    • TFSWarehouse.mdf and TFSWarehouse_log.LDF
    • TfsWorkItemTracking.mdf and TfsWorkItemTracking_log.LDF
    • TfsWorkItemTrackingAttachments.mdf and TfsWorkItemTrackingAttachments_log.LDF
  6. For each database, move the MDF and related LDF file from the source location to the new database files destination.
  7. On Microsoft SQL Server Management Studio reattach the database files that you moved in the previous step to their new locations.
  8. Restart the application pools that were shutdown in step 2 (or restart IIS).
  9. Start the services that were stopped in step 1.
  10. Open Team Explorer and make sure everything works well.

Good luck!

MSBuild Basics

One of my favorite technologies is MSBuild. I found that I didn't dedicate too much writing time about it in this blog. I think and feel that I really neglect MSBuild at my blog...:(

This post will be the first of series of posts about this technology.

So lets start with the basics of MSBuild.

The Microsoft Build Engine (MSBuild) is the new build platform for Microsoft and Visual Studio. MSBuild is completely transparent with regards to how it processes and builds software, enabling developers to orchestrate and build products in build lab environments where Visual Studio is not installed.

Quote from Microsoft site.

 

In principle, this definition is really injustice for MSBuild. When I read it I insulted for MSBuild. For me, MSBuild is a high level scripting technology. I can use MSBuild almost for everything. NOT only build!

The introduction of MSBuild as an official utility was very welcome among the development community as it provides close integration with the existing project and solution files created by Visual Studio. This close integration cuts down on the amount of detail necessary for the build scripts.T he MSBuild utility comes with .NET 2.0 and is available with the runtime even if Visual Studio is not installed.

MSBuild based on XML-based project. (like csproj,vbproj...)

The basic elements of the MSBuild project file format are:

  1. PropertyGroup
  2. ItemGroup
  3. Target
  4. Task

 

PropertyGroup

Properties are defined in the PropertyGroup element. You can simply add an arbitrary element and enclose the assigned value within that element. Properties represent key/value pairs that can be used to configure builds. Example of PropertyGroup:

<PropertyGroup>
    <AppName>My application name</AppName>
    <AppDir>C:\Apps</AppDir>
    <ThirdPartyDir>C:\3rdParty</ThirdPartyDir>
</PropertyGroup>

 

ItemGroup

Defining lists is done within an ItemGroup element. You will want to use a list with a Task occasionally, such as copying a group of files to another folder. Below is an example of an ItemGroup.Items are declared in the project file by creating an element with the name of the item collection as a child of an ItemGroup element. Example of ItemGroup:

<ItemGroup>
    <FilesToCopy Include = "file1.cs"/>
    <FilesToCopy Include = "file2.cs"/>
</ItemGroup>

 

You reference item collections throughout the project file with the syntax @(ItemGroupName). In thus case, you reference the item group with @(FilesToCopy).

 

Targets

Targets group tasks together in a particular order and expose sections of the project file as entry points into the build process. Targets are often grouped into logical sections to allow for expansion and increase readability.

Targets are declared in the project file with the Target element. For example, the target bellow occurs after build.

<Target Name="AfterBuild">
    Do something....
</Target>

Tasks

Tasks are reusable units of executable code used by MSBuild projects to perform build operations. For example, a task might create directories and copy files. Once created, tasks can be shared and reused.

You execute a task in an MSBuild project file by creating an element with the name of the task as a child of a Target element.

MSBuild shipped with a alot of built in tasks. For example: MakeDir,Copy and more.

See below an example for using tasks:

<Target Name="AfterBuild">
    <MakeDir Directories="$(AppDir)" />
    <Copy SourceFiles="$(FilesToCopy)" DestinationFolder="$(AppDir)" />
</Target>

Next in the series I'll dive deeper with the msbuild script.

The msbuild script below is a demonstration about my earlier sentence: "I can use MSBuild almost for everything". Save this as .proj file, and execute it from VS2005 command prompt as: msbuild YourSavedFileName

This script only opens windows calculator...

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="Build" >
        <Message Text="Executing calculator" />
        <Exec Command="calc" />
    </Target>
</Project>  

 

Technorati Tags:
September TFS Powertool released!

September version (1.3) of the Power Tool for TFS 2005 is now available for download.

This release includes new features:

  • Team Foundation Server Best Practice Analyzer: This tool helps a TFS Administrator gather configuration information about TFS deployment, perform tests on a server, analyze test results and more. In addition, this tool can be used to perform these tasks:
    • Determine configurations that differ from default, recommended, or required settings.
    • Verify a TFS deployment is configured according to recommended best practices.
  • WorkItem templates: supports the ability to create, apply, capture, and set default work item templates. Templates can be used to create or update work items, and they can automatically set field values.

This release is only compatible with Visual Studio 2005 Team Foundation Server. Visual Studio 2008 support are planned for release in few months.

 

For more details, check out Brian Harry's post.

Technorati Tags:
Subscribers - Update your reader!

I moved my RSS feed to FeedBurner. Please update your feed subscription to my new Feed.

http://feeds.feedburner.com/MaorDavid

svcutil.exe in Orcas Beta 2 problem

When I trying to run WCF test service on VS 2008 beta 2 I got an error:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly ’svcutil, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0×8013141A)

File name: ’svcutil, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ —> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0×8013141A)

It turns out that this is a known issue in Beta2. Svcutil.exe is not signed correctly.

I found a solution for this issue at WCF MSDN forum: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1932994&SiteID=1&pageid=0

The solution is:

1. Open the VS 2008 Beta 2 command prompt as Administrator (important especially in Vista).

2. Browse to the bin directory of the windows SDK ([C]:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin)

3. Type: sn –Vr svcutil.exe.

 

By the way,  sn -Vr will not sign it but rather tell .NET to skip signature verification for that assembly.

Technorati Tags: ,

Moving TFS Databases to new destination

In case you must move your's TFS databases files to new location, I posted about it at SRLTeam blog. There is workaround to solve this issue and it's not complicated.

Technorati Tags:

C# 3.0 Extension Methods

How many times have you written wrapper methods for objects that in reality you wished were part of the object itself?For example, we have the following method which returns the first and last char of a given string in upper case:

   1:  namespace MaorDavidsBlogExamples
   2:  {
   3:      public static class Extensions
   4:      {
   5:          public static string UpperFirstAndLast(string str)
   6:          {
   7:              string ret = "{0}{1}{2}";
   8:              ret = String.Format(ret,
   9:                  str.Substring(0, 1).ToUpper(),
  10:                  str.Substring(1, str.Length - 2),
  11:                  str.Substring(str.Length-1).ToUpper());
  12:              return ret;
  13:          }
  14:      }
  15:  }

We called this method:

   1:  static void Main(string[] args)
   2:  {
   3:      string str = "maordavid";
   4:      Console.WriteLine(Extensions.UpperFirstAndLast(str));
   5:      Console.ReadLine();
   6:  }

...when really, what you want is something more readable like this:

   1:  Console.WriteLine(str.UpperFirstAndLast());

That is exactly what Extension methods let you do.

Extension methods new feature of C# 3.0. They are static methods that can be invoked using instance method syntax. In effect, extension methods make it possible to extend existing types and constructed types with additional methods. Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type.

 

Now we want to add this new UpperFirstAndLast() method to the existing string type. Some of us can think that we can create our own class that inherits System.String and add that method there, but it's impossible - System.String is a seald class. What can we do? use Extension Methods!

Declaring Extension methods

Extension methods are declared by specifying the keyword this as a modifier on the first parameter of the methods. Extension methods can only be declared in static classes.

Let's rewrite the UpperFirstAndLast:

   1:  namespace MaorDavidsBlogExtensionExamples
   2:  {
   3:      public static class Extensions
   4:      {
   5:          public static string UpperFirstAndLast(this string str)
   6:          {
   7:              string ret = "{0}{1}{2}";
   8:              ret = String.Format(ret,
   9:                  str.Substring(0, 1).ToUpper(),
  10:                  str.Substring(1, str.Length - 2),
  11:                  str.Substring(str.Length-1).ToUpper());
  12:              return ret;
  13:          }
  14:      }
  15:  }

 

The static method above has a "this" keyword before the first parameter argument of type string.  This tells the compiler that this particular Extension Method should be added to objects of type "string". 

To add this specific Extension Method implementation to string instances within my code, I simply use a standard "using" statement to import the namespace containing the extension method implementation. (Line 6 below)

The compiler will then correctly resolve the UpperFirstAndLast() method on any string.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:   
   6:  using MaorDavidsBlogExtensionExamples;
   7:   
   8:  namespace MaorDavidsBlogExamples
   9:  {
  10:      class Program
  11:      {
  12:          static void Main(string[] args)
  13:          {
  14:              string str = "maordavid";
  15:              Console.WriteLine(str.UpperFirstAndLast());
  16:              Console.ReadLine();
  17:          }
  18:      }
  19:  }

 

The intellisense will help you to find the extension method: new icon indicates an "extension method:

ex

 

Another posts about C# 3.0:

C# Automatic Properties

Visual Studio 2008 and .NET 3.5 introduces us new feature: Automatic Properties.

You probably write classes with properties like this:

   1:  public class Student
   2:  {
   3:      private string _firstName;
   4:   
   5:      public string FirstName
   6:      {
   7:          get { return _firstName; }
   8:          set { _firstName = value; }
   9:      }
  10:   
  11:      private string _lastName;
  12:   
  13:      public string LastName
  14:      {
  15:          get { return _lastName; }
  16:          set { _lastName = value; }
  17:      }
  18:   
  19:      private string faculty;
  20:   
  21:      public string Faculty
  22:      {
  23:          get { return faculty; }
  24:          set { faculty = value; }
  25:      }
  26:   
  27:  }

 

Usually, you aren't actually adding any logic in the getters/setters of your properties - instead you just get/set the value directly to a field.

Basically, automatic properties allow you to replace this common pattern with this one:

   1:  public class Student
   2:  {
   3:      public string FirstName
   4:      {
   5:          get; set;
   6:      }
   7:   
   8:   
   9:      public string LastName
  10:      {
  11:          get; set;
  12:      }
  13:   
  14:   
  15:      public string Faculty
  16:      {
  17:          get; set;
  18:      }
  19:  }

No fields, only properties and declarations of get/set. The compiler can automate creating the private field and the default get/set operations for you.

This is certainly much more compact and requires fewer steps. When the compiler sees this class, (according to Reflector) it translates it to:

ap

There are a few things to look out for when using this syntax. The compiler forces you to declare properties with both a get and a set. You also don't get any kind of "safety" features, such as ensuring that you don't allow a null value to be assigned to a string property. If you want these more "advanced" features, you'll still need to define your property with the "old way".

Google Presentation

Google updated recently their Applications suite with the addition of Google Presentation. It was added to all of docs.google.com including Google Apps For Your Domain, which I also use. 1

 

Nice things in this application

  • It looks just like PowerPoint!
  • Great Revisions support - many copies are saved all the time, so you'll never lose anything.
  • You can start a presentation then give folks a URL and they can join up and watch.
  • Upload a PPT .
  • You can chat about the presentation being watched.
  • Save as a ZIP file. They'll create a "self-contained" ZIP with a single HTML file and the assets you need to run the presentation using any browser.

But there also annoying things:

  • No spellcheck support.
  • Can't link to pictures online, have to upload.
  • No animations, shapes, auto-layouts, wizards, etc.
  • Very basic. No PowerPoint-like experience on the web.
  • JavaScript errors.
  • You can upload PPT, but you can't Save As PPT.
  •  

    Nice application but I think I'll wait to the next versions.

    2

    Getting started with LINQ

    Language Integrated Query (LINQ) introducing a standard set of operators that can be used to query several different data stores such as SQL Server and XML. LINQ comes as part of the future revisions of both the C# and VB.NET compilers (VS 2008).

    LINQ architecture

    As we see at the figure below, the data to be queried can take the form of XML (LINQ to XML), databases (LINQ-enabled ADO.NET, which includes LINQ to SQL, LINQ to Dataset and LINQ to Entities), objects (LINQ to Objects), and so on.

    (Click to enlarge every image)

    Architecture

    Each middle tier component provides us with the required functionality to interact with that component’s data store.

     

    First application

    This application help us with core understanding of how a query is constructed and what types of collections you can query.

       1:          static void Main(string[] args)
       2:          {
       3:              string[] bloggers = { "Maor", "Leon", "Guy", "Mr. Elimelech"};
       4:   
       5:              IEnumerable<string> query = from b in bloggers
       6:                                          where b.StartsWith("M")
       7:                                          select b;
       8:   
       9:              foreach (string blogger in query)
      10:              {
      11:                  Console.WriteLine(blogger);
      12:              }
      13:   
      14:              Console.ReadLine();
      15:          }

    In this snippet we use several standard operators to construct a query which filters out all blogger which start with the letter ‘M’, however, of more significant importance is the collection which we have queried.

    We can query any in-memory collection which implements IEnumerable, or IEnumerable<T>.

    If we run this example in debug mode, placing a breakpoint on the same line as the foreach statement, we can see that the compiler is doing some extra work for us under the covers:

    1

    An implementation detail of the query given above is that we are actually creating a lambda expression when the code is compiled, this expression is used as a parameter for the Where() extension method of the bloggers collection.

    Linq to SQL

    LINQ to SQL is an O/RM (object relational mapping) implementation. LINQ to SQL allows you to model a relational database using .NET classes.  You can then query the database using LINQ, as well as update/insert/delete data from it.

    In my example, I'll use the Northwind database. I created a representation of the database like below. I can do it by SqlMetal or by adding Linq to Sql classes and drag the objects I want from the server explorer to the designer.

    Northwind

    The properties of each class map to the columns of a corresponding table in the database.  Each instance of a class entity represents a row within the database table.

    The DataContext: I pressed the "save" button within the LINQ to SQL designer surface and Visual Studio generated .NET classes that represent the entities and database relationships that we modeled. Every LINQ to SQL designer file has a custom DataContext class which also generated.  This DataContext class is the main conduit by which we'll query entities from the database as well as apply changes.  The DataContext class created will have properties that represent each Table we modeled within the database, as well as methods for each Stored Procedure we added.

     

    Query the database

    The code below query the database against customers which company name is 'Cactus Comidas para llevar'.

       1:  Northwind db = new Northwind();
       2:  var customers = from c in db.Customers
       3:                  where c.CompanyName == "Cactus Comidas para llevar"
       4:                  select c;

     

    Insert new data

    This code demonstrate how to insert new customer to customers table:

       1:  Northwind db = new Northwind();
       2:  Customer cust = new Customer();
       3:  cust.CustomerID = "MDP";
       4:  cust.CompanyName = "Maor David Ltd.";
       5:   
       6:  db.Customers.Add(cust);
       7:  db.SubmitChanges();

     

    Updating data

    Demonstration how to retrieve a single customer from the database, update its country, and then save the changes back to the database.

       1:  Northwind db = new Northwind();
       2:  var customers = from c in db.Customers
       3:                  where c.CompanyName == "Cactus Comidas para llevar"
       4:                  select c;
       5:   
       6:  Customer cus = db.Customers.Single(c => c.CompanyName == "Maison Dewey");
       7:  cus.Country = "IL";
       8:  db.SubmitChanges();

     

    Delete data

       1:  Northwind db = new Northwind();
       2:  var customers = from c in db.Customers
       3:                  where c.CompanyName == "Cactus Comidas para llevar"
       4:                  select c;
       5:   
       6:   
       7:  db.Customers.RemoveAll(customers);
       8:  db.SubmitChanges();

     

    Summary

    LINQ provides a simple set of standard operators to query in-memory collections as well as entities. LINQ for SQL allows us to create DAL’s quickly but more importantly they are more flexible and robust than the common approach.

    This is only the first post about LINQ. I'll continue to expand it. This is only the introduction.

     

    Astoria CTP Refresh for Visual Studio 2008 Beta 2

    The Astoria team has just released a refresh of the Astoria Prototype CTP to work with Visual Studio Beta 2 and the Entity Framework Beta 2.

    The goal of Microsoft Codename Astoria is to enable applications to expose data as a data service that can be consumed by web clients within a corporate network and across the internet. The data service is reachable over HTTP, and URIs are used to identify the various pieces of information available through the service. Interactions with the data service happens in terms of HTTP verbs such as GET, POST, PUT and DELETE, and the data exchanged in those interactions is represented in simple formats such as XML and JSON.

    The Astoria September 2007 CTP is now available for download.

    This CTP is a refresh of the May CTP/Prototype bits recompiled so they run with Visual Studio 2008/Entity Framework Beta 2.

    You can visit the Astoria Team Blog for more information.

    Technorati Tags: ,
    C# 3.0 var keyword

    C# 3.0 has many-a-new features. This post will explain the 'var' keywork and the concept of Implicitly Typed Variables.

    The var keyword is not a late-bound or un-typed variable reference. The var keyword always generates a strongly typed variable reference. The main idea is that the developer is not required to define the type of the variable at the time of declaration, but it is the task of the compiler to decide what type of the object the variable is. The compiler infer the type of the variable from the expression used to initialize the variable when it is first declared.

    Important points about var keyword:

    • The type of the variable is defined by the value declared and decided at the compile time. (Size depends on the type of the value initialised)
    • Type casting is simple and handled by CLR.
    • Explicit functions for parsing to specific type.
    • Can be used to reference any type in C#.
    • The CLR actually never knows that the var keyword is being used.

    What rules shuold you force to use the var keyword?

    When you declare variable with the var keyword, you must to always do an initial value assignment.  This is because the var keyword produces a strongly-typed variable declaration. Hence, the compiler needs to be able to infer the type to declare based on its usage.   If you don't, the compiler will produce a compiler error.

       1: var vAge = 32; 
       2: var vHeight = 175.2; 
       3: var vName = “Maor David“;  

     

    The compiler will infer the type of the "age", "height" and "name" variables based on the type of their initial assignment value. This means it will generate IL that is absolutely identical to the code below:

       1: int age = 32;
       2: double height = 175.2;
       3: string name = "Maor David";

    You can also use it to other data types:

       1: foreach (var vTable in ds.Tables) 
       2: {
       3:     foreach (var vRow in ((DataTable) vTable).Rows) 
       4:     {
       5:  
       6:     }
       7: }

    This is equal to:

       1: foreach (DataTable table in ds.Tables)
       2: {
       3:     foreach (DataRow vRow in table.Rows)
       4:     {
       5:     }
       6: }
    Technorati Tags: , ,
    MSBuild posts references

    I posted at SRLTeam blog 2 posts about msbuild. The first is about building data dude projects with SqlBuildTask. Big projects usually sufferes from time out expiration. The post introduce a workaround to solve this problem.

    The second post is about building .NET 3.0 projects from Team Build 2005.

    Technorati Tags: , ,

    del.icio.us Tags: , ,
    שנה טובה

    ברצוני לאחל לכולכם שנה טובה ומתוקה. שכל משאלותיכם תתגשמנה.

    והכי חשוב - בריאות, בריאות ובריאות!!!!!

    מאור

    ShanaTova 

    Microsoft Launches Translation Service

    Microsoft launched a service for automatic translation called Windows Live Translator. The site lets you translate a text limited to 500 words or a web page from English to German, Dutch, French, Spanish, Portuguese, Italian, Korean, Chinese, Japanese, Russian.

    liveTrans

    Microsoft uses Systran to produce most of the translations, but also offers an option to translate computer-related texts using a machine translation system developed in-house. Microsoft's translation technology has been used to translate technical materials, including MSDN Library.

    More Posts Next page »

    Search

    Go

    This Blog

    News

      RSS

       

      Connect with Me

      Maor's Facebook profile  Follow Maor on Twitter  Maor's profile on Linkedin  Maor in FriendFeed 
             

    Syndication