Index: Core/Common/src/Core.Common.Base/Service/Activity.cs =================================================================== diff -u -r3b28759abc544be3c226b517080a032b3b9d1401 -reeb8bcc69eda031ff6363caf83e8893e2abe9a04 --- Core/Common/src/Core.Common.Base/Service/Activity.cs (.../Activity.cs) (revision 3b28759abc544be3c226b517080a032b3b9d1401) +++ Core/Common/src/Core.Common.Base/Service/Activity.cs (.../Activity.cs) (revision eeb8bcc69eda031ff6363caf83e8893e2abe9a04) @@ -1,34 +1,44 @@ using System; +using System.Collections.Generic; using Core.Common.Base.Properties; using log4net; namespace Core.Common.Base.Service { /// - /// Defines basic activity which can be executed as part of the workflow. + /// Abstract class that can be used for performing activies (like calculations, data imports, data exports, etc.). + /// The regular workflow for completely performing an is: -> . + /// can be called for cancelling a running . /// - /// - /// Regular workflow for an activity is: Initialize -> Execute -> Finish -> Cleanup. - /// Regular workflow for an activity with an error occurring: [Initialize/Execute/Finish] -> ! Exception / Error ! -> Cleanup. - /// Regular workflow for an activity being cancelled: [Initialize/Execute/Finish] -> ! Cancel ! -> Cleanup. - /// public abstract class Activity { public event EventHandler ProgressChanged; + private readonly ILog log = LogManager.GetLogger(typeof(Activity)); private string progressText; + /// + /// Constructs a new . + /// protected Activity() { - Log = ""; + LogMessages = new List(); } - public string Log { get; set; } - + /// + /// Gets or sets the name of the . + /// public virtual string Name { get; set; } + /// + /// Gets or sets the of the . + /// public ActivityStatus Status { get; protected set; } + /// + /// Gets or sets the progress text of the . + /// listeners are notified when the progress text is set. + /// public string ProgressText { get @@ -43,41 +53,50 @@ } } + /// + /// Gets or sets the collection of log messages of the (which is appended while performing the ). + /// + public IList LogMessages { get; private set; } + + /// + /// This method runs the by sequentially making calls to and . + /// public void Run() { - try + Initialize(); + + if (Status == ActivityStatus.Failed) { - Initialize(); + log.ErrorFormat(Resources.Activity_Run_Initialization_of_0_has_failed, Name); + return; + } - if (Status == ActivityStatus.Failed) - { - throw new Exception(string.Format(Resources.Activity_Run_Initialization_of_0_has_failed, Name)); - } + if (Status == ActivityStatus.Cancelled) + { + log.WarnFormat(Resources.Activity_Run_Execution_of_0_has_been_canceled, Name); + return; + } - if (Status == ActivityStatus.Cancelled) - { - log.WarnFormat(Resources.Activity_Run_Execution_of_0_has_been_canceled, Name); - return; - } + Execute(); - Execute(); - - if (Status == ActivityStatus.Failed) - { - throw new Exception(string.Format(Resources.Activity_Run_Execution_of_0_has_failed, Name)); - } - } - catch (Exception exception) + if (Status == ActivityStatus.Failed) { - log.Error(exception.Message); + log.ErrorFormat(Resources.Activity_Run_Execution_of_0_has_failed, Name); } } + /// + /// This method cancels a running . + /// public void Cancel() { ChangeState(OnCancel, ActivityStatus.Cancelling, ActivityStatus.Cancelled); } + /// + /// This method finishes an that successfully ran. + /// Successfully ran activities can be identified by a not equal to or . + /// public void Finish() { if (Status != ActivityStatus.Failed && Status != ActivityStatus.Cancelled) @@ -86,11 +105,18 @@ } } + /// + /// This method initializes an . + /// protected void Initialize() { ChangeState(OnInitialize, ActivityStatus.Initializing, ActivityStatus.Initialized); } + /// + /// This method executes an that successfully initialized. + /// Successfully ran activities can be identified by a not equal to or . + /// protected void Execute() { if (Status == ActivityStatus.Finished || Status == ActivityStatus.Cancelled || Status == ActivityStatus.Failed || Status == ActivityStatus.None) @@ -126,14 +152,6 @@ Status = ActivityStatus.Executed; } - private void OnProgressChanged() - { - if (ProgressChanged != null) - { - ProgressChanged(this, EventArgs.Empty); - } - } - /// /// Initializes internal state to prepare for execution. After calling this method, /// will be set to if @@ -166,6 +184,14 @@ /// protected abstract void OnCancel(); + private void OnProgressChanged() + { + if (ProgressChanged != null) + { + ProgressChanged(this, EventArgs.Empty); + } + } + private void ChangeState(Action transitionAction, ActivityStatus statusBefore, ActivityStatus statusAfter) { try Index: Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialog.cs =================================================================== diff -u -r45c065296e76b454bcef8ae508bc39954ff813e1 -reeb8bcc69eda031ff6363caf83e8893e2abe9a04 --- Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialog.cs (.../ActivityProgressDialog.cs) (revision 45c065296e76b454bcef8ae508bc39954ff813e1) +++ Core/Common/src/Core.Common.Gui/Forms/ProgressDialog/ActivityProgressDialog.cs (.../ActivityProgressDialog.cs) (revision eeb8bcc69eda031ff6363caf83e8893e2abe9a04) @@ -59,7 +59,7 @@ { if (RunReportLogAppender.Instance != null) { - RunReportLogAppender.Instance.AppendMessageLineAction = message => runningActivity.Log += message; + RunReportLogAppender.Instance.AppendMessageLineAction = message => runningActivity.LogMessages.Add(message); } runningActivity.ProgressChanged += ActivityOnProgressChanged; Index: Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingCalculationActivity.cs =================================================================== diff -u -r1f79b34c12554e2b9878f6296168d18232cc9852 -reeb8bcc69eda031ff6363caf83e8893e2abe9a04 --- Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingCalculationActivity.cs (.../PipingCalculationActivity.cs) (revision 1f79b34c12554e2b9878f6296168d18232cc9852) +++ Ringtoets/Piping/src/Ringtoets.Piping.Service/PipingCalculationActivity.cs (.../PipingCalculationActivity.cs) (revision eeb8bcc69eda031ff6363caf83e8893e2abe9a04) @@ -35,6 +35,7 @@ } else { + LogMessages.Clear(); calculation.Output = null; } }