private void OnCommencing(object sender, EventArgs e) { List <string> variableNames = new List <string>(); if (VariableNames != null) { for (int i = 0; i < this.VariableNames.Length; i++) { // each variable name is now a GrazeFoodStoreType bool isDuplicate = StringUtilities.IndexOfCaseInsensitive(variableNames, this.VariableNames[i].Trim()) != -1; if (!isDuplicate && this.VariableNames[i] != string.Empty) { if (this.VariableNames[i].StartsWith("[")) { variableNames.Add(this.VariableNames[i]); } else { string[] splitName = this.VariableNames[i].Split('.'); if (splitName.Count() == 2) { // make each pool entry for (int j = 0; j <= 12; j++) { if (splitName[1].ToLower() != "growth" | j == 0) { variableNames.Add("[Resources].GrazeFoodStore." + splitName[0] + ".Pool(" + j.ToString() + ", true)." + splitName[1] + " as " + splitName[0] + "" + j.ToString() + "" + splitName[1]); } } if (splitName[1] == "Amount") { // add amounts variableNames.Add("[Resources].GrazeFoodStore." + splitName[0] + ".Amount as TotalAmount"); variableNames.Add("[Resources].GrazeFoodStore." + splitName[0] + ".KilogramsPerHa as TotalkgPerHa"); } } else { throw new ApsimXException(this, "Invalid report property. Expecting full property link or GrazeFoodStoreTypeName.Property"); } } } } // check if clock.today was included. if (!variableNames.Contains("[Clock].Today")) { variableNames.Insert(0, "[Clock].Today"); } } VariableNames = variableNames.ToArray(); if (EventNames == null || EventNames.Count() == 0) { EventNames = new string[] { "[Clock].CLEMHerdSummary" } } ; SubscribeToEvents(); } }
private void OnCommencing(object sender, EventArgs e) { dataToWriteToDb = null; // sanitise the variable names and remove duplicates IModel zone = Apsim.Parent(this, typeof(Zone)); List <string> variableNames = new List <string>(); if (VariableNames != null) { for (int i = 0; i < this.VariableNames.Length; i++) { // each variable name is now a GrazeFoodStoreType bool isDuplicate = StringUtilities.IndexOfCaseInsensitive(variableNames, this.VariableNames[i].Trim()) != -1; if (!isDuplicate && this.VariableNames[i] != string.Empty) { if (this.VariableNames[i].StartsWith("[")) { variableNames.Add(this.VariableNames[i]); } else { string[] splitName = this.VariableNames[i].Split('.'); if (splitName.Count() == 2) { // get specified grazeFoodStoreType grazeStore = Resources.GetResourceItem(this, typeof(GrazeFoodStore), splitName[0], OnMissingResourceActionTypes.Ignore, OnMissingResourceActionTypes.ReportErrorAndStop) as GrazeFoodStoreType; // make each pool entry for (int j = 0; j <= 12; j++) { variableNames.Add(splitName[0] + "-" + j.ToString() + "-" + splitName[1]); } if (splitName[1] == "Amount") { // add amounts variableNames.Add("[Resources].GrazeFoodStore." + splitName[0] + ".Amount as Total amount"); variableNames.Add("[Resources].GrazeFoodStore." + splitName[0] + ".KilogramsPerHa as Total kgPerHa"); } } else { throw new ApsimXException(this, "Invalid report property. Expecting full property link or GrazeFoodStoreTypeName.Property"); } } } } // check if clock.today was included. if (!variableNames.Contains("[Clock].Today")) { variableNames.Insert(0, "[Clock].Today"); } } // Tidy up variable/event names. VariableNames = variableNames.ToArray(); VariableNames = TidyUpVariableNames(); EventNames = TidyUpEventNames(); this.FindVariableMembers(); // Subscribe to events. if (EventNames == null || EventNames.Count() == 0) { events.Subscribe("[Clock].CLEMHerdSummary", DoOutputEvent); } else { foreach (string eventName in EventNames) { if (eventName != string.Empty) { events.Subscribe(eventName.Trim(), DoOutputEvent); } } } }