Ejemplo n.º 1
0
        // Can't use constructors because we have to have a method which we explicitly control outside
        // in order to delegate to a new thread. We don't need control over instance members from Main anyway.

        public async Task Init()
        {
            // Initialize data instance
            _DataInstance = new SwitchScreenshot.Main.Data();

            // Retrieve API keys.
            string[] TokenLines = System.IO.File.ReadAllLines("/home/jay/Programming/SwitchScreenshot/SwitchScreenshot/TwitterTokens.txt");
            _ConsumerKey       = TokenLines[0];
            _ConsumerSecretKey = TokenLines[1];
            _AccessToken       = TokenLines[2];
            _AccessSecretToken = TokenLines[3];

            // "log in"
            Auth.SetUserCredentials(_ConsumerKey, _ConsumerSecretKey, _AccessToken, _AccessSecretToken);
            var AuthenticatedUser = User.GetAuthenticatedUser();

            Utils.TwitterLog($"Logged into Twitter as {AuthenticatedUser.Name}", "Info", "Init");;
            _Stream = Tweetinvi.Stream.CreateUserStream();

            // Stream events
            _Stream.StreamStopped += (sender, args) => {
                Utils.TwitterLog($"Stream halted: {args.DisconnectMessage} ({args.Exception}",
                                 "Error", "Source unknown");
            };

            _Stream.TweetCreatedByFriend += OnFollowerTweet;

            await _Stream.StartStreamAsync();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            _stream = Stream.CreateUserStream();

            _stream.TweetCreatedByMe += (sender, args) =>
            {
            };

            _backgroundThread = new Thread(_stream.StartStream);
        }
Ejemplo n.º 3
0
        public void Start()
        {
            _stream = Stream.CreateUserStream();

            _stream.TweetCreatedByMe += (sender, args) =>
            {

            };

            _backgroundThread = new Thread(_stream.StartStream);
        }
