Exemplo n.º 1
0
 public string GetTwitterMessageByMessageId(string userid, string Msgid)
 {
     try
     {
         Domain.Myfashion.Domain.TwitterMessage _TwitterMessage = objTwitterMessageRepository.GetTwitterMessageByMessageId(Guid.Parse(userid), Msgid);
         return(new JavaScriptSerializer().Serialize(_TwitterMessage));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         return("Something Went Wrong");
     }
 }
        public void  getTwitterMessages(string UserId, oAuthTwitter OAuth)
        {
            TwitterUser twtuser;

            #region Add Twitter Messages
            twtuser = new TwitterUser();
            try
            {
                TimeLine tl = new TimeLine();
                JArray data = null;
                try
                {
                    data = tl.Get_Statuses_Mentions_Timeline(OAuth);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                    logger.Error("tl.Get_Statuses_Mentions_Timeline ex.StackTrace >> " + ex.StackTrace);
                    logger.Error("tl.Get_Statuses_Mentions_Timeline ex.Message >> " + ex.Message);
                }
                objTwitterMessage = new Domain.Myfashion.Domain.TwitterMessage();
                foreach (var item in data)
                {
                    objTwitterMessage.UserId = Guid.Parse(UserId);
                    objTwitterMessage.Type = "twt_mentions";
                    objTwitterMessage.Id = Guid.NewGuid();

                    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.TwitterMsg = item["text"].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);
                    }

                    try
                    {
                        objTwitterMessage.FromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                    }
                    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.InReplyToStatusUserId = item["in_reply_to_status_id_str"].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.ProfileId = objTwitterAccount.TwitterUserId;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    try
                    {
                        objTwitterMessage.ScreenName = item["user"]["screen_name"].ToString();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }

                    try
                    {
                        objTwitterMessage.EntryDate = DateTime.Now;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                    if (!objTwitterMessageRepository.checkTwitterMessageExists(objTwitterMessage.MessageId))
                    {
                        objTwitterMessageRepository.addTwitterMessage(objTwitterMessage);
                    }

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                logger.Error("tl.Get_Statuses_Mentions_Timeline ex.StackTrace >> " + ex.StackTrace);
                logger.Error("tl.Get_Statuses_Mentions_Timeline ex.Message >> " + ex.Message);
            }
            #endregion
        }
        public void getUserTweets(oAuthTwitter OAuth, string TwitterScreenName, string TwitterUserId, Guid userId, Domain.Myfashion.Domain.TwitterAccount objTwitterAccount)
        {
            int I = 0;
         
            try
            {
                GlobusTwitterLib.Twitter.Core.UserMethods.Users userinfo = new GlobusTwitterLib.Twitter.Core.UserMethods.Users();
                TwitterUser twtuser = new TwitterUser();
                JArray data = twtuser.GetStatuses_User_Timeline(OAuth);
                TwitterMessageRepository twtmsgrepo = new TwitterMessageRepository();
                // TwitterMessage twtmsg = new TwitterMessage();
                Domain.Myfashion.Domain.TwitterMessage ObjTwitterMessage = new Domain.Myfashion.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))
                    {
                        I++;
                        twtmsgrepo.addTwitterMessage(ObjTwitterMessage);
                        logger.Error("getUserTweetsCount>>>"+I);
                    }

                    #region Add TwitterFollowerCount
                    TwitterAccountFollowersRepository objTwitterAccountFollowersRepository = new TwitterAccountFollowersRepository();
                    Domain.Myfashion.Domain.TwitterAccountFollowers objTwitterAccountFollowers = new Domain.Myfashion.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);
            }
        }