Exemple #1
0
        private async void DoWork(object state)
        {
            using (var scope = _services.CreateScope())
            {
                var activityService =
                    scope.ServiceProvider
                    .GetRequiredService <IActivityService>();

                try
                {
                    var count = Interlocked.Increment(ref executionCount);

                    var activities = await activityService.GetActivitiesToSync();

                    var response = await _hqApi.SyncActivities(activities.Select(a => a.ToActivityHQ()));

                    if (response.IsSuccessStatusCode)
                    {
                        await activityService.UpdateSyncDateTime(activities.ToList());

                        _logger.LogInformation($"{activities.Count} records synced!");
                    }
                    else
                    {
                        _logger.LogWarning("No records to sync!");
                    }

                    _logger.LogInformation(
                        "Timed Hosted Service is working. Count: {Count}", count);
                }
                catch (Exception e)
                {
                    _logger.LogError(e.ToString());
                }
            }
        }
Exemple #2
0
        public async Task <IActionResult> SyncActivities()
        {
            try
            {
                var activities = await _activityService.GetActivitiesToSync();

                var response = await _hqApi.SyncActivities(activities.Select(a => a.ToActivityHQ()));

                if (response.IsSuccessStatusCode)
                {
                    await _activityService.UpdateSyncDateTime(activities.ToList());

                    return(Ok());
                }
                else
                {
                    return(BadRequest(new ErrorPayload(1, "Sync failed!")));
                }
            }
            catch (Exception e)
            {
                return(BadRequest(new ErrorPayload(1, e.Message)));
            }
        }