コード例 #1
0
        private void OnCLEMInitialiseActivity(object sender, EventArgs e)
        {
            // This method will only fire if the user has added this activity to the UI
            // Otherwise all details will be provided from GrazeAll code [CLEMInitialiseActivity]

            GrazeFoodStoreModel = Resources.FindResourceType <GrazeFoodStore, GrazeFoodStoreType>(this, GrazeFoodStoreTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop);

            //Create list of children by breed
            foreach (RuminantType herdType in Resources.FindResourceGroup <RuminantHerd>().FindAllChildren <RuminantType>())
            {
                RuminantActivityGrazePastureHerd ragpb = new RuminantActivityGrazePastureHerd
                {
                    GrazeFoodStoreModel = GrazeFoodStoreModel,
                    RuminantTypeModel   = herdType,
                    Parent = this,
                    Clock  = this.Clock,
                    Name   = "Graze_" + (GrazeFoodStoreModel as Model).Name + "_" + herdType.Name
                };

                ragpb.SetLinkedModels(Resources);

                if (ragpb.Clock == null)
                {
                    ragpb.Clock = this.Clock;
                }

                ragpb.InitialiseHerd(true, true);

                if (ActivityList == null)
                {
                    ActivityList = new List <CLEMActivityBase>();
                }

                ActivityList.Add(ragpb);
                ragpb.ResourceShortfallOccurred += Paddock_ResourceShortfallOccurred;
                ragpb.ActivityPerformed         += BubbleHerd_ActivityPerformed;
            }
        }
コード例 #2
0
        private void OnCLEMInitialiseActivity(object sender, EventArgs e)
        {
            GrazeFoodStore grazeFoodStore = Resources.FindResourceGroup <GrazeFoodStore>();

            if (grazeFoodStore != null)
            {
                this.InitialiseHerd(true, true);
                // create activity for each pasture type (and common land) and breed at startup
                // do not include common land pasture..
                foreach (GrazeFoodStoreType pastureType in grazeFoodStore.Children.Where(a => a.GetType() == typeof(GrazeFoodStoreType) || a.GetType() == typeof(CommonLandFoodStoreType)))
                {
                    RuminantActivityGrazePasture ragp = new RuminantActivityGrazePasture
                    {
                        GrazeFoodStoreModel = pastureType,
                        Clock  = clock,
                        Parent = this,
                        Name   = "Graze_" + (pastureType as Model).Name,
                        OnPartialResourcesAvailableAction = this.OnPartialResourcesAvailableAction
                    };
                    ragp.ActivityPerformed += BubblePaddock_ActivityPerformed;
                    ragp.SetLinkedModels(Resources);
                    ragp.InitialiseHerd(true, true);

                    foreach (RuminantType herdType in HerdResource.FindAllChildren <RuminantType>())
                    {
                        RuminantActivityGrazePastureHerd ragpb = new RuminantActivityGrazePastureHerd
                        {
                            GrazeFoodStoreModel = pastureType,
                            RuminantTypeModel   = herdType,
                            HoursGrazed         = HoursGrazed,
                            Parent = ragp,
                            Name   = ragp.Name + "_" + herdType.Name,
                            OnPartialResourcesAvailableAction = this.OnPartialResourcesAvailableAction
                        };

                        ragpb.SetLinkedModels(Resources);

                        if (ragpb.Clock == null)
                        {
                            ragpb.Clock = this.clock;
                        }

                        ragpb.InitialiseHerd(true, true);
                        if (ragp.ActivityList == null)
                        {
                            ragp.ActivityList = new List <CLEMActivityBase>();
                        }

                        ragp.ActivityList.Add(ragpb);
                        ragpb.ResourceShortfallOccurred += GrazeAll_ResourceShortfallOccurred;
                        ragpb.ActivityPerformed         += BubblePaddock_ActivityPerformed;
                    }
                    if (ActivityList == null)
                    {
                        ActivityList = new List <CLEMActivityBase>();
                    }
                    ActivityList.Add(ragp);
                }
            }
            else
            {
                Summary.WriteWarning(this, $"No GrazeFoodStore is available for the ruminant grazing activity [a={this.Name}]!");
            }
        }