Beispiel #1
0
        public async Task ExecuteAsync(DateTime from, DateTime to)
        {
            var users = await _brideForeverService.GetUsers(UserMode.Active, UserMode.Silent);

            var enumeratedUsers = users as User[] ?? users.ToArray();

            var dates = from.RangeTo(to).ToList();

            Task.WaitAll(dates.Select(async date =>
            {
                using (var context = _contextProvider.Create())
                {
                    foreach (var user in enumeratedUsers)
                    {
                        var contextUser = context.Set <User>().First(u => u.ID == user.ID);

                        Stopwatch stopwatch = Stopwatch.StartNew();

                        await ApplyUserUpdates(context, contextUser, date);

                        stopwatch.Stop();

                        Console.WriteLine($"Operation at {date.ToShortDateString()} for user {user.Name} completed in {stopwatch.Elapsed.Seconds} seconds.");

                        await context.SaveChangesAsync();
                    }
                }
            }).ToArray());
        }
        public async Task <IEnumerable <UserModel> > GetUsers()
        {
            var users = await _brideForeverService.GetUsers(UserMode.Active, UserMode.Silent);

            var result = new List <UserModel>();

            foreach (var user in users)
            {
                //TODO user automapper
                result.Add(new UserModel
                {
                    Title = user.Name
                });
            }

            return(result);
        }
Beispiel #3
0
        protected override async Task ExecuteAsync()
        {
            var users = await _brideForeverService.GetUsers(UserMode.Active, UserMode.Silent);

            var yesterday = (DateTime.UtcNow - TimeSpan.FromDays(1)).ToStartOfTheDay();

            var enumeratedUsers = users as User[] ?? users.ToArray();

            using (var context = _contextProvider.Create())
            {
                foreach (var user in enumeratedUsers)
                {
                    var contextUser = context.Set <User>().First(u => u.ID == user.ID);
                    await ApplyUserUpdatesAsync(context, contextUser, yesterday);
                }

                await context.SaveChangesAsync();
            }
        }