public async Task <IActionResult> getTwitterFeeds(long boardId, int skip, int count) { try { DatabaseRepository dbr = new DatabaseRepository(_logger, _env); Domain.Socioboard.Models.MongoBoards board = BoardMeRepository.getBoard(boardId, _redisCache, _appSettings, _logger, dbr); MongoRepository mongorepo = new MongoRepository("MongoBoardTwitterHashTag", _appSettings); MongoBoardTwitterHashTag twitterhashtag = await mongorepo.FindFirstOrDefault <MongoBoardTwitterHashTag>(x => x.Boardid.Equals(board.boardId)).ConfigureAwait(false); List <MongoBoardTwtFeeds> twtFeedsList = TwitterRepository.AddBoardTwitterHashTagFeeds(twitterhashtag.Screenname, board.twitterHashTag, null, _appSettings, _logger); if (twtFeedsList.Count == 0) { MongoRepository boardrepo = new MongoRepository("MongoBoardTwtFeeds", _appSettings); var builder = Builders <MongoBoardTwtFeeds> .Sort; var sort = builder.Descending(t => t.Publishedtime); IList <MongoBoardTwtFeeds> objTwitterPagelist = await boardrepo.FindWithRange <MongoBoardTwtFeeds>(t => t.Twitterprofileid.Equals(board.twitterHashTag) && t.Feedurl != null, sort, skip, count); return(Ok(objTwitterPagelist)); } return(Ok(twtFeedsList)); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } return(Ok("Something Went Wrong")); }
public string AddTwitterHashTag(string hashTag, string boardId) { MongoBoardTwitterHashTag twitteracc = new MongoBoardTwitterHashTag { Id = ObjectId.GenerateNewId(), strId = ObjectId.GenerateNewId().ToString(), Boardid = boardId, Statuscount = string.Empty, Entrydate = DateTime.UtcNow.ToString(), Screenname = hashTag.ToLower(), Twitterprofileid = "tag", Friendscount = string.Empty, Followingscount = string.Empty, Followerscount = string.Empty, Favouritescount = string.Empty, Photosvideos = string.Empty, Url = string.Empty, Tweet = string.Empty, Profileimageurl = "tag" }; MongoRepository mongorepo = new MongoRepository("MongoBoardTwitterHashTag"); MongoBoardTwitterHashTag objTwitterPage = new MongoBoardTwitterHashTag(); var ret = mongorepo.Find <MongoBoardTwitterHashTag>(t => t.Screenname.Equals(hashTag.ToLower())); var task = Task.Run(async() => { return(await ret); }); IList <MongoBoardTwitterHashTag> objTwitterPagelist = task.Result.ToList(); if (objTwitterPagelist.Count() > 0) { return(objTwitterPagelist.First().strId.ToString()); } mongorepo.Add <MongoBoardTwitterHashTag>(twitteracc); new Thread(delegate() { AddTwittertrendingHashTagFeeds(hashTag, twitteracc.strId.ToString(), null); }).Start(); return(twitteracc.strId.ToString()); }
public async Task <string> AddTwitterHashTag(string hashTag, string boardId, Helper.Cache _redisCache, Helper.AppSettings settings, ILogger _logger) { MongoBoardTwitterHashTag twitteracc = new MongoBoardTwitterHashTag { Id = ObjectId.GenerateNewId(), strId = ObjectId.GenerateNewId().ToString(), Boardid = boardId, Statuscount = string.Empty, Entrydate = DateTime.UtcNow.ToString(), Screenname = hashTag.ToLower(), Twitterprofileid = "tag", Friendscount = string.Empty, Followingscount = string.Empty, Followerscount = string.Empty, Favouritescount = string.Empty, Photosvideos = string.Empty, Url = string.Empty, Tweet = string.Empty, Profileimageurl = "tag" }; MongoRepository mongorepo = new MongoRepository("MongoBoardTwitterHashTag", settings); MongoBoardTwitterHashTag objTwitterPage = new MongoBoardTwitterHashTag(); IList <MongoBoardTwitterHashTag> objTwitterPagelist = await mongorepo.Find <MongoBoardTwitterHashTag>(t => t.Screenname.Equals(hashTag.ToLower())).ConfigureAwait(false); if (objTwitterPagelist.Count() > 0) { return(objTwitterPagelist.First().strId.ToString()); } await mongorepo.Add <MongoBoardTwitterHashTag>(twitteracc).ConfigureAwait(false); //AddBoardTwitterHashTagFeeds(hashTag, twitteracc.strId.ToString(), null, settings, _logger); //UpdaeTwt(twitteracc.strId); return(twitteracc.strId.ToString()); }
public void UpdaeTwt(string twtId, Helper.AppSettings settings, ILogger _logger) { MongoRepository mongorepo = new MongoRepository("MongoBoardTwitterHashTag", settings); var result = mongorepo.Find <MongoBoardTwitterHashTag>(t => t.strId.Equals(twtId)); var task = Task.Run(async() => { return(await result); }); IList <MongoBoardTwitterHashTag> boardtwitteracc = task.Result; MongoBoardTwitterHashTag twitteracc = boardtwitteracc.First(); MongoRepository boardtwtfeedsrepo = new MongoRepository("MongoBoardTwtFeeds", settings); var result1 = boardtwtfeedsrepo.Find <MongoBoardTwtFeeds>(t => t.Twitterprofileid.Equals(twtId)); var task1 = Task.Run(async() => { return(await result1); }); string LastTweetId = task1.Result.Max(t => t.Feedid); AddBoardTwitterHashTagFeeds(twitteracc.Screenname, twitteracc.strId, LastTweetId, settings, _logger); twitteracc.TotalRetweets = GetBoardTwitterFeedsRetweetsCount(twitteracc.strId, settings, _logger); twitteracc.TotalFavorites = GetBoardTwitterFeedsFavoritedCount(twitteracc.strId, settings, _logger); twitteracc.TotalTweets = GetBoardTwitterFeedsCount(twitteracc.strId, settings, _logger); twitteracc.Top5Retweeted.Clear(); twitteracc.Top5Retweeted.AddRange(GetBoardTwitterTopFeeds(twitteracc.strId, settings, _logger)); twitteracc.Top5FavTwitted.Clear(); twitteracc.Top5FavTwitted.AddRange(GetBoardTwitterTopFavTweets(twitteracc.strId, settings, _logger)); FilterDefinition <BsonDocument> filter = new BsonDocument("strId", twitteracc.strId); // var filter = Builders<MongoBoardTwtProfile>.Filter.Eq(s => s.strId, twitteracc.strId); var update = Builders <BsonDocument> .Update .Set("TotalRetweets", twitteracc.TotalRetweets) .Set("TotalFavorites", twitteracc.TotalFavorites) .Set("TotalTweets", twitteracc.TotalTweets) .Set("Top5Retweeted", twitteracc.Top5Retweeted) .Set("Top5FavTwitted", twitteracc.Top5FavTwitted); mongorepo.Update <MongoBoardTwitterHashTag>(update, filter); }