Ejemplo n.º 1
0
        private void ParseFacet(XmlReader xmlReader, PivotItem item)
        {
            PivotCollection cachedData = this.CachedCollectionData;

            String         facetCategoryName = null;
            PivotFacetType facetType         = null;

            while (xmlReader.Read())
            {
                if (xmlReader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (xmlReader.LocalName == "Facet")
                {
                    facetCategoryName = xmlReader.GetAttribute("Name");
                    PivotFacetCategory facetCategory = cachedData.FacetCategories[facetCategoryName];
                    facetType = facetCategory.Type;
                }
                else if ((facetType != null) && (xmlReader.LocalName == facetType.ToString()))
                {
                    if (facetType == PivotFacetType.Link)
                    {
                        PivotLink link = new PivotLink(xmlReader.GetAttribute("Name"), xmlReader.GetAttribute("Href"));
                        item.AddFacetValues(facetCategoryName, link);
                    }
                    else
                    {
                        String value = xmlReader.GetAttribute("Value");
                        item.AddFacetValues(facetCategoryName, facetType.ParseValue(value));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected override IEnumerable <PivotItem> LoadItems()
        {
            XPathHelper document = null;

            using (WebClient webClient = new WebClient())
            {
                document = new XPathHelper(webClient.DownloadString(this.BasePath));
            }

            int index = 0;

            foreach (XPathHelper itemNode in document.FindNodes("//item"))
            {
                PivotItem item = new PivotItem(index.ToString(), this);

                String value = null;
                if (itemNode.TryFindString("title", out value))
                {
                    item.Name = value;
                }

                if (itemNode.TryFindString("description", out value))
                {
                    item.Description = value;
                }

                if (itemNode.TryFindString("link", out value))
                {
                    item.Href = value;
                }

                if (itemNode.TryFindString("author", out value))
                {
                    item.AddFacetValues("Author", value);
                }

                foreach (XPathHelper categoryNode in itemNode.FindNodes("category"))
                {
                    item.AddFacetValues("Category", categoryNode.FindString("."));
                }

                if (itemNode.TryFindString("pubDate", out value))
                {
                    DateTime dateValue = DateTime.Now;
                    if (DateTime.TryParse(value, out dateValue))
                    {
                        item.AddFacetValues("Date", dateValue);
                    }
                }

                yield return(item);

                index++;
            }
        }
Ejemplo n.º 3
0
        public void TestAddFacetValueExistingFacetCategory()
        {
            emptyCollection.FacetCategories.Add(new PivotFacetCategory("bravo", PivotFacetType.String));

            PivotItem item = new PivotItem("alpha", emptyCollection);
            item.AddFacetValues("bravo", "charlie");
            item.AddFacetValues("bravo", "delta");

            AssertEqual("charlie", item.GetAllFacetValues("bravo")[0]);
            AssertEqual("delta", item.GetAllFacetValues("bravo")[1]);
            AssertEqual(2, item.GetAllFacetValues("bravo").Count);
            AssertEqual(1, item.FacetCategories.Count());
        }
Ejemplo n.º 4
0
        public void TestAddFacetValueExistingFacetCategory()
        {
            emptyCollection.FacetCategories.Add(new PivotFacetCategory("bravo", PivotFacetType.String));

            PivotItem item = new PivotItem("alpha", emptyCollection);

            item.AddFacetValues("bravo", "charlie");
            item.AddFacetValues("bravo", "delta");

            AssertEqual("charlie", item.GetAllFacetValues("bravo")[0]);
            AssertEqual("delta", item.GetAllFacetValues("bravo")[1]);
            AssertEqual(2, item.GetAllFacetValues("bravo").Count);
            AssertEqual(1, item.FacetCategories.Count());
        }
Ejemplo n.º 5
0
        public void TestBrokenRelatedLinks()
        {
            PivotCollection collection = new PivotCollection();

            collection.FacetCategories.Add(new PivotFacetCategory("alpha", PivotFacetType.String));

            PivotItem item = new PivotItem("0", collection);

            item.AddFacetValues("alpha", "alpha");
            item.AddRelatedLink(new PivotLink(null, "http://pauthor.codeplex.com"));
            collection.Items.Add(item);

            item = new PivotItem("1", collection);
            item.AddFacetValues("alpha", "bravo");
            item.AddRelatedLink(new PivotLink("charlie", null));
            collection.Items.Add(item);

            PivotCollectionBuffer buffer     = new PivotCollectionBuffer(collection);
            String targetPath                = Path.Combine(WorkingDirectory, "sample.cxml");
            LocalCxmlCollectionTarget target = new LocalCxmlCollectionTarget(targetPath);

            target.Write(buffer);

            AssertCxmlSchemaValid(targetPath);

            CxmlCollectionSource targetAsSource = new CxmlCollectionSource(targetPath);

            buffer.Write(targetAsSource);

            AssertEqual("Related Link", buffer.Collection.Items[0].RelatedLinks.First().Title);
            AssertEqual("http://pauthor.codeplex.com", buffer.Collection.Items[0].RelatedLinks.First().Url);
            AssertEqual(0, buffer.Collection.Items[1].RelatedLinks.Count());
        }
Ejemplo n.º 6
0
        public void TestBrokenRelatedLinks()
        {
            PivotCollection collection = new PivotCollection();
            collection.FacetCategories.Add(new PivotFacetCategory("alpha", PivotFacetType.String));

            PivotItem item = new PivotItem("0", collection);
            item.AddFacetValues("alpha", "alpha");
            item.AddRelatedLink(new PivotLink(null, "http://pauthor.codeplex.com"));
            collection.Items.Add(item);

            item = new PivotItem("1", collection);
            item.AddFacetValues("alpha", "bravo");
            item.AddRelatedLink(new PivotLink("charlie", null));
            collection.Items.Add(item);

            PivotCollectionBuffer buffer = new PivotCollectionBuffer(collection);
            String targetPath = Path.Combine(WorkingDirectory, "sample.cxml");
            LocalCxmlCollectionTarget target = new LocalCxmlCollectionTarget(targetPath);
            target.Write(buffer);

            AssertCxmlSchemaValid(targetPath);

            CxmlCollectionSource targetAsSource = new CxmlCollectionSource(targetPath);
            buffer.Write(targetAsSource);

            AssertEqual("Related Link", buffer.Collection.Items[0].RelatedLinks.First().Title);
            AssertEqual("http://pauthor.codeplex.com", buffer.Collection.Items[0].RelatedLinks.First().Url);
            AssertEqual(0, buffer.Collection.Items[1].RelatedLinks.Count());
        }
Ejemplo n.º 7
0
        public void TestAddFacetValueExistingFacetCategoryAlreadyInCollection()
        {
            PivotItem item = sampleCollection1.Items[1];

            item.AddFacetValues("Subject", "New Car");

            AssertEqual("Vehicle", item.GetAllFacetValues("Subject")[0]);
            AssertEqual("New Car", item.GetAllFacetValues("Subject")[1]);
            AssertEqual(2, item.GetAllFacetValues("Subject").Count);
            AssertEqual(2, item.FacetCategories.Count);
        }
Ejemplo n.º 8
0
 public void TestAddFacetValueNewFacetCategoryAlreadyInCollectionInferFacetCategoriesIncompatibleType()
 {
     try
     {
         PivotItem item = collection.Items[1];
         item.AddFacetValues("Letters", "bravo");
         Fail("Expected an exception");
     }
     catch (ArgumentException e)
     {
         AssertEqual("Item Id 1 has an incompatible value (type: String) for facet category Letters", e.Message);
     }
 }
Ejemplo n.º 9
0
        public void TestAddFacetValueNewFacetCategoryAlreadyInCollectionInferFacetCategories()
        {
            collection.InferFacetCategories = true;
            PivotItem item = collection.Items[1];

            item.AddFacetValues("alpha", "bravo");

            AssertEqual("bravo", item.GetFacetValue("alpha"));
            AssertEqual(1, item.GetAllFacetValues("alpha").Count);
            AssertEqual(3, item.FacetCategories.Count);

            AssertEqual("alpha", collection.FacetCategories[2].Name);
            AssertEqual(PivotFacetType.String, collection.FacetCategories[2].Type);
            AssertEqual(3, collection.FacetCategories.Count);
        }
Ejemplo n.º 10
0
        private void ParseFacet(XmlReader xmlReader, PivotItem item)
        {
            PivotCollection cachedData = this.CachedCollectionData;

            String facetCategoryName = null;
            PivotFacetType facetType = null;
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType != XmlNodeType.Element) continue;

                if (xmlReader.LocalName == "Facet")
                {
                    facetCategoryName = xmlReader.GetAttribute("Name");
                    PivotFacetCategory facetCategory = cachedData.FacetCategories[facetCategoryName];
                    facetType = facetCategory.Type;
                }
                else if ((facetType != null) && (xmlReader.LocalName == facetType.ToString()))
                {
                    if (facetType == PivotFacetType.Link)
                    {
                        PivotLink link = new PivotLink(xmlReader.GetAttribute("Name"), xmlReader.GetAttribute("Href"));
                        item.AddFacetValues(facetCategoryName, link);
                    }
                    else
                    {
                        String value = xmlReader.GetAttribute("Value");
                        item.AddFacetValues(facetCategoryName, facetType.ParseValue(value));
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private PivotItem ReadItem(OleDbDataReader dataReader, int rowId)
        {
            PivotItem item = new PivotItem(rowId.ToString(), this);

            for (int column = 0; column < dataReader.FieldCount; column++)
            {
                if (dataReader.IsDBNull(column)) continue;

                String columnName = dataReader.GetName(column).ToLowerInvariant();
                String value = dataReader.GetValue(column).ToString();
                if (String.IsNullOrEmpty(value)) continue;

                if (columnName == OleDbSchemaConstants.Item.Name)
                {
                    item.Name = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.Image)
                {
                    String imagePath = UriUtility.ExpandRelativeUri(this.BasePath, value);
                    item.Image = new PivotImage(imagePath);
                }
                else if (columnName == OleDbSchemaConstants.Item.Description)
                {
                    item.Description = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.Href)
                {
                    item.Href = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.RelatedLinks)
                {
                    StringReader valueReader = new StringReader(value);
                    String singleValue = null;
                    while ((singleValue = valueReader.ReadLine()) != null)
                    {
                        String[] parts = singleValue.Split(
                            new String[] { OleDbSchemaConstants.LinkPartDelimiter }, StringSplitOptions.None);
                        if (parts.Length > 0)
                        {
                            String name = null, url = null;
                            if (parts.Length == 1)
                            {
                                url = parts[0];
                            }
                            else if (parts.Length >= 2)
                            {
                                name = parts[0];
                                url = parts[1];
                            }
                            item.AddRelatedLink(new PivotLink(name, url));
                        }
                    }
                }
                else
                {
                    PivotFacetCategory facetCategory = null;
                    foreach (PivotFacetCategory currentFacetCategory in m_facetCategoryMap.Values)
                    {
                        if (columnName == currentFacetCategory.Name.Replace('.', '#').ToLowerInvariant())
                        {
                            facetCategory = currentFacetCategory;
                            break;
                        }
                    }

                    if (facetCategory != null)
                    {
                        item.AddFacetValues(facetCategory.Name, this.SplitJoinedStrings(value).ToArray());
                    }
                }
            }

            return item;
        }
Ejemplo n.º 12
0
        private PivotItem ReadItem(OleDbDataReader dataReader, int rowId)
        {
            PivotItem item = new PivotItem(rowId.ToString(), this);

            for (int column = 0; column < dataReader.FieldCount; column++)
            {
                if (dataReader.IsDBNull(column))
                {
                    continue;
                }

                String columnName = dataReader.GetName(column).ToLowerInvariant();
                String value      = dataReader.GetValue(column).ToString();
                if (String.IsNullOrEmpty(value))
                {
                    continue;
                }

                if (columnName == OleDbSchemaConstants.Item.Name)
                {
                    item.Name = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.Image)
                {
                    String imagePath = UriUtility.ExpandRelativeUri(this.BasePath, value);
                    item.Image = new PivotImage(imagePath);
                }
                else if (columnName == OleDbSchemaConstants.Item.Description)
                {
                    item.Description = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.Href)
                {
                    item.Href = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.RelatedLinks)
                {
                    StringReader valueReader = new StringReader(value);
                    String       singleValue = null;
                    while ((singleValue = valueReader.ReadLine()) != null)
                    {
                        String[] parts = singleValue.Split(
                            new String[] { OleDbSchemaConstants.LinkPartDelimiter }, StringSplitOptions.None);
                        if (parts.Length > 0)
                        {
                            String name = null, url = null;
                            if (parts.Length == 1)
                            {
                                url = parts[0];
                            }
                            else if (parts.Length >= 2)
                            {
                                name = parts[0];
                                url  = parts[1];
                            }
                            item.AddRelatedLink(new PivotLink(name, url));
                        }
                    }
                }
                else
                {
                    PivotFacetCategory facetCategory = null;
                    foreach (PivotFacetCategory currentFacetCategory in m_facetCategoryMap.Values)
                    {
                        if (columnName == currentFacetCategory.Name.Replace('.', '#').ToLowerInvariant())
                        {
                            facetCategory = currentFacetCategory;
                            break;
                        }
                    }

                    if (facetCategory != null)
                    {
                        item.AddFacetValues(facetCategory.Name, this.SplitJoinedStrings(value).ToArray());
                    }
                }
            }

            return(item);
        }
Ejemplo n.º 13
0
        protected override IEnumerable<PivotItem> LoadItems()
        {
            XPathHelper document = null;
            using (WebClient webClient = new WebClient())
            {
                document = new XPathHelper(webClient.DownloadString(this.BasePath));
            }

            int index = 0;
            foreach (XPathHelper itemNode in document.FindNodes("//item"))
            {
                PivotItem item = new PivotItem(index.ToString(), this);

                String value = null;
                if (itemNode.TryFindString("title", out value))
                {
                    item.Name = value;
                }

                if (itemNode.TryFindString("description", out value))
                {
                    item.Description = value;
                }

                if (itemNode.TryFindString("link", out value))
                {
                    item.Href = value;
                }

                if (itemNode.TryFindString("author", out value))
                {
                    item.AddFacetValues("Author", value);
                }

                foreach (XPathHelper categoryNode in itemNode.FindNodes("category"))
                {
                    item.AddFacetValues("Category", categoryNode.FindString("."));
                }

                if (itemNode.TryFindString("pubDate", out value))
                {
                    DateTime dateValue = DateTime.Now;
                    if (DateTime.TryParse(value, out dateValue))
                    {
                        item.AddFacetValues("Date", dateValue);
                    }
                }

                yield return item;
                index++;
            }
        }