Ejemplo n.º 4
0
 private async static void SubscribeStream(IUserStream stream)
 {
     try
     {
         stream.TweetCreatedByAnyoneButMe -= Stream_TweetCreatedByAnyoneButMe;
         stream.TweetCreatedByAnyoneButMe += Stream_TweetCreatedByAnyoneButMe;
         await stream.StartStreamAsync();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 5
0
 internal static void ReloadStream()
 {
     if (MainStream != null)
     {
         SuspendStream( );
         if (MainStream.StreamState == Tweetinvi.Core.Enum.StreamState.Running)
         {
             MainStream.StopStream( );
         }
         ResumeStream( );
         MainStream = CreateStream( );
     }
 }
Ejemplo n.º 6
0
        public TweetRepository(string apiKey, string apiKeySecret, string accessToken, string accessTokenSecret)
        {
            const string KEY_API          = @"ApiKey";
            const string KEY_APIPRIVATE   = @"ApiSecret";
            const string KEY_TOKEN        = @"AccessToken";
            const string KEY_TOKENPRIVATE = @"AccessTokenSecret";

            TwitterCredentials.SetCredentials(
                GetConfigValue(accessToken, KEY_TOKEN),
                GetConfigValue(accessTokenSecret, KEY_TOKENPRIVATE),
                GetConfigValue(apiKey, KEY_API),
                GetConfigValue(apiKeySecret, KEY_APIPRIVATE));

            _userStream = Stream.CreateUserStream();
            CreateEventBindings();
        }
Ejemplo n.º 7
0
        public TweetRepository(string apiKey, string apiKeySecret, string accessToken, string accessTokenSecret)
        {
            const string KEY_API = @"ApiKey";
            const string KEY_APIPRIVATE = @"ApiSecret";
            const string KEY_TOKEN = @"AccessToken";
            const string KEY_TOKENPRIVATE = @"AccessTokenSecret";

            TwitterCredentials.SetCredentials(
                GetConfigValue(accessToken,KEY_TOKEN),
                GetConfigValue(accessTokenSecret, KEY_TOKENPRIVATE),
                GetConfigValue(apiKey, KEY_API),
                GetConfigValue(apiKeySecret, KEY_APIPRIVATE));

            _userStream = Stream.CreateUserStream();
            CreateEventBindings();
        }
Ejemplo n.º 8
0
        public static string StartTwitterThread()
        {
            if (_twitterThread != null && _twitterThread.ThreadState == ThreadState.Running)
            {
                return("Already listening to twitter");
            }

            _twitterThread = new Thread(() => {
                _stream = Stream.CreateUserStream();
                _stream.AddTweetLanguageFilter(LanguageFilter.English);
                _stream.TweetCreatedByFriend += FriendTweeted;
                _stream.StartStream();
            });

            _twitterThread.Start();
            return("Started listening to twitter");
        }
Ejemplo n.º 9
0
        // Abrir flujo de tweets
        private void OpenUserTimelineStream()
        {
            IUserStream userStream = Tweetinvi.Stream.CreateUserStream();

            userStream.TweetCreatedByAnyoneButMe += (sender, e) =>
            {
                if (DBHelper.GenerateNamesList().Contains(e.Tweet.CreatedBy.ScreenName))
                {
                    this.Dispatcher.Invoke(() => new AlertWindow(e));
                }
            };
            userStream.StreamStopped += (sender, args) =>
            {
                Debug.WriteLine(args.Exception);
                Debug.WriteLine(args.DisconnectMessage);
            };
            userStream.StartStreamAsync();
        }
Ejemplo n.º 10
0
        internal static void Initialize(bool isUseStream = true)
        {
            StreamState = isUseStream;
            MainStream  = CreateStream( );

            Modules.OnModuleAttachLiestner.Add(delegate(Module module)
            {
                if (module is ITimeTask)
                {
                    var timetask = (ITimeTask)module;
                    Task.Factory.StartNew(() => timetask.Run( ));
                }
            });
            Modules.OnModuleDetachLiestner.Add(delegate(Module module)
            {
                module.Dispose( );
            });
            Modules.OnModuleAttachLiestner.Add(OnModuleAdd_AttachStream);
            Modules.OnModuleDetachLiestner.Add(OnModuleAdd_DetachStream);
        }
Ejemplo n.º 11
0
        public static async Task StartStream(CancellationToken token)
        {
            // Go to https://apps.twitter.com to get your own tokens.
            Auth.SetUserCredentials("CONSUMER_KEY",
                                    "CONSUMER_SECRET",
                                    "ACCESS_TOKEN",
                                    "ACCESS_TOKEN_SECRET");

            if (_stream == null)
            {
                _stream = Stream.CreateUserStream();

                // Other events can be used. This is just on YOUR twitter feed.
                _stream.TweetCreatedByAnyone += async(sender, args) =>
                {
                    if (token.IsCancellationRequested)
                    {
                        _stream.StopStream();
                        token.ThrowIfCancellationRequested();
                    }

                    // let's use the embed tweet from tweetinvi
                    var embedTweet = Tweet.GenerateOEmbedTweet(args.Tweet);
                    await _context.Clients.All.updateTweet(embedTweet);
                };

                // If anything changes the state, update the UI.
                _stream.StreamPaused  += async(sender, args) => { await _context.Clients.All.updateStatus("Paused."); };
                _stream.StreamResumed += async(sender, args) => { await _context.Clients.All.updateStatus("Streaming..."); };
                _stream.StreamStarted += async(sender, args) => { await _context.Clients.All.updateStatus("Started."); };
                _stream.StreamStopped += async(sender, args) => { await _context.Clients.All.updateStatus("Stopped (event)"); };

                await _stream.StartStreamAsync();
            }
            else
            {
                _stream.ResumeStream();
            }

            await _context.Clients.All.updateStatus("Started.");
        }
Ejemplo n.º 12
0
 public MainWindow()
 {
     InitializeComponent();
     TimerClock.Interval = (int)TimeSpan.FromMinutes(15).TotalMilliseconds;
     TimerClock.Tick    += delegate { TweetSendedWithin15MinWindow = 0; };
     TimerClock.Start();
     Auth.SetCredentials(Credentials.RandomCredential);
     Jarvis                      = User.GetAuthenticatedUser();
     KeywordStream               = Stream.CreateFilteredStream();
     UserStream                  = Stream.CreateUserStream();
     UserStream.FollowedByUser  += FlowedByUser;
     UserStream.LimitReached    += LimitReached;
     KeywordStream.LimitReached += LimitReached;
     KeywordStream.AddTrack("reallifejarvis");
     KeywordStream.AddTrack("real life jarvis");
     KeywordStream.AddTrack("talktomejarvis");
     KeywordStream.AddTrack("talk to me jarvis");
     KeywordStream.AddTrack("#retweetjarvis");
     KeywordStream.MatchingTweetReceived += NewTweetFound;
     KeywordStream.StartStreamMatchingAnyConditionAsync();
     UserStream.StartStreamAsync();
 }
Ejemplo n.º 13
0
        private static void EventsRelatedWithBlock(IUserStream userStream)
        {
            userStream.BlockedUser += (sender, args) =>
            {
                Console.WriteLine("I blocked a '{0}'", args.User.ScreenName);
            };

            userStream.UnBlockedUser += (sender, args) =>
            {
                Console.WriteLine("I un blocked a '{0}'", args.User.ScreenName);
            };
        }
Ejemplo n.º 14
0
        private void ConnectToTwitter()
        {
            Trace.TraceInformation("Connecting to Twitter");

            //IOAuthCredentials userAuthorizationToken = CredentialsCreator.GetCredentialsFromCallbackURL(callbackURI, _applicationCredentials);

            _activeStream = Tweetinvi.Stream.CreateUserStream();
            _activeStream.StartStreamAsync();

            _activeStream.TweetCreatedByAnyone += OnTweetReceived;

            Trace.TraceInformation("Connected to Twitter");
        }
Ejemplo n.º 15
0
        public static void EventsRelatedWithTweetCreation(IUserStream userStream)
        {
            userStream.TweetCreatedByAnyone += (sender, args) =>
            {
                Console.WriteLine(DateTime.Now.ToString() + " Tweet created by anyone");
            };

            userStream.TweetCreatedByMe += (sender, args) =>
            {
                Console.WriteLine(DateTime.Now.ToString() + " Tweet created by me");
            };

            userStream.TweetCreatedByAnyoneButMe += (sender, args) =>
            {
                Console.WriteLine(DateTime.Now.ToString() + " Tweet created by {0}", args.Tweet.CreatedBy.Name);
            };
        }
Ejemplo n.º 16
0
        public static void EventsRelatedWithBlock(IUserStream userStream)
        {
            userStream.BlockedUser += (sender, args) =>
            {
                Console.WriteLine(DateTime.Now.ToString() + " I blocked a '{0}'", args.User.ScreenName);
            };

            userStream.UnBlockedUser += (sender, args) =>
            {
                Console.WriteLine(DateTime.Now.ToString() + " I un blocked a '{0}'", args.User.ScreenName);
            };
        }
Ejemplo n.º 17
0
        private void StartStreaming()
        {
            #if !OFFLINE
            if (_userStream != null)
                StopStreaming();

            _userStream = Stream.CreateUserStream();

            _userStream.TweetCreatedByAnyone        += OnTweetCreated;
            _userStream.TweetFavouritedByAnyone     += OnTweetFavorited;
            _userStream.TweetUnFavouritedByAnyone   += OnTweetUnfavorited;
            _userStream.MessageReceived             += OnMessageReceived;
            _userStream.MessageSent                 += OnMessageSent;

            // do this on threadpool to not block our thread
            _streamWorker = new BackgroundWorker();
            _streamWorker.DoWork += (o,e) =>
            {
                _userStream.StartStreamAsync();
                Debug.WriteLine("BGW fallthrough");
            };
            _streamWorker.RunWorkerAsync();
            #endif
        }
Ejemplo n.º 18
0
        private static void EventsRelatedWithTweetAndFavourite(IUserStream userStream)
        {
            // Favourite
            userStream.TweetFavouritedByAnyone += (sender, args) =>
            {
                var tweet = args.Tweet;
                var userWhoFavouritedTheTweet = args.FavouritingUser;
                Console.WriteLine("User '{0}' favourited tweet '{1}'", userWhoFavouritedTheTweet.Name, tweet.Id);
            };

            userStream.TweetFavouritedByMe += (sender, args) =>
            {
                var tweet = args.Tweet;
                var loggedUser = args.FavouritingUser;
                Console.WriteLine("Logged User '{0}' favourited tweet '{1}'", loggedUser.Name, tweet.Id);
            };

            userStream.TweetFavouritedByAnyoneButMe += (sender, args) =>
            {
                var tweet = args.Tweet;
                var userWhoFavouritedTheTweet = args.FavouritingUser;
                Console.WriteLine("User '{0}' favourited tweet '{1}'", userWhoFavouritedTheTweet.Name, tweet.Id);
            };

            // Unfavourite
            userStream.TweetUnFavouritedByAnyone += (sender, args) =>
            {
                var tweet = args.Tweet;
                var userWhoFavouritedTheTweet = args.FavouritingUser;
                Console.WriteLine("User '{0}' unfavourited tweet '{1}'", userWhoFavouritedTheTweet.Name, tweet.Id);
            };

            userStream.TweetUnFavouritedByMe += (sender, args) =>
            {
                Console.WriteLine("Tweet unfavourited by me!");
            };

            userStream.TweetUnFavouritedByAnyoneButMe += (sender, args) =>
            {
                var tweet = args.Tweet;
                var userWhoFavouritedTheTweet = args.FavouritingUser;
                Console.WriteLine("User '{0}' favourited tweet '{1}'", userWhoFavouritedTheTweet.Name, tweet.Id);
            };
        }
Ejemplo n.º 19
0
        private static void EventsRelatedWithLists(IUserStream userStream)
        {
            userStream.ListCreated += (sender, args) =>
            {
                Console.WriteLine("List '{0}' created!", args.List.Name);
            };

            userStream.ListUpdated += (sender, args) =>
            {
                Console.WriteLine("List '{0}' updated!", args.List.Name);
            };

            userStream.ListDestroyed += (sender, args) =>
            {
                Console.WriteLine("List '{0}' destroyed!", args.List.Name);
            };

            // User Added
            userStream.LoggedUserAddedMemberToList += (sender, args) =>
            {
                var newUser = args.User;
                var list = args.List;
                Console.WriteLine("You added '{0}' to the list : '{1}'", newUser.Name, list.Name);
            };

            userStream.LoggedUserAddedToListBy += (sender, args) =>
            {
                var newUser = args.User;
                var list = args.List;
                Console.WriteLine("You haved been added to the list '{0}' by '{1}'", list.Name, newUser.Name);
            };

            // User Removed
            userStream.LoggedUserRemovedMemberFromList += (sender, args) =>
            {
                var newUser = args.User;
                var list = args.List;
                Console.WriteLine("You removed '{0}' from the list : '{1}'", newUser.Name, list.Name);
            };

            userStream.LoggedUserRemovedFromListBy += (sender, args) =>
            {
                var newUser = args.User;
                var list = args.List;
                Console.WriteLine("You haved been removed from the list '{0}' by '{1}'", list.Name, newUser.Name);
            };

            // User Subscribed
            userStream.LoggedUserSubscribedToListCreatedBy += (sender, args) =>
            {
                var list = args.List;
                Console.WriteLine("You have subscribed to the list '{0}", list.Name);
            };

            userStream.UserSubscribedToListCreatedByMe += (sender, args) =>
            {
                var list = args.List;
                var user = args.User;
                Console.WriteLine("'{0}' have subscribed to your list '{1}'", user.Name, list.Name);
            };

            // User Unsubscribed
            userStream.LoggedUserUnsubscribedToListCreatedBy += (sender, args) =>
            {
                var list = args.List;
                Console.WriteLine("You have unsubscribed from the list '{0}'", list.Name);
            };

            userStream.UserUnsubscribedToListCreatedByMe += (sender, args) =>
            {
                var list = args.List;
                var user = args.User;
                Console.WriteLine("'{0}' have unsubscribed from your list '{1}'", user.Name, list.Name);
            };
        }
Ejemplo n.º 20
0
 private static void EventsRelatedWithMessages(IUserStream userStream)
 {
     userStream.MessageSent += (sender, args) => { Console.WriteLine("message '{0}' sent", args.Message.Text); };
     userStream.MessageReceived += (sender, args) => { Console.WriteLine("message '{0}' received", args.Message.Text); };
 }
Ejemplo n.º 21
0
 public static void EventsRelatedWithMessages(IUserStream userStream)
 {
     userStream.MessageSent += (sender, args) => { Console.WriteLine(DateTime.Now.ToString() + " message '{0}' sent", args.Message.Text); };
     userStream.MessageReceived += (sender, args) => { Console.WriteLine(DateTime.Now.ToString() + " message '{0}' received", args.Message.Text); };
 }
Ejemplo n.º 22
0
        private static void EventsRelatedWithTweetCreation(IUserStream userStream)
        {
            userStream.TweetCreatedByAnyone += (sender, args) =>
            {
                Console.WriteLine("Tweet created by anyone");
            };

            userStream.TweetCreatedByMe += (sender, args) =>
            {
                Console.WriteLine("Tweet created by me");
            };

            userStream.TweetCreatedByAnyoneButMe += (sender, args) =>
            {
                Console.WriteLine("Tweet created by {0}", args.Tweet.Creator.Name);
            };
        }
Ejemplo n.º 23
0
 public void StartStreaming()
 {
     _twitterStream = Tweetinvi.Stream.CreateUserStream();
     _twitterStream.TweetCreatedByFriend += TweetCreated;
     _twitterStream.StartStreamAsync();
 }