Friday, December 25, 2009

WCF Data Services

Project Astoria == ADO.NET Data Services == WCF Data Services

As announced at PDC this afternoon by Pablo, the ADO.NET Data Services framework is being renamed WCF Data Services as the first part of a long term effort to align all the Microsoft technologies for building n-tier applications and services. 

While this change does not affect current product plans or deliverables for Dev 10 or Silverlight, it is the first key step in simplifying our offerings in this space.

Thursday, December 24, 2009

Microsoft Banned From Selling Word From 11th January 2010

Microsoft [MSFT], yesterday lost its appeal in a Federal Court, in the patent case brought against Microsoft by i41 Ltd of Canada, regarding the use of their XML related patents what were used in Microsoft Word 2007.

From the 11th of January 2010, Microsoft will have to stop selling Microsoft Word, which basically means Microsoft office, unless they agree some out of court settlement with i4i before that date.

Microsoft Banned From Selling Word From 11th January 2009

This injunction applies only to copies of Microsoft Word 2007 and Microsoft Office 2007 sold in the U.S. on or after the injunction date of January 11, 2010.  Copies of these products sold before this date are not affected.

With respect to Microsoft Word 2007 and Microsoft Office 2007, we have been preparing for this possibility since the District Court issued its injunction in August 2009 and have put the wheels in motion to remove this little-used feature from these products. Therefore, we expect to have copies of Microsoft Word 2007 and Office 2007, with this feature removed, available for U.S. sale and distribution by the injunction date.

It will be interesting to see if Microsoft manages to reach an agreement with i4i Ltd, or if they just remove the code from Microsoft Word as they have stated in their press release.

Monday, December 14, 2009

TextDecoration Class

In .Net Framework 3.0. There is one new class is introduced named Text Decoration under the name space System.Windows.

A TextDecoration object is a visual ornamentation you can add to text

There are four types of text decorations: underline, baseline, strikethrough, and overline. The following example shows the locations of the text decorations relative to the text.

Example of text decoration types

Diagram of text decoration locations

The following example shows a text decoration that has been styled with a linear gradient brush and a dashed pen.

Example of an underline styled with a linear gradient brush and dashed pen

Text decoration with linear gradient underline

 

Visit more here about Text Decoration class…..

Tuesday, December 08, 2009

Visual Studio 2008 SP1: LINQ to SQL and FILESTREAM

LINQ to SQL and FILESTREAM In Visual Studio 2008 and .Net Framework 3.5 SP1, not only that LINQ to SQL supports the new date and time types of SQL Server 2008, but is also supports forking with FILESTREAMs.

Using the File Management Schema from my SQL Server 2008 FILESTREAM post, I created a simple .net application that uses LINQ to SQL in order to access the file contents.

Just a reminder of how the Files table looks like:

CREATE TABLE [dbo].[Files]

(

    FileID uniqueidentifier NOT NULL ROWGUIDCOL PRIMARY KEY,

    FileContents varbinary(max) FILESTREAM DEFAULT(0x)

)

and the corresponding LINQ to SQL model and generated code look like:

[Table(Name="dbo.Files")]

imagepublic partial class File

{

  private System.Guid _FileID;

  private System.Data.Linq.Binary _FileContents;

 

  [Column(Storage="_FileID",
          DbType="UniqueIdentifier NOT NULL",
          IsPrimaryKey=true)]

  public System.Guid FileID

  {

    get { ... }

    set { ... }

  }

  [Column(Storage="_FileContents",
          DbType="VarBinary(MAX)",
          UpdateCheck=UpdateCheck.Never)]

  public System.Data.Linq.Binary FileContents

  {

    get { ... }

    set { ... }

  }

}

Notice that the FileContents field is defined as System.Data.Linq.Binary.

Reading a File Content

FileManagementDataContext db = new FileManagementDataContext();

var query = db.Files;

foreach (var file in query)

{

    byte[] buffer = file.FileContents.ToArray();

    System.IO.File.WriteAllBytes(file.FileID + ".txt", buffer);

}

In the above code block I create a new instance of the data context and query for all the files. Going over the files, I take out the file contents as a byte array from the System.Data.Linq.Binary field and write it to another file in the file system.

Adding a new File

byte[] inputBuffer = System.IO.File.ReadAllBytes("TextFile1.txt");

File newFile = new File();

newFile.FileID = Guid.NewGuid();

newFile.FileContents = new System.Data.Linq.Binary(inputBuffer);

