AppendVertexXmlNodes ( String sSearchTerm, WhatToInclude eWhatToInclude, Int32 iMaximumVideos, GraphMLXmlDocument oGraphMLXmlDocument, RequestStatistics oRequestStatistics, out HashSet<String> oVideoIDs, out Dictionary< String, LinkedList<String> > oCategoryDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sSearchTerm) ); Debug.Assert(iMaximumVideos> 0); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oRequestStatistics != null); AssertValid(); ReportProgress("Getting a list of videos."); // This is used to skip duplicate videos in the results returned by // YouTube. (I'm not sure why YouTube sometimes returns duplicates, // but it does.) oVideoIDs = new HashSet<String>(); // If an edge should be included for each pair of videos that share the // same category, the key is a lower-case category and the value is a // LinkedList of the video IDs that have the category. if ( WhatToIncludeFlagIsSet(eWhatToInclude, WhatToInclude.SharedCategoryEdges) ) { oCategoryDictionary = new Dictionary< String, LinkedList<String> >(); } else { oCategoryDictionary = null; } String sUrl = String.Format( "http://gdata.youtube.com/feeds/api/videos?q={0}" , EncodeUrlParameter(sSearchTerm) ); // The document consists of an "entry" XML node for each video. foreach ( XmlNode oEntryXmlNode in EnumerateXmlNodes(sUrl, "a:feed/a:entry", iMaximumVideos, false, oRequestStatistics) ) { XmlNamespaceManager oXmlNamespaceManager = CreateXmlNamespaceManager(oEntryXmlNode.OwnerDocument); // Use the video ID as the GraphML vertex name. The video title // can't be used because it is not unique. String sVideoID; if ( !XmlUtil2.TrySelectSingleNodeAsString(oEntryXmlNode, "media:group/yt:videoid/text()", oXmlNamespaceManager, out sVideoID) || oVideoIDs.Contains(sVideoID) ) { continue; } oVideoIDs.Add(sVideoID); XmlNode oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode( sVideoID); AppendStringGraphMLAttributeValue(oEntryXmlNode, "a:title/text()", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, TitleID); AppendStringGraphMLAttributeValue(oEntryXmlNode, "a:author/a:name/text()", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, AuthorID); AppendDoubleGraphMLAttributeValue(oEntryXmlNode, "gd:rating/@average", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, RatingID); AppendInt32GraphMLAttributeValue(oEntryXmlNode, "yt:statistics/@viewCount", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, ViewsID); AppendInt32GraphMLAttributeValue(oEntryXmlNode, "yt:statistics/@favoriteCount", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, FavoritedID); AppendInt32GraphMLAttributeValue(oEntryXmlNode, "gd:comments/gd:feedLink/@countHint", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, CommentsID); AppendYouTubeDateGraphMLAttributeValue(oEntryXmlNode, "a:published/text()", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, CreatedDateUtcID); AppendStringGraphMLAttributeValue(oEntryXmlNode, "media:group/media:thumbnail/@url", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, NodeXLGraphMLUtil.VertexImageFileID); if ( AppendStringGraphMLAttributeValue(oEntryXmlNode, "media:group/media:player/@url", oXmlNamespaceManager, oGraphMLXmlDocument, oVertexXmlNode, NodeXLGraphMLUtil.VertexMenuActionID) ) { oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, NodeXLGraphMLUtil.VertexMenuTextID, "Play Video in Browser"); } if (oCategoryDictionary != null) { CollectCategories(oEntryXmlNode, sVideoID, oXmlNamespaceManager, oCategoryDictionary); } } }
AppendVertexXmlNode ( String sTag, GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<String, XmlNode> oTagDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sTag) ); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oTagDictionary != null); if ( !oTagDictionary.ContainsKey(sTag) ) { XmlNode oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode( sTag); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, NodeXLGraphMLUtil.VertexLabelID, sTag); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, NodeXLGraphMLUtil.VertexMenuTextID, "Open Flickr Page for This Tag"); oGraphMLXmlDocument.AppendGraphMLAttributeValue( oVertexXmlNode, NodeXLGraphMLUtil.VertexMenuActionID, String.Format( "http://www.flickr.com/photos/tags/{0}/" , UrlUtil.EncodeUrlParameter(sTag) ) ); oTagDictionary.Add(sTag, oVertexXmlNode); } }
SaveGraphCore ( IGraph graph, Stream stream ) { Debug.Assert(graph != null); Debug.Assert(stream != null); AssertValid(); GraphMLXmlDocument oGraphMLXmlDocument = new GraphMLXmlDocument( graph.Directedness == GraphDirectedness.Directed); String [] asEdgeAttributeNames = GetAttributeNames(graph, false); String [] asVertexAttributeNames = GetAttributeNames(graph, true); // Define the GraphML-attributes. const String VertexAttributeIDPrefix = "V-"; const String EdgeAttributeIDPrefix = "E-"; foreach (String sVertexAttributeName in asVertexAttributeNames) { oGraphMLXmlDocument.DefineGraphMLAttribute(false, VertexAttributeIDPrefix + sVertexAttributeName, sVertexAttributeName, "string", null); } foreach (String sEdgeAttributeName in asEdgeAttributeNames) { oGraphMLXmlDocument.DefineGraphMLAttribute(true, EdgeAttributeIDPrefix + sEdgeAttributeName, sEdgeAttributeName, "string", null); } // Add the vertices and their GraphML-attribute values. foreach (IVertex oVertex in graph.Vertices) { XmlNode oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode( oVertex.Name); AppendGraphMLAttributeValues(oVertex, oGraphMLXmlDocument, oVertexXmlNode, asVertexAttributeNames, VertexAttributeIDPrefix); } // Add the edges and their GraphML-attribute values. foreach (IEdge oEdge in graph.Edges) { IVertex [] oVertices = oEdge.Vertices; XmlNode oEdgeXmlNode = oGraphMLXmlDocument.AppendEdgeXmlNode( oVertices[0].Name, oVertices[1].Name); AppendGraphMLAttributeValues(oEdge, oGraphMLXmlDocument, oEdgeXmlNode, asEdgeAttributeNames, EdgeAttributeIDPrefix); } oGraphMLXmlDocument.Save(stream); }
TryAppendVertexXmlNode ( String screenName, String userID, GraphMLXmlDocument graphMLXmlDocument, Dictionary<String, TwitterUser> userIDDictionary, out TwitterUser twitterUser ) { Debug.Assert( !String.IsNullOrEmpty(screenName) ); Debug.Assert( !String.IsNullOrEmpty(userID) ); Debug.Assert(graphMLXmlDocument != null); Debug.Assert(userIDDictionary != null); twitterUser = null; if ( userIDDictionary.TryGetValue(userID, out twitterUser) ) { // A vertex XML node already exists. return (false); } XmlNode vertexXmlNode = graphMLXmlDocument.AppendVertexXmlNode( screenName); twitterUser = new TwitterUser(screenName, vertexXmlNode); userIDDictionary.Add(userID, twitterUser); graphMLXmlDocument.AppendGraphMLAttributeValue(vertexXmlNode, NodeXLGraphMLUtil.VertexMenuTextID, "Open Twitter Page for This Person"); graphMLXmlDocument.AppendGraphMLAttributeValue( vertexXmlNode, NodeXLGraphMLUtil.VertexMenuActionID, String.Format(TwitterApiUrls.UserWebPageUrlPattern, screenName) ); return (true); }
TryAppendVertexXmlNode ( String sUserID, String sScreenName, GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<String, XmlNode> oUserIDDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sUserID) ); Debug.Assert( !String.IsNullOrEmpty(sScreenName) ); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oUserIDDictionary != null); XmlNode oVertexXmlNode; if ( oUserIDDictionary.TryGetValue(sUserID, out oVertexXmlNode) ) { return (false); } oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(sScreenName); oUserIDDictionary.Add(sUserID, oVertexXmlNode); return (true); }
TryAppendVertexXmlNode ( String sUserName, XmlNode oEntryXmlNode, GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<String, XmlNode> oUserNameDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sUserName) ); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oUserNameDictionary != null); XmlNode oVertexXmlNode; if ( oUserNameDictionary.TryGetValue(sUserName, out oVertexXmlNode) ) { return (false); } oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(sUserName); oUserNameDictionary.Add(sUserName, oVertexXmlNode); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, NodeXLGraphMLUtil.VertexMenuTextID, "Open YouTube Page for This Person"); oGraphMLXmlDocument.AppendGraphMLAttributeValue( oVertexXmlNode, NodeXLGraphMLUtil.VertexMenuActionID, String.Format(WebPageUrlPattern, sUserName)); return (true); }
AddPostVertices ( ref GraphMLXmlDocument oGraphMLXmlDocument, JSONObject streamPosts ) { XmlNode oVertexXmlNode; //Add nodes (posts) foreach (JSONObject ob in streamPosts.Array) { oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(ob.Dictionary["post_id"].String); //Add tooltip AppendVertexTooltipXmlNodes(oGraphMLXmlDocument, oVertexXmlNode, ob.Dictionary["post_id"].String, ob.Dictionary["message"].String); //Add attributes oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "type", "2"); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, LabelColumnName, ob.Dictionary["message"].String); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "content", ob.Dictionary["message"].String); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, MenuTextID, "Open Facebook Page for This Post"); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, MenuActionID, ob.Dictionary["permalink"].String); //If the post contains a link to a video, photo, document etc //and it has a picture, use it as the post image if(ob.Dictionary["attachment"].Dictionary.ContainsKey("media") && ob.Dictionary["attachment"].Dictionary["media"].Array.Length>0) { oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "Image", ob.Dictionary["attachment"].Dictionary["media"].Array[0].Dictionary["src"].String); } } }
AddLikerVertices ( ref GraphMLXmlDocument oGraphMLXmlDocument, Dictionary<string, List<string>> likersPost, Dictionary<string, Dictionary<string, JSONObject>> attributeValues, Dictionary<string, List<Dictionary<string, object>>> statusUpdates, Dictionary<string, List<Dictionary<string, object>>> wallPosts ) { XmlNode oVertexXmlNode; likersWithNoAttributes = new Dictionary<string, string>(); //Add nodes foreach (var item in likersPost) { if (!attributeValues.ContainsKey(item.Key)) { //This means that the liker is not a user but a page //FacebookAPI fb = new FacebookAPI(); JSONObject pageObject = CallGraphAPIWithRelogin("/" + item.Key); if (!pageObject.IsDictionary) continue; string vertexName = ManageDisplayNames(pageObject.Dictionary["name"].String, item.Key); if (String.IsNullOrEmpty(vertexName)) continue; oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(vertexName); //Add tooltip AppendVertexTooltipXmlNodes(oGraphMLXmlDocument, oVertexXmlNode, pageObject.Dictionary["name"].String, ""); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "type", "1"); if (pageObject.Dictionary.ContainsKey("picture")) { oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "Image", pageObject.Dictionary["picture"].String); } oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "v_weight", item.Value.Count); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, MenuTextID, "Open Facebook Page for This User"); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, MenuActionID, FacebookURL + item.Key); //Add this user to the appropriate "no attributes" dictionary //likersWithNoAttributes.Add(item.Key, pageObject.Dictionary["name"].String); } else { oVertexXmlNode = oGraphMLXmlDocument.AppendVertexXmlNode(usersDisplayName[item.Key]); //Add tooltip AppendVertexTooltipXmlNodes(oGraphMLXmlDocument, oVertexXmlNode, usersDisplayName[item.Key], ""); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "type", "1"); //Add attributes for the actual user AddAttributes(ref oGraphMLXmlDocument, ref oVertexXmlNode, attributeValues[item.Key] ); if (attributeValues[item.Key].ContainsKey("pic_small") && attributeValues[item.Key]["pic_small"] != null) { oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "Image", attributeValues[item.Key]["pic_small"].String); } oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, "v_weight", item.Value.Count); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, MenuTextID, "Open Facebook Page for This User"); oGraphMLXmlDocument.AppendGraphMLAttributeValue(oVertexXmlNode, MenuActionID, FacebookURL + item.Key); } if (bGetStatusUpdates) { AddStatusUpdates(ref oGraphMLXmlDocument, ref oVertexXmlNode, item.Key, statusUpdates ); } if (bGetWallPosts) { AddWallPosts(ref oGraphMLXmlDocument, ref oVertexXmlNode, item.Key, wallPosts ); } } }