Exemple #1
0
        public static bool TryCreateFromConfigurationFile(string filename, out TwitterClient twitterClient)
        {
            if (!File.Exists(filename))
            {
                twitterClient = null;
                return(false);
            }

            try
            {
                string     fileContent = File.ReadAllText(filename);
                JsonObject configuration;
                if (!JsonObject.TryParse(fileContent, out configuration))
                {
                    twitterClient = null;
                    return(false);
                }

                twitterClient                   = new TwitterClient();
                twitterClient.AccessToken       = configuration.GetNamedString("AccessToken");
                twitterClient.AccessTokenSecret = configuration.GetNamedString("AccessTokenSecret");
                twitterClient.CosumerSecret     = configuration.GetNamedString("ConsumerSecret");
                twitterClient.ConsumerKey       = configuration.GetNamedString("ConsumerKey");

                return(true);
            }
            catch (Exception)
            {
                twitterClient = null;
                return(false);
            }
        }
        public TweetAction(string message, TwitterClient twitterClient)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (twitterClient == null)
            {
                throw new ArgumentNullException(nameof(twitterClient));
            }

            _messageProvider = () => message;
            _twitterClient   = twitterClient;
        }
        public TweetAction(Func <string> messageProvider, TwitterClient twitterClient)
        {
            if (messageProvider == null)
            {
                throw new ArgumentNullException(nameof(messageProvider));
            }
            if (twitterClient == null)
            {
                throw new ArgumentNullException(nameof(twitterClient));
            }

            _messageProvider = messageProvider;
            _twitterClient   = twitterClient;
        }
Exemple #4
0
        public static bool TryCreateFromDefaultConfigurationFile(out TwitterClient twitterClient)
        {
            string filename = Path.Combine(ApplicationData.Current.LocalFolder.Path, "TwitterClientConfiguration.json");

            return(TryCreateFromConfigurationFile(filename, out twitterClient));
        }