Beispiel #1
0
        private async void BwCheckin_DoWork(object sender, DoWorkEventArgs e)
        {
            var submissionManager = new SubmissionManager(new DatabaseManager(_db, null));

            var pendingJobs = submissionManager.GetPendingSubmissions();

            if (!pendingJobs.Any())
            {
                Log.Debug("No Pending Jobs found");

                return;
            }

            Log.Debug($"{pendingJobs.Count} pending jobs found...");

            var workerHandler = new WorkerHandler(_config.WebServiceURL, _config.RegistrationKey);

            foreach (var pJob in pendingJobs)
            {
                Jobs job = null;

                try
                {
                    job = JsonConvert.DeserializeObject <Jobs>(pJob.JobJSON);
                } catch (Exception ex)
                {
                    Log.Error($"For Job ID {pJob.ID}, could not parse {pJob.JobJSON} into a Jobs object due to {ex}");
                }

                if (job == null)
                {
                    Log.Error($"Job was null - removing {pJob.ID} from Queue");

                    submissionManager.RemoveOfflineSubmission(pJob.ID);

                    continue;
                }

                var result = await workerHandler.UpdateWorkAsync(job);

                if (result)
                {
                    Log.Debug($"{job.ID} was successfully uploaded");

                    submissionManager.RemoveOfflineSubmission(pJob.ID);

                    continue;
                }

                Log.Debug($"{job.ID} was not able to be uploaded - will retry at a later date and time");
            }
        }