/// <summary>
 /// Try and parse a frequency line and return an instance of a IReportFrequency.
 /// </summary>
 /// <param name="line">The line to parse.</param>
 /// <param name="report">An instance of a report model.</param>
 /// <param name="events">An instance of an events publish/subcribe interface.</param>
 /// <param name="compiler">An instance of a c# compiler.</param>
 /// <returns>true if line was able to be parsed.</returns>
 public static bool TryParse(string line, Report report, IEvent events, ScriptCompiler compiler)
 {
     if (CSharpExpressionFunction.Compile(line, report, compiler, out IBooleanFunction function, out string errorMessages))
     {
         new ExpressionReportFrequency(report, events, function);
         return(true);
     }
     return(false);
 }
Example #2
0
        private void OnSimulationCommencing(object sender, EventArgs e)
        {
            if (forages == null)
            {
                throw new Exception("No forages component found in simulation.");
            }
            var parentZone = Parent as Zone;

            if (parentZone == null)
            {
                throw new Exception("SimpleGrazing is not in a zone");
            }
            allForages          = forages.ModelsWithDigestibleBiomass.Where(forage => forage.Zone == parentZone).ToList();
            ProportionOfTotalDM = new double[allForages.Count()];

            if (GrazingRotationType == GrazingRotationTypeEnum.TargetMass)
            {
                if (PreGrazeDMArray == null || PreGrazeDMArray.Length != 12)
                {
                    throw new Exception("There must be 12 values input for the pre-grazing DM");
                }
                if (PostGrazeDMArray == null || PostGrazeDMArray.Length != 12)
                {
                    throw new Exception("There must be 12 values input for the post-grazing DM");
                }
            }
            else if (GrazingRotationType == GrazingRotationTypeEnum.Flexible)
            {
                if (string.IsNullOrEmpty(FlexibleExpressionForTimingOfGrazing))
                {
                    throw new Exception("You must specify an expression for timing of grazing.");
                }
                if (CSharpExpressionFunction.Compile(FlexibleExpressionForTimingOfGrazing, this, compiler, out IBooleanFunction f, out string errors))
                {
                    expressionFunction = f;
                }
                else
                {
                    throw new Exception(errors);
                }
            }