Esempio n. 1
0
 public void UpdateTwitterAccountFollowerSecond(Domain.Socioboard.Domain.TwitterAccountFollowers _TwitterAccountFollowers)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //Begin session trasaction and opens up.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             string str = "Update TwitterAccountFollowers set FollowingsCount=:FollowingsCount, FollowersCount=:FollowersCount where UserId=:UserId and ProfileId=:ProfileId and EntryDate>=:EntryDate1 and EntryDate<=:EntryDate2";
             int    i   = session.CreateQuery(str)
                          .SetParameter("FollowingsCount", _TwitterAccountFollowers.FollowingsCount)
                          .SetParameter("FollowersCount", _TwitterAccountFollowers.FollowersCount)
                          .SetParameter("UserId", _TwitterAccountFollowers.UserId)
                          .SetParameter("ProfileId", _TwitterAccountFollowers.ProfileId)
                          .SetParameter("EntryDate1", DateTime.Now.Date.AddHours(12).AddSeconds(1))
                          .SetParameter("EntryDate2", DateTime.Now.AddDays(1).Date.AddSeconds(-1))
                          .ExecuteUpdate();
             transaction.Commit();
         }
     }
 }
Esempio n. 2
0
 public void addTwitterAccountFollower(Domain.Socioboard.Domain.TwitterAccountFollowers task)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 //Proceed action, to save new data.
                 session.Save(task);
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
             }
         } //End Transaction
     }     //End Session
 }
