public void FeedLinkTest() { PlaylistsEntry target = new PlaylistsEntry(); // TODO: Initialize to an appropriate value FeedLink expected = new FeedLink(); FeedLink actual; target.FeedLink = expected; actual = target.FeedLink; Assert.AreEqual(expected, actual); }
/// <summary> /// Persistence method for the Comment object /// </summary> /// <param name="writer">the xmlwriter to write into</param> public void Save(XmlWriter writer) { if (FeedLink != null) { // only save out if there is something to save writer.WriteStartElement(XmlPrefix, XmlName, XmlNameSpace); FeedLink.Save(writer); writer.WriteEndElement(); } }
/// <summary> /// Constructs a new PlayListEntry instance /// </summary> public PlaylistsEntry() : base() { Tracing.TraceMsg("Created PlaylistsEntry"); if (this.ProtocolMajor == 1) { Description d = new Description(); FeedLink f = new FeedLink(); this.AddExtension(d); this.AddExtension(f); } CountHint c = new CountHint(); this.AddExtension(c); this.AddExtension(new Private()); Categories.Add(PLAYLISTS_CATEGORY); }
///////////////////////////////////////////////////////////////////////////// #region FeedLink Parser ////////////////////////////////////////////////////////////////////// /// <summary>Parses an xml node to create an FeedLink object.</summary> /// <param name="node">feedLink node</param> /// <returns> the created FeedLink object</returns> ////////////////////////////////////////////////////////////////////// public static FeedLink ParseFeedLink(XmlNode node) { Tracing.TraceCall(); FeedLink link = null; Tracing.Assert(node != null, "node should not be null"); if (node == null) { throw new ArgumentNullException("node"); } object localname = node.LocalName; if (localname.Equals(GDataParserNameTable.XmlFeedLinkElement)) { link = new FeedLink(); if (node.Attributes != null) { if (node.Attributes[GDataParserNameTable.XmlAttributeHref] != null) { link.Href = node.Attributes[GDataParserNameTable.XmlAttributeHref].Value; } if (node.Attributes[GDataParserNameTable.XmlAttributeReadOnly] != null) { link.ReadOnly = node.Attributes[GDataParserNameTable.XmlAttributeReadOnly].Value.Equals(Utilities.XSDTrue); } if (node.Attributes[GDataParserNameTable.XmlAttributeRel] != null) { link.Rel = node.Attributes[GDataParserNameTable.XmlAttributeRel].Value; } if (node.Attributes[GDataParserNameTable.XmlAttributeCountHint] != null) { try { link.CountHint = Int32.Parse(node.Attributes[GDataParserNameTable.XmlAttributeCountHint].Value); } catch (FormatException fe) { throw new ArgumentException("Invalid g:feedLink/@countHint.", fe); } } } if (node.HasChildNodes) { XmlNode feedChild = node.FirstChild; while (feedChild != null && feedChild is XmlElement) { if (feedChild.LocalName == AtomParserNameTable.XmlFeedElement && feedChild.NamespaceURI == BaseNameTable.NSAtom) { if (link.Feed == null) { link.Feed = new AtomFeed(null, new Service()); Stream feedStream = new MemoryStream(ASCIIEncoding.Default.GetBytes(feedChild.OuterXml)); link.Feed.Parse(feedStream, AlternativeFormat.Atom); } else { throw new ArgumentException("Only one feed is allowed inside the g:feedLink"); } } feedChild = feedChild.NextSibling; } } } return link; }
////////////////////////////////////////////////////////////////////// /// <summary>Parses an xml node to create a Where object.</summary> /// <param name="node">the node to parse node</param> /// <param name="parser">the xml parser to use if we need to dive deeper</param> /// <returns>the created Where object</returns> ////////////////////////////////////////////////////////////////////// public IExtensionElementFactory CreateInstance(XmlNode node, AtomFeedParser parser) { return(FeedLink.ParseFeedLink(node)); }
///////////////////////////////////////////////////////////////////////////// #region FeedLink Parser ////////////////////////////////////////////////////////////////////// /// <summary>Parses an xml node to create an FeedLink object.</summary> /// <param name="node">feedLink node</param> /// <returns> the created FeedLink object</returns> ////////////////////////////////////////////////////////////////////// public static FeedLink ParseFeedLink(XmlNode node) { Tracing.TraceCall(); FeedLink link = null; Tracing.Assert(node != null, "node should not be null"); if (node == null) { throw new ArgumentNullException("node"); } object localname = node.LocalName; if (localname.Equals(GDataParserNameTable.XmlFeedLinkElement)) { link = new FeedLink(); if (node.Attributes != null) { if (node.Attributes[GDataParserNameTable.XmlAttributeHref] != null) { link.Href = node.Attributes[GDataParserNameTable.XmlAttributeHref].Value; } if (node.Attributes[GDataParserNameTable.XmlAttributeReadOnly] != null) { link.ReadOnly = node.Attributes[GDataParserNameTable.XmlAttributeReadOnly].Value.Equals(Utilities.XSDTrue); } if (node.Attributes[GDataParserNameTable.XmlAttributeRel] != null) { link.Rel = node.Attributes[GDataParserNameTable.XmlAttributeRel].Value; } if (node.Attributes[GDataParserNameTable.XmlAttributeCountHint] != null) { try { link.CountHint = Int32.Parse(node.Attributes[GDataParserNameTable.XmlAttributeCountHint].Value); } catch (FormatException fe) { throw new ArgumentException("Invalid g:feedLink/@countHint.", fe); } } } if (node.HasChildNodes) { XmlNode feedChild = node.FirstChild; while (feedChild != null && feedChild is XmlElement) { if (feedChild.LocalName == AtomParserNameTable.XmlFeedElement && feedChild.NamespaceURI == BaseNameTable.NSAtom) { if (link.Feed == null) { link.Feed = new AtomFeed(null, new Service()); Stream feedStream = new MemoryStream(ASCIIEncoding.Default.GetBytes(feedChild.OuterXml)); link.Feed.Parse(feedStream, AlternativeFormat.Atom); } else { throw new ArgumentException("Only one feed is allowed inside the g:feedLink"); } } feedChild = feedChild.NextSibling; } } } return(link); }
public void LoadDataFile(string LogFileContents) { List<clsVideoEntry> init = new List<clsVideoEntry>(); Dictionary<string, List<clsDataPoint>> hist = new Dictionary<string, List<clsDataPoint>>(); string log = LogFileContents; Regex r = new Regex("init : .+?{(.+?)}.+?{(.+?)}.+?{(.+?)}.+?{(.+?)}.+?{(.+?)}.+?{(.+?)}.+?{(.+?)}.+?{(.+?)}.+?{(.+?)}"); MatchCollection matches = r.Matches(log); foreach (Match m in matches) { Google.GData.YouTube.YouTubeEntry entry = new Google.GData.YouTube.YouTubeEntry(); entry.VideoId = m.Groups[3].Value; Google.GData.Extensions.FeedLink feedlink = new Google.GData.Extensions.FeedLink(); feedlink.CountHint = int.Parse(m.Groups[8].Value); entry.Comments = new Google.GData.Extensions.Comments(); entry.Comments.FeedLink = feedlink; entry.Statistics = new Google.GData.YouTube.Statistics(); entry.Statistics.ViewCount = m.Groups[7].Value; entry.Statistics.FavoriteCount = m.Groups[9].Value; entry.Rating = new Google.GData.Extensions.Rating(); entry.Rating.NumRaters = int.Parse(m.Groups[5].Value); entry.Rating.Average = double.Parse(m.Groups[6].Value); entry.Title = new Google.GData.Client.AtomTextConstruct(Google.GData.Client.AtomTextConstructElementType.Title, m.Groups[4].Value); clsVideoEntry new_e = new clsVideoEntry(entry); new_e.Time = DateTime.Parse(m.Groups[1].Value + " " + m.Groups[2].Value); clsVideoEntry old_entry = _GetEntryByIdFromList(init, new_e.VideoID); if ( old_entry == null) init.Add(new_e); else { List<clsDataPoint> new_dps = _compare_entities(new_e, old_entry); if (new_e.Time < old_entry.Time) old_entry = new_e; foreach (clsDataPoint dp in new_dps) { if (!hist.ContainsKey(new_e.VideoID)) hist.Add(new_e.VideoID, new List<clsDataPoint>()); hist[new_e.VideoID].Add(dp); } } } r = new Regex("upd : d{(.*)},t{(.*)},vId{(.*),(.*)},old{(.*)},new{(.*)}"); matches = r.Matches(log); foreach (Match m in matches) { string v = m.Groups[3].Value; string f = m.Groups[4].Value; double Iv = double.Parse(m.Groups[5].Value); double Nv = double.Parse(m.Groups[6].Value); if (!hist.ContainsKey(v)) hist.Add(v, new List<clsDataPoint>()); clsDataPointField field = new clsDataPointField(); switch (f) { case "VIEWS": field.Field = clsDataPointField.VideoDataFields.VIEWS; break; case "RATERS": field.Field = clsDataPointField.VideoDataFields.RATERS; break; case "AVERAGE_RATING": field.Field = clsDataPointField.VideoDataFields.AVERAGE_RATING; break; case "COMMENT_COUNT": field.Field = clsDataPointField.VideoDataFields.COMMENT_COUNT; break; case "FAVORITED_COUNT": field.Field = clsDataPointField.VideoDataFields.FAVORITED_COUNT; break; } clsDataPoint new_dp = new clsDataPoint(Iv, Nv, field, v); new_dp.Time = DateTime.Parse(m.Groups[1].Value + " " + m.Groups[2].Value); hist[v].Add(new_dp); } _initial_dataset = init; _historical_data = hist; _sort_historical_data(); }