/// <summary> /// /// </summary> /// <param name="tweetList"></param> /// <param name="actionState"></param> public void AddTweets(List<TwitterEntity> tweetList, ActionState actionState) { TwitterRepository twitterRepository = new TwitterRepository(); for (int i = 0; i < tweetList.Count; i++) { twitterRepository.Insert(tweetList[i], actionState); } }
public ActionResult GetLastMonthStatistics() { ActionState actionState = new ActionState(); TwitterController twitterController = new TwitterController(); List<UserStatistics> userStat = new List<UserStatistics>(); userStat = twitterController.GetLastMonthStatistics(actionState); ViewData[CommonConstants.ActionState] = actionState; return View(userStat); }
public ActionResult GetTweets() { ActionState actionState = new ActionState(); TwitterController twitterController = new TwitterController(); List<TwitterEntity> twitterEntity = new List<TwitterEntity>(); twitterEntity = twitterController.GetTweets(actionState); ViewData[CommonConstants.ActionState] = actionState; return View(twitterEntity); }
/// <summary> /// /// </summary> /// <param name="actionState"></param> /// <returns></returns> public List<UserStatistics> FindAllUserStatistics(ActionState actionState) { List<UserStatistics> userStattisticsList = new List<UserStatistics>(); IEnumerable<BsonValue> userNameList = FindAUsersID(actionState); for (int i = 0; i < userNameList.ToArray<BsonValue>().Count(); i++) { UserStatistics userStatistic = new UserStatistics(); userStatistic.Name = userNameList.ToArray<BsonValue>()[i].AsString; userStatistic.Count = FindTwitterCountByName(userStatistic.Name, actionState); userStattisticsList.Add(userStatistic); } return userStattisticsList; }
public List<TwitterEntity> FindAll(DateTime start,DateTime end, ActionState actionState) { List<TwitterEntity> twitterEntityList; MongoServer server = null; MongoDatabase database = null; TwitterEntity entity; twitterEntityList = new List<TwitterEntity>(); entity = null; try { server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]); database = server.GetDatabase(CommonConstants.DatabaseName); var query = Query.And(Query.GTE(TwitterConstants.CreatedDate, start), Query.LTE(TwitterConstants.CreatedDate, end)); MongoCollection<BsonDocument> tweet = database.GetCollection<BsonDocument>(TwitterConstants.TweetsCollection); foreach (BsonDocument tweetEntity in tweet.Find(query)) { entity = new TwitterEntity(); entity.ID = tweetEntity[TwitterConstants.ID].ToString(); entity.Name = tweetEntity[TwitterConstants.Name].AsString; entity.ScreenName = tweetEntity[TwitterConstants.ScreenName].AsString; entity.CreatedDate = tweetEntity[TwitterConstants.CreatedDate].AsDateTime; entity.Tweet = tweetEntity[TwitterConstants.Tweets].AsString; entity.UserID = tweetEntity[TwitterConstants.UserID].AsString; twitterEntityList.Add(entity); } actionState.SetSuccess(); } catch (Exception ex) { actionState.SetFail(ActionStateEnum.Exception, ex.Message); } finally { server.Disconnect(); server = null; database = null; } return twitterEntityList; }
public void DeleteAll( ActionState actionState) { MongoServer server = null; MongoDatabase database = null; try { server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]); database = server.GetDatabase(CommonConstants.DatabaseName); MongoCollection<BsonDocument> twiter = database.GetCollection<BsonDocument>(TwitterConstants.TweetsCollection); twiter.RemoveAll(); actionState.SetSuccess(); } catch (Exception ex) { actionState.SetFail(ActionStateEnum.Exception, ex.Message); } finally { server.Disconnect(); server = null; database = null; } }
public List<UserStatistics> AllStatistics(ActionState actionState) { TwitterDomain domain = new TwitterDomain(); return domain.FindAllUserStatistics(actionState); }
public void AddTweets(List<TwitterEntity>tweetList, ActionState actionState) { TwitterDomain domain = new TwitterDomain(); domain.AddTweets(tweetList, actionState); }
public void Insert(TwitterEntity entity, ActionState actionState) { MongoServer server = null; MongoDatabase database = null; try { server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]); database = server.GetDatabase(CommonConstants.DatabaseName); var dataCollection = database.CollectionExists(TwitterConstants.TweetsCollection); if (Convert.ToBoolean(dataCollection) == false) { database.CreateCollection(TwitterConstants.TweetsCollection); MongoCollection<BsonDocument> tweet = database.GetCollection<BsonDocument>(TwitterConstants.TweetsCollection); BsonDocument tweetEntity = new BsonDocument { { TwitterConstants.Name, entity.Name }, { TwitterConstants.ScreenName, entity.ScreenName }, { TwitterConstants.Tweets, entity.Tweet }, { TwitterConstants.UserID, entity.UserID }, { TwitterConstants.CreatedDate, entity.CreatedDate } }; tweet.Insert(tweetEntity); actionState.SetSuccess(); } else { MongoCollection<BsonDocument> tweet = database.GetCollection<BsonDocument>(TwitterConstants.TweetsCollection); BsonDocument tweetEntity = new BsonDocument { { TwitterConstants.Name, entity.Name }, { TwitterConstants.ScreenName, entity.ScreenName }, { TwitterConstants.Tweets, entity.Tweet }, { TwitterConstants.UserID, entity.UserID }, { TwitterConstants.CreatedDate, entity.CreatedDate } }; tweet.Insert(tweetEntity); actionState.SetSuccess(); } } catch (Exception ex) { actionState.SetFail(ActionStateEnum.Exception, ex.Message); } finally { server.Disconnect(); server = null; database = null; } }
/// <summary> /// /// </summary> /// <param name="userName"></param> /// <param name="actionState"></param> /// <returns></returns> public int FindTwitterCountByName(string userName, ActionState actionState) { TwitterRepository twitterRepository = new TwitterRepository(); return twitterRepository.FindTwitterCountByName(userName, actionState); }
/// <summary> /// /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="actionState"></param> /// <returns></returns> public List<TwitterEntity> FindAll(DateTime start, DateTime end, ActionState actionState) { TwitterRepository twitterRepository = new TwitterRepository(); return twitterRepository.FindAll(start, end, actionState); }
/// <summary> /// /// </summary> /// <param name="actionState"></param> /// <returns></returns> public List<TwitterEntity> FindAll(ActionState actionState) { TwitterRepository twitterRepository = new TwitterRepository(); return twitterRepository.FindAll(actionState); }
/// <summary> /// /// </summary> /// <param name="actionState"></param> public void DeleteAll(ActionState actionState) { TwitterRepository twitterRepository = new TwitterRepository(); twitterRepository.DeleteAll(actionState); }
/// <summary> /// /// </summary> /// <param name="actionState"></param> /// <returns></returns> public List<TwitterEntity> GetTwitter(ActionState actionState) { List<TwitterEntity> list = new List<TwitterEntity>(); try { var mvcAuthorizer = new MvcAuthorizer { Credentials = new InMemoryCredentials { ConsumerKey = ConfigurationManager.AppSettings[CommonConstants.ConsumerKey], ConsumerSecret = ConfigurationManager.AppSettings[CommonConstants.ConsumerSecret], AccessToken = ConfigurationManager.AppSettings[CommonConstants.AccessToken], OAuthToken = ConfigurationManager.AppSettings[CommonConstants.OAuthToken], ScreenName = ConfigurationManager.AppSettings[CommonConstants.ScreenName] } }; var twitterCtx = new TwitterContext(mvcAuthorizer); var friendTweets = (from tweet in twitterCtx.Status where tweet.Type == StatusType.Home && tweet.Count == Convert.ToInt32(ConfigurationManager.AppSettings[CommonConstants.TwittegGetFieldCount]) select new TwitterEntity { Name = tweet.User.Name, Tweet = tweet.Text, UserID = tweet.User.Identifier.ID, ScreenName = tweet.User.Identifier.ScreenName, CreatedDate = tweet.CreatedAt }); list = friendTweets.ToList<TwitterEntity>(); actionState.SetSuccess(); } catch (Exception ex) { actionState.SetFail(Enums.ActionStateEnum.Exception, ex.Message); } return list; }
/// <summary> /// /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="name"></param> /// <param name="actionState"></param> /// <returns></returns> public int FindTwitterCountByName(DateTime start, DateTime end, string name, ActionState actionState) { TwitterRepository twitterRepository = new TwitterRepository(); return twitterRepository.FindTwitterCountByName(start, end, name, actionState); }
public List<UserStatistics> GetLastMonthStatistics(ActionState actionState) { TwitterDomain domain = new TwitterDomain(); return domain.FindAllUserStatistics(DateTime.Now.AddMonths(-1), DateTime.Now, actionState); }
public List<TwitterEntity> GetTweets(ActionState actionState) { TwitterDomain domain = new TwitterDomain(); return domain.GetTwitter(actionState); }
public IEnumerable<BsonValue> FindAUsersID(ActionState actionState) { IEnumerable<BsonValue> tweetList = null; MongoServer server = null; MongoDatabase database = null; try { server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]); database = server.GetDatabase(CommonConstants.DatabaseName); IEnumerable<BsonValue> tweet = database.GetCollection<BsonDocument>(TwitterConstants.TweetsCollection).Distinct(TwitterConstants.Name); tweetList = tweet.ToList(); } catch (Exception ex) { actionState.SetFail(ActionStateEnum.Exception, ex.Message); } finally { server.Disconnect(); server = null; database = null; } return tweetList; }
public int FindTwitterCountByName(DateTime start, DateTime end, string name, ActionState actionState) { int count = 0; MongoServer server = null; MongoDatabase database = null; try { server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]); database = server.GetDatabase(CommonConstants.DatabaseName); MongoCollection<BsonDocument> tweet = database.GetCollection<BsonDocument>(TwitterConstants.TweetsCollection); var query = Query.And(Query.EQ(TwitterConstants.Name, name),Query.GTE(TwitterConstants.CreatedDate, start), Query.LTE(TwitterConstants.CreatedDate, end)); var cursor = tweet.Find(query); count = Convert.ToInt32(cursor.Count()); } catch (Exception ex) { actionState.SetFail(ActionStateEnum.Exception, ex.Message); } finally { server.Disconnect(); server = null; database = null; } return count; }
/// <summary> /// /// </summary> /// <param name="actionState"></param> /// <returns></returns> public IEnumerable<BsonValue> FindAUsersID(ActionState actionState) { TwitterRepository twitterRepository = new TwitterRepository(); return twitterRepository.FindAUsersID(actionState); }