// This method will be called by the application framework when the page is first loaded protected override async void OnNavigatedTo(NavigationEventArgs navArgs) { try { _BME280 = new BME280Sensor(_localSeaLevelPressure); // Create a new object for our sensor class await _BME280.InitializeDevice(); // Initialize the sensor if (_BME280.init) { // If all goes well, our BME280 is initialized and we can set up // a timer which will take a reading and send data to the cloud _weatherDataSender = new EventHubDataSender(_eventHubConnectionString); _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(_timerInterval) }; _timer.Tick += TakeReadingAsync; // Register this method to the dispatcher so that it is called every tick _timer.Start(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
static void Main(string[] args) { //Configure Twitter OAuth var oauthToken = ConfigurationManager.AppSettings["oauth_token"]; var oauthTokenSecret = ConfigurationManager.AppSettings["oauth_token_secret"]; var oauthCustomerKey = ConfigurationManager.AppSettings["oauth_consumer_key"]; var oauthConsumerSecret = ConfigurationManager.AppSettings["oauth_consumer_secret"]; var keywords = ConfigurationManager.AppSettings["twitter_keywords"]; //Configure EventHub var config = new EventHubConfig(); config.ConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"]; config.EventHubName = ConfigurationManager.AppSettings["EventHubName"]; var myEventHubDataSender = new EventHubDataSender(config); var tweeterData = Tweet.StreamStatuses(new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret, keywords)).Select(tweet => Sentiment.ComputeScore(tweet, keywords)).Select(tweet => new Payload { CreatedAt = tweet.CreatedAt, Text = tweet.Text, Topic = tweet.Topic, SentimentScore = tweet.SentimentScore }); tweeterData.ToObservable().Subscribe(myEventHubDataSender); }