コード例 #1
0
 private void Window_Closed(object sender, EventArgs e)
 {
     if (Filteredstream != null)
     {
         Filteredstream.StopStream();
     }
 }
コード例 #2
0
ファイル: TwitterService.cs プロジェクト: eimink/TVNK
 public void StopMonitoring(string query, EventHandler <Tweetinvi.Events.MatchedTweetReceivedEventArgs> callback)
 {
     tweetStream.MatchingTweetReceived -= callback;
     tweetStream.StopStream();
     tweetStream.RemoveTrack(query);
     status = 2;
 }
コード例 #3
0
 public void Dispose()
 {
     if (_filteredStream != null)
     {
         _filteredStream.StreamStarted         -= OnStreamStarted;
         _filteredStream.MatchingTweetReceived -= OnMatchingTweetReceived;
         _filteredStream.StopStream();
         _filteredStream = null;
     }
 }
コード例 #4
0
 public void Dispose()
 {
     if (_filteredStream != null)
     {
         streamWorker.CancelAsync();
         _filteredStream.MatchingTweetReceived -= OnMatchingTweetReceived;
         _filteredStream.StopStream();
         _filteredStream = null;
     }
 }
コード例 #5
0
        public JsonResult StartStream(string[] list)
        {
            try
            {
                var keyword = list[0];
                var path    = list[1];
                //var iterations = 100000;
                path = path + "\\" + "API_" + keyword + "_" + string.Format("{0:yyyy-MM-dd_hh-mm-ss-fff}", DateTime.Now) + ".txt";

                object lock1 = new Object();

                lock (lock1)
                {
                    if (!System.IO.File.Exists(path))
                    {
                        System.IO.File.Create(path);
                    }
                }
                try{
                    if (t != null)
                    {
                        stream.StopStream();
                    }
                } catch (Exception e) {
                    return(new JsonResult(new { success = true, responseText = "Failed to abort old thread" }));
                }
                this.t = new Thread(() =>
                {
                    this.stream = Tweetinvi.Stream.CreateFilteredStream();
                    if (keyword != "")
                    {
                        stream.AddTrack(keyword);
                    }

                    stream.MatchingTweetReceived += (sender, args) =>
                    {
                        System.IO.File.AppendAllText(path, args.Json + "\n");
                        Console.WriteLine(args.Tweet);
                    };
                    stream.StartStreamMatchingAllConditions();
                    Console.WriteLine("Stream started");
                    //stream.StopStream();
                });
                lock (lock1)
                {
                    t.Start();
                }
                return(new JsonResult(new { success = true, responseText = "Started stream for keyword" + keyword + ". Saving to file at location " + path + "." }));
            }
            catch (Exception e)
            {
                return(Json(new { success = false, responseText = "Exceptions occured while attempting to open stream." }));
            }
        }
コード例 #6
0
        public void callTweetApi(string searchTerm)
        {
            if (!string.IsNullOrEmpty(searchTermHolder))
            {
                stream.RemoveTrack(searchTermHolder);
                stream.StopStream();
            }

            searchTermHolder = searchTerm;
            stream.AddTrack(searchTerm);
            stream.AddTweetLanguageFilter(LanguageFilter.English);

            stream.MatchingTweetReceived += (sender, arguments) =>
            {
                if (!(arguments.Tweet.Media == null || arguments.Tweet.Media.Count <= 0))
                {
                    foreach (var item in arguments.Tweet.Media)
                    {
                        if (item.MediaType == "photo" && arguments.MatchingTracks[0] == searchTermHolder)
                        {
                            try
                            {
                                List <FaceModel> faceList = WebApplication1.FaceApi.FaceApi.MakeAnalysisRequest(arguments.Tweet.Media[0].MediaURL).Result;
                                tweet            twt      = new tweet();
                                twt.Text      = arguments.Tweet.FullText;
                                twt.MediaUrl  = arguments.Tweet.Media[0].MediaURL;
                                twt.CreatedAt = arguments.Tweet.CreatedAt;

                                foreach (var gender in faceList)
                                {
                                    if (gender.faceAttributes.gender == "male")
                                    {
                                        twt.MaleFace += 1;
                                    }
                                    else if (gender.faceAttributes.gender == "femail")
                                    {
                                        twt.FemailFace += 1;
                                    }
                                }

                                twt.MatchingTrack = arguments.MatchingTracks[0] + " - " + faceList.Count + " Face(s) Detected, " + twt.FemailFace + " female and " + twt.MaleFace + " male";
                                sendMessage(twt);
                            }
                            catch (System.Exception)
                            {
                                stream.ResumeStream();
                            }
                        }
                    }
                }
            };

            stream.StartStreamMatchingAllConditions();
        }
コード例 #7
0
        private void addUser()
        {
            bool restart = STREAM.StreamState == StreamState.Running;

            if (restart)
            {
                STREAM.StopStream();
            }

            if (STREAM.ContainsFollow(UserId))
            {
                STREAM.FollowingUserIds[UserId] += x => TweetReceived(x);
            }
            else
            {
                STREAM.AddFollow(UserId, x => TweetReceived(x));
            }

            if (restart && STREAM.FollowingUserIds.Count == 1)
            {
                STREAM.StartStreamMatchingAllConditionsAsync();
            }
        }
コード例 #8
0
 public void Stop()
 {
     stream.StopStream();
 }