GetTwitterSearchNetworkConfiguration ( out String searchTerm, out TwitterSearchNetworkAnalyzer.WhatToInclude whatToInclude, out Int32 maximumPeoplePerRequest, out String networkFileFolderPath, out NetworkFileFormats networkFileFormats, out Boolean automateNodeXLWorkbook ) { 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); whatToInclude = GetRequiredEnumValue <TwitterSearchNetworkAnalyzer.WhatToInclude>( oTwitterSearchNetworkConfigurationNode, "WhatToInclude/text()", "WhatToInclude"); GetTwitterCommonConfiguration(oTwitterSearchNetworkConfigurationNode, out maximumPeoplePerRequest, out networkFileFolderPath, out networkFileFormats, out automateNodeXLWorkbook); }
LoadGraphCore ( Stream stream ) { Debug.Assert(stream != null); AssertValid(); XmlDocument oXmlDocument = new XmlDocument(); oXmlDocument.Load(stream); XmlNamespaceManager oXmlNamespaceManager = new XmlNamespaceManager( oXmlDocument.NameTable); oXmlNamespaceManager.AddNamespace(GraphMLPrefix, GraphMLUri); XmlNode oGraphMLXmlNode = oXmlDocument.DocumentElement; XmlNode oGraphXmlNode = XmlUtil2.SelectRequiredSingleNode( oGraphMLXmlNode, GraphMLPrefix + ":graph", oXmlNamespaceManager); // Parse the vertex and edge attribute definitions. // // The key is the id attribute of a "key" XML node, and the value is // the corresponding GraphMLAttribute object. Dictionary <String, GraphMLAttribute> oGraphMLAttributeDictionary = ParseGraphMLAttributeDefinitions(oGraphMLXmlNode, oXmlNamespaceManager); GraphDirectedness eGraphDirectedness = GetGraphDirectedness(oGraphXmlNode); IGraph oGraph = new Graph(eGraphDirectedness); // The key is the id attribute of the "node" XML node, and the value is // the corresponding IVertex. Dictionary <String, IVertex> oVertexDictionary = ParseVertices(oGraph, oGraphXmlNode, oXmlNamespaceManager, oGraphMLAttributeDictionary); ParseEdges(oGraph, oGraphXmlNode, oXmlNamespaceManager, oVertexDictionary, oGraphMLAttributeDictionary); SaveGraphMLAttributeNames(oGraph, oGraphMLAttributeDictionary); return(oGraph); }
OnNetworkObtained ( XmlDocument oGraphMLXmlDocument, RequestStatistics oRequestStatistics, String sNetworkDescription, String sNetworkTitle, String sPartialFileName ) { Debug.Assert(oGraphMLXmlDocument != null); Debug.Assert(oRequestStatistics != null); Debug.Assert(!String.IsNullOrEmpty(sNetworkDescription)); Debug.Assert(!String.IsNullOrEmpty(sNetworkTitle)); Debug.Assert(!String.IsNullOrEmpty(sPartialFileName)); AssertValid(); XmlNode oGraphXmlNode = XmlUtil2.SelectRequiredSingleNode( oGraphMLXmlDocument, "g:graphml/g:graph", GraphMLXmlDocument.CreateXmlNamespaceManager( oGraphMLXmlDocument, "g") ); XmlUtil2.SetAttributes(oGraphXmlNode, "description", sNetworkDescription); XmlUtil2.SetAttributes(oGraphXmlNode, "suggestedTitle", sNetworkTitle); String sSuggestedFileNameNoExtension = String.Format( "{0} NodeXL {1}" , DateTimeUtil2.ToCultureInvariantFileName( oRequestStatistics.StartTimeUtc), sPartialFileName ); XmlUtil2.SetAttributes(oGraphXmlNode, "suggestedFileNameNoExtension", sSuggestedFileNameNoExtension); if (oRequestStatistics.UnexpectedExceptions > 0) { // The network is partial. throw new PartialNetworkException(oGraphMLXmlDocument, oRequestStatistics); } }
LoadGraphCore ( Stream stream ) { Debug.Assert(stream != null); AssertValid(); XmlDocument oXmlDocument = new XmlDocument(); if (stream.Position > 0) { stream.Position = 0; } string fileName; //Code from: http://msdn.microsoft.com/en-us/library/system.io.stream.read%28v=vs.110%29.aspx byte[] buffer; { int length = (int)stream.Length; // get file length buffer = new byte[length]; // create buffer int count; // actual number of bytes read int sum = 0; // total number of bytes read // read until Read method returns 0 (end of the stream has been reached) while ((count = stream.Read(buffer, sum, length - sum)) > 0) { sum += count; // sum is a buffer offset for next reading } fileName = System.Text.Encoding.UTF8.GetString(buffer); fileName = fileName.Replace(System.Environment.NewLine, ""); } oXmlDocument.Load(fileName); XmlNamespaceManager oXmlNamespaceManager = new XmlNamespaceManager( oXmlDocument.NameTable); oXmlNamespaceManager.AddNamespace(GraphMLPrefix, GraphMLNamespaceUri); XmlNode oGraphMLXmlNode = oXmlDocument.DocumentElement; XmlNode oGraphXmlNode = XmlUtil2.SelectRequiredSingleNode( oGraphMLXmlNode, GraphMLPrefix + ":graph", oXmlNamespaceManager); // Parse the vertex and edge attribute definitions. // // The key is the id attribute of a "key" XML node, and the value is // the corresponding GraphMLAttribute object. Dictionary <String, GraphMLAttribute> oGraphMLAttributeDictionary = ParseGraphMLAttributeDefinitions(oGraphMLXmlNode, oXmlNamespaceManager); GraphDirectedness eGraphDirectedness = GetGraphDirectedness(oGraphXmlNode); IGraph oGraph = new Graph(eGraphDirectedness); // The key is the id attribute of the "node" XML node, and the value is // the corresponding IVertex. Dictionary <String, IVertex> oVertexDictionary = ParseVertices(oGraph, oGraphXmlNode, oXmlNamespaceManager, oGraphMLAttributeDictionary); ParseEdges(oGraph, oGraphXmlNode, oXmlNamespaceManager, oVertexDictionary, oGraphMLAttributeDictionary); ParseGraphAttribute(oGraph, oGraphXmlNode, "description", ReservedMetadataKeys.GraphDescription); ParseGraphAttribute(oGraph, oGraphXmlNode, "suggestedTitle", ReservedMetadataKeys.SuggestedTitle); ParseGraphAttribute(oGraph, oGraphXmlNode, "suggestedFileNameNoExtension", ReservedMetadataKeys.SuggestedFileNameNoExtension); SaveGraphMLAttributeNames(oGraph, oGraphMLAttributeDictionary); return(oGraph); }
CopyAndFilterSettings ( String sSourceSettings, String sDestinationSettings ) { Debug.Assert(!String.IsNullOrEmpty(sSourceSettings)); Debug.Assert(!String.IsNullOrEmpty(sDestinationSettings)); AssertValid(); // We don't want to modify the user's notification, dialog position, // or password settings that are stored in the destination. Use // XmlDocuments to copy only the other settings from the source to the // destination. XmlDocument oSourceDocument = new XmlDocument(); oSourceDocument.LoadXml(sSourceSettings); XmlDocument oDestinationDocument = new XmlDocument(); oDestinationDocument.LoadXml(sDestinationSettings); // See the DefaultStandardSettingsFileContents constant for an example // of what the XML documents look like. const String SectionGroupXPath = "configuration/configSections/sectionGroup"; const String UserSettingsXPath = "configuration/userSettings"; XmlNode oSourceSectionGroupNode = XmlUtil2.SelectRequiredSingleNode(oSourceDocument, SectionGroupXPath, null); XmlNode oDestinationSectionGroupNode = XmlUtil2.SelectRequiredSingleNode(oDestinationDocument, SectionGroupXPath, null); XmlNode oSourceUserSettingsNode = XmlUtil2.SelectRequiredSingleNode(oSourceDocument, UserSettingsXPath, null); XmlNode oDestinationUserSettingsNode = XmlUtil2.SelectRequiredSingleNode(oDestinationDocument, UserSettingsXPath, null); foreach (XmlNode oSourceUserSettingsChildNode in oSourceUserSettingsNode.ChildNodes) { // Work item: // // Figure out a more robust scheme that doesn't use hard-coded // class names. String sChildName = oSourceUserSettingsChildNode.Name; if ( sChildName.IndexOf("Dialog") >= 0 || sChildName.IndexOf("NotificationUserSettings") >= 0 || sChildName.IndexOf("PasswordUserSettings") >= 0 ) { continue; } // This user settings child node needs to be copied from the source // to the destination. XmlNode oSourceUserSettingsChildNodeClone = oDestinationDocument.ImportNode( oSourceUserSettingsChildNode, true); // Does the node already exist in the destination? XmlNode oDestinationUserSettingsChildNode = oDestinationUserSettingsNode.SelectSingleNode(sChildName); if (oDestinationUserSettingsChildNode == null) { // No. Append the node and its corresponding section child // node to the destination. oDestinationUserSettingsNode.AppendChild( oSourceUserSettingsChildNodeClone); XmlNode oSourceSectionNode = XmlUtil2.SelectRequiredSingleNode( oSourceSectionGroupNode, "section[@name=\"" + sChildName + "\"]", null); oDestinationSectionGroupNode.AppendChild( oDestinationDocument.ImportNode( oSourceSectionNode, true)); } else { // Yes. Replace the destination node. oDestinationUserSettingsNode.ReplaceChild( oSourceUserSettingsChildNodeClone, oDestinationUserSettingsChildNode); } } // Write the edited copy to a string in such a way that it includes a // UTF-8 encoding attribute. oSourceDocument = null; MemoryStream oMemoryStream = new MemoryStream(); oDestinationDocument.Save(oMemoryStream); oDestinationDocument = null; return(Encoding.UTF8.GetString(oMemoryStream.ToArray())); }
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); }