Ejemplo n.º 1
0
        public List<TwitterEntity> FindAll(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);
                MongoCollection<BsonDocument> tweet = database.GetCollection<BsonDocument>(TwitterConstants.TweetsCollection);
                foreach (BsonDocument tweetEntity in tweet.FindAll())
                {
                    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;
        }
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
        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;

            }
        }
Ejemplo n.º 4
0
        /// <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;
        }