Beispiel #1
0
 public EventHubObserver(EventHubConfig config, bool azureOn = true)
 {
     AzureOn = azureOn;
     try
     {
         _config = config;
         if (AzureOn)
         {
             // _eventHubClient = EventHubClient.CreateFromConnectionString(_config.ConnectionString, config.EventHubName);
         }
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            var appSettings = ConfigurationManager.AppSettings;

            //Configure Twitter OAuth
            var oauthToken          = appSettings["oauth_token"];
            var oauthTokenSecret    = appSettings["oauth_token_secret"];
            var oauthCustomerKey    = appSettings["oauth_consumer_key"];
            var oauthConsumerSecret = appSettings["oauth_consumer_secret"];
            var searchGroups        = appSettings["twitter_keywords"];
            var removeAllUndefined  = !string.IsNullOrWhiteSpace(appSettings["clear_all_with_undefined_sentiment"]) ?
                                      Convert.ToBoolean(appSettings["clear_all_with_undefined_sentiment"])
                : false;
            var sendExtendedInformation = !string.IsNullOrWhiteSpace(appSettings["send_extended_information"]) ?
                                          Convert.ToBoolean(appSettings["send_extended_information"])
                : false;
            var AzureOn = !string.IsNullOrWhiteSpace(appSettings["AzureOn"]) ?
                          Convert.ToBoolean(appSettings["AzureOn"])
                : false;
            var mode          = appSettings["match_mode"];
            var createBigFile = !string.IsNullOrWhiteSpace(appSettings["create_big_file"]) ?
                                Convert.ToBoolean(appSettings["create_big_file"]) : false;

            long fileSizeLimit = !string.IsNullOrWhiteSpace(appSettings["filesizelimit"]) ?
                                 Convert.ToInt64(appSettings["filesizelimit"])
                : defaultFileSizeLimit;

            if (fileSizeLimit < minFileSizeLimit)
            {
                fileSizeLimit = minFileSizeLimit;
                Console.WriteLine("File size limit in config was too small and has been set to {0:N0}", fileSizeLimit);
            }

            var includeRetweets = !string.IsNullOrWhiteSpace(appSettings["IncludeRetweets"]) ?
                                  Convert.ToBoolean(appSettings["IncludeRetweets"])
                : false;

            //Configure EventHub
            var config = new EventHubConfig();

            config.ConnectionString = appSettings["EventHubConnectionString"];
            config.EventHubName     = appSettings["EventHubName"];

            //var myEventHubObserver = new EventHubObserver(config, AzureOn);
            var keywords = searchGroups.Contains('|') ? string.Join(",", searchGroups.Split('|')) : searchGroups;
            var tweet    = new Tweet();

            Console.WriteLine("Searching Tweets for keywords: {0}", keywords);

            var folderName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"tweets\");

            EnsureDirectory(folderName);

            var twitterConfig = new TwitterConfig(oauthToken, oauthTokenSecret, oauthCustomerKey, oauthConsumerSecret,
                                                  keywords, searchGroups, createBigFile, folderName, includeRetweets, fileSizeLimit);

            // Write out the config especially the keywords... (can only happen AFTER TwitterConfig has been created!
            string path = Path.Combine(folderName, Path.ChangeExtension(twitterConfig.BigFileName, ".config"));

            File.WriteAllText(path, @"CAS BDA Search (Team Pharma) for Tweets was started with the following keywords:" + Environment.NewLine + Environment.NewLine + keywords, Encoding.UTF8);

            // test
            foreach (var sendingPayload in tweet.StreamStatuses(twitterConfig))
            {
            }

            // end test
            //**var sendingPayload = tweet.StreamStatuses(twitterConfig).Where(e => !string.IsNullOrWhiteSpace(e.Text)).Select(t => Sentiment.ComputeScore(t, searchGroups, mode)).Select(t => new Payload { CreatedAt = t.CreatedAt, Topic = t.Topic, SentimentScore = t.SentimentScore, Author = t.UserName, Text = t.Text, SendExtended = sendExtendedInformation, Language = t.Language});
            //if (removeAllUndefined)
            //{
            //	sendingPayload = sendingPayload.Where(e => e.SentimentScore > -1);
            //}
            //sendingPayload.Where(e => e.Topic != "No Match").ToObservable().Subscribe(myEventHubObserver);
        }