Contains methods for interacting with the Twitter API over the network.
コード例 #1
0
        /// <summary>
        /// Get the search results from the Twitter API. Cache the results.
        /// </summary>
        /// <returns></returns>
        private IList <TwitterStatus> GetSearch()
        {
            var cacheKey = String.Format("__TwitterSearch_{0}_{1}", this.Search, this.Count);

            var results = (IList <TwitterStatus>) this.Context.Cache[cacheKey];

            if (results == null)
            {
                var api = new TwitterAPI();
                try {
                    results = api.GetSearch(this.Search, this.Count);
                } catch {
                    return(null);
                }
                this.Context.Cache.Insert(
                    cacheKey,
                    results,
                    null,
                    DateTime.UtcNow.AddSeconds(this.CacheDuration),
                    System.Web.Caching.Cache.NoSlidingExpiration
                    );
            }

            return(results);
        }
コード例 #2
0
        /// <summary>
        /// Get the Profile tweets from the Twitter API. Cache the results.
        /// </summary>
        /// <returns></returns>
        private IList <TwitterStatus> GetProfile()
        {
            var cacheKey = String.Format("__TwitterProfile_{0}_{1}_{2}_{3}", this.ScreenName, this.Count, this.IncludeRetweets, this.IncludeReplies);

            var results = (IList <TwitterStatus>) this.Context.Cache[cacheKey];

            if (results == null)
            {
                var api = new TwitterAPI();
                try {
                    results = api.GetProfile(this.ScreenName, this.Count, this.IncludeRetweets, this.IncludeReplies);
                } catch {
                    return(null);
                }
                this.Context.Cache.Insert(
                    cacheKey,
                    results,
                    null,
                    DateTime.UtcNow.AddSeconds(this.CacheDuration),
                    System.Web.Caching.Cache.NoSlidingExpiration
                    );
            }

            return(results);
        }
コード例 #3
0
ファイル: TwitterDesigner.cs プロジェクト: syurov/rt.srz
        private IList <TwitterStatus> GenerateData()
        {
            if (_twitter.IsLiveContentOnDesignMode)
            {
                /*---- live mode---*/
                IList <TwitterStatus> statuses = null;
                var api = new TwitterAPI();
                switch (_twitter.Mode)
                {
                case TwitterMode.Profile:
                    statuses = api.GetProfile(_twitter.ScreenName, _twitter.Count,
                                              _twitter.IncludeRetweets, _twitter.IncludeReplies);
                    if (statuses != null && statuses.Count > 0)
                    {
                        var user = statuses[0].User;
                        _twitter.Title           = _twitter.Title ?? user.Name;
                        _twitter.Caption         = _twitter.Caption ?? user.ScreenName;
                        _twitter.ProfileImageUrl = _twitter.ProfileImageUrl ?? user.ProfileImageUrl;
                    }
                    break;

                default:
                    statuses = api.GetSearch(_twitter.Search, _twitter.Count);
                    break;
                }
                return(statuses);
            }

            /*---- fake mode --*/
            return(GenerateFakeData());
        }
コード例 #4
0
        public override string GetDesignTimeHtml()
        {
            // grab original HTML for base designer so user can resize control at design time
            var originalHtml = base.GetDesignTimeHtml();
            var lastIdx = originalHtml.IndexOf("<div", 1);
            originalHtml = lastIdx > 0
                ? originalHtml.Substring(0, (originalHtml.IndexOf("<div", 1)))
                : originalHtml.Remove(originalHtml.Length - 6, 6);

            // remove all tabs and new lines
            originalHtml = originalHtml
                    .Replace("\r", "")
                    .Replace("\n", "")
                    .Replace("\t", "");

            string twitterHtml = null;
            try {
                switch (_twitter.Mode) {
                    case TwitterMode.Profile:
                        if (string.IsNullOrEmpty(_twitter.ScreenName))
                            throw new Exception("Please specify a screen name");
                        break;
                    default:
                        if (string.IsNullOrEmpty(_twitter.Search))
                            throw new Exception("Please specify a search keyword");
                        break;
                }

                string userName = null;
                var api = new TwitterAPI();
                var statuses = GenerateData();
                if (statuses.Count > 0)
                    twitterHtml = RenderLayout(statuses);
                else
                    twitterHtml = RenderEmptyData();
            } catch (Exception ex) {
                if (twitterHtml == null) {
                    twitterHtml = "<div>" + ex.Message + "</div>";
                }
            }

            var styleSheetUrl = ViewControl.Page.ClientScript.GetWebResourceUrl(
                this.GetType(), "Twitter.Twitter_resource.css");

            var styleSheetHtml = string.Format(@"<link href=""{0}"" rel=""stylesheet"" type=""text/css""/>",
                styleSheetUrl);

            return originalHtml + styleSheetHtml + twitterHtml + "</div>";
        }
