Ejemplo n.º 1
0
        /// <summary>
        /// Performs the Twitter authorization
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="re"></param>
        private void btnAuthorise_onClick(object sender, RoutedEventArgs re)
        {
            Uri              authUrl;
            string           pin;
            OAuthAccessToken accessToken;
            Twitter          twitter;

            try
            {
                // Gernerating and opening the Twitter authorization URL
                twitter = new Twitter();
                if (Twitter.checkForInternetConnection() == true)
                {
                    authUrl = twitter.getAuthorizationUri();
                    if (authUrl != null)
                    {
                        if (string.IsNullOrEmpty(authUrl.ToString()) == false)
                        {
                            Process.Start(authUrl.ToString());
                        }
                        else
                        {
                            throw new Exception("Generating Twitter authorization URL failed.");
                        }
                    }
                    else
                    {
                        throw new Exception("Generating Twitter authorization URL failed.");
                    }

                    // Get the access token using the entered PIN
                    pin = Interaction.InputBox("Plese enter the twitter authorization PIN code provided by the twitter website.", "Enter Twitter PIN code");
                    if (string.IsNullOrEmpty(pin) == false)
                    {
                        accessToken = twitter.getAccessToken(pin);

                        if (accessToken != null)
                        {
                            // Save the access token for later usage
                            Settings.saveAccessToken(accessToken.Token, accessToken.TokenSecret);
                            checkTwitterAuth();
                        }
                        else
                        {
                            throw new Exception("Generating Twitter access token failed.");
                        }
                    }
                }
                else
                {
                    throw new Exception("No internet connection available.");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get result list
        /// Sub routines will be called to build the specific results for each command (search, tweet and so on)
        /// </summary>
        /// <param name="query">Query entered by the user in the wox search panel</param>
        /// <returns>Wox results</returns>
        public List <Result> Query(Query query)
        {
            List <Result> results;
            Result        result;
            validCommands command;
            bool          isValidCommand;

            try
            {
                results = new List <Result>();
                if (twitter == null)
                {
                    getTwitterAccess();
                }

                // Start building results
                if (twitter != null)
                {
                    // Check for valid command --> see enum "validCommands"
                    isValidCommand = System.Enum.IsDefined(typeof(validCommands), query.FirstSearch);
                    if (isValidCommand == true)
                    {
                        command = (validCommands)System.Enum.Parse(typeof(validCommands), query.FirstSearch, true);
                        switch (command)
                        {
                        case validCommands.tweet:
                            if (query.SecondToEndSearch.Length <= 140)
                            {
                                results.Add(buildTweetResult(query.SecondToEndSearch));     // Tweet
                            }
                            break;

                        case validCommands.search:
                            if (query.SecondToEndSearch.Length > 0)
                            {
                                results = buildSearchResult(query.SecondToEndSearch);     // Search for tweets
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        // No valid command
                        result = new Result("Twitter commands: " + getConcValidCommands(), twitterIconPath, "Use one of the following commands: " + getConcValidCommands());
                        results.Add(result);
                    }
                }
                else
                {
                    if (Twitter.checkForInternetConnection() == false)
                    {
                        // No internet connection
                        result = new Result("No internet connection available", twitterIconPath);
                        results.Add(result);
                    }
                    else
                    {
                        // No access
                        result = new Result("No Twitter access granted", twitterIconPath, "Please grant access to Twitter using the settings panel of wox");
                        results.Add(result);
                    }
                }

                return(results);
            }
            catch (Exception)
            {
                throw;
            }
        }