コード例 #1
0
        public async Task <TwitterStats> AddStats(TwitterStats twitterStats)
        {
            _context.TwitterStats.Add(twitterStats);
            await _context.SaveChangesAsync();

            return(twitterStats);
        }
コード例 #2
0
        public async Task <TwitterStats> UpdateStats(TwitterStats twitterStats)
        {
            _context.Entry(twitterStats).State = EntityState.Modified;
            _context.Set <TwitterStats>().Update(twitterStats);
            await _context.SaveChangesAsync();

            return(twitterStats);
        }
コード例 #3
0
 public void addTwitterStats(TwitterStats TwtStats)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             session.Save(TwtStats);
             transaction.Commit();
         }
     }
 }
コード例 #4
0
ファイル: TwitterData.cs プロジェクト: thinkgandhi/socioboard
        public void getTwitterStats(TwitterAccount twitterAccount)
        {
            TwitterStatsRepository   objTwtstats     = new TwitterStatsRepository();
            TwitterMessageRepository objTweetMsgRepo = new TwitterMessageRepository();
            TwitterStats             objStats        = new TwitterStats();
            Random rNum = new Random();

            objStats.Id             = Guid.NewGuid();
            objStats.TwitterId      = twitterAccount.TwitterUserId;
            objStats.UserId         = twitterAccount.UserId;
            objStats.FollowingCount = twitterAccount.FollowingCount;
            objStats.FollowerCount  = twitterAccount.FollowersCount;
            objStats.Age1820        = rNum.Next(twitterAccount.FollowersCount);
            objStats.Age2124        = rNum.Next(twitterAccount.FollowersCount);
            objStats.Age2534        = rNum.Next(twitterAccount.FollowersCount);
            objStats.Age3544        = rNum.Next(twitterAccount.FollowersCount);
            objStats.Age4554        = rNum.Next(twitterAccount.FollowersCount);
            objStats.Age5564        = rNum.Next(twitterAccount.FollowersCount);
            objStats.Age65          = rNum.Next(twitterAccount.FollowersCount);
            int replies  = objTweetMsgRepo.getRepliesCount(twitterAccount.UserId, twitterAccount.TwitterUserId);
            int retweets = objTweetMsgRepo.getRetweetCount(twitterAccount.UserId, twitterAccount.TwitterUserId);

            if (twitterAccount.FollowersCount != 0)
            {
                objStats.Engagement = (replies + retweets) / twitterAccount.FollowersCount;
            }
            else
            {
                objStats.Engagement = 0;
            }
            //  objStats.Influence=
            // objStats.Engagement=
            objStats.EntryDate = DateTime.Now;
            if (!objTwtstats.checkTwitterStatsExists(twitterAccount.TwitterUserId, twitterAccount.UserId))
            {
                objTwtstats.addTwitterStats(objStats);
            }
        }
コード例 #5
0
 public int updateTwitterStats(TwitterStats TwtStats)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 int i = session.CreateQuery("Update  from TwitterStats where TwitterId = :twtuserid and UserId = :userid")
                         .SetParameter("twtuserid", TwtStats.TwitterId)
                         .SetParameter("userid", TwtStats.UserId)
                         .ExecuteUpdate();
                 transaction.Commit();
                 return(i);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 return(0);
             }
         }
     }
 }
