/// <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>creates a new, in memory atom entry</summary> /// <returns>the new AtomEntry </returns> ////////////////////////////////////////////////////////////////////// public static AtomEntry CreateAtomEntry(int iCount) { AtomEntry entry = new AtomEntry(); // some unicode chars Char[] chars = new Char[] { '\u0023', // # '\u0025', // % '\u03a0', // Pi '\u03a3', // Sigma '\u03d1', // beta '&', }; AtomPerson author = new AtomPerson(AtomPersonType.Author); author.Name = "John Doe" + chars[0] + chars[1] + chars[2] + chars[3] + chars[4] + chars[5]; author.Email = "*****@*****.**"; entry.Authors.Add(author); AtomCategory cat = new AtomCategory(); cat.Label = "Default"; cat.Term = "Default" + chars[4] + " Term"; entry.Categories.Add(cat); entry.Content.Content = "this is the default text & entry"; entry.Content.Type = "html"; entry.Published = new DateTime(2001, 11, 20, 22, 30, 0); entry.Title.Text = "This is a entry number: " + iCount; entry.Updated = DateTime.Now; return entry; }
////////////////////////////////////////////////////////////////////// /// <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 ToggleCategoryTest() { AbstractEntry target = CreateAbstractEntry(); AtomCategory cat = new AtomCategory("testcat"); target.ToggleCategory(cat, true); Assert.IsTrue(target.Categories.Contains(cat), "Category should now be part of it"); target.ToggleCategory(cat, false); Assert.IsFalse(target.Categories.Contains(cat), "Category should be gone"); }
public void OperatorTest() { AtomCategory category = new AtomCategory("term"); QueryCategory target = new QueryCategory(category); // TODO: Initialize to an appropriate value QueryCategoryOperator expected = QueryCategoryOperator.AND; QueryCategoryOperator actual; target.Operator = expected; actual = target.Operator; Assert.AreEqual(expected, actual); }
/// <summary>parses an xml stream to create an AtomCategory object</summary> /// <param name="reader">correctly positioned xmlreader</param> /// <param name="owner">the object containing the person</param> /// <returns> the created AtomCategory object</returns> protected AtomCategory ParseCategory(XmlReader reader, AtomBase owner) { Tracing.TraceCall(); Tracing.Assert(reader != null, "reader should not be null"); if (reader == null) { throw new ArgumentNullException("reader"); } if (owner == null) { throw new ArgumentNullException("owner"); } AtomCategory category = owner.CreateAtomSubElement(reader, this) as AtomCategory; if (category != null) { bool noChildren = reader.IsEmptyElement; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { object localname = reader.LocalName; if (localname.Equals(this.nameTable.Term)) { category.Term = Utilities.DecodedValue(reader.Value); } else if (localname.Equals(this.nameTable.Scheme)) { category.Scheme = new AtomUri(reader.Value); } else if (localname.Equals(this.nameTable.Label)) { category.Label = Utilities.DecodedValue(reader.Value); } else { ParseBaseAttributes(reader, category); } } } if (!noChildren) { reader.MoveToElement(); int lvl = -1; while (NextChildElement(reader, ref lvl)) { ParseExtensionElements(reader, category); } } } return(category); }
public void ItemTest() { AtomCategoryCollection target = new AtomCategoryCollection(); int index = 0; AtomCategory expected = new AtomCategory("test"); AtomCategory actual; target.Add(expected); target[index] = expected; actual = target[index]; Assert.AreEqual(expected, actual); }
/// <summary> /// helper to toggle categories /// </summary> /// <param name="cat"></param> /// <param name="value"></param> public void ToggleCategory(AtomCategory cat, bool value) { if (value == true) { if (this.Categories.Contains(cat) == false) { this.Categories.Add(cat); } } else { this.Categories.Remove(cat); } }
////////////////////////////////////////////////////////////////////// /// <summary>[Test] public QueryObjectTest()</summary> ////////////////////////////////////////////////////////////////////// [Test] public void QueryObjectTest() { Tracing.TraceInfo("Entering QueryObject Test"); FeedQuery query = new FeedQuery(); query.Uri = new Uri(this.defaultHost); AtomCategory aCat = new AtomCategory("Test", new AtomUri("urn:test.com")); QueryCategory qCat = new QueryCategory(aCat); query.Categories.Add(qCat); aCat = new AtomCategory("TestNotAndOr", new AtomUri("urn:test.com")); qCat = new QueryCategory(aCat); qCat.Operator = QueryCategoryOperator.OR; qCat.Excluded = true; query.Categories.Add(qCat); aCat = new AtomCategory("ANDTHISONE", new AtomUri("")); qCat = new QueryCategory(aCat); query.Categories.Add(qCat); aCat = new AtomCategory("AnotherOrWithoutCategory"); qCat = new QueryCategory(aCat); qCat.Operator = QueryCategoryOperator.OR; qCat.Excluded = true; query.Categories.Add(qCat); query.Query = "Hospital"; query.NumberToRetrieve = 20; Tracing.TraceInfo("query: " + query.Uri); Uri uri = query.Uri; Tracing.TraceInfo("Uri: query= " + uri.Query); query.Uri = uri; Tracing.TraceInfo("Parsed Query URI: " + query.Uri); Assert.IsTrue(uri.AbsolutePath.Equals(query.Uri.AbsolutePath), "both query URIs should be identical, uri: " + uri.AbsolutePath + " compared to query: " + query.Uri.AbsolutePath); query.CategoryQueriesAsParameter = true; uri = query.Uri; Tracing.TraceInfo("Uri: query= " + uri.Query); query.Uri = uri; Tracing.TraceInfo("Parsed Query URI: " + query.Uri.AbsoluteUri); Assert.IsTrue(uri.AbsolutePath.Equals(query.Uri.AbsolutePath), "both query URIs should be identical, uri: " + uri.AbsolutePath + " compared to query: " + query.Uri.AbsolutePath); }
/// <summary>tries to parse a category collection document</summary> /// <param name="reader"> xmlReader positioned at the start element</param> /// <param name="owner">the base object that the collection belongs to</param> /// <returns></returns> public AtomCategoryCollection ParseCategories(XmlReader reader, AtomBase owner) { Tracing.Assert(reader != null, "reader should not be null"); if (reader == null) { throw new ArgumentNullException("reader"); } AtomCategoryCollection ret = new AtomCategoryCollection(); MoveToStartElement(reader); Tracing.TraceCall("entering Categories Parser"); object localname = reader.LocalName; Tracing.TraceInfo("localname is: " + reader.LocalName); if (IsCurrentNameSpace(reader, BaseNameTable.AppPublishingNamespace(owner)) && localname.Equals(this.nameTable.Categories)) { Tracing.TraceInfo("Found categories document"); int depth = -1; while (NextChildElement(reader, ref depth)) { localname = reader.LocalName; if (IsCurrentNameSpace(reader, BaseNameTable.NSAtom)) { if (localname.Equals(this.nameTable.Category)) { AtomCategory category = ParseCategory(reader, owner); ret.Add(category); } } } } else { Tracing.TraceInfo("ParseCategories called and nothing was parsed" + localname); throw new ClientFeedException("An invalid Atom Document was passed to the parser. This was not an app:categories document: " + localname); } return(ret); }
public AtomEntry createWebPage(String title, String html, String pageName) { SiteEntry entry = new SiteEntry(); AtomCategory category = new AtomCategory(SitesService.WEBPAGE_TERM, SitesService.KIND_SCHEME); category.Label = "webpage"; entry.Categories.Add(category); entry.Title.Text = title; entry.Content.Type = "xhtml"; entry.Content.Content = html; entry.ExtensionElements.Add(makePageNameExtension(pageName)); AtomEntry newEntry = null; try { newEntry = service.Insert(new Uri(makeFeedUri("content")), entry); } catch (GDataRequestException e) { Console.WriteLine(e.ResponseString); } return newEntry; }
public void IndexOfTest() { AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value AtomCategory value = new AtomCategory("test"); target.Add(value); int expected = 0; // TODO: Initialize to an appropriate value int actual; actual = target.IndexOf(value); Assert.AreEqual(expected, actual); }
public void InsertTest() { AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value AtomCategory value = new AtomCategory("test"); int index = 0; Assert.IsTrue(target.Count == 0); target.Insert(index, value); Assert.IsTrue(target.Count == 1); }
/// <summary>reads one of the feed entries at a time</summary> /// <param name="reader"> XmlReader positioned at the entry element</param> /// <returns> notifies user using event mechanism</returns> public void ParseEntry(XmlReader reader) { Tracing.Assert(reader != null, "reader should not be null"); if (reader == null) { throw new ArgumentNullException("reader"); } object localname = reader.LocalName; Tracing.TraceCall("Parsing atom entry"); if (localname.Equals(this.nameTable.Entry) == false) { throw new ClientFeedException("trying to parse an atom entry, but reader is not at the right spot"); } AtomEntry entry = OnCreateNewEntry(); ParseBasicAttributes(reader, entry); // remember the depth of entry int depth = -1; while (NextChildElement(reader, ref depth)) { localname = reader.LocalName; if (IsCurrentNameSpace(reader, BaseNameTable.NSAtom)) { if (localname.Equals(this.nameTable.Id)) { entry.Id = entry.CreateAtomSubElement(reader, this) as AtomId; ParseBaseLink(reader, entry.Id); } else if (localname.Equals(this.nameTable.Link)) { entry.Links.Add(ParseLink(reader, entry)); } else if (localname.Equals(this.nameTable.Updated)) { entry.Updated = DateTime.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture); } else if (localname.Equals(this.nameTable.Published)) { entry.Published = DateTime.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture); } else if (localname.Equals(this.nameTable.Author)) { entry.Authors.Add(ParsePerson(reader, entry)); } else if (localname.Equals(this.nameTable.Contributor)) { entry.Contributors.Add(ParsePerson(reader, entry)); } else if (localname.Equals(this.nameTable.Rights)) { entry.Rights = ParseTextConstruct(reader, entry); } else if (localname.Equals(this.nameTable.Category)) { AtomCategory category = ParseCategory(reader, entry); entry.Categories.Add(category); } else if (localname.Equals(this.nameTable.Summary)) { entry.Summary = ParseTextConstruct(reader, entry); } else if (localname.Equals(this.nameTable.Content)) { entry.Content = ParseContent(reader, entry); } else if (localname.Equals(this.nameTable.Source)) { entry.Source = entry.CreateAtomSubElement(reader, this) as AtomSource; ParseSource(reader, entry.Source); } else if (localname.Equals(this.nameTable.Title)) { entry.Title = ParseTextConstruct(reader, entry); } // all parse methods should leave the reader at the end of their element reader.Read(); } else if (IsCurrentNameSpace(reader, BaseNameTable.gBatchNamespace)) { // parse the google batch extensions if they are there ParseBatch(reader, entry); } else { // default extension parsing ParseExtensionElements(reader, entry); } } OnNewAtomEntry(entry); return; }
public void XmlNameTest() { AtomCategory target = new AtomCategory(); // TODO: Initialize to an appropriate value Assert.AreEqual(AtomParserNameTable.XmlCategoryElement, target.XmlName); }
////////////////////////////////////////////////////////////////////// /// <summary>Constructor, given a category.</summary> ////////////////////////////////////////////////////////////////////// public QueryCategory(AtomCategory category) { this.category = category; this.categoryOperator = QueryCategoryOperator.AND; }
public void ShouldBePersistedTest() { AtomCategory target = new AtomCategory(); // TODO: Initialize to an appropriate value target.Label = "new label"; Assert.IsTrue(target.ShouldBePersisted()); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>parses an xml stream to create an AtomCategory object</summary> /// <param name="reader">correctly positioned xmlreader</param> /// <param name="owner">the object containing the person</param> /// <returns> the created AtomCategory object</returns> ////////////////////////////////////////////////////////////////////// protected AtomCategory ParseCategory(XmlReader reader, AtomBase owner) { Tracing.TraceCall(); Tracing.Assert(reader != null, "reader should not be null"); if (reader == null) { throw new ArgumentNullException("reader"); } AtomCategory category = owner.CreateAtomSubElement(reader, this) as AtomCategory; if (category != null) { category = new AtomCategory(); if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { object localname = reader.LocalName; if (localname.Equals(this.nameTable.Term)) { category.Term = Utilities.DecodedValue(reader.Value); } else if (localname.Equals(this.nameTable.Scheme)) { category.Scheme = new AtomUri(Utilities.DecodedValue(reader.Value)); } else if (localname.Equals(this.nameTable.Label)) { category.Label = Utilities.DecodedValue(reader.Value); } else { ParseBaseAttributes(reader, category); } } } } return category; }
/// <summary>standard typed accessor method </summary> public int Add( AtomCategory value ) { // Remove category with the same term to avoid duplication. AtomCategory oldCategory = Find(value.Term, value.Scheme); if (oldCategory != null) { List.Remove(oldCategory); } return( List.Add( value ) ); }
public void TermTest() { AtomCategory target = new AtomCategory(); // TODO: Initialize to an appropriate value string expected = "TestValue"; string actual; target.Term = expected; actual = target.Term; Assert.AreEqual(expected, actual); }
public void UriStringTest() { AtomCategory target = new AtomCategory("term", "scheme"); Assert.AreEqual("{scheme}term", target.UriString); }
public void FindTest() { AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value AtomCategory value = new AtomCategory("test"); target.Add(value); string term = "test"; AtomCategory actual; actual = target.Find(term); Assert.AreEqual(value, actual); }
public void AddTest() { AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value AtomCategory value = new AtomCategory("test"); target.Add(value); Assert.IsTrue(target.Contains(value)); }
public void AtomCategoryConstructorTest1() { string term = "Test"; AtomCategory target = new AtomCategory(term); Assert.AreEqual(target.Term, term); }
public void RemoveTest() { AtomCategoryCollection target = new AtomCategoryCollection(); // TODO: Initialize to an appropriate value AtomCategory expected = new AtomCategory("test"); Assert.IsTrue(target.Count == 0); target.Add(expected); Assert.IsTrue(target.Count == 1); target.Remove(expected); Assert.IsTrue(target.Count == 0); }
public void AtomCategoryConstructorTest2() { AtomCategory target = new AtomCategory(); Assert.IsNotNull(target); Assert.IsTrue(String.IsNullOrEmpty(target.Label)); Assert.IsTrue(String.IsNullOrEmpty(target.Term)); Assert.IsNull(target.Scheme); }
/// <summary>standard typed accessor method </summary> public int IndexOf( AtomCategory value ) { return( List.IndexOf( value ) ); }
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"); }
/// <summary> /// Searches YouTube for tracks matching a certain query /// </summary> /// <param name="query">The query to search for</param> /// <returns>An observable collection of TrackData with all YouTube tracks that match query</returns> public static ObservableCollection<TrackData> Search(string query) { ObservableCollection<TrackData> tracks = new ObservableCollection<TrackData>(); try { string filter = SettingsManager.YouTubeFilter; YouTubeQuery q = new YouTubeQuery(YouTubeQuery.DefaultVideoUri); q.OrderBy = "relevance"; q.Query = query; q.Formats.Add(YouTubeQuery.VideoFormat.Embeddable); q.NumberToRetrieve = 50; q.SafeSearch = YouTubeQuery.SafeSearchValues.None; if (!String.IsNullOrWhiteSpace(filter) && filter != "None") { AtomCategory category = new AtomCategory(filter, YouTubeNameTable.CategorySchema); q.Categories.Add(new QueryCategory(category)); } YouTubeRequest request = new YouTubeRequest(settings); Feed<Video> videoFeed = request.Get<Video>(q); foreach (Video entry in videoFeed.Entries) { tracks.Add(YouTubeManager.CreateTrack(entry)); } } catch (Exception exc) { U.L(LogLevel.Error, "YOUTUBE", "Error while performing search: " + exc.Message); VerifyConnectivity(); } TrackSource = tracks; return tracks; }
/// <summary>standard typed accessor method </summary> public void Insert( int index, AtomCategory value ) { List.Insert( index, value ); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>creates a new, in memory atom entry</summary> /// <returns>the new AtomEntry </returns> ////////////////////////////////////////////////////////////////////// public static EventEntry CreateEventEntry(int iCount) { EventEntry entry = new EventEntry(); // some unicode chars Char[] chars = new Char[] { '\u0023', // # '\u0025', // % '\u03a0', // Pi '\u03a3', // Sigma '\u03d1', // beta }; // if unicode needs to be disabled for testing, just uncomment this line // chars = new Char[] { 'a', 'b', 'c', 'd', 'e'}; AtomPerson author = new AtomPerson(AtomPersonType.Author); author.Name = "John Doe" + chars[0] + chars[1] + chars[2] + chars[3]; author.Email = "*****@*****.**"; entry.Authors.Add(author); AtomCategory cat = new AtomCategory(); cat.Label = "Default"; cat.Term = "Default" + chars[4] + " Term"; entry.Categories.Add(cat); entry.Content.Content = "this is the default text entry"; entry.Published = new DateTime(2001, 11, 20, 22, 30, 0); entry.Title.Text = "This is a entry number: " + iCount; entry.Updated = DateTime.Now; When newTime = new When(); newTime.StartTime = DateTime.Today.AddDays(-3); newTime.EndTime = DateTime.Today.AddDays(1); entry.Times.Add(newTime); entry.Reminder = new Reminder(); entry.Reminder.Minutes = DEFAULT_REMINDER_TIME; Who someone = new Who(); someone.ValueString = "*****@*****.**"; Who.AttendeeStatus status = new Who.AttendeeStatus(); status.Value = "event.accepted"; someone.Attendee_Status = status; someone.Rel = "http://schemas.google.com/g/2005#event.organizer"; entry.Participants.Add(someone); Where newPlace = new Where(); newPlace.ValueString = "A really nice place"; entry.Locations.Add(newPlace); newPlace = new Where(); newPlace.ValueString = "Another really nice place"; newPlace.Rel = Where.RelType.EVENT_ALTERNATE; entry.Locations.Add(newPlace); return entry; }
/// <summary>standard typed accessor method </summary> public void Remove( AtomCategory value ) { List.Remove( value ); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>compares a category</summary> /// <param name="theOne">the One category </param> /// <param name="theOther">the Other category</param> /// <returns>true if identical </returns> ////////////////////////////////////////////////////////////////////// public static bool IsCategoryIdentical(AtomCategory theOne, AtomCategory theOther) { if (theOne == null && theOther == null) { return true; } if (ObjectModelHelper.IsBaseIdentical(theOne, theOther)==false) { return false; } if (String.Compare(theOne.Label, theOther.Label)!=0) { return false; } if (String.Compare(theOne.Term, theOther.Term) != 0) { return false; } if (AtomUri.Compare(theOne.Scheme, theOther.Scheme)!= 0) { return false; } return true; }
/// <summary>standard typed accessor method </summary> public bool Contains( AtomCategory value ) { if (value == null) { return( List.Contains( value ) ); } // If value is not of type AtomCategory, this will return false. if (Find(value.Term, value.Scheme) != null) { return true; } return false; }