public static bool AreSame(TwitterUser user, Tweeter tweeter)
        {
            if (user == null || tweeter == null) return false;

            if (tweeter.TwitterId != (long)user.Id ||
                (tweeter.Language != null && !tweeter.Language.Code.Equals(user.Language, StringComparison.InvariantCultureIgnoreCase)) ||
                tweeter.Username != user.ScreenName ||
                tweeter.FullName != user.Name ||
                tweeter.ImageUrl != user.ProfileImageLocation ||
                tweeter.BackgroundImageUrl != user.ProfileBackgroundImageLocation ||
                tweeter.IsBackgroundImageTiled != user.IsProfileBackgroundTiled ||
                tweeter.Bio != user.Description ||
                tweeter.Website != user.Website ||
                tweeter.Location != user.Location ||
                tweeter.NumberOfTweets != user.NumberOfStatuses ||
                tweeter.NumberOfFollowers != user.NumberOfFollowers ||
                tweeter.NumberFollowing != user.NumberOfFriends ||
                tweeter.NumberListed != user.NumberOfFavorites ||
                tweeter.TimeZoneOffset != (int)user.TimeZoneOffset.GetValueOrDefault(0.0) ||
                tweeter.IsProtected != user.IsProtected)
            {
                return false;
            }

            return true;
        }
Exemple #2
0
 public Vote(Tweet tweet, Tweeter tweeter)
 {
     this.Tweet = tweet;
     this.Tweeter = tweeter;
 }
Exemple #3
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (Tweeter == null)
            {
                HttpCookie loginCookie = Request.Cookies["Login_Cookie"];
                if (loginCookie != null)
                {
                    loginCookie.Expires = DateTime.UtcNow.AddYears(-9);

                    int id = Int32.TryParse(loginCookie.Values["ID"], out id) ? id : -1;
                    string code = (loginCookie.Values["Code"] ?? "").Trim();

                    if (code.Length > 0)
                    {
                        Tweeter foundTweeter = TweeterRepository.FromTwitterId(id);

                        if (foundTweeter != null)
                        {
                            // Expire old logins
                            IList<PersistentLogin> loginsToRemove = foundTweeter.PersistentLogins
                                .Where(pl => pl.LastLoginDate < DateTime.UtcNow.AddDays(-30.0)).ToList();
                            foundTweeter.PersistentLogins.RemoveAll(loginsToRemove);

                            // Find a login that matches the key
                            PersistentLogin foundLogin = foundTweeter.PersistentLogins
                                .FirstOrDefault(pl => pl.SecureKey == code);

                            if (foundLogin != null)
                            {
                                // Generate new code
                                string newCode = SecurityUtils.GenerateSecureKey(KeyStrength._512bit);

                                // Set cookie
                                loginCookie.Values["Code"] = newCode;
                                loginCookie.Expires = DateTime.UtcNow.AddDays(30.0);
                                loginCookie.HttpOnly = true;

                                // Update login entity
                                foundLogin.SecureKey = newCode;
                                foundLogin.LastLoginDate = DateTime.UtcNow;

                                // Assign Tweeter as logged in user
                                Tweeter = foundTweeter;
                            }

                            // Update user in database
                            TweeterRepository.Save(foundTweeter);
                        }
                    }

                    Response.Cookies.Add(loginCookie);
                }
            }

            LanguageSelectForm languageForm = new LanguageSelectForm();
            languageForm.Languages = LanguageRepository.ListLanguages(false);
            languageForm.SelectedLanguage = DefaultLanguage != null ? (int?)DefaultLanguage.Id : null;

            IList<TagReport> tags = TweetRepository.MostPopularTags(App, DefaultLanguage, 30).OrderBy(t => t.Tag).ToList();

            long lowestUsageCount = tags.Count > 0 ? tags.Min(t => t.UsageCount) : 0;
            long highestUsageCount = tags.Count > 0 ? tags.Max(t => t.UsageCount) : 0;

            TagCloudView tagCloud = new TagCloudView();

            foreach (TagReport tag in tags)
            {
                double weight = Math.Log((double)tag.UsageCount) / Math.Log((double)highestUsageCount) * 100.0;

                TagCloudView.TagStrenth strength;

                if (weight >= 99)
                {
                    strength = TagCloudView.TagStrenth.VeryLarge;
                }
                else if (weight >= 75)
                {
                    strength = TagCloudView.TagStrenth.Large;
                }
                else if (weight >= 50)
                {
                    strength = TagCloudView.TagStrenth.Medium;
                }
                else if (weight >= 25)
                {
                    strength = TagCloudView.TagStrenth.Small;
                }
                else
                {
                    strength = TagCloudView.TagStrenth.VerySmall;
                }

                tagCloud.Tags.Add(new TagCloudView.Tag()
                {
                    Name = tag.Tag,
                    Strenth = strength
                });
            }

            MasterFrontEndView masterView = new MasterFrontEndView(App, languageForm, tagCloud);

            if (Tweeter != null)
            {
                masterView.TweeterPanel = new TweeterPanelView()
                {
                    Username = Tweeter.Username,
                    ImageUrl = Tweeter.ImageUrl,
                    TotalVotes = TweeterRepository.TotalVotesByTweeter(Tweeter, App),
                    ApplicationName = App.Title
                };
            }

            if (DefaultLanguage != null)
            {
                masterView.DefaultLanguage = DefaultLanguage;
            }

            ViewData["MasterView"] = masterView;

            base.OnActionExecuting(filterContext);
        }
Exemple #4
0
 public Tweet(Application app, Tweeter tweeter)
     : this()
 {
     this.App = app;
     this.Tweeter = tweeter;
 }
Exemple #5
0
        public virtual void CastVote(Tweeter tweeter)
        {
            Vote vote = new Vote(this, tweeter);
            vote.VotedDate = DateTime.UtcNow;

            bool wasAdded = Votes.Add(vote);

            if (wasAdded)
            {
                if (FirstVoteCast == null)
                {
                    FirstVoteCast = DateTime.UtcNow;
                }
            }
        }
Exemple #6
0
 public PersistentLogin(Tweeter tweeter)
 {
     this.Tweeter = tweeter;
 }
Exemple #7
0
        private Tweet CreateTweet()
        {
            Application app = new Application();
            Tweeter tweeter = new Tweeter();

            return new Tweet(app, tweeter);
        }