Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Streaming Linq eventhandler

$
0
0

Hello,

I want to use a realtime twitter stream into my WPF application, i've created an twitter class:

public class twitter
    {

        ITwitterAuthorizer auth = doTwitterAuth();

        public event EventHandler tweetUpdate;

        public twitter()
        {
            using (var twitterCtx = new TwitterContext(auth))
            {
                Run(twitterCtx);
            }
        }

        static ITwitterAuthorizer doTwitterAuth()
        {
            // configure the OAuth object
            var auth = new SingleUserAuthorizer
            {
                Credentials = new SingleUserInMemoryCredentials
                {
                    ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
                    TwitterAccessToken = ConfigurationManager.AppSettings["twitterAccessToken"],
                    TwitterAccessTokenSecret = ConfigurationManager.AppSettings["twitterAccessTokenSecret"]
                }
            };

            return auth;
        }

        public static void Run(TwitterContext twitterCtx)
        {
            filteredTweets(twitterCtx);
        }

 
        public static void filteredTweets(TwitterContext twitterCtx)
        {
            twitterCtx.AuthorizedClient.UseCompression = false;
           
           Streaming cInfo = (from strm in twitterCtx.Streaming
             where strm.Type == StreamingType.Filter &&
                 //strm.Follow == "15411837"
                 //strm.Language == "fr,jp,en" &&
                   strm.Track == "#dtv"
             select strm)
            .StreamingCallback(strm =>
            {
                if (strm.Status != TwitterErrorStatus.Success)
                {
                    Console.WriteLine(strm.Error.ToString());
                    return;
                }


                JsonData data = JsonMapper.ToObject(strm.Content);
                try
                {
                    Console.WriteLine(data["text"]);
                }
                catch
                {
                   Console.WriteLine(strm.Content + "\n");
                }
            })
            .SingleOrDefault<Streaming>();          
        }
    }

It is using Linq to get streaming Twitter data, the response is data["text"], when receiving new data I want to launch the tweetUpdate event and get the data["text"] into the mainwindow.

I can't set a public var from the streamingcallback or launch an event.

Can someone help me with this.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>