Esempio n. 1
0
 public TweetListener(TwitterAuthConfig authConfig, TweetListenerConfig tweetListenerConfig, IDataForwarderFactory tweetForwarderFactory, ILocationFinder locationFinder)
 {
     _twitterAuthConfig     = authConfig;
     _listenerConfig        = tweetListenerConfig;
     _locationFinder        = locationFinder;
     _tweetForwarderFactory = tweetForwarderFactory;
 }
Esempio n. 2
0
        private static Task MainAsync(string[] args)
        {
            //https://blog.bitscry.com/2017/05/30/appsettings-json-in-net-core-console-app/
            //https://blogs.msdn.microsoft.com/fkaduk/2017/02/22/using-strongly-typed-configuration-in-net-core-console-app/
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            IConfigurationRoot config = builder.Build();

            //PurpleFridayTweetListener.

            var streamConfig = new TwitterAuthConfig();

            config.Bind("TwitterCredentials", streamConfig);

            var dataForwarderConfig = new DataForwarderConfiguration();

            config.Bind("DataForwarder", dataForwarderConfig);
            dataForwarderConfig.BaseUrl = new Uri(config["DataForwarder:BaseUri"]);

            if (bool.Parse(config["Logging:LogToFile"]))
            {
                // Log to console and file.
                Logging.SetupLogging(config["Logging:LogFolderPath"]);
            }
            else
            {
                // Log to console only.
                Logging.SetupLogging(null);
            }

            Logging.Information("Starting PurpleFridayTweetListener");

            var tweetListenerConfig = new TweetListenerConfig();

            config.Bind("Listener", tweetListenerConfig);

            var locationFinderConfig = new LocationFinderConfiguration();

            config.Bind("LocationFinder", locationFinderConfig);

            var locationFinder = new LocationFinder.LocationFinder(locationFinderConfig, new BingMapsGeocoder(locationFinderConfig.BingMapsKey));

            var tweetListener = new TweetListener(streamConfig, tweetListenerConfig, new DataForwarderFactory(dataForwarderConfig), locationFinder);

            tweetListener.StartStream(args.Any()? args[0]: tweetListenerConfig.Filter);

            Console.Read();

            return(null);
        }