Step-by-Step into the cloud

a blog of Dirk Eisenberg (>)
posts - 81, comments - 15, trackbacks - 17

My Links

News

Article Categories

Archives

Post Categories

Image Galleries

Blogs

Projects

So einfach gehts, items filtern mit WinFs

using System;
using System.Storage;
using System.Storage.Contacts;
using System.Collections.Generic;
using System.Text;

/*
 *  This sample application generates 3 new items of the type person.
 *  After that the application generates a list of all people which was born
 *  in the year 1979.
 */
namespace WinFSConsoleApplication1
{
 class Program
 {
  static void Main(string[] args)
  {
   /* instancing a winfs data object to get
    * access to the storage.
    */
   WinFSData winfsdata = new WinFSData();

   /* Every item is associated with a parent item (like a normal filesystem).
    * All items generated in this demo are child of the root item
    */
   System.Storage.Item itemRoot = winfsdata.GetRootItem();

   /* We need 3 persons as contact */
   System.Storage.Contacts.Person person1 = new System.Storage.Contacts.Person(itemRoot);
   person1.FullName = new System.Storage.Contacts.FullName("Dirk", "Eisenberg");
   person1.Gender = System.Storage.Contacts.Gender.Male;
   person1.BirthDate = new System.DateTime(1979, 07, 01);

   System.Storage.Contacts.Person person2 = new System.Storage.Contacts.Person(itemRoot);
   person2.FullName = new System.Storage.Contacts.FullName("Hans", "Müller");
   person2.Gender = System.Storage.Contacts.Gender.Male;
   person2.BirthDate = new System.DateTime(1980, 01, 01);

   System.Storage.Contacts.Person person3 = new System.Storage.Contacts.Person(itemRoot);
   person3.FullName = new System.Storage.Contacts.FullName("Maria", "Knot");
   person3.Gender = System.Storage.Contacts.Gender.Female;
   person3.BirthDate = new System.DateTime(1979, 07, 09);
   
   /* To do all changes persistent it necessary to call the SaveChanges method of the
    * WinFSData-Object
    */
   winfsdata.SaveChanges();

   /* This queries returns all persons stored in the root folder and subfolders */
   System.Storage.StorageSearcher all_persons = winfsdata.Items.FilterByType();

   foreach (Person p in all_persons)
   {
    Console.WriteLine("Person: {0} {1}", p.FullName.GivenName, p.FullName.Surname);
   }
   
   /* Now we want to filter for some attributes in our collection*/
   System.Storage.StorageSearcher all_female_persons = all_persons.Filter("BirthDate.Year = 1979");

   foreach(Person p in all_female_persons)
   {
    Console.WriteLine("Person: {0} {1}", p.FullName.GivenName, p.FullName.Surname);
   }

   /* We remove our created items from the storage */
   person1.Delete();
   person2.Delete();
   person3.Delete();
   winfsdata.SaveChanges();

  }
 }
}

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Wednesday, August 31, 2005 3:39 AM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: