using System; using Core.Common.Base.Service; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.Merge; namespace Ringtoets.Integration.Service.Merge { /// /// Activity to load a collection of from a file. /// internal class LoadAssessmentSectionsActivity : Activity { private readonly AssessmentSectionsOwner owner; private readonly IAssessmentSectionProvider assessmentSectionProvider; private readonly string filePath; private bool canceled; /// /// Creates a new instance of . /// /// The owner to set the retrieved collection /// of on. /// The provider defining how to /// retrieve the collection of from a file. /// The file path to retrieve the collection of /// from. /// Thrown when any of the arguments is null. public LoadAssessmentSectionsActivity(AssessmentSectionsOwner owner, IAssessmentSectionProvider assessmentSectionProvider, string filePath) { if (owner == null) { throw new ArgumentNullException(nameof(owner)); } if (assessmentSectionProvider == null) { throw new ArgumentNullException(nameof(assessmentSectionProvider)); } if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } this.owner = owner; this.assessmentSectionProvider = assessmentSectionProvider; this.filePath = filePath; } protected override void OnRun() { owner.AssessmentSections = assessmentSectionProvider.GetAssessmentSections(filePath); } protected override void OnCancel() { canceled = true; } protected override void OnFinish() { if (canceled) { owner.AssessmentSections = null; } } } }