October 25, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

WinFS Basics: Working with a Data Store

  • January 25, 2006
  • By Sahil Malik
  • Send Email »
  • More Articles »

WinFS is probably one of the most exciting offerings in the Microsoft pipeline. The next step in information storage on the Windows platform, WinFS is an active storage platform based on a data model that is an organizational framework of WinFS Types. Some of the out-of-the-box types in WinFS are Document, Contact, Picture, VideoRecord, etc. You can also extend the built-in type system by creating your own types, which makes the type model extensible. And because it enables you to represent your data as objects, you can have synchronization and rules capabilities built right into the framework that supports them.

Conceptually, WinFS is structured very much like the world around us. When I think of my head, for example, I see an information storage and retrieval machine with various objects in it: people, books, cities—distinct entities that work independently and yet are somehow loosely related to each other. I also see various behaviors and interrelationships between these various objects. As another example, consider the persons at Microsoft who author the fantastic WinFS blog in Redmond. This example contains three distinct EntityTypes, "Persons", "Blog", and "City". Let's examine two of these more closely:

  • "Persons" theoretically are "Employees of Microsoft", which is an ordered, unsorted array of "Employee of Microsoft", which inherits from "Intelligent Person", which itself inherits from "Human Being".
  • "City" could have a latitude, longitude, population—it even has a City name, and it's related to yet another EntityType called "State" (Redmond is in Washington State).

So, if all this information were represented in a computing environment, you'd typically represent them in objects or, more specifically, semistructured hierarchical object structures. That's a mouthful, but conceptually the world is full of semistructured hierarchical objects. (My head is full of them, in fact.) The problem is historically we have tried to store all this information in file systems, which let you store only flat files with almost no relationships between them. Clearly that needs to evolve and WinFS is part of that growth.

No single article can cover all WinFS that offers, but this article explains how to work with a main WinFS feature: the data store. It then demonstrates the basic operations that you can perform on a WinFS data store.

A WinFS Data Store

A traditional file system stores information in a directory structure. In addition to being a file system, WinFS offers the capability of storing your various items (object instances) in item data stores, which WinFS stores in a relational backend. Giving data an object or item representation instills behavior in your flat files.

At the same time, because WinFS also comes with a new file system driver (RsFxDrv.sys), a WinFS item is also made available as a file-backed item. This allows you to access a WinFS item both as a file stream through the Win32 API or as an item via the WinFS API. The two representations of the item—file based and item based—are kept in synch using the WinFS Infrastructure. The synch process consists of two distinct steps:

  1. Extracting data from a file and populating an item (also known as promotion)
  2. Persisting itemized data to streams of the underlying file (also known as demotion)

This allows WinFS to be backwards compatible with both NTFS- and FAT-based file systems. This means the user never knows whether he or she is working on WinFS or just NTFS, because the change is seamless. You get the extra capabilities of the new file system while being fully backwards compatible.

Organizing Your Data

Historically, file and folder structures give you a rather strict and limited method of organizing your data; a file is contained within a folder. This model doesn't explain the richness of your data. For example, the ring that you just bought for your fiancée could be sitting under \Finance\Bills\CreditCard and also under \Family\UndyingLove. In addition to being able to store your data in a much richer logical structure, you can also assign keywords to your objects in WinFS as follows:
ItemKeywords keywords = new ItemKeywords();
keywords.Keywords.Add(new Keyword("Diamonds"));
ringDocument.Extensions.Add(keywords);

Once you have your data properly tagged, you can search it as follows:

StorageSearcher<Document> docs = 
wd.Items.FilterByType<Document>().Filter(
"Exists(Extensions.FilterByType(@0).Filter(Exists(Keywords.Filter(Value==@1))))",
typeof(ItemKeywords), "Diamonds"); foreach (Document doc in docs) { Console.WriteLine("Doc's Title = {0}", doc.Title); }

Not only can you add keywords to existing documents, but a given document may also have the capability of exposing such metadata about itself, making itself easily searchable. For instance, if you author a Microsoft Word document, it is automatically promoted to an instance of System.Storage.Documents.Document, which then automatically populates its various relevant properties such as title, subtitle, author, etc.

So what is the big deal? The big deal is that if you were to search for "Diamonds", you would not only get the ring you bought in one of the results, you would also get the word document that stores the history of the transaction, the PDF download that holds your credit card transaction information, all emails between you and the jeweler, and all other such relevant information. Also, now you could easily establish further relationships between various items in your WinFS data stores. Also, you can turn these items into active data by associating them with rules.





Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel