/// <summary>Constructor, given a category as a string from the URI.</summary> public QueryCategory(string strCategory, QueryCategoryOperator op) { Tracing.TraceMsg("Depersisting category from: " + strCategory); this.categoryOperator = op; strCategory = FeedQuery.CleanPart(strCategory); // let's parse the string if (strCategory[0] == '-') { // negator this.isExcluded = true; // remove him strCategory = strCategory.Substring(1, strCategory.Length - 1); } // let's extract the scheme if there is one... int iStart = strCategory.IndexOf('{'); int iEnd = strCategory.IndexOf('}'); AtomUri scheme = null; if (iStart != -1 && iEnd != -1) { iEnd++; iStart++; scheme = new AtomUri(strCategory.Substring(iStart, iEnd - iStart - 1)); // the rest is then strCategory = strCategory.Substring(iEnd, strCategory.Length - iEnd); } Tracing.TraceMsg("Category found: " + strCategory + " - scheme: " + scheme); this.category = new AtomCategory(strCategory, scheme); }
////////////////////////////////////////////////////////////////////// /// <summary>Constructor, given a category as a string from the URI.</summary> ////////////////////////////////////////////////////////////////////// public QueryCategory(string strCategory, QueryCategoryOperator op) { Tracing.TraceMsg("Depersisting category from: " + strCategory); this.categoryOperator = op; strCategory = FeedQuery.CleanPart(strCategory); // let's parse the string if (strCategory[0] == '-') { // negator this.isExcluded = true; // remove him strCategory = strCategory.Substring(1, strCategory.Length - 1); } // let's extract the scheme if there is one... int iStart = strCategory.IndexOf('{'); int iEnd = strCategory.IndexOf('}'); AtomUri scheme = null; if (iStart != -1 && iEnd != -1) { // iEnd++; iStart++; scheme = new AtomUri(strCategory.Substring(iStart, iEnd - iStart - 1)); // the rest is then strCategory = strCategory.Substring(iEnd, strCategory.Length - iEnd); } Tracing.TraceMsg("Category found: " + strCategory + " - scheme: " + scheme); this.category = new AtomCategory(strCategory, scheme); }
public void UriTest() { AtomBaseLink target = CreateAtomBaseLink(); AtomUri expected = new AtomUri("http://www.test.com/"); AtomUri actual; target.Uri = expected; actual = target.Uri; Assert.AreEqual(expected, actual); }
///////////////////////////////////////////////////////////////////////////// #endregion #region overloaded for property changes, xml:base ////////////////////////////////////////////////////////////////////// /// <summary>just go down the child collections</summary> /// <param name="uriBase"> as currently calculated</param> ////////////////////////////////////////////////////////////////////// internal override void BaseUriChanged(AtomUri uriBase) { base.BaseUriChanged(uriBase); foreach (AtomPerson person in this.Authors) { person.BaseUriChanged(uriBase); } // saving Contributors foreach (AtomPerson person in this.Contributors) { person.BaseUriChanged(uriBase); } // saving Categories foreach (AtomCategory category in this.Categories) { category.BaseUriChanged(uriBase); } // saving the generator if (this.Generator != null) { this.Generator.BaseUriChanged(uriBase); } // save the icon if (this.Icon != null) { this.Icon.BaseUriChanged(uriBase); } // save the logo if (this.Logo != null) { this.Logo.BaseUriChanged(uriBase); } // save the ID if (this.Id != null) { this.Id.BaseUriChanged(uriBase); } // save the Links foreach (AtomLink link in this.Links) { link.BaseUriChanged(uriBase); } if (this.Rights != null) { this.Rights.BaseUriChanged(uriBase); } if (this.Subtitle != null) { this.Subtitle.BaseUriChanged(uriBase); } if (this.Title != null) { this.Title.BaseUriChanged(uriBase); } }
/// <summary>just go down the child collections</summary> /// <param name="uriBase"> as currently calculated</param> internal override void BaseUriChanged(AtomUri uriBase) { base.BaseUriChanged(uriBase); // now pass it to the properties. uriBase = new AtomUri(Utilities.CalculateUri(this.Base, uriBase, null)); if (this.Title != null) { this.Title.BaseUriChanged(uriBase); } if (this.Id != null) { this.Id.BaseUriChanged(uriBase); } foreach (AtomLink link in this.Links) { link.BaseUriChanged(uriBase); } foreach (AtomPerson person in this.Authors) { person.BaseUriChanged(uriBase); } foreach (AtomPerson person in this.Contributors) { person.BaseUriChanged(uriBase); } foreach (AtomCategory category in this.Categories) { category.BaseUriChanged(uriBase); } if (this.Rights != null) { this.Rights.BaseUriChanged(uriBase); } if (this.Summary != null) { this.Summary.BaseUriChanged(uriBase); } if (this.Content != null) { this.Content.BaseUriChanged(uriBase); } if (this.Source != null) { this.Source.BaseUriChanged(uriBase); } }
public void ContentTest() { Uri uri = new Uri("http://www.test.com/"); AtomUri target = new AtomUri(uri); // TODO: Initialize to an appropriate value string expected = "http://www.test.com/"; string actual; target.Content = expected; actual = target.Content; Assert.AreEqual(expected, actual); }
/// <summary>comparison method similar to strings</summary> public static int Compare(AtomUri oneAtomUri, AtomUri anotherAtomUri) { if (oneAtomUri != null) { return(oneAtomUri.CompareTo(anotherAtomUri)); } else if (anotherAtomUri == null) { return(0); } return(-1); }
/// <summary>comparison method similar to strings</summary> public static int Compare(AtomUri a, AtomUri b) { if (a != null) { return a.CompareTo(b); } else if (b == null) { return 0; } return -1; }
/// <summary>comparison method similar to strings</summary> public static int Compare(AtomUri oneAtomUri, AtomUri anotherAtomUri) { if (oneAtomUri != null) { return oneAtomUri.CompareTo(anotherAtomUri); } else if (anotherAtomUri == null) { return 0; } return -1; }
///////////////////////////////////////////////////////////////////////////// #region overloaded for property changes, xml:base ////////////////////////////////////////////////////////////////////// /// <summary>just go down the child collections</summary> /// <param name="uriBase"> as currently calculated</param> ////////////////////////////////////////////////////////////////////// internal override void BaseUriChanged(AtomUri uriBase) { base.BaseUriChanged(uriBase); // now walk over the entries and forward... uriBase = new AtomUri(Utilities.CalculateUri(this.Base, uriBase, null)); foreach (AtomEntry entry in this.Entries) { entry.BaseUriChanged(uriBase); } }
/// <summary>helper method to encapsulate a string encoding, uses HTML encoding now</summary> /// <param name="writer">the xml writer to write to</param> /// <param name="content">the string to encode</param> static protected void WriteEncodedString(XmlWriter writer, AtomUri content) { if (writer == null) { throw new System.ArgumentNullException("writer", "No valid xmlWriter"); } if (Utilities.IsPersistable(content)) { string encoded = Utilities.EncodeString(content.ToString()); writer.WriteString(encoded); } }
////////////////////////////////////////////////////////////////////// /// <summary>public static string CalculateUri(string base, string inheritedBase, string local)</summary> /// <param name="localBase">the baseUri from xml:base </param> /// <param name="inheritedBase">the pushed down baseUri from an outer element</param> /// <param name="localUri">the Uri value</param> /// <returns>the absolute Uri to use... </returns> ////////////////////////////////////////////////////////////////////// internal static string CalculateUri(AtomUri localBase, AtomUri inheritedBase, string localUri) { try { Uri uriBase = null; Uri uriSuperBase = null; Uri uriComplete = null; if (inheritedBase != null && inheritedBase.ToString() != null) { uriSuperBase = new Uri(inheritedBase.ToString()); } if (localBase != null && localBase.ToString() != null) { if (uriSuperBase != null) { uriBase = new Uri(uriSuperBase, localBase.ToString()); } else { uriBase = new Uri(localBase.ToString()); } } else { // if no local xml:base, take the passed down one uriBase = uriSuperBase; } if (localUri != null) { if (uriBase != null) { uriComplete = new Uri(uriBase, localUri.ToString()); } else { uriComplete = new Uri(localUri.ToString()); } } else { uriComplete = uriBase; } return(uriComplete != null ? uriComplete.AbsoluteUri : null); } catch (System.UriFormatException) { return("Unsupported URI format"); } }
/// <summary> /// finds a category with a given term and scheme /// </summary> /// <param name="term"></param> /// <param name="scheme"></param> /// <returns>AtomCategory or NULL</returns> public AtomCategory Find(string term, AtomUri scheme) { foreach (AtomCategory category in List) { if (scheme == null || scheme == category.Scheme) { if (term == category.Term) { return(category); } } } return(null); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>This starts the calculation, to push down the base /// URI changes.</summary> /// <param name="uriValue">the baseuri calculated so far</param> ////////////////////////////////////////////////////////////////////// internal virtual void BaseUriChanged(AtomUri uriValue) { // if this is ever getting called explicitly (parsing), we turn on recalc this.fAllowRecalc = true; this.uriImpliedBase = uriValue; }
/// <summary>Little helper that checks if a string is XML persistable</summary> public static bool IsPersistable(AtomUri uriString) { return uriString == null ? false : Utilities.IsPersistable(uriString.ToString()); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>Category constructor</summary> /// <param name="term">the term of the category</param> /// <param name="scheme">the scheme of the category</param> ////////////////////////////////////////////////////////////////////// public AtomCategory(string term, AtomUri scheme) { this.Term = term; this.Scheme = scheme; }
/// <summary>This starts the calculation, to push down the base /// URI changes.</summary> /// <param name="uriValue">the baseuri calculated so far</param> internal virtual void BaseUriChanged(AtomUri uriValue) { // if this is ever getting called explicitly (parsing), we turn on recalc this.fAllowRecalc = true; this.uriImpliedBase = uriValue; }
public void AbsoluteUriTest() { AtomBaseLink target = CreateAtomBaseLink(); // TODO: Initialize to an appropriate value AtomUri actual = new AtomUri(target.AbsoluteUri); Assert.AreEqual(target.Uri, actual); }
public void IsPersistableTest() { AtomUri uriString = new AtomUri("http://www.test.com/"); bool expected = true; // TODO: Initialize to an appropriate value bool actual; actual = Utilities.IsPersistable(uriString); Assert.AreEqual(expected, actual); }
public void BaseTest() { AtomBase target = CreateAtomBase(); // TODO: Initialize to an appropriate value AtomUri expected =new AtomUri("http://www.test.com/"); AtomUri actual; target.Base = expected; actual = target.Base; Assert.AreEqual(expected, actual); }
public void SchemeTest() { AtomCategory target = new AtomCategory(); // TODO: Initialize to an appropriate value AtomUri expected = new AtomUri("scheme"); AtomUri actual; target.Scheme = expected; actual = target.Scheme; Assert.AreEqual(expected, actual); }
public void AtomCategoryConstructorTest() { string term = "term"; AtomUri scheme = new AtomUri("scheme"); AtomCategory target = new AtomCategory(term, scheme); Assert.AreEqual(target.Term, term); Assert.AreEqual(target.Scheme.ToString(), "scheme"); }
public void AbsoluteUriTest() { AtomLink target = new AtomLink(); // TODO: Initialize to an appropriate value AtomUri expected = new AtomUri("http://www.test.com/"); target.HRef = expected; Assert.AreEqual(target.AbsoluteUri, "http://www.test.com/"); }
public void HRefTest() { AtomLink target = new AtomLink(); // TODO: Initialize to an appropriate value AtomUri expected = new AtomUri("http://www.test.com/"); AtomUri actual; target.HRef = expected; actual = target.HRef; Assert.AreEqual(expected, actual); }
public void SrcTest() { AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value AtomUri expected = new AtomUri("http://www.test.com/"); AtomUri actual; target.Src = expected; actual = target.Src; Assert.AreEqual(expected, actual); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>helper method to encapsulate encoding, uses HTML encoding now</summary> /// <param name="writer">the xml writer to write to</param> /// <param name="attributeName">the attribute the write</param> /// <param name="content">the atomUri to encode</param> ////////////////////////////////////////////////////////////////////// static protected void WriteEncodedAttributeString(XmlWriter writer, string attributeName, AtomUri content) { if (writer == null) { throw new System.ArgumentNullException("writer", "No valid xmlWriter"); } if (attributeName == null) { throw new System.ArgumentNullException( "attributeName", "No valid attributename"); } if (Utilities.IsPersistable(content)) { string encoded = Utilities.EncodeString(content.ToString()); writer.WriteAttributeString(attributeName, encoded); } }
/// <summary>helper method to encapsulate encoding, uses HTML encoding now</summary> /// <param name="writer">the xml writer to write to</param> /// <param name="elementName">the attribute the write</param> /// <param name="content">the string to encode</param> static protected void WriteEncodedElementString(XmlWriter writer, string elementName, AtomUri content) { if (writer == null) { throw new ArgumentNullException("writer"); } if (Utilities.IsPersistable(content)) { string encoded = Utilities.EncodeString(content.ToString()); writer.WriteElementString(elementName, BaseNameTable.NSAtom, encoded); } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>helper method to encapsulate encoding, uses HTML encoding now</summary> /// <param name="writer">the xml writer to write to</param> /// <param name="elementName">the attribute the write</param> /// <param name="content">the string to encode</param> ////////////////////////////////////////////////////////////////////// static protected void WriteEncodedElementString(XmlWriter writer, string elementName, AtomUri content) { if (Utilities.IsPersistable(content)) { string encoded = Utilities.EncodeString(content.ToString()); writer.WriteElementString(elementName, BaseNameTable.NSAtom, encoded); } }
public void UriTest() { AtomGenerator target = new AtomGenerator(); // TODO: Initialize to an appropriate value AtomUri expected = new AtomUri("http://www.test.com/"); AtomUri actual; target.Uri = expected; actual = target.Uri; Assert.AreEqual(expected, actual); }
public void op_InequalityTest() { AtomUri a = new AtomUri("A"); AtomUri b = new AtomUri("B"); bool expected = true; // TODO: Initialize to an appropriate value bool actual; actual = (a != b); Assert.AreEqual(expected, actual); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>Category constructor</summary> /// <param name="term">the term of the category</param> /// <param name="scheme">the scheme of the category</param> /// <param name="label"> the label for the category</param> ////////////////////////////////////////////////////////////////////// public AtomCategory(string term, AtomUri scheme, string label) { this.Term = term; this.Scheme = scheme; this.label = label; }
public void AbsoluteUriTest() { AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value AtomUri expected = new AtomUri("http://www.test.com/"); target.Src = expected; string actual; actual = target.AbsoluteUri; Assert.AreEqual(actual, "http://www.test.com/"); }
///////////////////////////////////////////////////////////////////////////// #region overloaded for property changes, xml:base ////////////////////////////////////////////////////////////////////// /// <summary>just go down the child collections</summary> /// <param name="uriBase"> as currently calculated</param> ////////////////////////////////////////////////////////////////////// internal override void BaseUriChanged(AtomUri uriBase) { base.BaseUriChanged(uriBase); // now walk over the entries and forward... uriBase = new AtomUri(Utilities.CalculateUri(this.Base, uriBase, null)); foreach (AtomEntry entry in this.Entries ) { entry.BaseUriChanged(uriBase); } }
public void op_LessThanTest() { AtomUri a = new AtomUri("A"); AtomUri b = new AtomUri("A"); bool expected = false; bool actual; actual = (a < b); Assert.AreEqual(expected, actual); }
/// <summary>Little helper that checks if a string is XML persistable</summary> public static bool IsPersistable(AtomUri uriString) { return(uriString == null ? false : Utilities.IsPersistable(uriString.ToString())); }
public void FindTest1() { AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value AtomCategory value = new AtomCategory("test", "scheme"); target.Add(value); string term = "test"; AtomUri scheme = new AtomUri("scheme"); AtomCategory actual; actual = target.Find(term, scheme); Assert.AreEqual(value, actual); }
////////////////////////////////////////////////////////////////////// /// <summary>public static string CalculateUri(string base, string inheritedBase, string local)</summary> /// <param name="localBase">the baseUri from xml:base </param> /// <param name="inheritedBase">the pushed down baseUri from an outer element</param> /// <param name="localUri">the Uri value</param> /// <returns>the absolute Uri to use... </returns> ////////////////////////////////////////////////////////////////////// internal static string CalculateUri(AtomUri localBase, AtomUri inheritedBase, string localUri) { try { Uri uriBase = null; Uri uriSuperBase= null; Uri uriComplete = null; if (inheritedBase != null) { uriSuperBase = new Uri(inheritedBase.ToString()); } if (localBase != null) { if (uriSuperBase != null) { uriBase = new Uri(uriSuperBase, localBase.ToString()); } else { uriBase = new Uri(localBase.ToString()); } } else { // if no local xml:base, take the passed down one uriBase = uriSuperBase; } if (localUri != null) { if (uriBase != null) { uriComplete = new Uri(uriBase, localUri.ToString()); } else { uriComplete = new Uri(localUri.ToString()); } } else { uriComplete = uriBase; } return uriComplete != null ? uriComplete.AbsoluteUri : null; } catch (System.UriFormatException) { return "Unsupported URI format"; } }
/// <summary>just go down the child collections</summary> /// <param name="uriBase"> as currently calculated</param> internal override void BaseUriChanged(AtomUri uriBase) { base.BaseUriChanged(uriBase); foreach (AtomPerson person in this.Authors) { person.BaseUriChanged(uriBase); } // saving Contributors foreach (AtomPerson person in this.Contributors) { person.BaseUriChanged(uriBase); } // saving Categories foreach (AtomCategory category in this.Categories) { category.BaseUriChanged(uriBase); } // saving the generator if (this.Generator != null) { this.Generator.BaseUriChanged(uriBase); } // save the icon if (this.Icon != null) { this.Icon.BaseUriChanged(uriBase); } // save the logo if (this.Logo != null) { this.Logo.BaseUriChanged(uriBase); } // save the ID if (this.Id != null) { this.Id.BaseUriChanged(uriBase); } // save the Links foreach (AtomLink link in this.Links) { link.BaseUriChanged(uriBase); } if (this.Rights != null) { this.Rights.BaseUriChanged(uriBase); } if (this.Subtitle != null) { this.Subtitle.BaseUriChanged(uriBase); } if (this.Title != null) { this.Title.BaseUriChanged(uriBase); } }
/// <summary> /// finds a category with a given term and scheme /// </summary> /// <param name="term"></param> /// <param name="scheme"></param> /// <returns>AtomCategory or NULL</returns> public AtomCategory Find(string term, AtomUri scheme) { foreach (AtomCategory category in List) { if (scheme == null || scheme == category.Scheme) { if (term == category.Term) { return category; } } } return null; }