Ejemplo n.º 1
0
        public void Bug_CSHARP_44()
        {
            var table = ents.GetTable<Tweets>();

            byte[] buf = new byte[256];
            for (int i = 0; i < 256; i++)
                buf[i] = (byte)i;

            int RowsNo = 100;
            List<Tweets> entL = new List<Tweets>();
            for (int i = 0; i < RowsNo; i++)
            {
                var ent = new Tweets() { tweet_id = Guid.NewGuid(), author = "test" + i.ToString(), body = "body" + i.ToString(), isok = (i % 2 == 0) };
                ent.exampleSet.Add(i.ToString());
                ent.exampleSet.Add((i + 1).ToString());
                ent.exampleSet.Add((i - 1).ToString());
                ent.data = null;
                table.AddNew(ent, EntityTrackingMode.KeepAttachedAfterSave);
                entL.Add(ent);
            }
            ents.SaveChanges(SaveChangesMode.Batch);

            var cnt = table.Count().Execute();

            Assert.Equal(RowsNo, cnt);

            foreach (var enti in entL)
                enti.data = buf;

            ents.SaveChanges(SaveChangesMode.Batch);

            var dat = (from e in table select e.data).FirstOrDefault().Execute();

            Assert.ArrEqual(dat, buf);
        }
Ejemplo n.º 2
0
        public void Test1()
        {
            var table = ents.GetTable<Tweets>();

            int RowsNo = 2000;
            List<Tweets> entL = new List<Tweets>();
            for (int i = 0; i < RowsNo; i++)
            {
                var ent = new Tweets() { tweet_id = Guid.NewGuid(), author = "test" + i.ToString(), body = "body" + i.ToString(), isok = (i % 2 == 0) };
                ent.exampleSet.Add(i.ToString());
                ent.exampleSet.Add((i + 1).ToString());
                ent.exampleSet.Add((i - 1).ToString());
                table.AddNew(ent, EntityTrackingMode.KeepAttachedAfterSave);
                entL.Add(ent);
            }
            ents.SaveChanges(SaveChangesMode.Batch);

            var cnt = table.Count().Execute();

            Assert.Equal(RowsNo, cnt);

            foreach (var ent in entL)
                table.Delete(ent);

            ents.SaveChanges(SaveChangesMode.Batch);

            var cnt2 = table.Count().Execute();
            Assert.Equal(0, cnt2);
        }
 public void SaveObject(Tweets tweet)
 {
     using (Repository<Tweets> DataAccessHelper = new Repository<Tweets>())
     {
         DataAccessHelper.Add(tweet);
         DataAccessHelper.SaveChanges();
     }
 }
 //redundant
 //public List<Accounts>AccountsList { get; set; }
 public void Create(Tweets persistObject)
 {
     using (Repository<Tweets> DataAccessHelper = new Repository<Tweets>())
     {
         DataAccessHelper.Add(persistObject);
         DataAccessHelper.SaveChanges();
     }
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            String ini;
            if (args.Length < 1) {
                Console.WriteLine("Please enter the name of the ini file");
                ini = Console.ReadLine();
            }
            else
                ini = args[0];
            Console.WriteLine(ini);
            var twit = new Twitter(ini);
            //twit.testStream();
            var testCount = 100;
            twit.populateData(testCount);

            while (twit.Data.Count() < testCount - 1) {
                Console.WriteLine(twit.Data.Count());
                System.Threading.Thread.Sleep(5000);
            }
            twit.writeDateToFile(@"C:\Users\Kevin\Documents\TestJson\data.txt");
            //twit.testStream("Disney");

            Tweets data = new Tweets();
            JsonSerializer serializer = new JsonSerializer();
            serializer.NullValueHandling = NullValueHandling.Ignore;
            using (StreamReader sr = new StreamReader(@"C:\Users\Kevin\Documents\TestJson\data.txt"))
            using (JsonTextReader jr = new JsonTextReader(sr)) {
                if(!jr.Read() || jr.TokenType != JsonToken.StartArray) {
                    throw new Exception("Expected start of array");
                }
                while (jr.Read()) {
                    if (jr.TokenType == JsonToken.EndArray) break;
                    var item = serializer.Deserialize<TweetData>(jr);
                    data.add(item);
                }
            }
            Console.WriteLine("done");
            foreach (var tweet in data) {
                Console.WriteLine(tweet.text);
            }

            //twit.getData();
            //while (twit.Data.Length <= 1) ;
            //Console.WriteLine(twit.Data+"\n");

            //Twitter.testStream(ini);
            var news = new News();
            news.getGoogleNews("Disney");
            foreach (var article in news.Data) {
                Console.WriteLine(article.Title+" "+article.publishData.ToString() );
            }
            Console.WriteLine("Done with everything");
            Console.ReadLine();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// This method reads the file line at a time and extract the people the user is following
        /// </summary>
        /// <param name="UserFileReader"></param>
        /// <returns></returns>
        private static Tweets GetFollowing(StreamReader UserFileReader)
        {
            List<string> following = new List<string>();
            Tweets tweet = new Tweets();
            tweet.Following = new List<string>();
            tweet.UserHandle = new List<string>();

            using (UserFileReader)
            {
                string rawline, @handler, follwers;

                string[] Splittedfollowing;

                try
                {
                    //Read the file one line at a time.
                    while ((rawline = UserFileReader.ReadLine()) != null)
                    {
                        @handler = rawline.Substring(0, (rawline.IndexOf("follows") - 1));
                        follwers = rawline.Substring((rawline.IndexOf("follows"))).Replace(",", "").Replace("follows", "");
                        Splittedfollowing = follwers.Split(' ');

                        tweet.UserHandle.Add(@handler);
                        //Console.WriteLine(@handler);
                        foreach (string follow in Splittedfollowing)
                        {
                            if (!String.IsNullOrEmpty(follow))
                            {
                                tweet.Following.Add(follow);
                                //Console.WriteLine("\t {0}", follow);
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine("GetFollowing: Unexpected file layout! Correct the file and try again.");
                    Console.ReadKey();
                }
            }
            return tweet;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///  This method reads the tweets.txt file and extract the tweets line by line
        /// </summary>
        /// <param name="tweetFileReader"></param>
        /// <param name="listOfTwetterHandles"></param>
        /// <param name="tweetObj"></param>
        private static void GetTweets(StreamReader tweetFileReader, List<string> listOfTwetterHandles, Tweets tweetObj)
        {
            List<string> tweetlineList = new List<string>();

            try
            {
                using (tweetFileReader)
                {
                    string tweetLine;

                    //Read the file one line at a time.
                    while ((tweetLine = tweetFileReader.ReadLine()) != null)
                    {
                        //Append the @ sign and replace > with : in the tweet
                        tweetLine = "@" + tweetLine.Replace(">", ":");
                        //Add all tweets messages to a list
                        tweetlineList.Add(tweetLine);
                    }
                }
                /*
                  Enumerate the the list of twitter handles (users) and out handle and their tweets
                  and tweets of those they follow or following them.
                */
                foreach (string tweetHandle in listOfTwetterHandles)
                {
                    Console.WriteLine("{0} \n", tweetHandle);
                    foreach (string tweets in tweetlineList)
                    {
                        if (tweets.Contains("@" + tweetHandle + ":"))
                        {
                            Console.WriteLine("\t {0}", tweets);             
                        }
                        else
                        {
                            foreach (var f in tweetObj.UserHandle)
                            {
                                if ((tweetHandle != f) && (!tweetObj.Following.Contains(tweetHandle)))
                                {
                                    if (tweets.Contains("@" + f + ":"))
                                    {
                                        Console.WriteLine("\t {0}", tweets);
                                    }
                                }
                            }
                        }               
                    }
                }
            }
            catch (Exception e)
            {
                //Handle exception in a user friendly manner
                Console.WriteLine("GetTweets: Unexpected file layout! Correct the file and try again.");

                //Console.WriteLine(e.Message); // General error logging will go here for troubleshooting purposes.
                Console.ReadKey();
            }
        }
Ejemplo n.º 8
0
        //Search Twitter for youtube videos to determine how many times they've been shared.
        public int getTWYTVideoShares(string video_id)
        {
            Tweets tweetsChoreo = new Tweets(session);

            // Set inputs
            tweetsChoreo.setAccessToken(accessToken);
            tweetsChoreo.setQuery("https://www.youtube.com/watch?v="+video_id);
            tweetsChoreo.setAccessTokenSecret(accessTokenSecret);
            tweetsChoreo.setConsumerSecret(consumer_secret);
            tweetsChoreo.setConsumerKey(consumer_key);

            // Execute Choreo
            TweetsResultSet tweetsResults = tweetsChoreo.execute();
            JObject jo = JObject.Parse(tweetsResults.Response);
            try
            {
                JArray ja = (JArray)jo["statuses"];
                return ja.Count;
            }
            catch (Exception e)
            {
                return 0;
            }
        }
Ejemplo n.º 9
0
        public void getTwitterHashtagData(string hashTag, DateTime since)
        {
            Tweets tweetsChoreo = new Tweets(session);

            // hastag search
            tweetsChoreo.setAccessToken(accessToken);
            tweetsChoreo.setQuery(hashTag);
            tweetsChoreo.setAccessTokenSecret(accessTokenSecret);
            tweetsChoreo.setConsumerSecret(consumer_secret);
            tweetsChoreo.setConsumerKey(consumer_key);
            tweetsChoreo.setCount("200");
            tweetsChoreo.setUntil(since.ToString("yyyy-MM-dd"));

            // Execute Choreo
            TweetsResultSet tweetsResults = tweetsChoreo.execute();
            //Create JSON objects
            string s_tweets = tweetsResults.Response;
            processTweeting(s_tweets, hashTag);

            JObject json_tweets = JObject.Parse(s_tweets);
            string tweet_id = (string)json_tweets["statuses"][0]["id"];

            tweetsChoreo = new Tweets(session);
            tweetsChoreo.setAccessToken(accessToken);
            tweetsChoreo.setQuery(hashTag);
            tweetsChoreo.setAccessTokenSecret(accessTokenSecret);
            tweetsChoreo.setConsumerSecret(consumer_secret);
            tweetsChoreo.setConsumerKey(consumer_key);
            tweetsChoreo.setCount("200");
            tweetsChoreo.setSinceId(tweet_id);

            tweetsResults = tweetsChoreo.execute();
            s_tweets = tweetsResults.Response;
            processTweeting(s_tweets, hashTag);
        }
Ejemplo n.º 10
0
        public void getTwitterHashtagData(string hashTag)
        {
            Tweets tweetsChoreo = new Tweets(session);

            // hastag search
            tweetsChoreo.setAccessToken(accessToken);
            tweetsChoreo.setQuery(hashTag);
            tweetsChoreo.setAccessTokenSecret(accessTokenSecret);
            tweetsChoreo.setConsumerSecret(consumer_secret);
            tweetsChoreo.setConsumerKey(consumer_key);
            tweetsChoreo.setCount("200");
            string tomorrow = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
            tweetsChoreo.setUntil(tomorrow);

            // Execute Choreo
            TweetsResultSet tweetsResults = tweetsChoreo.execute();

            // Print results
            //Console.WriteLine(tweetsResults.Response);
            Console.WriteLine(DateTime.Now.ToString());
            //Console.WriteLine(tweetsResults.Limit);
            //Console.WriteLine(tweetsResults.Remaining);
            //Console.WriteLine(tweetsResults.Reset);
            //Create JSON objects
            string s_tweets = tweetsResults.Response;
            processTweeting(s_tweets, hashTag);
        }
Ejemplo n.º 11
0
        public void testBuffering()
        {
            var table = ents.GetTable<Tweets>();

            var q2 = (from e in table where CqlToken.Create(e.idx) <= 0 select e).Take(10).OrderBy((e) => e.idx).ThenByDescending((e) => e.isok);

            var qxx = q2.ToString();
            int RowsNb = 10;
            for (int i = 0; i < RowsNb; i++)
            {
                var ent = new Tweets() { tweet_id = Guid.NewGuid(), author = "author" + i.ToString(), isok = i % 2 == 0, body = "blablabla", idx = i };
                table.AddNew(ent, EntityTrackingMode.KeepAttachedAfterSave);
            }
            var ent2 = new Tweets() { tweet_id = Guid.NewGuid(), author = "author" + RowsNb + 1, isok = false, body = "blablabla", idx = RowsNb + 1 };
            table.AddNew(ent2, EntityTrackingMode.KeepAttachedAfterSave);
            ents.SaveChanges(SaveChangesMode.OneByOne);

            table.Attach(ent2, EntityUpdateMode.ModifiedOnly);
            ent2.author = "Koko";
            ents.SaveChanges(SaveChangesMode.OneByOne);

            var iq = table.Count();
            var c = iq.Execute();

            foreach (var r in (from e in table where e.isok == true && e.idx == 0 select e).Execute())
            {
                var x = r;
            }

            //https://issues.apache.org/jira/browse/CASSANDRA-5303?page=com.atlassian.streams.streams-jira-plugin:activity-stream-issue-tab
            //foreach (var r in (from e in table where e.isok == true && new int[] { 0, 1, 2 }.Contains(e.idx) select new { x = e.idx, y = e.tweet_id }).Execute())
            //{
            //    var x = r;
            //}

            foreach (var r in (from e in table where e.isok == false && e.idx == 0 select new { Key = e.idx }).Execute())
            {
                var x = r;
            }

            foreach (var r in (from e in table where e.isok == true && e.idx == 0 select new { Key = e.idx, e.isok }).Execute())
            {
                var x = r;
            }

            foreach (var r in (from e in table where e.isok == true && e.idx == 0 select new X() { x = e.author, y = e.idx }).Execute())
            {
                var x = r;
            }

            foreach (var r in (from e in table where e.isok == false && e.idx == 0 select e.author).Execute())
            {
                var x = r;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// ロードしたツイートを追加する
        /// </summary>
        /// <param name="newTweets"></param>
        public void AddTweets(Tweets newTweets)
        {
            Debug.WriteLine("AddTweets");
            bool ageChanged = false;

            foreach (var tweet in this.tweets.Where(x => x.Age < 4))
            {
                tweet.Age++;
                ageChanged = true;
            }

            // 重複チェックして、新着だけ取り出す
            Tweets uniqueTweets = new Tweets();

            foreach (var tweet in newTweets.Where(x => tweets.FindId(x.Id) == null))
            {
                tweet.Age = 0;
                uniqueTweets.Add(tweet);
            }

            // 追加するツイートがある?
            if (uniqueTweets.Count > 0)
            {
                if (tweetsPanel.TopItemIndex > 0)
                {
                    AddNewTweets(uniqueTweets);
                }
                else
                {
                    if (uniqueTweets.Count < tweetsPanel.VisibleTweetCount)
                    {
                        AddNewTweets(uniqueTweets);
                    }
                    else
                    {
                        double stopSec = 1;
                        double divAdd = ((App.Settings.AutoReload - 2) / stopSec);
                        DispatcherTimer dt = new DispatcherTimer();
                        int addCountPerOne = (int)Math.Ceiling(uniqueTweets.Count / Math.Max(1, divAdd));
                        if (addCountPerOne < 1) addCountPerOne = 1;

                        dt.Interval = TimeSpan.FromSeconds(0);
                        dt.Tick += (s, e) =>
                        {
                            dt.Interval = TimeSpan.FromSeconds(stopSec);
                            int oneIdx = Math.Max(0, uniqueTweets.Count - addCountPerOne);
                            int oneCount = Math.Min(addCountPerOne, uniqueTweets.Count);
                            AddNewTweets(uniqueTweets.GetRange(oneIdx, oneCount));
                            uniqueTweets.RemoveRange(oneIdx, oneCount);
                            if (uniqueTweets.Count == 0)
                            {
                                dt.Stop();
                            }
                        };
                        dt.Start();
                    }
                }
            }
            else if (ageChanged)
            {
                // 追加はないけど、Ageが変更された
                tweetsPanel.LayoutTweets(TweetsPanelLayoutMode.Relayout);
            }
            Debug.WriteLine("/AddTweets");
        }
Ejemplo n.º 13
0
        public void testBuffering()
        {
            var table = ents.GetTable <Tweets>();

            var q2 = (from e in table where CqlToken.Create(e.idx) <= 0 select e).Take(10).OrderBy((e) => e.idx).ThenByDescending((e) => e.isok);

            var qxx    = q2.ToString();
            int RowsNb = 10;

            for (int i = 0; i < RowsNb; i++)
            {
                var ent = new Tweets()
                {
                    tweet_id = Guid.NewGuid(), author = "author" + i.ToString(), isok = i % 2 == 0, body = "blablabla", idx = i
                };
                table.AddNew(ent, EntityTrackingMode.KeepAttachedAfterSave);
            }
            var ent2 = new Tweets()
            {
                tweet_id = Guid.NewGuid(), author = "author" + RowsNb + 1, isok = false, body = "blablabla", idx = RowsNb + 1
            };

            table.AddNew(ent2, EntityTrackingMode.KeepAttachedAfterSave);
            ents.SaveChanges(SaveChangesMode.OneByOne);

            table.Attach(ent2, EntityUpdateMode.ModifiedOnly);
            ent2.author = "Koko";
            ents.SaveChanges(SaveChangesMode.OneByOne);


            var iq = table.Count();
            var c  = iq.Execute();


            foreach (var r in (from e in table where e.isok == true && e.idx == 0 select e).Execute())
            {
                var x = r;
            }

            //https://issues.apache.org/jira/browse/CASSANDRA-5303?page=com.atlassian.streams.streams-jira-plugin:activity-stream-issue-tab
            //foreach (var r in (from e in table where e.isok == true && new int[] { 0, 1, 2 }.Contains(e.idx) select new { x = e.idx, y = e.tweet_id }).Execute())
            //{
            //    var x = r;
            //}

            foreach (var r in (from e in table where e.isok == false && e.idx == 0 select new { Key = e.idx }).Execute())
            {
                var x = r;
            }

            foreach (var r in (from e in table where e.isok == true && e.idx == 0 select new { Key = e.idx, e.isok }).Execute())
            {
                var x = r;
            }

            foreach (var r in (from e in table where e.isok == true && e.idx == 0 select new X()
            {
                x = e.author, y = e.idx
            }).Execute())
            {
                var x = r;
            }

            foreach (var r in (from e in table where e.isok == false && e.idx == 0 select e.author).Execute())
            {
                var x = r;
            }
        }
Ejemplo n.º 14
0
        public async Task ExecuteLoadTweetsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            LoadTweetsCommand.ChangeCanExecute();
            try
            {
                Tweets.Clear();
                var auth = new ApplicationOnlyAuthorizer()
                {
                    CredentialStore = new InMemoryCredentialStore
                    {
                        ConsumerKey    = "ZTmEODUCChOhLXO4lnUCEbH2I",
                        ConsumerSecret = "Y8z2Wouc5ckFb1a0wjUDT9KAI6DUat5tFNdmIkPLl8T4Nyaa2J",
                    },
                };
                await auth.AuthorizeAsync();

                var twitterContext = new TwitterContext(auth);

                if (Device.OS != TargetPlatform.WinPhone)
                {
                    IQueryable <LinqToTwitter.Status> queryResponse =
                        (from tweet in twitterContext.Status
                         where tweet.Type == StatusType.User &&
                         tweet.ScreenName == "shanselman" &&
                         tweet.Count == 100 &&
                         tweet.IncludeRetweets == true &&
                         tweet.ExcludeReplies == true
                         select tweet);

                    var queryTweets = queryResponse.ToList();
                    var tweets      =
                        (from tweet in queryTweets
                         select new Tweet
                    {
                        StatusID = tweet.StatusID,
                        ScreenName = tweet.User.ScreenNameResponse,
                        Text = tweet.Text,
                        CurrentUserRetweet = tweet.CurrentUserRetweet,
                        CreatedAt = tweet.CreatedAt,
                        Image = tweet.RetweetedStatus != null && tweet.RetweetedStatus.User != null ?
                                tweet.RetweetedStatus.User.ProfileImageUrl : (tweet.User.ScreenNameResponse == "shanselman" ? "scott159.png" : tweet.User.ProfileImageUrl)
                    }).ToList();
                    foreach (var tweet in tweets)
                    {
                        Tweets.Add(tweet);
                    }

                    if (Device.OS == TargetPlatform.iOS)
                    {
                        // only does anything on iOS, for the Watch
                        DependencyService.Get <ITweetStore>().Save(tweets);
                    }
                }
                else
                {
                    var tweets =
                        await(from tweet in twitterContext.Status
                              where tweet.Type == StatusType.User &&
                              tweet.ScreenName == "shanselman" &&
                              tweet.Count == 100 &&
                              tweet.IncludeRetweets == true &&
                              tweet.ExcludeReplies == true
                              select new Tweet
                    {
                        StatusID           = tweet.StatusID,
                        ScreenName         = tweet.User.ScreenNameResponse,
                        Text               = tweet.Text,
                        CurrentUserRetweet = tweet.CurrentUserRetweet,
                        CreatedAt          = tweet.CreatedAt,
                        Image              = tweet.RetweetedStatus != null && tweet.RetweetedStatus.User != null ?
                                             tweet.RetweetedStatus.User.ProfileImageUrl : (tweet.User.ScreenNameResponse == "shanselman" ? "scott159.png" : tweet.User.ProfileImageUrl)
                    }).ToListAsync();
                    foreach (var tweet in tweets)
                    {
                        Tweets.Add(tweet);
                    }
                }
            }
            catch (Exception ex)
            {
                var page = new ContentPage();
                page.DisplayAlert("Error", "Unable to load tweets.", "OK");
            }

            IsBusy = false;
            LoadTweetsCommand.ChangeCanExecute();
        }