コード例 #6
0
 public static TwitterUserViewModel TwitterUserToTwitterUserViewModel(TwitterUser twitterUser, TwitterStats twitterStats)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
        public async Task <TwitterUserViewModel> NewOrUpdatedTwitterDetails(string screenName, long?id, bool forceUpdate = false)
        {
            if (id.HasValue)
            {
                // twitter user already in db, but we don't always want to update the details
                if (forceUpdate)
                {
                    var twitterUser = await _twitterRepository.GetUser(id.Value);

                    var twitterStats = await _twitterRepository.GetStats(id.Value);

                    Auth.SetUserCredentials(consumerKey, consumerSecret, accessToken, accessTokenSecret);
                    var user = User.GetUserFromId(id.Value);

                    if (user == null)
                    {
                        // throw an error
                    }

                    twitterUser.ScreenName = user.ScreenName;
                    twitterUser.CreatedAt  = user.CreatedAt;

                    twitterStats.FriendCount   = user.FriendsCount;
                    twitterStats.FollowerCount = user.FollowersCount;

                    await _twitterRepository.UpdateUser(twitterUser);

                    await _twitterRepository.UpdateStats(twitterStats);

                    return(ModelTransformer.TwitterUserToTwitterUserViewModel(twitterUser, twitterStats));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                Auth.SetUserCredentials(consumerKey, consumerSecret, accessToken, accessTokenSecret);
                var user = User.GetUserFromScreenName(screenName);

                if (user == null)
                {
                    // throw an error
                }

                var twitterUser = new TwitterUser
                {
                    Id         = user.Id,
                    ScreenName = user.ScreenName,
                    CreatedAt  = user.CreatedAt
                };

                var twitterStats = new TwitterStats
                {
                    Id            = user.Id,
                    FriendCount   = user.FriendsCount,
                    FollowerCount = user.FollowersCount
                };

                await _twitterRepository.AddUser(twitterUser);

                await _twitterRepository.AddStats(twitterStats);

                return(ModelTransformer.TwitterUserToTwitterUserViewModel(twitterUser, twitterStats));
            }
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        private void getTwitterUserProfile()
        {
            var requestToken    = (String)Request.QueryString["oauth_token"];
            var requestSecret   = (String)Session["requestSecret"];
            var requestVerifier = (String)Request.QueryString["oauth_verifier"];


            OAuth.AccessToken       = requestToken;
            OAuth.AccessTokenSecret = requestVerifier;
            OAuth.AccessTokenGet(requestToken, requestVerifier);

            JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, OAuth.TwitterScreenName);
            User   user    = (User)Session["LoggedUser"];
            SocialProfilesRepository socioprofilerepo = new SocialProfilesRepository();
            SocialProfile            socioprofile     = new SocialProfile();

            #region for managing referrals
            ManageReferrals(OAuth);
            #endregion

            foreach (var item in profile)
            {
                try
                {
                    twitterAccount.FollowingCount = Convert.ToInt32(item["friends_count"].ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    twitterAccount.FollowersCount = Convert.ToInt32(item["followers_count"].ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                twitterAccount.Id          = Guid.NewGuid();
                twitterAccount.IsActive    = true;
                twitterAccount.OAuthSecret = OAuth.AccessTokenSecret;
                twitterAccount.OAuthToken  = OAuth.AccessToken;
                try
                {
                    twitterAccount.ProfileImageUrl = item["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    twitterAccount.ProfileUrl = string.Empty;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                try
                {
                    twitterAccount.TwitterUserId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                }
                catch (Exception er)
                {
                    try
                    {
                        twitterAccount.TwitterUserId = item["id"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception err)
                    {
                        Console.WriteLine(err.StackTrace);
                    }
                    Console.WriteLine(er.StackTrace);
                }

                try
                {
                    twitterAccount.TwitterScreenName = item["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                twitterAccount.UserId = user.Id;

                socioprofile.Id          = Guid.NewGuid();
                socioprofile.ProfileDate = DateTime.Now;
                socioprofile.ProfileId   = twitterAccount.TwitterUserId;
                socioprofile.ProfileType = "twitter";
                socioprofile.UserId      = user.Id;

                if (HttpContext.Current.Session["login"] != null)
                {
                    if (HttpContext.Current.Session["login"].ToString().Equals("twitter"))
                    {
                        User           usr       = new User();
                        UserRepository userrepo  = new UserRepository();
                        Registration   regObject = new Registration();
                        usr.AccountType = "free";
                        usr.CreateDate  = DateTime.Now;
                        usr.ExpiryDate  = DateTime.Now.AddMonths(1);
                        usr.Id          = Guid.NewGuid();
                        usr.UserName    = twitterAccount.TwitterName;
                        usr.Password    = regObject.MD5Hash(twitterAccount.TwitterName);
                        usr.EmailId     = "";
                        usr.UserStatus  = 1;
                        if (!userrepo.IsUserExist(usr.EmailId))
                        {
                            UserRepository.Add(usr);
                        }
                    }
                }

                TwitterStatsRepository objTwtstats = new TwitterStatsRepository();
                TwitterStats           objStats    = new TwitterStats();
                Random rNum = new Random();
                objStats.Id             = Guid.NewGuid();
                objStats.TwitterId      = twitterAccount.TwitterUserId;
                objStats.UserId         = user.Id;
                objStats.FollowingCount = twitterAccount.FollowingCount;
                objStats.FollowerCount  = twitterAccount.FollowersCount;
                objStats.Age1820        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age2124        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age2534        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age3544        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age4554        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age5564        = rNum.Next(twitterAccount.FollowersCount);
                objStats.Age65          = rNum.Next(twitterAccount.FollowersCount);
                objStats.EntryDate      = DateTime.Now;
                if (!objTwtstats.checkTwitterStatsExists(twitterAccount.TwitterUserId, user.Id))
                {
                    objTwtstats.addTwitterStats(objStats);
                }
                if (!twtrepo.checkTwitterUserExists(twitterAccount.TwitterUserId, user.Id))
                {
                    twtrepo.addTwitterkUser(twitterAccount);
                    if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                    {
                        socioprofilerepo.addNewProfileForUser(socioprofile);


                        GroupRepository        objGroupRepository = new GroupRepository();
                        SocioBoard.Domain.Team team = (SocioBoard.Domain.Team)HttpContext.Current.Session["GroupName"];
                        Groups lstDetails           = objGroupRepository.getGroupName(team.GroupId);
                        if (lstDetails.GroupName == "Socioboard")
                        {
                            TeamMemberProfileRepository objTeamMemberProfileRepository = new TeamMemberProfileRepository();
                            TeamMemberProfile           teammemberprofile = new TeamMemberProfile();
                            teammemberprofile.Id               = Guid.NewGuid();
                            teammemberprofile.TeamId           = team.Id;
                            teammemberprofile.ProfileId        = twitterAccount.TwitterUserId;
                            teammemberprofile.ProfileType      = "twitter";
                            teammemberprofile.StatusUpdateDate = DateTime.Now;

                            objTeamMemberProfileRepository.addNewTeamMember(teammemberprofile);
                        }
                    }
                    else
                    {
                        socioprofilerepo.updateSocialProfile(socioprofile);
                    }
                }
                else
                {
                    HttpContext.Current.Session["alreadyexist"] = twitterAccount;
                    twtrepo.updateTwitterUser(twitterAccount);
                    TwitterMessageRepository twtmsgreponew = new TwitterMessageRepository();
                    twtmsgreponew.updateScreenName(twitterAccount.TwitterUserId, twitterAccount.TwitterScreenName);
                    if (!socioprofilerepo.checkUserProfileExist(socioprofile))
                    {
                        socioprofilerepo.addNewProfileForUser(socioprofile);
                    }
                    else
                    {
                        socioprofilerepo.updateSocialProfile(socioprofile);
                    }
                }
                if (Session["UserAndGroupsForTwitter"] != null)
                {
                    if (Session["UserAndGroupsForTwitter"].ToString() == "twitter")
                    {
                        try
                        {
                            if (Session["GroupName"] != null)
                            {
                                Groups                 group            = (Groups)Session["GroupName"];
                                GroupProfile           groupprofile     = new GroupProfile();
                                GroupProfileRepository groupprofilerepo = new GroupProfileRepository();
                                groupprofile.Id           = Guid.NewGuid();
                                groupprofile.ProfileId    = socioprofile.ProfileId;
                                groupprofile.ProfileType  = "twitter";
                                groupprofile.GroupOwnerId = user.Id;
                                groupprofile.EntryDate    = DateTime.Now;
                                groupprofile.GroupId      = group.Id;
                                if (!groupprofilerepo.checkGroupProfileExists(user.Id, group.Id, groupprofile.ProfileId))
                                {
                                    groupprofilerepo.AddGroupProfile(groupprofile);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.StackTrace);
                        }
                    }
                }
            }
        }