Exemple #1
0
        SaveNetwork
        (
            DateTime oStartTime,
            XmlDocument oXmlDocument,
            String sNetworkConfigurationFilePath,
            String sNetworkFileFolderPath,
            NetworkFileFormats eNetworkFileFormats,
            Boolean bAutomateNodeXLWorkbook
        )
        {
            Debug.Assert(oXmlDocument != null);
            Debug.Assert(!String.IsNullOrEmpty(sNetworkConfigurationFilePath));
            Debug.Assert(!String.IsNullOrEmpty(sNetworkFileFolderPath));

            if ((eNetworkFileFormats & NetworkFileFormats.GraphML)
                != NetworkFileFormats.None)
            {
                SaveNetworkToGraphML(oStartTime, oXmlDocument,
                                     sNetworkConfigurationFilePath, sNetworkFileFolderPath);
            }

            if ((eNetworkFileFormats & NetworkFileFormats.NodeXLWorkbook)
                != NetworkFileFormats.None)
            {
                SaveNetworkToNodeXLWorkbook(oStartTime, oXmlDocument,
                                            sNetworkConfigurationFilePath, sNetworkFileFolderPath,
                                            bAutomateNodeXLWorkbook);
            }
        }
        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);
        }
        GetTwitterCommonConfiguration
        (
            XmlNode oParentNode,
            out Int32 iMaximumPeoplePerRequest,
            out String sNetworkFileFolderPath,
            out NetworkFileFormats eNetworkFileFormats,
            out Boolean bAutomateNodeXLWorkbook
        )
        {
            Debug.Assert(oParentNode != null);
            AssertValid();

            String sMaximumPeoplePerRequest;

            iMaximumPeoplePerRequest = Int32.MaxValue;

            if (XmlUtil2.TrySelectSingleNodeAsString(oParentNode,
                                                     "MaximumPeoplePerRequest/text()", null,
                                                     out sMaximumPeoplePerRequest))
            {
                if (!Int32.TryParse(sMaximumPeoplePerRequest,
                                    out iMaximumPeoplePerRequest))
                {
                    throw new XmlException(
                              "The MaximumPeoplePerRequest value is not valid."
                              );
                }
            }

            sNetworkFileFolderPath = XmlUtil2.SelectRequiredSingleNodeAsString(
                oParentNode, "NetworkFileFolder/text()", null);

            eNetworkFileFormats = GetRequiredEnumValue <NetworkFileFormats>(
                oParentNode, "NetworkFileFormats/text()", "NetworkFileFormats");

            // The AutomateNodeXLWorkbook node was added in a later version of the
            // program, so it is not required.

            if (!XmlUtil2.TrySelectSingleNodeAsBoolean(
                    oParentNode, "AutomateNodeXLWorkbook/text()", null,
                    out bAutomateNodeXLWorkbook))
            {
                bAutomateNodeXLWorkbook = false;
            }
        }
Exemple #4
0
        RunProgram
        (
            string[] args
        )
        {
            String sNetworkConfigurationFilePath;

            ParseCommandLine(args, out sNetworkConfigurationFilePath);

            NetworkConfigurationFileParser oNetworkConfigurationFileParser =
                new NetworkConfigurationFileParser();

            NetworkType eNetworkType = NetworkType.TwitterSearch;

            try
            {
                oNetworkConfigurationFileParser.OpenNetworkConfigurationFile(
                    sNetworkConfigurationFilePath);

                eNetworkType = oNetworkConfigurationFileParser.GetNetworkType();
            }
            catch (XmlException oXmlException)
            {
                OnNetworkConfigurationFileException(oXmlException);
            }

            XmlDocument        oXmlDocument            = null;
            String             sNetworkFileFolderPath  = null;
            DateTime           oStartTime              = DateTime.Now;
            NetworkFileFormats eNetworkFileFormats     = NetworkFileFormats.None;
            Boolean            bAutomateNodeXLWorkbook = false;

            switch (eNetworkType)
            {
            case NetworkType.TwitterSearch:

                GetTwitterSearchNetwork(oStartTime,
                                        sNetworkConfigurationFilePath,
                                        oNetworkConfigurationFileParser, out oXmlDocument,
                                        out sNetworkFileFolderPath, out eNetworkFileFormats,
                                        out bAutomateNodeXLWorkbook);

                break;

            case NetworkType.TwitterUser:

                GetTwitterUserNetwork(oStartTime,
                                      sNetworkConfigurationFilePath,
                                      oNetworkConfigurationFileParser, out oXmlDocument,
                                      out sNetworkFileFolderPath, out eNetworkFileFormats,
                                      out bAutomateNodeXLWorkbook);

                break;

            default:

                Debug.Assert(false);
                break;
            }

            Debug.Assert(oXmlDocument != null);

            SaveNetwork(oStartTime, oXmlDocument, sNetworkConfigurationFilePath,
                        sNetworkFileFolderPath, eNetworkFileFormats,
                        bAutomateNodeXLWorkbook);

            Exit(ExitCode.Success, null);
        }
