示例#1
0
 public void SaveChanges()
 {
     using (var context = new ViberConfigDbContext(_dataSource))
     {
         context.SaveChangesAsync();
     }
 }
示例#2
0
        public async Task <List <Account> > WaitNewAccountAsync()
        {
            try
            {
                using (var context = new ViberConfigDbContext(_dataSource))
                {
                    var count = context.Accounts.Count();
                    while (Viber.IsOpen())
                    {
                        await Task.Delay(100);

                        if (count < context.Accounts.Count())
                        {
                            break;
                        }
                    }

                    foreach (var account in context.Accounts)
                    {
                        account.IsValid = true;
                        context.Entry(account).State = EntityState.Modified;
                    }
                    await context.SaveChangesAsync();

                    return(await context.Accounts.ToListAsync());
                }
            }
            catch
            {
                throw;
            }
        }
示例#3
0
        public async Task <int> GetNextActiveAccountAsync()
        {
            var resultIndex = 0;

            try
            {
                using (var context = new ViberConfigDbContext(_dataSource))
                {
                    var accounts = context.Accounts.Where(a => a.IsAutoSignIn).ToList();
                    var index    = accounts.FindIndex(a => a.IsDefault);
                    if (index == accounts.Count - 1)
                    {
                        resultIndex = 0;
                    }
                    else
                    {
                        resultIndex = index + 1;
                    }

                    if (index >= 0)
                    {
                        accounts[index].IsDefault = false;
                    }
                    accounts[resultIndex].IsDefault = true;
                    await context.SaveChangesAsync();
                }
            }
            catch
            {
                // ignored
            }

            return(resultIndex);
        }
示例#4
0
 public async Task OffAccountsAsync()
 {
     try
     {
         using (var context = new ViberConfigDbContext(_dataSource))
         {
             foreach (var account in context.Accounts)
             {
                 account.IsValid = false;
             }
             await context.SaveChangesAsync();
         }
     }
     catch
     {
         // ignored
     }
 }
示例#5
0
 public async Task SaveAccountAsync(Account entity)
 {
     using (var context = new ViberConfigDbContext(_dataSource))
     {
         var account = context.Accounts.Find(entity.Id);
         if (account != null)
         {
             account.IsDefault    = entity.IsDefault;
             account.IsAutoSignIn = entity.IsAutoSignIn;
             account.DeviceKey    = entity.DeviceKey;
             account.Email        = entity.Email;
             account.IsValid      = entity.IsValid;
             account.NickName     = entity.NickName;
             account.TimeStamp    = entity.TimeStamp;
             account.Token        = entity.Token;
             await context.SaveChangesAsync();
         }
     }
 }