/// <summary> /// Deletes a single command from the IDFCommands container. /// </summary> /// <param name="command">Command object to be removed.</param> public void DeleteCommand(IDFCommand command) { if (this.IDFCommandList.Contains(command)) { this.IDFCommandList.Remove(command); } ; this.UpdateAllObjectLists(); }
/// <summary> /// Converts a clean string into a command object. /// </summary> /// <param name="inputstring">string data of a command, no comments or spaces.</param> /// <returns>A command object.</returns> public IDFCommand CreateCommandFromTextString(string inputstring) { IDFCommand new_command; //remove ; inputstring = Regex.Replace(inputstring, @"(^.*)(;\s*$)", @"$1").Trim(); //split along , List<string> items = inputstring.Split(',').ToList(); //find object. IDDObject object_type = this.idd.GetObject(items[0].Trim()); new_command = new IDFCommand(this, object_type); //remove name from List. items.RemoveAt(0); //some values arguments are trailing optional. So to account for that. set the following to what is greater. int limit = items.Count() < object_type.RegularFields.Count() ? items.Count() : object_type.RegularFields.Count(); for (int itemcounter = 0; itemcounter < limit; itemcounter++) { new_command.RegularArguments[itemcounter].Value = items[itemcounter]; } if (limit < Convert.ToInt32(object_type.MinimumFields()) && object_type.NumberOfExtensibleFields == 0) { for (int emptyfieldcounter = limit; emptyfieldcounter < Convert.ToInt32(object_type.MinimumFields()); emptyfieldcounter++) { if (object_type.RegularFields[emptyfieldcounter].Default() != null) { new_command.RegularArguments[emptyfieldcounter].Value = object_type.RegularFields[emptyfieldcounter].Default(); } else { new_command.RegularArguments[emptyfieldcounter].Value = null; } } } //Test that the if the required number of field is defined and that it is >= the number of fields present. Otherwise add error. if (object_type.MinimumFields() != null && items.Count() < Convert.ToInt32(object_type.MinimumFields())) { string message = "Warning:In Command " + object_type.Name + " = " + new_command.GetName() + "\r\n"; message += "\tCommand has " + items.Count() + " when IDD requires " + object_type.MinimumFields() + "\r\n"; this.ErrorList.Add(message); } if (object_type.NumberOfExtensibleFields > 0) { //remove regular argument items from List. items.RemoveRange(0, object_type.RegularFields.Count()); if (items.Count % object_type.NumberOfExtensibleFields != 0 && object_type.IsUniqueObject() == false) { string message = "Warning:In Command " + object_type.Name + " = " + new_command.GetName() + "\r\n"; message += "\tCommand has extensible items of" + items.Count() + " when IDD requires that extensibles be multiples of " + object_type.NumberOfExtensibleFields + "\r\n"; this.ErrorList.Add(message); } if ((items.Count % object_type.NumberOfExtensibleFields != 0) && (object_type.IsUniqueObject())) { string message = "Warning:In Command " + object_type.Name + "\r\n"; message += "\tCommand has extensible items of" + items.Count() + " when IDD requires that extensibles be multiples of " + object_type.NumberOfExtensibleFields + "\r\n"; this.ErrorList.Add(message); } //Clear existing sets if any. new_command.ExtensibleSetArguments.Clear(); for (int itemcounter = 0; itemcounter < items.Count; itemcounter = itemcounter + object_type.NumberOfExtensibleFields) { var ArgumentList = new List<IDFArgument>(); for (int fieldcounter = 0; fieldcounter < object_type.NumberOfExtensibleFields; fieldcounter++) { string value; try { // Some of the example file do not have full extensible sets. Energyplus seemd to ignore this. I guess the interface should // as well. //To-Do implement a warning that we are adding a empty "" argument. value = items[itemcounter + fieldcounter]; } catch (ArgumentOutOfRangeException) { if (object_type.ExtensibleFields[fieldcounter].Default() != null) { value = object_type.ExtensibleFields[fieldcounter].Default(); } else { value = null; } } ArgumentList.Add(new IDFArgument(this, object_type.ExtensibleFields[fieldcounter], value)); } new_command.ExtensibleSetArguments.Add(ArgumentList); } } if (inputstring.ToUpper() + ";" != new_command.ToIDFStringTerse().ToUpper().Trim()) { string error = ("Read In Mismatch\r\n" + "\t" + inputstring.ToUpper() + ";" + "\r\n" + "\t" + new_command.ToIDFStringTerse().ToUpper().Trim() + "\r\n"); this.ErrorList.Add(error); } return new_command; }