private void OnCLEMDoCutAndCarry(object sender, EventArgs e)
 {
     // get resources needed such as labour before DoActivity
     // when not going to a GrazeFoodStore that uses CLEMUpdatePasture
     if (LinkedResourceItem.GetType() != typeof(GrazeFoodStoreType))
     {
         GetResourcesRequiredForActivity();
     }
 }
 private void OnCLEMUpdatePasture(object sender, EventArgs e)
 {
     if (LinkedResourceItem.GetType() == typeof(GrazeFoodStoreType))
     {
         if (this.TimingOK)
         {
             Status = ActivityStatus.NotNeeded;
             DoActivity();
         }
     }
 }
        /// <summary>
        /// Method used to perform activity if it can occur as soon as resources are available.
        /// </summary>
        public override void DoActivity()
        {
            int year  = Clock.Today.Year;
            int month = Clock.Today.Month;

            AmountHarvested           = 0;
            AmountAvailableForHarvest = 0;

            if (NextHarvest != null)
            {
                //if this month is a harvest month for this crop
                if ((year == NextHarvest.HarvestDate.Year) && (month == NextHarvest.HarvestDate.Month))
                {
                    if (this.TimingOK)
                    {
                        if (IsTreeCrop)
                        {
                            AmountHarvested = NextHarvest.AmtKg * TreesPerHa * parentManagementActivity.Area * UnitsToHaConverter * ProportionKept;
                        }
                        else
                        {
                            AmountHarvested = NextHarvest.AmtKg * parentManagementActivity.Area * UnitsToHaConverter * ProportionKept;
                        }

                        AmountAvailableForHarvest = AmountHarvested;
                        // reduce amount by limiter if present.
                        if (limiter != null)
                        {
                            double canBeCarried = limiter.GetAmountAvailable(Clock.Today.Month);
                            AmountHarvested = Math.Max(AmountHarvested, canBeCarried);

                            // now modify by labour limits as this is the amount labour was calculated for.
                            double labourLimit = this.LabourLimitProportion;
                            AmountHarvested *= labourLimit;

                            if (labourLimit < 1)
                            {
                                this.Status = ActivityStatus.Partial;
                            }

                            // now limit further by fees not paid
                            double financeLimit = this.LimitProportion(typeof(Finance));


                            limiter.AddWeightCarried(AmountHarvested);
                        }

                        if (AmountHarvested > 0)
                        {
                            double percentN = 0;
                            // if no nitrogen provided form file
                            if (double.IsNaN(NextHarvest.Npct))
                            {
                                if (LinkedResourceItem.GetType() == typeof(GrazeFoodStoreType))
                                {
                                    // grazed pasture with no N read assumes the green biomass N content
                                    percentN = (LinkedResourceItem as GrazeFoodStoreType).GreenNitrogen;
                                }
                            }
                            else
                            {
                                percentN = NextHarvest.Npct;
                            }

                            if (percentN == 0)
                            {
                                //Add without adding any new nitrogen.
                                //The nitrogen value for this feed item in the store remains the same.
                                LinkedResourceItem.Add(AmountHarvested, this, addReason);
                            }
                            else
                            {
                                FoodResourcePacket packet = new FoodResourcePacket()
                                {
                                    Amount   = AmountHarvested,
                                    PercentN = percentN
                                };
                                if (LinkedResourceItem.GetType() == typeof(GrazeFoodStoreType))
                                {
                                    packet.DMD = (LinkedResourceItem as GrazeFoodStoreType).EstimateDMD(packet.PercentN);
                                }
                                LinkedResourceItem.Add(packet, this, addReason);
                            }
                            SetStatusSuccess();
                        }
                        else
                        {
                            if (Status == ActivityStatus.Success)
                            {
                                Status = ActivityStatus.NotNeeded;
                            }
                        }
                    }
                }
                else
                {
                    this.Status = ActivityStatus.NotNeeded;
                }
            }
            else
            {
                this.Status = ActivityStatus.NotNeeded;
            }
        }