It Is Here!

Guy has uploaded the source code to now include the the various ways to create Pivot Collections. There are two different ways to build Pivot Collection one is to us Pivot Collection Attributes on existing business entity objects. Another way is to build a CXML DOM and then populate the DOM along with using a Pivot Table in the same manner as one would use a DataTable in ADO.Net.

DeepZoomTools when creating the images for deep zoom

Project Description
This project aims to make a very easy to use set of tools for creating collections for use with Pivot. This project is not made by Live Labs. Live labs makes Pauthor which is at http://pauthor.codeplex.com/

Examples

The two examples below use a class that drives the Facebook Friends Collection from my blog

Attribute Declaration and Reflections

public class FacebookUser
{
	[PivotItem(IsName = true)]
	public string Name { get; set; }
	
	[PivotItem(IsDescription = true)]
	public string Desc { get; set; }

	[PivotItem( IsImage = true)]
	public string Image { get; set; }

	[PivotItem(FacetDisplayName = "Books", FacetType = FacetTypes.String, IsFacet = true,IsCollection = true)]
	public List<string> Books{get;set;}

	[PivotItem(FacetDisplayName = "Gender", FacetType = FacetTypes.String, IsFacet = true)]
	public string Sex { get; set; }
}

    Console.WindowWidth = 120;
    // this is the xml dump of all your facebook friends created in the Pivot Collection Builder Demo
    // that demo can be found here http://www.anythingtheycando.com/blog/index.php/2009/12/03/facebook-friends-collection-builder/
    // that will allow you to download just download friends and then use the xml output with this app. 
    TextReader tr = new StreamReader("../../../FacebookFriends.xml");
    XmlSerializer s = new XmlSerializer(typeof(List<user>));
    var data = s.Deserialize(tr) as List<user>;
    
    
    PivotCollectionTools.BasicCollection.PivotCollection<FacebookUser> friends = new PivotCollection<FacebookUser>();
    // this turns on item image caching ie if two items link to the same image then it will only run it through the deep zoom composer once 
    friends.AllImagesUnique = false;
    // name to display for the collection (shows up in pivot
    friends.CollectionName = "Facebook Friends";
    
    friends.SupressActionChanged = false;
    // output each step to the console
    friends.ActionChanged += new EventHandler(friends_ActionChanged);

    foreach (user friend in data)
    {
        friends.Items.Add(new FacebookUser(friend));
    }
    // lets build the collection 
    friends.WriteCollectionToFileSystem("../../../TestAttributes.cxml");


CXML DOM

    TextReader tr = new StreamReader("FacebookFriends.xml");
    XmlSerializer s = new XmlSerializer(typeof(List<user>));
    var data = s.Deserialize(tr) as List<user>;

    var friends = new PivotXml() { Name = "Facebook Friends", SchemaVersion = 1.0m };

    friends.AddCategory(new FacetCategory("Activities", FacetDataType.String, true, true, true));
    friends.AddCategory(new FacetCategory("Books", FacetDataType.String, true, true, true));
    friends.AddCategory(new FacetCategory("Interests", FacetDataType.String, true, true, true));

    friends.AddItemList("image\\imag.xml");
    int counter = 0;
    foreach (user friend in data)
    {
        var newItem = new Item(counter.ToString()) { Name = friend.name };

        newItem.Facets.AddTextFacet("Activities", friend.activities.AsListOfValues());
        newItem.Facets.AddTextFacet("Books", friend.books.AsListOfValues());

        friends.ItemList[0].Items.Add(newItem);
        counter++;
    }
    friends.WriteXml("../../../TestObject.cxml");


    // Create a CXML DOM from the specified CXML file name.

    PivotXml xml = PivotXml.CreateFromXml(fileName);
    
    foreach (var facetCategory in xml.FacetCategories)
    {
        string name = facetCategory.Name;
        string isFilterVisable = facetCategory.IsFilterVisibleValue;
    }


    // Create a CXML DOM from the specified CXML file name.

    PivotXml xml = PivotXml.CreateFromXml(fileName);

    foreach (var item in xml.ItemList[0].Items)
    {
        string name = item.Name;
        decimal x = item.Facets[0].Number[0].Value;
    }


PivotTable, DataRows, Columns, Categories (Similar to ADO.Net)

    // Read a CXML into a PivotTable then enumerate thru the DataRows.

    PivotTableBuilder target = new PivotTableBuilder();
    PivotTable table = target.ReadFromXml(fileName);

    foreach (var dataRow in table.DataRows)
    {
        string tackles1 = dataRow.Cells["Tackles 1"].Value;
        string team= dataRow.Cells["Team"].Value;
    }

Last edited Jul 2, 2010 at 3:14 AM by y2k4life, version 15