public void TestWordWheelNotVisibleWhenShouldNotBe() { try { PivotFacetCategory category = new PivotFacetCategory("bravo", PivotFacetType.Number); category.IsWordWheelVisible = true; Fail("Expected an exception"); } catch (ArgumentException e) { AssertEqual("A facet can only be word wheel visible if it is a Link, LongString, or String facet " + "type (currently: Number)", e.Message); } try { PivotFacetCategory category = new PivotFacetCategory("charlie", PivotFacetType.DateTime); category.IsWordWheelVisible = true; Fail("Expected an exception"); } catch (ArgumentException e) { AssertEqual("A facet can only be word wheel visible if it is a Link, LongString, or String facet " + "type (currently: DateTime)", e.Message); } }
public void TestFilterNotVisbleWhenShouldNotBe() { try { PivotFacetCategory category = new PivotFacetCategory("bravo", PivotFacetType.LongString); category.IsFilterVisible = true; Fail("Expected an exception"); } catch (ArgumentException e) { AssertEqual("A facet can only be filter visible if it is a DateTime, Number or String facet type " + "(currently: LongString)", e.Message); } try { PivotFacetCategory category = new PivotFacetCategory("charlie", PivotFacetType.Link); category.IsFilterVisible = true; Fail("Expected an exception"); } catch (ArgumentException e) { AssertEqual("A facet can only be filter visible if it is a DateTime, Number or String facet type " + "(currently: Link)", e.Message); } }
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)); } } } }
private void DeriveFacetCategoriesFromItems(OleDbConnection connection) { String itemsCommandString = this.ItemsDataQuery; if (itemsCommandString == null) { return; } OleDbCommand command = new OleDbCommand(itemsCommandString, connection); OleDbDataReader dataReader = command.ExecuteReader(); for (int column = 0; column < dataReader.FieldCount; column++) { String name = dataReader.GetName(column).ToLowerInvariant(); if (OleDbSchemaConstants.Item.AllColumns.Contains(name)) { continue; } PivotFacetCategory facetCategory = new PivotFacetCategory(name, PivotFacetType.String); this.CachedCollectionData.FacetCategories.Add(facetCategory); m_facetCategoryMap.Add(facetCategory.Name, facetCategory); } }
private void WriteFacetCategory(XmlWriter xmlWriter, PivotFacetCategory facetCategory) { xmlWriter.WriteStartElement("FacetCategory"); xmlWriter.WriteAttributeString("Name", facetCategory.Name); xmlWriter.WriteAttributeString("Type", facetCategory.Type.ToString()); if (facetCategory.Format != null) { xmlWriter.WriteAttributeString("Format", facetCategory.Format); } xmlWriter.WriteAttributeString("IsFilterVisible", PivotNamespace, facetCategory.IsFilterVisible.ToString().ToLowerInvariant()); xmlWriter.WriteAttributeString("IsMetaDataVisible", PivotNamespace, facetCategory.IsMetaDataVisible.ToString().ToLowerInvariant()); xmlWriter.WriteAttributeString("IsWordWheelVisible", PivotNamespace, facetCategory.IsWordWheelVisible.ToString().ToLowerInvariant()); if (facetCategory.SortOrder != null) { xmlWriter.WriteStartElement("Extension"); xmlWriter.WriteStartElement("SortOrder", PivotNamespace); xmlWriter.WriteAttributeString("Name", facetCategory.SortOrder.Name); foreach (String sortValue in facetCategory.SortOrder.Values) { xmlWriter.WriteStartElement("SortValue", PivotNamespace); xmlWriter.WriteAttributeString("Value", sortValue); xmlWriter.WriteEndElement(); // SortValue } xmlWriter.WriteEndElement(); // SortOrder xmlWriter.WriteEndElement(); // Extension } xmlWriter.WriteEndElement(); // FacetCategory }
protected override void LoadHeaderData() { PivotCollection cachedData = this.CachedCollectionData; using (FileStream fileStream = new FileStream(this.BasePath, FileMode.Open, FileAccess.Read)) { using (XmlReader xmlReader = XmlReader.Create(fileStream)) { while (xmlReader.Read()) { if (xmlReader.NodeType != XmlNodeType.Element) { continue; } if (xmlReader.LocalName == "Collection") { cachedData.Name = xmlReader.GetAttribute("Name"); cachedData.AdditionalSearchText = xmlReader.GetAttribute("AdditionalSearchText"); cachedData.SchemaVersion = xmlReader.GetAttribute("SchemaVersion"); String value = null; if ((value = xmlReader.GetAttribute("Icon", PivotNamespace)) != null) { cachedData.Icon = new PivotImage(new Uri(this.BasePathAsUri, value).ToString()); } if ((value = xmlReader.GetAttribute("BrandImage", PivotNamespace)) != null) { cachedData.BrandImage = new PivotImage(new Uri(this.BasePathAsUri, value).ToString()); } } else if (xmlReader.LocalName == "Items") { String imageBase = xmlReader.GetAttribute("ImgBase"); if (imageBase != null) { cachedData.ImageBase = new Uri(this.BasePathAsUri, imageBase).ToString(); xmlReader.Skip(); } } else if (xmlReader.LocalName == "Copyright") { cachedData.Copyright = new PivotLink(xmlReader.GetAttribute("Name"), xmlReader.GetAttribute("Href")); } else if (xmlReader.LocalName == "FacetCategory") { PivotFacetCategory facetCategory = this.ParseFacetCategory(xmlReader.ReadSubtree()); cachedData.FacetCategories.Add(facetCategory); } } } } }
public void TestWordWheelVisibleWhenShouldBe() { PivotFacetCategory category = new PivotFacetCategory("alpha", PivotFacetType.String); category.IsWordWheelVisible = true; category = new PivotFacetCategory("bravo", PivotFacetType.LongString); category.IsWordWheelVisible = true; category = new PivotFacetCategory("charlie", PivotFacetType.Link); category.IsWordWheelVisible = true; }
public void TestFilterVisibleWhenShouldBe() { PivotFacetCategory category = new PivotFacetCategory("alpha", PivotFacetType.String); category.IsFilterVisible = true; category = new PivotFacetCategory("bravo", PivotFacetType.Number); category.IsFilterVisible = true; category = new PivotFacetCategory("charlie", PivotFacetType.DateTime); category.IsFilterVisible = true; }
/// <summary> /// Creates a copy of this image creator's <see cref="HtmlTemplate"/> by replacing all the tags with appropriate /// values based upon a given image. /// </summary> /// <param name="item">the item containing the specific data to use</param> /// <returns>an HTML document with the given item's data</returns> public String InstantiateTemplate(PivotItem item) { String text = m_htmlTemplate; text = this.Replace(text, "{id}", item.Id); text = this.Replace(text, "{name}", item.Name ?? ""); if (item.Image != null) { text = this.Replace(text, "{image}", item.Image.SourcePath ?? ""); } text = this.Replace(text, "{href}", item.Href ?? ""); text = this.Replace(text, "{description}", item.Description ?? ""); foreach (String facetCategoryName in item.FacetCategories) { String replaceStringBase = "{" + facetCategoryName; String textValue = item.GetFacetValueAsString(facetCategoryName); text = this.Replace(text, replaceStringBase + "}", textValue); text = this.PerformJoinInstantiation(facetCategoryName, item, text); List <IComparable> values = new List <IComparable>(item.GetAllFacetValues(facetCategoryName)); int index = 0; while (true) { String replaceString = replaceStringBase + ":" + index + "}"; if (text.IndexOf(replaceString, StringComparison.InvariantCultureIgnoreCase) == -1) { break; } textValue = ""; if (index < values.Count) { PivotFacetCategory facetCategory = item.CollectionDefinition.FacetCategories[facetCategoryName]; if (facetCategory.Format != null) { textValue = String.Format("{0:" + facetCategory.Format + "}", values[index]); } else { textValue = facetCategory.Type.FormatValue(values[index]); } } text = this.Replace(text, replaceString, textValue); index++; } } return(text); }
private String GenerateSortValuesString(PivotFacetCategory facetCategory) { if (facetCategory.SortOrder == null) { return(null); } String[] allValues = new String[facetCategory.SortOrder.Values.Count()]; int index = 0; foreach (String value in facetCategory.SortOrder.Values) { allValues[index++] = value; } String facetValueString = String.Join(OleDbSchemaConstants.FacetValueDelimiter, allValues); return(facetValueString); }
private void WriteFacet(XmlWriter xmlWriter, String facetCategoryName, PivotItem item) { PivotFacetCategory facetCategory = item.CollectionDefinition.FacetCategories[facetCategoryName]; xmlWriter.WriteAttributeString("Name", facetCategoryName); foreach (IComparable value in item.GetAllFacetValues(facetCategoryName)) { if (facetCategory.Type == PivotFacetType.Link) { PivotLink linkValue = (PivotLink)value; xmlWriter.WriteStartElement(facetCategory.Type.ToString()); if (linkValue.Title != null) { xmlWriter.WriteAttributeString("Name", linkValue.Title); } if (linkValue.Url != null) { xmlWriter.WriteAttributeString("Href", linkValue.Url); } xmlWriter.WriteEndElement(); // FacetType } else if (facetCategory.Type == PivotFacetType.DateTime) { xmlWriter.WriteStartElement(facetCategory.Type.ToString()); xmlWriter.WriteAttributeString("Value", ((DateTime)value).ToString("s")); xmlWriter.WriteEndElement(); // FacetType } else if (facetCategory.Type == PivotFacetType.Number) { xmlWriter.WriteStartElement(facetCategory.Type.ToString()); xmlWriter.WriteAttributeString("Value", value.ToString()); xmlWriter.WriteEndElement(); // FacetType } else { xmlWriter.WriteStartElement(facetCategory.Type.ToString()); xmlWriter.WriteAttributeString("Value", item.ConvertFacetValueToString(facetCategoryName, value)); xmlWriter.WriteEndElement(); // FacetType } } }
private PivotFacetCategory ParseFacetCategory(XmlReader xmlReader) { PivotFacetCategory facetCategory = null; while (xmlReader.Read()) { if (xmlReader.NodeType != XmlNodeType.Element) { continue; } if (xmlReader.LocalName == "FacetCategory") { String name = xmlReader.GetAttribute("Name"); String type = xmlReader.GetAttribute("Type"); facetCategory = new PivotFacetCategory(name, PivotFacetType.Parse(type)); String value = null; if ((value = xmlReader.GetAttribute("Format")) != null) { facetCategory.Format = value; } if ((value = xmlReader.GetAttribute("IsFilterVisible", PivotNamespace)) != null) { facetCategory.IsFilterVisible = Boolean.Parse(value); } if ((value = xmlReader.GetAttribute("IsMetaDataVisible", PivotNamespace)) != null) { facetCategory.IsMetaDataVisible = Boolean.Parse(value); } if ((value = xmlReader.GetAttribute("IsWordWheelVisible", PivotNamespace)) != null) { facetCategory.IsWordWheelVisible = Boolean.Parse(value); } } else if (xmlReader.LocalName == "SortOrder") { if (facetCategory == null) { continue; } String name = xmlReader.GetAttribute("Name"); facetCategory.SortOrder = new PivotFacetSortOrder(name); } else if (xmlReader.LocalName == "SortValue") { if (facetCategory == null) { continue; } if (facetCategory.SortOrder == null) { continue; } facetCategory.SortOrder.AddValue(xmlReader.GetAttribute("Value")); } } return(facetCategory); }
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); }
private void LoadFacetCategoriesData(OleDbConnection connection) { String facetCategoriesDataQuery = this.FacetCategoriesDataQuery; if (facetCategoriesDataQuery == null) { return; } OleDbCommand command = new OleDbCommand(facetCategoriesDataQuery, connection); OleDbDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { PivotFacetCategory facetCategory = this.CreateFacetCategory(dataReader); 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 (columnName == OleDbSchemaConstants.FacetCategory.Format) { facetCategory.Format = value; } else if (columnName == OleDbSchemaConstants.FacetCategory.IsFilterVisible) { facetCategory.IsFilterVisible = Boolean.Parse(value.ToLowerInvariant()); } else if (columnName == OleDbSchemaConstants.FacetCategory.IsMetadataVisible) { facetCategory.IsMetaDataVisible = Boolean.Parse(value.ToLowerInvariant()); } else if (columnName == OleDbSchemaConstants.FacetCategory.IsWordWheelVisible) { facetCategory.IsWordWheelVisible = Boolean.Parse(value.ToLowerInvariant()); } else if (columnName == OleDbSchemaConstants.FacetCategory.SortName) { PivotFacetSortOrder sortOrder = new PivotFacetSortOrder(value); if (facetCategory.SortOrder != null) { sortOrder.AddAllValues(facetCategory.SortOrder.Values); } facetCategory.SortOrder = sortOrder; } else if (columnName == OleDbSchemaConstants.FacetCategory.SortValues) { if (facetCategory.SortOrder == null) { facetCategory.SortOrder = new PivotFacetSortOrder(facetCategory.Name); } facetCategory.SortOrder.AddAllValues(this.SplitJoinedStrings(value)); } } this.CachedCollectionData.FacetCategories.Add(facetCategory); m_facetCategoryMap.Add(facetCategory.Name.ToLowerInvariant(), facetCategory); } }