/// <summary> /// Method used to perform activity if it can occur as soon as resources are available. /// </summary> public override void PerformActivity() { if (ResourceRequestList.Count() > 0) { Area = ResourceRequestList.FirstOrDefault().Available; } return; }
private void OnCLEMInitialiseResource(object sender, EventArgs e) { if (Area == 0 & AreaRequested > 0) { ResourceRequestList = new List <ResourceRequest>(); ResourceRequestList.Add(new ResourceRequest() { AllowTransmutation = false, Required = AreaRequested, ResourceType = typeof(Land), ResourceTypeName = LandTypeNameToUse, ActivityModel = this, Reason = "Assign", FilterDetails = null } ); } // if we get here we assume some land has been supplied if (ResourceRequestList != null || ResourceRequestList.Count() > 0) { gotLandRequested = TakeResources(ResourceRequestList, false); } //Now the Land has been allocated we have an Area if (gotLandRequested) { //get the units of area for this run from the Land resource parent. unitsOfArea2Ha = Resources.Land().UnitsOfAreaToHaConversion; // locate Pasture Type resource LinkedNativeFoodType = Resources.GetResourceItem(this, typeof(GrazeFoodStore), FeedTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as GrazeFoodStoreType; //Assign the area actually got after taking it. It might be less than AreaRequested (if partial) Area = ResourceRequestList.FirstOrDefault().Provided; LinkedNativeFoodType.Area = Area; soilIndex = ((LandType)ResourceRequestList.FirstOrDefault().Resource).SoilType; LinkedNativeFoodType.CurrentEcologicalIndicators.LandConditionIndex = LandConditionIndex.StartingValue; LinkedNativeFoodType.CurrentEcologicalIndicators.GrassBasalArea = GrassBasalArea.StartingValue; LinkedNativeFoodType.CurrentEcologicalIndicators.StockingRate = StartingStockingRate; StockingRateSummed = StartingStockingRate; //Now we have a stocking rate and we have starting values for Land Condition and Grass Basal Area //get the starting pasture data list from GRASP GetPastureDataList_TodayToNextEcolCalculation(); SetupStartingPasturePools(StartingAmount); } }
private void OnCLEMInitialiseResource(object sender, EventArgs e) { // activity is performed in CLEMUpdatePasture not CLEMGetResources and has no labour this.AllocationStyle = ResourceAllocationStyle.Manual; // locate Land Type resource for this forage. LinkedLandItem = Resources.GetResourceItem(this, LandTypeNameToUse, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as LandType; LandConditionIndex = Apsim.Children(this, typeof(Relationship)).Where(a => a.Name == "LandConditionIndex").FirstOrDefault() as Relationship; GrassBasalArea = Apsim.Children(this, typeof(Relationship)).Where(a => a.Name == "GrassBasalArea").FirstOrDefault() as Relationship; FileGRASP = Apsim.ChildrenRecursively(ZoneCLEM.Parent).Where(a => a.Name == ModelNameFileGRASP).FirstOrDefault() as IFileGRASP; if (UseAreaAvailable) { LinkedLandItem.TransactionOccurred += LinkedLandItem_TransactionOccurred; } if (Area == 0 && AreaRequested > 0) { ResourceRequestList = new List <ResourceRequest> { new ResourceRequest() { AllowTransmutation = false, Required = UseAreaAvailable ? LinkedLandItem.AreaAvailable : AreaRequested, ResourceType = typeof(Land), ResourceTypeName = LandTypeNameToUse.Split('.').Last(), ActivityModel = this, Reason = "Assign", FilterDetails = null } }; } // if we get here we assume some land has been supplied if (ResourceRequestList != null && ResourceRequestList.Count() > 0) { CheckResources(ResourceRequestList, Guid.NewGuid()); gotLandRequested = TakeResources(ResourceRequestList, false); } //Now the Land has been allocated we have an Area if (gotLandRequested) { //get the units of area for this run from the Land resource parent. unitsOfArea2Ha = Resources.Land().UnitsOfAreaToHaConversion; // locate Pasture Type resource LinkedNativeFoodType = Resources.GetResourceItem(this, FeedTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as GrazeFoodStoreType; //Assign the area actually got after taking it. It might be less than AreaRequested (if partial) Area = ResourceRequestList.FirstOrDefault().Provided; // ensure no other activity has set the area of this GrazeFoodStore LinkedNativeFoodType.Manager = this as IPastureManager; soilIndex = ((LandType)ResourceRequestList.FirstOrDefault().Resource).SoilType; LinkedNativeFoodType.CurrentEcologicalIndicators.LandConditionIndex = LandConditionIndex.StartingValue; LinkedNativeFoodType.CurrentEcologicalIndicators.GrassBasalArea = GrassBasalArea.StartingValue; LinkedNativeFoodType.CurrentEcologicalIndicators.StockingRate = StartingStockingRate; StockingRateSummed = StartingStockingRate; //Now we have a stocking rate and we have starting values for Land Condition and Grass Basal Area //get the starting pasture data list from GRASP GetPastureDataList_TodayToNextEcolCalculation(); SetupStartingPasturePools(StartingAmount); } }