Beispiel #1
0
 public void AddAccount(Account account)
 {
     using (var session = _store.OpenSession())
     {
         session.Store(account);
         session.SaveChanges();
     }
 }
        public void Initialize(Account account)
        {
            var twitterContextBuilder = new TwitterContextBuilder();
            var context = twitterContextBuilder.Build(account.TwitterCredentials);
            IQueryBuilder queryBuilder = new QueryTimeLineBuilder(context);

            var result = LoadStatuses(queryBuilder, account.MinId - 1);
            result = result.OrderByDescending(x => x.CreatedAt).ToList();
            account.MarkAsInitialized();
            if (result.Count != 0)
            {
                account.MinId = result[result.Count - 1].StatusID;
                if (account.MaxId < result[0].StatusID)
                {
                    account.MaxId = result[0].StatusID;
                }
            }
            var following = Followers(context, account.TwitterCredentials.ScreenName);

            _storage.AddStatuses(_statusMapper.Map(result));
            _storage.UpdateIdsAccount(account, true);
            _storage.SetFollowing(account, following);
        }
Beispiel #3
0
        public void UpdateIdsAccount(Account account, bool markAsInitialized = false)
        {
            _store.DatabaseCommands.Patch(
                account.Id,
                new[]
                {
                    new PatchRequest
                    {

                        Name = "MaxId",
                        Value = account.MaxId
                    }
                });
            _store.DatabaseCommands.Patch(
                account.Id,
                new[]
                {
                    new PatchRequest
                    {

                        Name = "MinId",
                        Value = account.MinId
                    }
                });
            _store.DatabaseCommands.Patch(
                account.Id,
                new[]
                {
                    new PatchRequest
                    {

                        Name = "IsInitialized",
                        Value = account.IsInitialized
                    }
                });
        }
Beispiel #4
0
 public void SetFollowing(Account account, IEnumerable<string> following)
 {
     using (var session = _store.OpenSession())
     {
         var firstOrDefault =
             session.Query<Account>()
                 .FirstOrDefault(x => x.TwitterCredentials.UserId == account.TwitterCredentials.UserId);
         if (firstOrDefault == null) return;
         firstOrDefault.Following = following;
         session.SaveChanges();
     }
 }