コード例 #5
0
        /// <summary>
        /// Get the search results from the Twitter API. Cache the results.
        /// </summary>
        /// <returns></returns>
        private IList<TwitterStatus> GetSearch()
        {
            var cacheKey = String.Format("__TwitterSearch_{0}_{1}", this.Search, this.Count);

            var results = (IList<TwitterStatus>)this.Context.Cache[cacheKey];
            if (results == null) {
                var api = new TwitterAPI();
                try {
                    results = api.GetSearch(this.Search, this.Count);
                } catch {
                    return null;
                }
                this.Context.Cache.Insert(
                    cacheKey,
                    results,
                    null,
                    DateTime.UtcNow.AddSeconds(this.CacheDuration),
                    System.Web.Caching.Cache.NoSlidingExpiration
                );
            }

            return results;
        }
コード例 #6
0
        /// <summary>
        /// Get the Profile tweets from the Twitter API. Cache the results.
        /// </summary>
        /// <returns></returns>
        private IList<TwitterStatus> GetProfile()
        {
            var cacheKey = String.Format("__TwitterProfile_{0}_{1}_{2}_{3}", this.ScreenName, this.Count, this.IncludeRetweets, this.IncludeReplies);

            var results = (IList<TwitterStatus>)this.Context.Cache[cacheKey];
            if (results == null) {
                var api = new TwitterAPI();
                try {
                    results = api.GetProfile(this.ScreenName, this.Count, this.IncludeRetweets, this.IncludeReplies);
                } catch {
                    return null;
                }
                this.Context.Cache.Insert(
                    cacheKey,
                    results,
                    null,
                    DateTime.UtcNow.AddSeconds(this.CacheDuration),
                    System.Web.Caching.Cache.NoSlidingExpiration
                );
            }

            return results;
        }
コード例 #7
0
        private IList<TwitterStatus> GenerateData()
        {
            if (_twitter.IsLiveContentOnDesignMode) {
                /*---- live mode---*/
                IList<TwitterStatus> statuses = null;
                var api = new TwitterAPI();
                switch (_twitter.Mode) {
                    case TwitterMode.Profile:
                        statuses = api.GetProfile(_twitter.ScreenName, _twitter.Count,
                                                    _twitter.IncludeRetweets, _twitter.IncludeReplies);
                        if (statuses != null && statuses.Count > 0) {
                            var user = statuses[0].User;
                            _twitter.Title = _twitter.Title ?? user.Name;
                            _twitter.Caption = _twitter.Caption ?? user.ScreenName;
                            _twitter.ProfileImageUrl = _twitter.ProfileImageUrl ?? user.ProfileImageUrl;
                        }
                        break;
                    default:
                        statuses = api.GetSearch(_twitter.Search, _twitter.Count);
                        break;
                }
                return statuses;
            }

            /*---- fake mode --*/
            return GenerateFakeData();
        }
コード例 #8
0
ファイル: TwitterDesigner.cs プロジェクト: syurov/rt.srz
        public override string GetDesignTimeHtml()
        {
            // grab original HTML for base designer so user can resize control at design time
            var originalHtml = base.GetDesignTimeHtml();
            var lastIdx      = originalHtml.IndexOf("<div", 1);

            originalHtml = lastIdx > 0
                ? originalHtml.Substring(0, (originalHtml.IndexOf("<div", 1)))
                : originalHtml.Remove(originalHtml.Length - 6, 6);

            // remove all tabs and new lines
            originalHtml = originalHtml
                           .Replace("\r", "")
                           .Replace("\n", "")
                           .Replace("\t", "");

            string twitterHtml = null;

            try {
                switch (_twitter.Mode)
                {
                case TwitterMode.Profile:
                    if (string.IsNullOrEmpty(_twitter.ScreenName))
                    {
                        throw new Exception("Please specify a screen name");
                    }
                    break;

                default:
                    if (string.IsNullOrEmpty(_twitter.Search))
                    {
                        throw new Exception("Please specify a search keyword");
                    }
                    break;
                }

                string userName = null;
                var    api      = new TwitterAPI();
                var    statuses = GenerateData();
                if (statuses.Count > 0)
                {
                    twitterHtml = RenderLayout(statuses);
                }
                else
                {
                    twitterHtml = RenderEmptyData();
                }
            } catch (Exception ex) {
                if (twitterHtml == null)
                {
                    twitterHtml = "<div>" + ex.Message + "</div>";
                }
            }

            var styleSheetUrl = ViewControl.Page.ClientScript.GetWebResourceUrl(
                this.GetType(), "Twitter.Twitter_resource.css");

            var styleSheetHtml = string.Format(@"<link href=""{0}"" rel=""stylesheet"" type=""text/css""/>",
                                               styleSheetUrl);

            return(originalHtml + styleSheetHtml + twitterHtml + "</div>");
        }