예제 #1
0
        public void getTwitterEngagement(string UserId, oAuthTwitter OAuth)
        {
            #region Add Twitter Engagement
            Tweet objTweet = new Tweet();
            TwitterEngagement objTwitterEngagement = new TwitterEngagement();
            TwitterEngagementRepository objTwitterEngagementRepository = new TwitterEngagementRepository();

            //TwitterMessageRepository objTwitterMessageRepository=new TwitterMessageRepository ();
            List<Domain.Socioboard.Domain.TwitterMessage> lsttwtmessage = objTwitterMessageRepository.getAllTwitterMessagesRetweet(Guid.Parse(UserId), objTwitterAccount.TwitterUserId);
            List<Domain.Socioboard.Domain.TwitterMessage> tsttwtwmessagetweet = objTwitterMessageRepository.getAllTwitterMessagestweet(Guid.Parse(UserId), objTwitterAccount.TwitterUserId);
            foreach (var itemmsg in lsttwtmessage)
            {

                JArray EngagementData = objTweet.Get_Statuses_RetweetsById(OAuth, itemmsg.MessageId);
                foreach (var item in EngagementData)
                {
                    objTwitterEngagement.Id = Guid.NewGuid();
                    objTwitterEngagement.UserId = Guid.Parse(UserId);
                    objTwitterEngagement.EntryDate = DateTime.Now;
                    objTwitterEngagement.ProfileId = objTwitterAccount.TwitterUserId;
                    try
                    {
                        objTwitterEngagement.RetweetCount = item["retweet_count"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterEngagement.ReplyCount = objTwitterMessageRepository.getReplyCountbyProfileId(objTwitterAccount.TwitterUserId, Guid.Parse(UserId)).ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterEngagement.Engagement = ((Int32.Parse(objTwitterEngagement.ReplyCount) + Int32.Parse(objTwitterEngagement.RetweetCount)) * 100 / (objTwitterAccount.FollowersCount)).ToString();
                    }
                    catch (Exception ex)
                    {
                        objTwitterEngagement.Engagement = "0".ToString();
                        Console.WriteLine(ex.StackTrace);
                    } try
                    {
                        objTwitterEngagement.Influence = (((tsttwtwmessagetweet.Count)) * 100 / (objTwitterAccount.FollowersCount)).ToString();
                    }
                    catch (Exception ex)
                    {
                        objTwitterEngagement.Influence = "0".ToString();
                        Console.WriteLine(ex.StackTrace);
                    }
                    objTwitterEngagementRepository.Add(objTwitterEngagement);

                }
            }
            #endregion
        }
예제 #2
0
        public void getUserRetweet(oAuthTwitter OAuth, string TwitterUserId, Guid userId)
        {
            try
            {
                TimeLine _TimeLine = new TimeLine();
                JArray jdata = _TimeLine.Get_Statuses_Retweet_Of_Me(OAuth);
                Domain.Socioboard.Domain.InboxMessages _InboxMessages;
                foreach (var item in jdata)
                {
                    try
                    {
                        _InboxMessages = new Domain.Socioboard.Domain.InboxMessages();
                    
                        _InboxMessages.UserId = userId;
                        _InboxMessages.ProfileId = TwitterUserId;
                        _InboxMessages.ProfileType = "twt";
                        _InboxMessages.MessageType = "twt_retweet";
                        _InboxMessages.EntryTime = DateTime.Now;
                        try
                        {
                            _InboxMessages.MessageId = item["id_str"].ToString();
                        }
                        catch (Exception ex)
                        {
                            _InboxMessages.MessageId = item["id"].ToString();
                        }
                        try
                        {
                            _InboxMessages.Message = item["text"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Twitter.asmx => getUserRetweets => " + ex.Message);
                        }
                        try
                        {
                            _InboxMessages.RecipientId = item["user"]["id_str"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Twitter.asmx => getUserRetweets => " + ex.Message);
                        }
                        try
                        {
                            _InboxMessages.RecipientName = item["user"]["screen_name"].ToString();
                        }
                        catch (Exception ex)
                        {
                            logger.Error("Twitter.asmx => getUserRetweets => " + ex.Message);
                        }
                        try
                        {
                            _InboxMessages.RecipientImageUrl = item["user"]["profile_image_url"].ToString();
                        }
                        catch (Exception ex)
                        {
                            _InboxMessages.RecipientImageUrl = item["user"]["profile_image_url_https"].ToString();
                        }
                        Tweet _tweet = new Tweet();
                        JArray retweet_data = _tweet.Get_Statuses_RetweetsById(OAuth, _InboxMessages.MessageId);
                        foreach (var item_retweet in retweet_data)
                        {
                            _InboxMessages.Id = Guid.NewGuid();
                            try
                            {
                                _InboxMessages.CreatedTime = Utility.ParseTwitterTime(item_retweet["created_at"].ToString());
                            }
                            catch (Exception ex)
                            {
                                logger.Error("Twitter.asmx => getUserRetweets => " + ex.Message);
                            }
                            try
                            {
                                _InboxMessages.FromId = item_retweet["user"]["id_str"].ToString();
                            }
                            catch (Exception ex)
                            {
                                _InboxMessages.FromId = item_retweet["user"]["id"].ToString();
                            }
                            try
                            {
                                _InboxMessages.FromName = item_retweet["user"]["screen_name"].ToString();
                            }
                            catch (Exception ex)
                            {
                                logger.Error("Twitter.asmx => getUserRetweets => " + ex.Message);
                            }
                            try
                            {
                                _InboxMessages.FromImageUrl = item_retweet["user"]["profile_image_url"].ToString();
                            }
                            catch (Exception ex)
                            {
                                _InboxMessages.FromImageUrl = item_retweet["user"]["profile_image_url_https"].ToString();
                            }

                            if (!objInboxMessagesRepository.checkInboxMessageRetweetExists(userId, _InboxMessages.MessageId, _InboxMessages.FromId, _InboxMessages.RecipientId, _InboxMessages.MessageType))
                            {
                                objInboxMessagesRepository.AddInboxMessages(_InboxMessages);
                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error("Twitter.asmx => getUserRetweets => " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Twitter.asmx => getUserRetweets => " + ex.Message);
            }
        }