public IActionResult PostSyncModels(List <SyncModel> syncModels)
        {
            syncModels.ForEach(x =>
            {
                if (x.Id == Guid.Empty)
                {
                    x.Id = Guid.NewGuid();
                }
            });

            using (SyncDbContext context = _dbFactory.CreateDbContext())
            {
                List <Guid> apiIds = context.SyncModels.AsNoTracking().Select(x => x.Id).ToList();

                List <SyncModel> updatedModels = syncModels.Where(x => apiIds.Any(o => o == x.Id)).ToList();
                List <SyncModel> newModels     = syncModels.Where(x => !apiIds.Any(o => o == x.Id)).ToList();

                context.UpdateRange(updatedModels);
                context.AddRange(newModels);

                context.SaveChanges();

                return(Ok());
            }
        }
예제 #2
0
        async Task NotifyAsync(IDiscordClient client, SyncDbContext db, CancellationToken cancellationToken = default)
        {
            var time = DateTimeOffset.UtcNow;

            while (true)
            {
                var notifications = await db.Notifications.Include(n => n.User).Where(n => n.Time <= time).OrderBy(n => n.Time).Take(50).ToListAsync(cancellationToken);

                if (notifications.Count == 0)
                {
                    break;
                }

                await Task.WhenAll(notifications.Select(async notification =>
                {
                    try
                    {
                        await SendAsync(client, notification);
                    }
                    catch (Exception e)
                    {
                        _logger.LogWarning(e, $"Could not send notification '{notification.Key}' to user {notification.User.DiscordUserId}.");
                    }
                }));

                db.RemoveRange(notifications);

                await db.SaveChangesAsync(cancellationToken);

                _logger.LogInformation($"Removed {notifications.Count} notifications from queue.");
            }
        }
        public IActionResult AddNewCharacterSyncModel()
        {
            Character character = new Character
            {
                Id            = Guid.NewGuid(),
                Name          = "New Character",
                Skills        = new Skills(),
                Attributes    = new Attributes(),
                Ammo          = new Ammo(),
                CharacterGear = new List <Gear>(),
                Armor         = new List <Armor>(),
                Weapons       = new List <Weapon>(),
                Talents       = new List <Talent>(),
                PsychicPowers = new List <PyschicPower>(),
            };

            SyncModel syncModel = new SyncModel
            {
                Id = character.Id,
                LastUpdateDateTime = DateTime.Now,
                ModelType          = ModelType.Character,
                Json = JsonConvert.SerializeObject(character)
            };

            using (SyncDbContext context = _dbFactory.CreateDbContext())
            {
                context.Add(syncModel);

                context.SaveChanges();

                return(Ok());
            }
        }
예제 #4
0
 public AuthController(SyncDbContext db, HashHelper hash, AuthHelper auth, ILogger <AuthController> logger)
 {
     _db     = db;
     _hash   = hash;
     _auth   = auth;
     _logger = logger;
 }
        public IActionResult GetSyncModels()
        {
            using (SyncDbContext context = _dbFactory.CreateDbContext())
            {
                List <SyncModel> syncModels = context.SyncModels.ToList();

                return(Ok(syncModels));
            }
        }
        public IActionResult GetSyncModelsSinceLastSyncTime(DateTime dateTime)
        {
            using (SyncDbContext context = _dbFactory.CreateDbContext())
            {
                List <SyncModel> syncModels = context.SyncModels.Where(x => x.LastUpdateDateTime >= dateTime).ToList();

                return(Ok(syncModels));
            }
        }
        public IActionResult GetSyncModelsSinceLastSyncTime(Guid id)
        {
            using (SyncDbContext context = _dbFactory.CreateDbContext())
            {
                SyncModel syncModel = context.SyncModels.Find(id);
                context.Remove(syncModel);

                context.SaveChanges();

                return(Ok());
            }
        }
예제 #8
0
        public Toggl2TempoSynchronizer(
            IConfiguration configuration,
            SyncDbContext context,
            ITogglClient togglClient,
            ITempoClient tempoClient)
        {
            _configuration = configuration;
            _context       = context;

            _togglClient = togglClient;
            _tempoClient = tempoClient;
        }
예제 #9
0
 public SyncController(SyncDbContext db, ILogger <SyncController> logger)
 {
     _db     = db;
     _logger = logger;
 }
예제 #10
0
 public ToggleModule(AuthHelper auth, SyncDbContext db)
 {
     _auth = auth;
     _db   = db;
 }
 /// <summary>
 /// Injected the DbContext in Srevice class
 /// </summary>
 /// <param name="ctx"></param>
 public CategoryService(SyncDbContext ctx)
 {
     this.ctx = ctx;
 }
예제 #12
0
 public ApplicationUserService(SyncDbContext context, IHttpContextAccessor httpContextAccessor)
 {
     _context             = context;
     _httpContextAccessor = httpContextAccessor;
 }
 /// <summary>
 /// Injected the DbContext in Srevice class
 /// </summary>
 /// <param name="ctx"></param>
 public ProductService(SyncDbContext ctx)
 {
     this.ctx = ctx;
 }
예제 #14
0
 public UserController(SyncDbContext db, AuthHelper auth, ILogger <UserController> logger)
 {
     _db     = db;
     _auth   = auth;
     _logger = logger;
 }
 public NotificationController(SyncDbContext db, ILogger <NotificationController> logger)
 {
     _db     = db;
     _logger = logger;
 }