Esempio n. 3
0
        public string AddTwitterAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string requestToken, string requestSecret, string requestVerifier)
        {
            try
            {
                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;

                string ret = string.Empty;
                Users userinfo = new Users();
                oAuthTwitter OAuth = new oAuthTwitter(client_id, client_secret, redirect_uri);
                OAuth.AccessToken = requestToken;
                OAuth.AccessTokenSecret = requestVerifier;
                OAuth.AccessTokenGet(requestToken, requestVerifier);
                JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, OAuth.TwitterScreenName);

                if (profile != null)
                {
                    logger.Error("Twitter.asmx >> AddTwitterAccount >> Twitter profile : " + profile);
                }
                else
                {
                    logger.Error("Twitter.asmx >> AddTwitterAccount >> NULL Twitter profile : " + profile);
                }

                objTwitterAccount = new Domain.Socioboard.Domain.TwitterAccount();
                TwitterUser twtuser;
                foreach (var item in profile)
                {
                    #region Add Twitter Account
                    try
                    {
                        objTwitterAccount.FollowingCount = Convert.ToInt32(item["friends_count"].ToString());
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterAccount.FollowersCount = Convert.ToInt32(item["followers_count"].ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    objTwitterAccount.Id = Guid.NewGuid();
                    objTwitterAccount.IsActive = true;
                    objTwitterAccount.OAuthSecret = OAuth.AccessTokenSecret;
                    objTwitterAccount.OAuthToken = OAuth.AccessToken;
                    try
                    {
                        objTwitterAccount.ProfileImageUrl = item["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);

                    }
                    try
                    {
                        objTwitterAccount.ProfileUrl = string.Empty;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterAccount.TwitterUserId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception er)
                    {
                        try
                        {
                            objTwitterAccount.TwitterUserId = item["id"].ToString().TrimStart('"').TrimEnd('"');
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        Console.WriteLine(er.StackTrace);

                    }

                    try
                    {
                        objTwitterAccount.TwitterScreenName = item["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    objTwitterAccount.UserId = Guid.Parse(UserId);
                    #endregion
                    if (!objTwitterAccountRepository.checkTwitterUserExists(objTwitterAccount.TwitterUserId, Guid.Parse(UserId)))
                    {
                        objTwitterAccountRepository.addTwitterkUser(objTwitterAccount);
                        #region Add TeamMemberProfile
                        Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                        Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile();
                        objTeamMemberProfile.Id = Guid.NewGuid();
                        objTeamMemberProfile.TeamId = objTeam.Id;
                        objTeamMemberProfile.Status = 1;
                        objTeamMemberProfile.ProfileType = "twitter";
                        objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                        objTeamMemberProfile.ProfileId = objTwitterAccount.TwitterUserId;

                        objTeamMemberProfile.ProfileName = objTwitterAccount.TwitterScreenName;
                        objTeamMemberProfile.ProfilePicUrl = objTwitterAccount.ProfileImageUrl;

                        objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                        #endregion
                        #region SocialProfile
                        Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile();
                        objSocialProfile.Id = Guid.NewGuid();
                        objSocialProfile.ProfileType = "twitter";
                        objSocialProfile.ProfileId = objTwitterAccount.TwitterUserId;
                        objSocialProfile.UserId = Guid.Parse(UserId);
                        objSocialProfile.ProfileDate = DateTime.Now;
                        objSocialProfile.ProfileStatus = 1;
                        #endregion
                        #region Add Twitter Stats
                        if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                        {
                            objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                        }
                        objTwitterStats = new Domain.Socioboard.Domain.TwitterStats();
                        Random rNum = new Random();
                        objTwitterStats.Id = Guid.NewGuid();
                        objTwitterStats.TwitterId = objTwitterAccount.TwitterUserId;
                        objTwitterStats.UserId = Guid.Parse(UserId);
                        objTwitterStats.FollowingCount = objTwitterAccount.FollowingCount;
                        objTwitterStats.FollowerCount = objTwitterAccount.FollowersCount;
                        objTwitterStats.Age1820 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age2124 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age2534 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age3544 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age4554 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age5564 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.Age65 = rNum.Next(objTwitterAccount.FollowersCount);
                        objTwitterStats.EntryDate = DateTime.Now;
                        if (!objTwtstats.checkTwitterStatsExists(objTwitterAccount.TwitterUserId, Guid.Parse(UserId)))
                        {
                            objTwtstats.addTwitterStats(objTwitterStats);
                        }
                        #endregion

                        #region AddTwitterFollowerCount
                        Domain.Socioboard.Domain.TwitterAccountFollowers objTwitterAccountFollowers = new Domain.Socioboard.Domain.TwitterAccountFollowers();
                        TwitterAccountFollowersRepository objTwitterAccountFollowersRepository = new TwitterAccountFollowersRepository();
                        objTwitterAccountFollowers.Id = Guid.NewGuid();
                        objTwitterAccountFollowers.UserId = Guid.Parse(UserId);
                        objTwitterAccountFollowers.EntryDate = DateTime.Now;
                        objTwitterAccountFollowers.FollowingsCount = Convert.ToInt32(item["friends_count"].ToString());
                        objTwitterAccountFollowers.FollowersCount = Convert.ToInt32(item["followers_count"].ToString());
                        try
                        {
                            objTwitterAccountFollowers.ProfileId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                        }
                        catch (Exception er)
                        {
                            try
                            {
                                objTwitterAccountFollowers.ProfileId = item["id"].ToString().TrimStart('"').TrimEnd('"');
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            Console.WriteLine(er.StackTrace);

                        }
                        objTwitterAccountFollowersRepository.addTwitterAccountFollower(objTwitterAccountFollowers);
                        #endregion

                        ret = "Account Added Successfully";
                    }
                    else
                    {
                        ret = "Account already Exist !";
                    }
                }
                getTwitterMessages(UserId, OAuth);

                getUserRetweets(UserId, OAuth);


                //edited by avinash[24-03-15]

                getTwitterEngagement(UserId, OAuth);

                getUserTweets(UserId, OAuth);

                getTwitterFeeds(UserId, OAuth);

                getTwitterDirectMessageSent(UserId, OAuth);
                getTwittwrDirectMessageRecieved(OAuth,UserId);
                getUserMentions(OAuth, objTwitterAccount.TwitterUserId, Guid.Parse(UserId));
                getUserFollowers(OAuth, objTwitterAccount.TwitterScreenName, objTwitterAccount.TwitterUserId, Guid.Parse(UserId));
                getUserRetweet(OAuth, objTwitterAccount.TwitterUserId, Guid.Parse(UserId));

                //return ret;
                return new JavaScriptSerializer().Serialize(objTwitterAccount);
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
                return "";
            }
        }
Esempio n. 4
0
        public void getUserTweets(oAuthTwitter OAuth, string TwitterScreenName, string TwitterUserId, Guid userId, Domain.Socioboard.Domain.TwitterAccount objTwitterAccount)
        {

            try
            {
                Users userinfo = new Users();
                TwitterUser twtuser = new TwitterUser();
                JArray data = twtuser.GetStatuses_User_Timeline(OAuth);
                TwitterMessageRepository twtmsgrepo = new TwitterMessageRepository();
                // TwitterMessage twtmsg = new TwitterMessage();
                Domain.Socioboard.Domain.TwitterMessage ObjTwitterMessage = new Domain.Socioboard.Domain.TwitterMessage();
                foreach (var item in data)
                {
                    ObjTwitterMessage.UserId = userId;
                    ObjTwitterMessage.Type = "twt_usertweets";
                    try
                    {
                        ObjTwitterMessage.TwitterMsg = item["text"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.SourceUrl = item["source"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.ScreenName = TwitterScreenName;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.ProfileId = TwitterUserId;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.MessageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.MessageDate = Utility.ParseTwitterTime(item["created_at"].ToString().TrimStart('"').TrimEnd('"'));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.InReplyToStatusUserId = item["in_reply_to_status_id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.Id = Guid.NewGuid();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.FromProfileUrl = item["user"]["profile_image_url"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.FromName = item["user"]["name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        ObjTwitterMessage.FromId = item["user"]["id_str"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    ObjTwitterMessage.EntryDate = DateTime.Now;
                    try
                    {
                        ObjTwitterMessage.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    if (!twtmsgrepo.checkTwitterMessageExists(ObjTwitterMessage.ProfileId, ObjTwitterMessage.UserId, ObjTwitterMessage.MessageId))
                    {
                        twtmsgrepo.addTwitterMessage(ObjTwitterMessage);
                    }

                    #region Add TwitterFollowerCount
                    TwitterAccountFollowersRepository objTwitterAccountFollowersRepository = new TwitterAccountFollowersRepository();
                    Domain.Socioboard.Domain.TwitterAccountFollowers objTwitterAccountFollowers = new Domain.Socioboard.Domain.TwitterAccountFollowers();
                    objTwitterAccountFollowers.Id = Guid.NewGuid();
                    objTwitterAccountFollowers.UserId = userId;
                    objTwitterAccountFollowers.EntryDate = DateTime.Now;
                    objTwitterAccountFollowers.ProfileId = TwitterUserId;
                    JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, TwitterScreenName);
                    foreach (var item_followerdata in profile)
                    {

                        try
                        {
                            objTwitterAccountFollowers.FollowingsCount = Convert.ToInt32(item_followerdata["friends_count"].ToString());
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        try
                        {
                            objTwitterAccountFollowers.FollowersCount = Convert.ToInt32(item_followerdata["followers_count"].ToString());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    objTwitterAccountFollowersRepository.addTwitterAccountFollower(objTwitterAccountFollowers);

                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
Esempio n. 5
0
        public void AddTwitteruserFollower(oAuthTwitter OAuth, Guid userId, string TwitterUserId, string TwitterScreenName)
        {
            #region Add TwitterFollowerCount
            Users userinfo = new Users();
            TwitterAccountFollowersRepository objTwitterAccountFollowersRepository = new TwitterAccountFollowersRepository();
            Domain.Socioboard.Domain.TwitterAccountFollowers objTwitterAccountFollowers = new Domain.Socioboard.Domain.TwitterAccountFollowers();
            objTwitterAccountFollowers.Id = Guid.NewGuid();
            objTwitterAccountFollowers.UserId = userId;
            objTwitterAccountFollowers.EntryDate = DateTime.Now;
            objTwitterAccountFollowers.ProfileId = TwitterUserId;
            try
            {
                JArray profile = userinfo.Get_Users_LookUp_ByScreenName(OAuth, TwitterScreenName);
                foreach (var item_followerdata in profile)
                {

                    try
                    {
                        objTwitterAccountFollowers.FollowingsCount = Convert.ToInt32(item_followerdata["friends_count"].ToString());
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterAccountFollowers.FollowersCount = Convert.ToInt32(item_followerdata["followers_count"].ToString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }

                DateTime t1 = DateTime.Now.Date;
                DateTime t2 = DateTime.Now.Date.AddHours(12);
                DateTime t3 = DateTime.Now.AddDays(1).Date.AddSeconds(-1);
                if (DateTime.Now.TimeOfDay >= t1.TimeOfDay && DateTime.Now.TimeOfDay < t2.TimeOfDay)
                {
                    if (objTwitterAccountFollowersRepository.IsTwitterAccountExistsFirst(userId, TwitterUserId))
                    {
                        objTwitterAccountFollowersRepository.UpdateTwitterAccountFollowerFirst(objTwitterAccountFollowers);
                    }
                    else
                    {
                        objTwitterAccountFollowersRepository.addTwitterAccountFollower(objTwitterAccountFollowers);
                    }
                }
                if (DateTime.Now.TimeOfDay >= t2.TimeOfDay && DateTime.Now.TimeOfDay < t3.TimeOfDay)
                {
                    if (objTwitterAccountFollowersRepository.IsTwitterAccountExistsSecond(userId, TwitterUserId))
                    {
                        objTwitterAccountFollowersRepository.UpdateTwitterAccountFollowerSecond(objTwitterAccountFollowers);
                    }
                    else
                    {
                        objTwitterAccountFollowersRepository.addTwitterAccountFollower(objTwitterAccountFollowers);
                    }
                }

            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }

            #endregion
        }