Tracking activity status
Advanced topic - requires coding skills
The status of activities through time is an important outcomes of the farming system simulation as it defines the ability of the tasks to be performed and any problems that may have been encountered. The status of an activity will inform the user when it was successful, not needed (skipped due to timers), performed with partial resources available, or even performed but with no action needed. The ledger of activity status is displayed in the Activities performed report which automatically handles creation of the activities performed ledger which is used for generating the display. The status of each activity is handled in the code of each activity and the CLEMActivityBase provides methods to clear and report all activities' status as well as some setting of activity status as resources are taken and used.

This simple interface ensures that the components provide an ActivityPerformed event handler. All timers inherit from this interface to ensure they can be reported in the activity ledger along with other activities of type CLEMActivityBase.

Each activity has an ActivityPerformed EventHandler and an OnActivityPerformed method
public event EventHandler ActivityPerformed;
protected virtual void OnActivityPerformed(EventArgs e)
{
ActivityPerformed?.Invoke(this, e);
}

The Activities holder is responsible for reporting the status of every activity provided as children of the component. During the Commencing and Completed APSIM events the Activities Holder binds and unbinds to all children's ActivityPerformed event respectively so that it can catch, handle and report these events occurring.
This component also contains a LastActivityPerformed property of type CLEMActivityBase which is used by the reporting to determine the activity details and status for writing.
This component also calls the ReportAllActivitiesPerformed() method of all children as well as all timers at the CLEMEndOfTimeStep event, as well as clearing all activity status with ClearAllActivitiesPerformedStatus() method for all children at the CLEMStartOfTimeStep event.


The CLEMActivityBase provides a property to store the current status of each activity.
[XmlIgnore]
public ActivityStatus Status { get; set; }
Each resource type inherits the IResourceType interface. This ensures the resource follows the standard that CLEM uses to manage all resources and resource types are only updated through accepted methods. with store amounts a private property

The CLEMActivityBase provides a public method to clear all activities performed status.
public virtual void ClearAllAllActivitiesPerformedStatus()
{
ClearActivitiesPerformedStatus();
}
This public method calls a protected void method (ClearActivitiesPerformedStatus) to cascade through all children activities and custom created activities in the ActivitiesList and clear their status.

The CLEMActivityBase provides a public method to report the status of all activities.
public virtual void ReportAllAllActivitiesPerformed()
{
ReportActivitiesPerformed();
}
This public method calls a protected void method (ReportActivitiesPerformed) to cascade through all children activities and custom created activities in the ActivitiesList and report their status.