Exemple #5
0
        GetTwitterUserNetwork
        (
            DateTime oStartTime,
            String sNetworkConfigurationFilePath,
            NetworkConfigurationFileParser oNetworkConfigurationFileParser,
            out XmlDocument oXmlDocument,
            out String sNetworkFileFolderPath,
            out NetworkFileFormats eNetworkFileFormats,
            out Boolean bAutomateNodeXLWorkbook
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(sNetworkConfigurationFilePath));
            Debug.Assert(oNetworkConfigurationFileParser != null);

            oXmlDocument            = null;
            sNetworkFileFolderPath  = null;
            eNetworkFileFormats     = NetworkFileFormats.None;
            bAutomateNodeXLWorkbook = false;

            String sScreenNameToAnalyze = null;

            TwitterUserNetworkAnalyzer.WhatToInclude eWhatToInclude =
                TwitterUserNetworkAnalyzer.WhatToInclude.None;

            NetworkLevel eNetworkLevel            = NetworkLevel.One;
            Int32        iMaximumPeoplePerRequest = Int32.MaxValue;

            try
            {
                oNetworkConfigurationFileParser.GetTwitterUserNetworkConfiguration(
                    out sScreenNameToAnalyze, out eWhatToInclude,
                    out eNetworkLevel, out iMaximumPeoplePerRequest,
                    out sNetworkFileFolderPath, out eNetworkFileFormats,
                    out bAutomateNodeXLWorkbook);
            }
            catch (XmlException oXmlException)
            {
                // (This call exits the program.)

                OnNetworkConfigurationFileException(oXmlException);
            }

            TwitterUserNetworkAnalyzer oTwitterUserNetworkAnalyzer =
                new TwitterUserNetworkAnalyzer();

            oTwitterUserNetworkAnalyzer.ProgressChanged +=
                new ProgressChangedEventHandler(
                    HttpNetworkAnalyzer_ProgressChanged);

            Console.WriteLine(
                "Getting the Twitter User network specified in \"{0}\".  The"
                + " screen name is \"{1}\"."
                ,
                sNetworkConfigurationFilePath,
                sScreenNameToAnalyze
                );

            try
            {
                oXmlDocument = oTwitterUserNetworkAnalyzer.GetNetwork(
                    sScreenNameToAnalyze, eWhatToInclude, eNetworkLevel,
                    iMaximumPeoplePerRequest);
            }
            catch (PartialNetworkException oPartialNetworkException)
            {
                oXmlDocument = OnGetNetworkPartialNetworkException(oStartTime,
                                                                   oPartialNetworkException, sNetworkConfigurationFilePath,
                                                                   sNetworkFileFolderPath, oTwitterUserNetworkAnalyzer);
            }
            catch (Exception oException)
            {
                // (This call exits the program.)

                OnGetNetworkOtherException(oStartTime, oException,
                                           sNetworkConfigurationFilePath, sNetworkFileFolderPath,
                                           oTwitterUserNetworkAnalyzer);
            }
        }
    SaveNetwork
    (
        DateTime oStartTime,
        XmlDocument oXmlDocument,
        String sNetworkConfigurationFilePath,
        String sNetworkFileFolderPath,
        NetworkFileFormats eNetworkFileFormats,
        String sNodeXLWorkbookSettingsFilePath,
        Boolean bAutomateNodeXLWorkbook
    )
    {
        Debug.Assert(oXmlDocument != null);
        Debug.Assert( !String.IsNullOrEmpty(sNetworkConfigurationFilePath) );
        Debug.Assert( !String.IsNullOrEmpty(sNetworkFileFolderPath) );

        if ( (eNetworkFileFormats & NetworkFileFormats.GraphML)
            != NetworkFileFormats.None )
        {
            SaveNetworkToGraphML(oStartTime, oXmlDocument,
                sNetworkConfigurationFilePath, sNetworkFileFolderPath);
        }

        if ( (eNetworkFileFormats & NetworkFileFormats.NodeXLWorkbook)
            != NetworkFileFormats.None )
        {
            SaveNetworkToNodeXLWorkbook(oStartTime, oXmlDocument,
                sNetworkConfigurationFilePath, sNetworkFileFolderPath,
                sNodeXLWorkbookSettingsFilePath, bAutomateNodeXLWorkbook);
        }
    }
    GetTwitterListNetwork
    (
        DateTime oStartTime,
        String sNetworkConfigurationFilePath,
        NetworkConfigurationFileParser oNetworkConfigurationFileParser,
        out XmlDocument oXmlDocument,
        out String sNetworkFileFolderPath,
        out NetworkFileFormats eNetworkFileFormats,
        out String sNodeXLWorkbookSettingsFilePath,
        out Boolean bAutomateNodeXLWorkbook
    )
    {
        Debug.Assert( !String.IsNullOrEmpty(sNetworkConfigurationFilePath) );
        Debug.Assert(oNetworkConfigurationFileParser != null);

        oXmlDocument = null;
        sNetworkFileFolderPath = null;
        eNetworkFileFormats = NetworkFileFormats.None;
        sNodeXLWorkbookSettingsFilePath = null;
        bAutomateNodeXLWorkbook = false;

        Boolean bUseListName = false;
        String sListName = null;
        ICollection<String> oScreenNames = null;

        TwitterListNetworkAnalyzer.WhatToInclude eWhatToInclude =
            TwitterListNetworkAnalyzer.WhatToInclude.None;

        try
        {
            oNetworkConfigurationFileParser.GetTwitterListNetworkConfiguration(
                out bUseListName, out sListName, out oScreenNames,
                out eWhatToInclude, out sNetworkFileFolderPath,
                out eNetworkFileFormats, out sNodeXLWorkbookSettingsFilePath,
                out bAutomateNodeXLWorkbook);
        }
        catch (XmlException oXmlException)
        {
            // (This call exits the program.)

            OnNetworkConfigurationFileException(oXmlException);
        }

        TwitterListNetworkAnalyzer oTwitterListNetworkAnalyzer =
            new TwitterListNetworkAnalyzer();

        oTwitterListNetworkAnalyzer.ProgressChanged +=
            new ProgressChangedEventHandler(
                HttpNetworkAnalyzer_ProgressChanged);

        Console.WriteLine(
            "Getting the Twitter List network specified in \"{0}\"."
            ,
            sNetworkConfigurationFilePath
            );

        try
        {
            oXmlDocument = oTwitterListNetworkAnalyzer.GetNetwork(bUseListName,
                sListName, oScreenNames, eWhatToInclude);
        }
        catch (PartialNetworkException oPartialNetworkException)
        {
            oXmlDocument = OnGetNetworkPartialNetworkException(oStartTime,
                oPartialNetworkException, sNetworkConfigurationFilePath,
                sNetworkFileFolderPath, oTwitterListNetworkAnalyzer);
        }
        catch (Exception oException)
        {
            // (This call exits the program.)

            OnGetNetworkOtherException(oStartTime, oException,
                sNetworkConfigurationFilePath, sNetworkFileFolderPath,
                oTwitterListNetworkAnalyzer);
        }
    }
    GetTwitterUserNetwork
    (
        DateTime oStartTime,
        String sNetworkConfigurationFilePath,
        NetworkConfigurationFileParser oNetworkConfigurationFileParser,
        out XmlDocument oXmlDocument,
        out String sNetworkFileFolderPath,
        out NetworkFileFormats eNetworkFileFormats,
        out String sNodeXLWorkbookSettingsFilePath,
        out Boolean bAutomateNodeXLWorkbook
    )
    {
        Debug.Assert( !String.IsNullOrEmpty(sNetworkConfigurationFilePath) );
        Debug.Assert(oNetworkConfigurationFileParser != null);

        oXmlDocument = null;
        sNetworkFileFolderPath = null;
        eNetworkFileFormats = NetworkFileFormats.None;
        sNodeXLWorkbookSettingsFilePath = null;
        bAutomateNodeXLWorkbook = false;

        String sScreenNameToAnalyze = null;

        TwitterUserNetworkAnalyzer.WhatToInclude eWhatToInclude =
            TwitterUserNetworkAnalyzer.WhatToInclude.None;

        NetworkLevel eNetworkLevel = NetworkLevel.One;
        Int32 iMaximumPeoplePerRequest = Int32.MaxValue;

        try
        {
            oNetworkConfigurationFileParser.GetTwitterUserNetworkConfiguration(
                out sScreenNameToAnalyze, out eWhatToInclude,
                out eNetworkLevel, out iMaximumPeoplePerRequest,
                out sNetworkFileFolderPath, out eNetworkFileFormats,
                out sNodeXLWorkbookSettingsFilePath,
                out bAutomateNodeXLWorkbook);
        }
        catch (XmlException oXmlException)
        {
            // (This call exits the program.)

            OnNetworkConfigurationFileException(oXmlException);
        }

        TwitterUserNetworkAnalyzer oTwitterUserNetworkAnalyzer =
            new TwitterUserNetworkAnalyzer();

        oTwitterUserNetworkAnalyzer.ProgressChanged +=
            new ProgressChangedEventHandler(
                HttpNetworkAnalyzer_ProgressChanged);

        Console.WriteLine(
            "Getting the Twitter User network specified in \"{0}\".  The"
            + " screen name is \"{1}\"."
            ,
            sNetworkConfigurationFilePath,
            sScreenNameToAnalyze
            );

        try
        {
            oXmlDocument = oTwitterUserNetworkAnalyzer.GetNetwork(
                sScreenNameToAnalyze, eWhatToInclude, eNetworkLevel,
                iMaximumPeoplePerRequest);
        }
        catch (PartialNetworkException oPartialNetworkException)
        {
            oXmlDocument = OnGetNetworkPartialNetworkException(oStartTime,
                oPartialNetworkException, sNetworkConfigurationFilePath,
                sNetworkFileFolderPath, oTwitterUserNetworkAnalyzer);
        }
        catch (Exception oException)
        {
            // (This call exits the program.)

            OnGetNetworkOtherException(oStartTime, oException,
                sNetworkConfigurationFilePath, sNetworkFileFolderPath,
                oTwitterUserNetworkAnalyzer);
        }
    }