public Argument(Field field, string Value) { this.Field = field; this.Value = Value; idd = IDDDataModel.GetInstance(); }
public void LoadIDDFile(string path) { IDDObjects = new List<Object>(); List<String> FileAsString = File.ReadAllLines(path).ToList<string>(); #region regex strings. // blank regex. Regex blank = new Regex(@"^$"); // object name regex. Regex object_regex = new Regex(@"^\s*(\S*),\s*$", RegexOptions.IgnoreCase); // Field start and switch. Regex field_regex = new Regex(@"^(\s*(A|N)\d*)\s*(\,|\;)\s*\\field\s(.*)?!?", RegexOptions.IgnoreCase); Regex extensible_regex = new Regex(@"^(.*):(\d*)"); // switch. Regex switch_regex = new Regex(@"^\s*(\\\S*)(\s*(.*)?)", RegexOptions.IgnoreCase); // group switch. Regex group_regex = new Regex(@"^\s*(\\group)\s*(.*)$", RegexOptions.IgnoreCase); #endregion Object current_object = null; String current_group = null; String current_object_name = null; Field current_field = null; int iExtensible = 0; int field_counter = 0; bool bBeginExtensible = false; foreach (string line in FileAsString) { //Todo - Rewrite the field and maybe object so that only when a full list of object switches and all the field and field switches are present to add to the class. //clear comments. string newline = Regex.Replace(line, @"^(.*)(\!.*)$", "$1"); //check if blank line Match match = blank.Match(newline); if (!match.Success) { //Search for a /group match Match group_match = group_regex.Match(newline); if (group_match.Success) { //store group name. current_group = group_match.Groups[2].ToString().Trim(); } //Search for a Object Match Match object_match = object_regex.Match(newline); if (object_match.Success) { //Found new object. iExtensible = 0; bBeginExtensible = false; current_object_name = object_match.Groups[1].ToString().Trim(); //Create new object. current_object = new Object(current_object_name, current_group); IDDObjects.Add(current_object); current_field = null; field_counter = 0; } //Search for a Field Match Match field_match = field_regex.Match(newline); // I want to skip this if bBeginExtensible is true and iExtensible <=0 if (field_match.Success && !(bBeginExtensible == true && iExtensible <= 0)) { //Found new field. string field_data_name = field_match.Groups[1].ToString().Trim(); int field_position = field_counter++; current_field = new Field(field_data_name, field_position, current_object); current_object.AddField(current_field); //Found First Switch. //Get rid of the "1" if it is an extensible field as to not confuse people. string field_switch = @"\field"; string field_switch_value = field_match.Groups[4].ToString().Trim(); current_field.AddSwitch(new FieldSwitch(field_switch, field_switch_value)); if (bBeginExtensible == true) iExtensible--; } //Search for a swtich match. Match switch_match = switch_regex.Match(newline); //check if object switch. if (current_field == null && !(bBeginExtensible == true && iExtensible == 0) && (switch_match.Success && !group_match.Success)) { //Since this is an object switch, save to object switch table. string object_switch_name; string object_switch_value; if (switch_match.Groups[1].ToString().Trim().Contains(@"\extensible")) { string temp = switch_match.Groups[1].ToString().Trim(); Match extensible_match = extensible_regex.Match(temp); object_switch_name = extensible_match.Groups[1].ToString().Trim(); object_switch_value = extensible_match.Groups[2].ToString().Trim(); iExtensible = Convert.ToInt32(object_switch_value); current_object.NumberOfExtensibleFields = iExtensible; } else { object_switch_name = switch_match.Groups[1].ToString().Trim(); object_switch_value = switch_match.Groups[2].ToString().Trim(); } current_object.AddSwitch(new ObjectSwitch(object_switch_name, object_switch_value)); } //Check if a field switch. if (current_field != null && !(bBeginExtensible == true && iExtensible < 0) && (switch_match.Success && !group_match.Success)) { //new field switch. string field_switch = switch_match.Groups[1].ToString().Trim(); string field_switch_value = switch_match.Groups[2].ToString().Trim(); //Get rid of the "1" if it is an extensible field as to not confuse people. current_field.AddSwitch(new FieldSwitch(field_switch, field_switch_value)); if (field_switch == @"\begin-extensible") { current_object.NumberOfRegularFields = field_counter - 1; bBeginExtensible = true; iExtensible--; } } } } //Sort fields in all objects. foreach (Object obj in IDDObjects) { obj.SortFields(); } GetObjectList(); var q = from object1 in IDDObjects from field in object1.RegularFields select field.UpdateRelationships() ; }
public virtual void AddField(Field Field_pass) { RegularFields.Add(Field_pass); }