예제 #1
0
        /// <summary>
        /// Downloads the image and returns the local filepath
        /// </summary>
        /// <param name="imageUrl">Twitter image url</param>
        /// <returns>The local path to the downloaded image</returns>
        public static string cacheUserImage(string imageUrl)
        {
            WebClient webclient;
            string    path;

            try
            {
                path = "";
                if (string.IsNullOrEmpty(imageUrl) == false)
                {
                    path = TwitterImage.getCompleteCachePath(imageUrl);
                    if (File.Exists(path) == false)
                    {
                        if (string.IsNullOrEmpty(path) == false)
                        {
                            webclient = new WebClient();
                            try
                            {
                                webclient.DownloadFile(imageUrl, path);
                            }
                            catch (Exception) { }
                        }
                    }
                }

                return(path);
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #2
0
 public void Init(PluginInitContext context)
 {
     try
     {
         // init cache
         TwitterImage.initCacheFolder();
         // init Twitter access
         getTwitterAccess();
         // perform update check
         if (GitHubUpdate.updateAvailable() == true)
         {
             context.API.ShowMsg("Update for SwiftTweet plugin available", "Use \"wpm uninstall SwiftTweet\" and \"wpm install SwiftTweet\"", twitterIconPath);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #3
0
        /// <summary>
        /// Get results entries for twitter search
        /// </summary>
        /// <param name="query">Query entered by the user in the wox search panel without the keywords</param>
        /// <returns>Results of the twitter query</returns>
        protected List <Result> buildSearchResult(string query)
        {
            Result        result;
            List <Result> results;
            IEnumerable <TwitterStatus> searchResults;
            string text;
            string textEnd;

            try
            {
                results = new List <Result>();
                // check for errors from twitter for example rate limit exceeded
                if (twitter.getServiceResponse().Error != null)
                {
                    result = new Result
                    {
                        IcoPath = twitterIconPath,
                        Title   = "Twitter response error: " + twitter.getServiceResponse().Error.ToString()
                    };

                    results.Add(result);
                }

                // execute search
                searchResults = twitter.search(query);
                if (searchResults != null)
                {
                    // handle image cache
                    foreach (TwitterStatus twitterStatus in searchResults)
                    {
                        TwitterImage.cacheUserImage(twitterStatus.Author.ProfileImageUrl);
                    }

                    // process results
                    foreach (TwitterStatus twitterStatus in searchResults)
                    {
                        text    = twitterStatus.Text.Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " "); // remove carriege returns and line feeds
                        textEnd = "";
                        // split the tweet if it's too long to display it completly within the first result line
                        // the rest of the tweet will be displayed in the subtitle of the wox result list
                        if (text.Length > splitTweetPos)
                        {
                            textEnd  = text.Substring(splitTweetPos);
                            textEnd += "\t\t";
                            text     = text.Substring(0, splitTweetPos);
                        }

                        // build up the result entry
                        result = new Result
                        {
                            IcoPath  = TwitterImage.getCompleteCachePath(twitterStatus.Author.ProfileImageUrl),
                            Title    = text,
                            SubTitle = textEnd + twitterStatus.User.Name + " | @" + twitterStatus.User.ScreenName + " | " + twitterStatus.CreatedDate.ToString(),
                            Action   = (c) =>
                            {
                                return(twitter.openTweet(twitterStatus.IdStr));
                            }
                        };

                        results.Add(result);
                    }
                }

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