Example #1
0
        GetNetworkInternal
        (
            StatusCriteria oStatusCriteria,
            Boolean bExpandStatusUrls,
            String sGraphServerUserName,
            String sGraphServerPassword,
            RequestStatistics oRequestStatistics
        )
        {
            Debug.Assert(oStatusCriteria != null);
            Debug.Assert(!String.IsNullOrEmpty(sGraphServerUserName));
            Debug.Assert(!String.IsNullOrEmpty(sGraphServerPassword));
            Debug.Assert(oRequestStatistics != null);
            AssertValid();

            GraphServiceClient oClient = new GraphServiceClient(
                GetWcfServiceBinding(), new EndpointAddress(GraphServiceUrl));

            Byte [] abtZippedGraphML;

            // There are two ways to get the network: With a maximum status date,
            // and with a maximum number of statuses.

            if (oStatusCriteria.HasDateRange)
            {
                abtZippedGraphML = oClient.GetTwitterSearchNetworkAsZippedGraphML(
                    oStatusCriteria.SearchTerm,
                    oStatusCriteria.MinimumStatusDateUtc,
                    oStatusCriteria.MaximumStatusDateUtc,
                    bExpandStatusUrls,
                    sGraphServerUserName,
                    sGraphServerPassword
                    );
            }
            else
            {
                abtZippedGraphML = oClient.GetTwitterSearchNetworkAsZippedGraphML2(
                    oStatusCriteria.SearchTerm,
                    oStatusCriteria.MaximumStatusDateUtc,
                    oStatusCriteria.MaximumStatusesGoingBackward,
                    bExpandStatusUrls,
                    sGraphServerUserName,
                    sGraphServerPassword
                    );
            }

            String sGraphML = ZipUtil.UnzipOneTextFile(abtZippedGraphML);

            abtZippedGraphML = null;

            XmlDocument oXmlDocument = new XmlDocument();

            // Note: When the DotNetZip library used by ZipUtil unzips the GraphML,
            // it includes a BOM as the first character.  Remove that character.

            oXmlDocument.LoadXml(sGraphML.Substring(1));

            return(oXmlDocument);
        }
Example #2
0
        GetNetworkInternal
        (
            StatusCriteria oStatusCriteria,
            Boolean bExpandStatusUrls,
            String sGraphServerUserName,
            String sGraphServerPassword
        )
        {
            Debug.Assert(oStatusCriteria != null);
            Debug.Assert(!String.IsNullOrEmpty(sGraphServerUserName));
            Debug.Assert(!String.IsNullOrEmpty(sGraphServerPassword));
            AssertValid();

            XmlDocument       oGraphMLXmlDocument = null;
            RequestStatistics oRequestStatistics  = new RequestStatistics();

            try
            {
                oGraphMLXmlDocument = GetNetworkInternal(
                    oStatusCriteria, bExpandStatusUrls, sGraphServerUserName,
                    sGraphServerPassword, oRequestStatistics);
            }
            catch (Exception oException)
            {
                OnUnexpectedException(oException, new XmlDocument(),
                                      oRequestStatistics);
            }

            OnNetworkObtained(oGraphMLXmlDocument, oRequestStatistics,

                              GetNetworkDescription(oStatusCriteria, oGraphMLXmlDocument),

                              SnaTitleCreator.CreateSnaTitle(
                                  oStatusCriteria.SearchTerm,
                                  oRequestStatistics),

                              "Graph Server " + oStatusCriteria.SearchTerm
                              );

            return(oGraphMLXmlDocument);
        }
Example #3
0
        GetNetwork
        (
            String searchTerm,
            DateTime maximumStatusDateUtc,
            Int32 maximumStatusesGoingBackward,
            Boolean expandStatusUrls,
            String graphServerUserName,
            String graphServerPassword
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(searchTerm));
            Debug.Assert(maximumStatusesGoingBackward > 0);
            Debug.Assert(!String.IsNullOrEmpty(graphServerUserName));
            Debug.Assert(!String.IsNullOrEmpty(graphServerPassword));
            AssertValid();

            StatusCriteria oStatusCriteria = new StatusCriteria(
                searchTerm, maximumStatusDateUtc, maximumStatusesGoingBackward);

            return(GetNetworkInternal(oStatusCriteria, expandStatusUrls,
                                      graphServerUserName, graphServerPassword));
        }
Example #4
0
        GetNetworkDescription
        (
            StatusCriteria oStatusCriteria,
            XmlDocument oGraphMLXmlDocument
        )
        {
            Debug.Assert(oStatusCriteria != null);
            Debug.Assert(oGraphMLXmlDocument != null);
            AssertValid();

            const String Int32FormatString = "N0";

            NetworkDescriber oNetworkDescriber = new NetworkDescriber();

            Int32 iVertexCount = GetVertexCount(oGraphMLXmlDocument);

            oNetworkDescriber.AddSentence(

                "The graph represents a network of {0} Twitter {1} whose tweets in"
                + " the requested range contained \"{2}\", or who {3} replied to"
                + " or mentioned in those tweets."
                ,
                iVertexCount.ToString(Int32FormatString),
                StringUtil.MakePlural("user", iVertexCount),
                oStatusCriteria.SearchTerm,
                iVertexCount > 1 ? "were" : "was"
                );

            oNetworkDescriber.AddNetworkTime(NetworkSource);

            if (oStatusCriteria.HasDateRange)
            {
                oNetworkDescriber.AddSentenceNewParagraph(

                    "The requested date range was from {0} through {1}."
                    ,
                    oNetworkDescriber.FormatEventTime(
                        oStatusCriteria.MinimumStatusDateUtc),

                    oNetworkDescriber.FormatEventTime(
                        oStatusCriteria.MaximumStatusDateUtc)
                    );
            }
            else
            {
                oNetworkDescriber.AddSentenceNewParagraph(

                    "The requested start date was {0} and the maximum number of"
                    + " tweets (going backward in time) was {1}."
                    ,
                    oNetworkDescriber.FormatEventTime(
                        oStatusCriteria.MaximumStatusDateUtc),

                    oStatusCriteria.MaximumStatusesGoingBackward.ToString(
                        Int32FormatString)
                    );
            }

            oNetworkDescriber.StartNewParagraph();

            TweetDateRangeAnalyzer.AddTweetDateRangeToNetworkDescription(
                oGraphMLXmlDocument, oNetworkDescriber);

            oNetworkDescriber.AddSentenceNewParagraph(
                "There is an edge for each \"replies-to\" relationship in a tweet,"
                + " an edge for each \"mentions\" relationship in a tweet, and a"
                + " self-loop edge for each tweet that is not a \"replies-to\" or"
                + " \"mentions\"."
                );

            return(oNetworkDescriber.ConcatenateSentences());
        }