GetAttributeValue ( XmlNode dataXmlNode ) { Debug.Assert(dataXmlNode != null); Debug.Assert(dataXmlNode.Name == "data"); AssertValid(); String sKey = XmlUtil2.SelectRequiredSingleNodeAsString(dataXmlNode, "@key", null); Debug.Assert(sKey == m_sID); String sAttributeValue; if (!XmlUtil2.TrySelectSingleNodeAsString(dataXmlNode, "text()", null, out sAttributeValue)) { // Allow missing inner text for GraphML-attributes of type string. // This was found in a GraphML file created by the yED program. sAttributeValue = String.Empty; } try { return(ConvertAttributeValue(sAttributeValue)); } catch (FormatException) { throw new XmlException( "The GraphML-attribute value specified for a \"data\" XML node" + " with the key \"" + sKey + "\" is not of the specified" + " type." ); } }
ParseGraphMLAttributeValues ( XmlNode oNodeOrEdgeXmlNode, XmlNamespaceManager oXmlNamespaceManager, IMetadataProvider oEdgeOrVertex, Boolean bIsVertex, Dictionary <String, GraphMLAttribute> oGraphMLAttributeDictionary ) { Debug.Assert(oNodeOrEdgeXmlNode != null); Debug.Assert(oXmlNamespaceManager != null); Debug.Assert(oEdgeOrVertex != null); Debug.Assert(oGraphMLAttributeDictionary != null); AssertValid(); // For each GraphML-attribute that has a default value, set a metadata // value on the edge or vertex. This value may may get overwritten // later. foreach (GraphMLAttribute oGraphMLAttribute in oGraphMLAttributeDictionary.Values) { if (oGraphMLAttribute.IsForVertex == bIsVertex) { Object oDefaultAttributeValue; if (oGraphMLAttribute.TryGetDefaultAttributeValue( out oDefaultAttributeValue)) { oEdgeOrVertex.SetValue(oGraphMLAttribute.Name, oDefaultAttributeValue); } } } // For each "data" XML node specified for this edge or vertex, set // a metadata value on the edge or vertex. This may overwrite a // previously-written default value. foreach (XmlNode oDataXmlNode in oNodeOrEdgeXmlNode.SelectNodes( GraphMLPrefix + ":data", oXmlNamespaceManager)) { String sGraphMLAttributeID = XmlUtil2.SelectRequiredSingleNodeAsString(oDataXmlNode, "@key", null); GraphMLAttribute oGraphMLAttribute; if (!oGraphMLAttributeDictionary.TryGetValue(sGraphMLAttributeID, out oGraphMLAttribute)) { throw new XmlException( "A \"data\" XML node has the key \"" + sGraphMLAttributeID + "\", for which there is no corresponding \"key\" XML" + " node." ); } oEdgeOrVertex.SetValue(oGraphMLAttribute.Name, oGraphMLAttribute.GetAttributeValue(oDataXmlNode)); } }
GetRelatedTagsRecursive ( String sTag, WhatToInclude eWhatToInclude, NetworkLevel eNetworkLevel, String sApiKey, Int32 iRecursionLevel, GraphMLXmlDocument oGraphMLXmlDocument, Dictionary <String, XmlNode> oTagDictionary, RequestStatistics oRequestStatistics ) { Debug.Assert(!String.IsNullOrEmpty(sTag)); Debug.Assert(eNetworkLevel == NetworkLevel.One || eNetworkLevel == NetworkLevel.OnePointFive || eNetworkLevel == NetworkLevel.Two); Debug.Assert(!String.IsNullOrEmpty(sApiKey)); Debug.Assert(iRecursionLevel == 1 || iRecursionLevel == 2); Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oTagDictionary != null); Debug.Assert(oRequestStatistics != null); AssertValid(); /* * Here is what this method should do, based on the eNetworkLevel and * iRecursionLevel parameters. * * eNetworkLevel * |One | OnePointFive | Two * ---|------------------| ------------------| ----------------- * i 1 |Add all vertices. | Add all vertices. | Add all vertices. * R | | | * e |Add all edges. | Add all edges. | Add all edges. * c | | | * u |Do not recurse. | Recurse. | Recurse. * r | | | * s ---|------------------|-------------------|------------------ * i 2 |Impossible. | Do not add | Add all vertices. * o | | vertices. | * n | | | * L | | Add edges only if | Add all edges. * e | | vertices are | * v | | already included. | * e | | | * l | | Do not recurse. | Do not recurse. | | | | ---|------------------|-------------------|------------------ */ Boolean bNeedToRecurse = GetNeedToRecurse(eNetworkLevel, iRecursionLevel); Boolean bNeedToAppendVertices = GetNeedToAppendVertices( eNetworkLevel, iRecursionLevel); ReportProgress("Getting tags related to \"" + sTag + "\"."); String sUrl = GetFlickrMethodUrl("flickr.tags.getRelated", sApiKey, "&tag=" + UrlUtil.EncodeUrlParameter(sTag)); XmlDocument oXmlDocument; try { oXmlDocument = GetXmlDocument(sUrl, oRequestStatistics); } catch (Exception oException) { // If the exception is not a WebException or XmlException, or if // none of the network has been obtained yet, throw the exception. if (!HttpSocialNetworkUtil.ExceptionIsWebOrXml(oException) || !oGraphMLXmlDocument.HasVertexXmlNode) { throw oException; } return; } // The document consists of a single "tags" node with zero or more // "tag" child nodes. String sOtherTag = null; XmlNodeList oTagNodes = oXmlDocument.DocumentElement.SelectNodes( "tags/tag"); if (oTagNodes.Count > 0) { AppendVertexXmlNode(sTag, oGraphMLXmlDocument, oTagDictionary); } foreach (XmlNode oTagNode in oTagNodes) { sOtherTag = XmlUtil2.SelectRequiredSingleNodeAsString(oTagNode, "text()", null); if (bNeedToAppendVertices) { AppendVertexXmlNode(sOtherTag, oGraphMLXmlDocument, oTagDictionary); } if (bNeedToAppendVertices || oTagDictionary.ContainsKey(sOtherTag)) { oGraphMLXmlDocument.AppendEdgeXmlNode(sTag, sOtherTag); } } if (bNeedToRecurse) { foreach (XmlNode oTagNode in oTagNodes) { sOtherTag = XmlUtil2.SelectRequiredSingleNodeAsString(oTagNode, "text()", null); GetRelatedTagsRecursive(sOtherTag, eWhatToInclude, eNetworkLevel, sApiKey, 2, oGraphMLXmlDocument, oTagDictionary, oRequestStatistics); } } }
ParseKeyXmlNode ( XmlNode oKeyXmlNode, XmlNamespaceManager oXmlNamespaceManager, String sGraphMLPrefix ) { Debug.Assert(oKeyXmlNode != null); Debug.Assert(oXmlNamespaceManager != null); Debug.Assert(!String.IsNullOrEmpty(sGraphMLPrefix)); m_sID = XmlUtil2.SelectRequiredSingleNodeAsString(oKeyXmlNode, "@id", null); String sFor = XmlUtil2.SelectRequiredSingleNodeAsString(oKeyXmlNode, "@for", null); // Note that the @attr.name and @attr.type attributes are optional. // Default to sensible values if they are missing. if (!XmlUtil2.TrySelectSingleNodeAsString(oKeyXmlNode, "@attr.name", null, out m_sName)) { m_sName = m_sID; } String sType; if (!XmlUtil2.TrySelectSingleNodeAsString(oKeyXmlNode, "@attr.type", null, out sType)) { sType = "string"; } switch (sFor) { case "node": m_bIsForVertex = true; break; case "edge": m_bIsForVertex = false; break; // NodeXL doesn't support the "graph" or "all" values allowed by // the GraphML specification. The caller should filter out such // "key" XML nodes before using this class. default: throw new XmlException( "The \"for\" attribute on the \"key\" XML node with the" + " id \"" + m_sID + "\" must be either \"node\" or" + " \"edge\"." ); } switch (sType) { case "boolean": m_eType = AttributeType.Boolean; break; case "int": m_eType = AttributeType.Int; break; case "long": m_eType = AttributeType.Long; break; case "float": m_eType = AttributeType.Float; break; case "double": m_eType = AttributeType.Double; break; case "string": m_eType = AttributeType.String; break; default: throw new XmlException( "The \"attr.type\" attribute on the \"key\" XML node with" + " id \"" + m_sID + "\" does not have a valid value." ); } m_oDefaultAttributeValue = null; String sDefaultAttributeValue; XmlNode oDefaultXmlNode = oKeyXmlNode.SelectSingleNode( sGraphMLPrefix + ":default", oXmlNamespaceManager); if ( oDefaultXmlNode != null && XmlUtil2.TrySelectSingleNodeAsString(oDefaultXmlNode, "text()", null, out sDefaultAttributeValue) ) { try { m_oDefaultAttributeValue = ConvertAttributeValue(sDefaultAttributeValue); } catch (FormatException) { throw new XmlException( "The default value specified for the \"key\" XML node with" + " the id \"" + m_sID + "\" is not of the specified type." ); } } AssertValid(); }
GetGraphServerTwitterSearchNetworkConfiguration ( out String searchTerm, out Int32 startDateInDaysBeforeToday, out Int32 maximumStatusesGoingBackward, out Boolean expandStatusUrls, out String graphServerUserName, out String graphServerPassword, out String networkFileFolderPath ) { AssertValid(); Debug.Assert(m_oNetworkConfigurationXmlDocument != null); Debug.Assert(GetNetworkType() == NetworkType.GraphServerTwitterSearch); XmlNode oGraphServerTwitterSearchNetworkConfigurationNode = XmlUtil2.SelectRequiredSingleNode( m_oNetworkConfigurationXmlDocument, "/NetworkConfiguration/" + " GraphServerTwitterSearchNetworkConfiguration", null); searchTerm = XmlUtil2.SelectRequiredSingleNodeAsString( oGraphServerTwitterSearchNetworkConfigurationNode, "SearchTerm/text()", null); startDateInDaysBeforeToday = XmlUtil2.SelectRequiredSingleNodeAsInt32( oGraphServerTwitterSearchNetworkConfigurationNode, "StartDateInDaysBeforeToday/text()", null); if (startDateInDaysBeforeToday < 0) { throw new XmlException( "The StartDateInDaysBeforeToday value can't be less than 0." ); } maximumStatusesGoingBackward = XmlUtil2.SelectRequiredSingleNodeAsInt32( oGraphServerTwitterSearchNetworkConfigurationNode, "MaximumStatusesGoingBackward/text()", null); if (maximumStatusesGoingBackward < 1) { throw new XmlException( "The MaximumStatusesGoingBackward value can't be less than 1." ); } expandStatusUrls = XmlUtil2.SelectRequiredSingleNodeAsBoolean( oGraphServerTwitterSearchNetworkConfigurationNode, "ExpandStatusUrls/text()", null); graphServerUserName = XmlUtil2.SelectRequiredSingleNodeAsString( oGraphServerTwitterSearchNetworkConfigurationNode, "GraphServerUserName/text()", null); graphServerPassword = XmlUtil2.SelectRequiredSingleNodeAsString( oGraphServerTwitterSearchNetworkConfigurationNode, "GraphServerPassword/text()", null); GetCommonConfiguration( oGraphServerTwitterSearchNetworkConfigurationNode, out networkFileFolderPath); }
GetTwitterSearchNetworkConfiguration ( out String searchTerm, out TwitterSearchNetworkAnalyzer.WhatToInclude whatToInclude, out Int32 maximumStatuses, out String networkFileFolderPath ) { AssertValid(); Debug.Assert(m_oNetworkConfigurationXmlDocument != null); Debug.Assert(GetNetworkType() == NetworkType.TwitterSearch); XmlNode oTwitterSearchNetworkConfigurationNode = XmlUtil2.SelectRequiredSingleNode( m_oNetworkConfigurationXmlDocument, "/NetworkConfiguration/TwitterSearchNetworkConfiguration", null); searchTerm = XmlUtil2.SelectRequiredSingleNodeAsString( oTwitterSearchNetworkConfigurationNode, "SearchTerm/text()", null); if (!XmlUtil2.TrySelectSingleNodeAsInt32( oTwitterSearchNetworkConfigurationNode, "MaximumStatuses/text()", null, out maximumStatuses)) { // Older versions of NodeXL used a MaximumPeoplePerRequest value, // which has been replaced with MaximumStatuses. To avoid breaking // older configuration files, accept either one. try { maximumStatuses = XmlUtil2.SelectRequiredSingleNodeAsInt32( oTwitterSearchNetworkConfigurationNode, "MaximumPeoplePerRequest/text()", null); } catch { throw new XmlException( "There must be a MaximumStatuses value. (This was called" + " MaximumPeoplePerRequest in previous versions of" + " NodeXL.)" ); } } whatToInclude = GetRequiredEnumValue <TwitterSearchNetworkAnalyzer.WhatToInclude>( oTwitterSearchNetworkConfigurationNode, "WhatToInclude/text()", // These WhatToInclude values were removed in version // 1.0.1.328. They are now automatically included in the // network. Old configuration files might still specify them, // so they need to be ignored. new String[] { "Statuses", "Statistics", "RepliesToEdges", "MentionsEdges", "NonRepliesToNonMentionsEdges", }, "None", "WhatToInclude" ); GetCommonConfiguration(oTwitterSearchNetworkConfigurationNode, out networkFileFolderPath); }