/// <summary> /// Process the specific stage and handle the errors /// </summary> /// <param name="processingStage">Stage to process</param> /// <returns>true iff successfully processed with error causing process to stop</returns> private async Task <bool> ProcessStage(ProcessingStage processingStage) { try { Repo.RecordProcessingStart(processingStage); await Repo.Committer.Invoke(); switch (processingStage) { case ProcessingStage.Load: await Load(); return(true); case ProcessingStage.Analyze: await Analyze(); return(true); case ProcessingStage.Apply: await Apply(); return(true); default: return(false); } } catch (Exception ex) { RefreshContext(); var pe = (ex as ProcessingException) ?? new ProcessingException(Logger.Here(), $"Unhandled processing error. {ex.Message}", ex); Repo.RecordProcessingError(pe.Message, processingStage); await Repo.Committer.Invoke(); return(false); } finally { RefreshContext(); Repo.RecordProcessingStop(processingStage); await Repo.Committer.Invoke(); } }