/// <summary> /// Initialize the Twitter helper class and get the Twitter access /// </summary> /// <returns>Twitter helper class</returns> private Twitter getTwitterAccess() { string accessToken; string accessTokenSecret; try { if (twitter == null) { // Get saved token to perform Twitter access accessToken = Settings.getAccessToken(); accessTokenSecret = Settings.getAccessTokenSecret(); if (string.IsNullOrEmpty(accessToken) == false && string.IsNullOrEmpty(accessTokenSecret) == false) { twitter = new Twitter(accessToken, accessTokenSecret); // Check access if (twitter.checkAuthorization(false) == false) { twitter = null; } return(twitter); } else { return(null); } } else { return(twitter); } } catch (Exception) { throw; } }
/// <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; } }