public static void AddTweetToGraph(Message msg, Source src)
 {
     using (var context = new HelloWorldExample("bolt://localhost:7687", "neo4j", "localneo4j"))
     {
         context.AddTweet(msg, src);
     }
 }
        public static async Task SingleStatusQueryAsync(TwitterContext twitterCtx)
        {
            _twitterCtx = twitterCtx;


            // ulong tweetID = 806571633754284032;

            //Random gen = new Random();
            //DateTime randomDate = new DateTime(2018, 1, 1);
            //int range = (DateTime.Today - randomDate).Days;
            //randomDate = randomDate.AddDays(gen.Next(range));

            var searchResponse =
                await
                    (from search in twitterCtx.Search
                    where search.Type == SearchType.Search &&
                    search.IncludeEntities == true &&
                    search.ResultType == ResultType.Mixed &&
                    search.TweetMode == TweetMode.Extended &&
                    search.SearchLanguage == "en" &&
                    search.Count == 25 &&
                    search.Query == "\"a\""   // &&
                    //          search.Until == randomDate
                    select search)
                .SingleOrDefaultAsync();

            foreach (var t in searchResponse.Statuses)
            {
                if (t != null && t.User != null)
                {
                    MessageBox.Show(String.Format(
                                        "User: {0}, \nTweet: {1}",
                                        t.User.ScreenNameResponse,
                                        t.FullText.StripHTMLandURLs()), "Tweet status"
                                    , MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                }

                //ADD to graph
                var message = new Message()
                {
                    ID            = (long)t.StatusID,
                    Text          = t.FullText.StripHTMLandURLs(),
                    RetweetCount  = t.RetweetCount,
                    FavoriteCount = t.FavoriteCount ?? 0
                };
                HelloWorldExample.AddTweetToGraph(message, twitter);
                await GetTweetHistoryUpwardsAsync(t);
            }
        }
        public static async Task GetTweetHistoryUpwardsAsync(Status status)
        {
            if (status.InReplyToStatusID != 0)
            {
                var searchResponse =
                    await
                        (from search in _twitterCtx.Status
                        where search.Type == StatusType.Show &&
                        search.ID == status.InReplyToStatusID &&
                        search.IncludeEntities == true &&
                        search.IncludeAltText == true &&
                        search.TweetMode == TweetMode.Extended
                        select search)
                    .SingleOrDefaultAsync();

                MessageBox.Show(String.Format(
                                    "User: {0}, \n\nTweet:\n\t {1}",
                                    searchResponse.User.ScreenNameResponse,
                                    searchResponse.FullText.StripHTMLandURLs()), "Tweet status",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);

                var msg1 = new Message()
                {
                    ID            = (long)status.StatusID,
                    Text          = status.FullText.StripHTMLandURLs(),
                    RetweetCount  = status.RetweetCount,
                    FavoriteCount = status.FavoriteCount ?? 0
                };

                var msg2 = new Message()
                {
                    ID            = (long)searchResponse.StatusID,
                    Text          = searchResponse.FullText.StripHTMLandURLs(),
                    RetweetCount  = searchResponse.RetweetCount,
                    FavoriteCount = searchResponse.FavoriteCount ?? 0
                };

                HelloWorldExample.AddTweetRelation(msg1, msg2, twitter);

                await GetTweetHistoryUpwardsAsync(searchResponse);
            }
            else
            {
                return;
            }
        }
 public static void AddTweetRelation(Message msg1, Message msg2, Source src)
 {
     using (var context = new HelloWorldExample("bolt://localhost:7687", "neo4j", "localneo4j"))
     {
         using (var session = context._driver.Session())
         {//TODO: MERGE (s:SOURCE {name: $src.Name})
             session.WriteTransaction(tx =>
             {
                 tx.Run("MATCH (m1:MESSAGE {id: $msg1.ID}) " +
                        "MERGE(s: SOURCE { name: $src.Name})" +
                        "CREATE (m2:MESSAGE:RAW {id:$msg2.ID, text:$msg2.Text, favoriteCount:$msg2.FavoriteCount, retweetCount:$msg2.RetweetCount, loaded:$timestamp}) " +
                        "CREATE (m2)-[from:FROM]->(s) " +
                        "CREATE (m1)-[r:PRECEDES]->(m2) " +
                        "RETURN m1,m2,r",
                        new { msg1, msg2, timestamp = DateTime.Now.Ticks, src });
             });
         }
     }
 }