Ejemplo n.º 1
0
        private static void SaveUserTweets(string profileId, string screenName, oAuthTwitter oAuth)
        {
            try
            {
                TwitterUser twtuser  = new TwitterUser();
                JArray      Timeline = twtuser.GetStatuses_User_Timeline(oAuth);
                if (Timeline != null)
                {
                    apiHitsCount++;
                    foreach (var item in Timeline)
                    {
                        Domain.Socioboard.Models.Mongo.MongoTwitterMessage objTwitterMessage = new Domain.Socioboard.Models.Mongo.MongoTwitterMessage();
                        objTwitterMessage.id   = ObjectId.GenerateNewId();
                        objTwitterMessage.type = Domain.Socioboard.Enum.TwitterMessageType.TwitterUsertweet;
                        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.mediaUrl = item["extended_entities"]["media"][0]["media_url_https"].ToString().TrimStart('"').TrimEnd('"');
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                        try
                        {
                            objTwitterMessage.screenName = screenName;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                        try
                        {
                            objTwitterMessage.profileId = profileId;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                        try
                        {
                            objTwitterMessage.messageId = item["id_str"].ToString().TrimStart('"').TrimEnd('"');
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                        try
                        {
                            const string format = "ddd MMM dd HH:mm:ss zzzz yyyy";
                            objTwitterMessage.messageDate      = DateTime.ParseExact(item["created_at"].ToString().TrimStart('"').TrimEnd('"'), format, System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy/MM/dd HH:mm:ss");
                            objTwitterMessage.messageTimeStamp = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.ParseExact(item["created_at"].ToString().TrimStart('"').TrimEnd('"'), format, System.Globalization.CultureInfo.InvariantCulture));
                        }
                        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.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);
                        }

                        try
                        {
                            objTwitterMessage.fromScreenName = item["user"]["screen_name"].ToString().TrimStart('"').TrimEnd('"');
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                        MongoRepository mongorepo = new MongoRepository("MongoTwitterMessage");
                        mongorepo.Add <Domain.Socioboard.Models.Mongo.MongoTwitterMessage>(objTwitterMessage);
                    }
                }
                else
                {
                    apiHitsCount = MaxapiHitsCount;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                apiHitsCount = MaxapiHitsCount;
            }
        }
Ejemplo n.º 2
0
 public static void SaveUserFollowers(oAuthTwitter OAuth, string screeenName, string TwitterUserId)
 {
     try
     {
         TimeLine _TimeLine   = new TimeLine();
         JArray   jdata       = _TimeLine.Get_User_Followers(OAuth);
         JArray   user_data   = JArray.Parse(jdata[0]["users"].ToString());
         string   curser      = string.Empty;
         string   curser_next = string.Empty;
         try
         {
             curser_next = jdata[0]["next_cursor"].ToString();
         }
         catch (Exception ex)
         {
             curser_next = "0";
         }
         do
         {
             curser = curser_next;
             Domain.Socioboard.Models.Mongo.MongoTwitterMessage _InboxMessages;
             if (jdata != null)
             {
                 apiHitsCount++;
                 foreach (var item in user_data)
                 {
                     try
                     {
                         _InboxMessages            = new Domain.Socioboard.Models.Mongo.MongoTwitterMessage();
                         _InboxMessages.id         = ObjectId.GenerateNewId();
                         _InboxMessages.profileId  = TwitterUserId;
                         _InboxMessages.type       = Domain.Socioboard.Enum.TwitterMessageType.TwitterFollower;
                         _InboxMessages.messageId  = "";
                         _InboxMessages.readStatus = 1;
                         try
                         {
                             _InboxMessages.twitterMsg = item["description"].ToString();
                         }
                         catch (Exception ex)
                         {
                         }
                         try
                         {
                             _InboxMessages.fromId = item["id_str"].ToString();
                         }
                         catch (Exception ex)
                         {
                             _InboxMessages.fromId = item["id"].ToString();
                         }
                         try
                         {
                             _InboxMessages.fromName = item["screen_name"].ToString();
                         }
                         catch (Exception ex)
                         {
                         }
                         try
                         {
                             _InboxMessages.FollowerCount = Convert.ToInt32(item["followers_count"].ToString());
                         }
                         catch (Exception ex)
                         {
                         }
                         try
                         {
                             _InboxMessages.FollowingCount = Convert.ToInt32(item["friends_count"].ToString());
                         }
                         catch (Exception ex)
                         {
                         }
                         try
                         {
                             _InboxMessages.fromProfileUrl = item["profile_image_url"].ToString();
                         }
                         catch (Exception ex)
                         {
                             _InboxMessages.fromProfileUrl = item["profile_image_url_https"].ToString();
                         }
                         try
                         {
                             _InboxMessages.messageDate      = DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss");
                             _InboxMessages.messageTimeStamp = Domain.Socioboard.Helpers.SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                         }
                         catch (Exception ex)
                         {
                         }
                         _InboxMessages.RecipientId   = TwitterUserId;
                         _InboxMessages.RecipientName = screeenName;
                         MongoRepository mongorepo = new MongoRepository("MongoTwitterMessage");
                         var             result    = mongorepo.Find <Domain.Socioboard.Models.Mongo.MongoTwitterMessage>(t => t.fromId == _InboxMessages.fromId && t.RecipientId == _InboxMessages.RecipientId && t.type == Domain.Socioboard.Enum.TwitterMessageType.TwitterFollower);
                         var             task      = Task.Run(async() =>
                         {
                             return(await result);
                         });
                         IList <Domain.Socioboard.Models.Mongo.MongoTwitterMessage> lstMongoTwitterMessage = task.Result;
                         if (lstMongoTwitterMessage.Count > 0)
                         {
                             mongorepo.UpdateReplace <Domain.Socioboard.Models.Mongo.MongoTwitterMessage>(_InboxMessages, t => t.id == lstMongoTwitterMessage[0].id);
                         }
                         else
                         {
                             mongorepo.Add <Domain.Socioboard.Models.Mongo.MongoTwitterMessage>(_InboxMessages);
                         }
                     }
                     catch (Exception ex)
                     {
                     }
                 }
             }
             else
             {
                 apiHitsCount = MaxapiHitsCount;
             }
             if (curser != "0")
             {
                 jdata       = _TimeLine.Get_User_FollowersWithCurser(OAuth, curser);
                 user_data   = JArray.Parse(jdata[0]["users"].ToString());
                 curser_next = jdata[0]["next_cursor"].ToString();
             }
         }while (curser != "0");
     }
     catch (Exception ex)
     {
         apiHitsCount = MaxapiHitsCount;
     }
 }
Ejemplo n.º 3
0
        public static void SavePageNotification(string AccessToken, string ProfileIds)
        {
            try
            {
                dynamic data = FbUser.notifications(AccessToken);
                Domain.Socioboard.Models.Mongo.MongoTwitterMessage _InboxMessages;
                if (data != null)
                {
                    apiHitsCount++;
                    foreach (var item in data["data"])
                    {
                        _InboxMessages = new Domain.Socioboard.Models.Mongo.MongoTwitterMessage();

                        _InboxMessages.profileId        = ProfileIds;
                        _InboxMessages.type             = Domain.Socioboard.Enum.TwitterMessageType.FacebookPageNotification;
                        _InboxMessages.messageTimeStamp = SBHelper.ConvertToUnixTimestamp(DateTime.UtcNow);
                        try
                        {
                            _InboxMessages.twitterMsg = item["title"].ToString();
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            _InboxMessages.messageId = item["id"].ToString();
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            _InboxMessages.fromId = item["from"]["id"].ToString();
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            _InboxMessages.fromName       = item["from"]["name"].ToString();
                            _InboxMessages.fromScreenName = item["from"]["name"].ToString();
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            _InboxMessages.fromProfileUrl = "http://graph.facebook.com/" + _InboxMessages.fromId + "/picture?type=small";
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            _InboxMessages.RecipientId = item["to"]["id"].ToString();
                        }
                        catch (Exception ex)
                        {
                        }
                        try
                        {
                            _InboxMessages.RecipientName = item["to"]["name"].ToString();
                        }
                        catch (Exception ex)
                        {
                        }
                        //try
                        //{
                        //    _InboxMessages.r = "http://graph.facebook.com/" + _InboxMessages.RecipientId + "/picture?type=small";
                        //}
                        //catch (Exception ex)
                        //{
                        //    _logger.LogError("Facebook.asmx = > getUserNotifications = > " + ex.Message);
                        //}
                        try
                        {
                            _InboxMessages.messageDate = Convert.ToDateTime(item["created_time"].ToString());
                        }
                        catch (Exception ex)
                        {
                        }
                        MongoRepository mongorepo = new MongoRepository("MongoTwitterMessage");
                        var             ret       = mongorepo.Find <Domain.Socioboard.Models.Mongo.MongoTwitterMessage>(t => t.profileId == _InboxMessages.profileId && t.messageId == _InboxMessages.messageId);
                        var             task      = Task.Run(async() =>
                        {
                            return(await ret);
                        });
                        int count = task.Result.Count;
                        if (count < 1)
                        {
                            mongorepo.Add <Domain.Socioboard.Models.Mongo.MongoTwitterMessage>(_InboxMessages);
                        }
                    }
                }
            }
            catch (Exception)
            {
                apiHitsCount = MaxapiHitsCount;
            }
        }