db.Files.InsertOnSubmit(newFile);

db.SubmitChanges();

In the above code I read all the contents of a file and get it as a byte array. Then, I create a new File object, assign a new ID and create a new instance of System.Data.Linq.Binary and pass the contents. Then, I use standard LINQ to SQL methods to add the file into the table and submit the changes to the database.

Conclusion

LINQ to SQL adds the support of using SQL Server 2008 FILESTREAM in Visual Studio 2008 and .Net Framework 3.5 SP1. The FILESTREAM columns is represented as a System.Data.Linq.Binary field that we can access it and get the file contents as a byte array.

Enjoy!

Monday, December 07, 2009

SQL Server 2008 FILESTREAM - Part 1

SQL Server 2008 FILESTREAM SQL Server 2008 has a lot of new cool features that I've talked about before:

 

One of the great features in SQL 2008 is it's FILESTEAM support. To make things short, we can now not only store the path to the file in our database, but we can now store the whole file inside the SQL Server and than backup, restore and manage it just as we would do with any other data.

In this post series I will build a file management database with SQL 2008 FILESREAM and build a .net client application that works with it.

1. Enable FILESTREAM support

To enable FILESTREAM support, run the following sql command

exec [sp_filestream_configure] @enable_level = 3;

This command enables or disables the support according to the parameter. The value 3 means that FILESTREAM will be enabled for Transact-SQL, local file system access, and remote file system access.

You can find more details about sp_filestream_configure here.

2. Create a database with a File Group that contains FILESTREAM

To create a database instance with a file group that contains FILESTREAM, run the following sql command. This creates the database with 3 file groups, but only one of them contains FILESTREAM as you can see in the command.

CREATE DATABASE FileManagement

ON

PRIMARY (

    NAME = FileManagement_Primary,

    FILENAME = 'c:\temp\data\FileManagement.mdf'),

FILEGROUP FileStreamGroup CONTAINS FILESTREAM (

    NAME = FileManagement_FileGroup,

    FILENAME = 'c:\temp\data\FileManagement')

LOG ON ( NAME = FileManagement_Log,

    FILENAME = 'c:\temp\data\FileManagementLog.ldf')

GO

This command will create the following directories structure:

SQL Server 2008 FILESTREAM

In the Data Directory, I could find the files specified above:

SQL Server 2008 FILESTREAM

and in the FileManagement directory, I could find the following content:

SQL Server 2008 FILESTREAM

3. Create a Table with FILESTREAM

Note: FILESTREAM is not a type of a column, but it is a property you put on a varbinary(max) column.

So, in order to create a table with a varbinary(max) column that will be used for FILESTREAM, run the following command. Note that I don't have any additional columns to the file itself.

CREATE TABLE [dbo].[Files]

(

    FileID uniqueidentifier NOT NULL ROWGUIDCOL PRIMARY KEY,

    FileContents varbinary(max) FILESTREAM DEFAULT NULL

)

4. Add Test Data

In order to get the feeling of the experience of working with files, let add an empty file:

insert into Files

values (newid(), null);

If we now query the database to see the files in it:

select * from Files

we will get the following result (the GUID will probably be different...)

FileID                               FileContents

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

8247CE78-74DF-4BDE-A08D-9760AE0B1555

and If we look at the FileManagement directory, we can see that a new directory has been created

SQL Server 2008 FILESTREAM

If we add a file with some content:

insert into Files

values (newid(), CAST ('my test file' as varbinary(max)));

we can query for it and see:

FileID                               FileContents

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

8247CE78-74DF-4BDE-A08D-9760AE0B1555

3C028D84-BA68-4E7B-8E87-B9889900D728 0x6D7920746573742066696C65

Since this hexadecimal content doesn't mean anything to use, and the fact that File is a type in SQL, we can query for some additional data such as path name:

select FileID, FileContents.PathName() as Path from Files

and get the following result:

FileID                               Path

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

8247CE78-74DF-4BDE-A08D-9760AE0B1555 NULL

3C028D84-BA68-4E7B-8E87-B9889900D728 \\GUYBUR-PC1\SQLEXPRESS\v1\ 
                                     \FileManagement\dbo\Files\FileContents\ 
                                     \3C028D84-BA68-4E7B-8E87-B9889900D728

Summary

In this post I showed how to create an SQL Server 2008 database with FILESTREAM support and add some text data into it. In the next post I will show how to write a .net client application that works with this database to add and change files.

Enjoy!