private Participant GetParticipantOutOfXML(XElement participantElement) { int id = int.Parse(participantElement.Attribute("id").Value); List <Criterion> loCriteria = new List <Criterion>(); foreach (XElement CriterionElement in participantElement.Elements("Criterion")) { String name = CriterionElement.Attribute("name").Value; float minVal = float.Parse(CriterionElement.Attribute("minValue").Value); float maxVal = float.Parse(CriterionElement.Attribute("maxValue").Value); float weight = float.Parse(CriterionElement.Attribute("weight").Value); bool isHomogeneous = bool.Parse(CriterionElement.Attribute("isHomogeneous").Value); int valueCount = CriterionElement.Elements("Value").Count(); float [] values = new float[valueCount]; // may I ask WTF foreach (XElement val in CriterionElement.Elements("Value")) { int pos = int.Parse(Regex.Match(val.Attribute("name").Value, @"\d+").Value); values[pos] = float.Parse(val.Attribute("value").Value, ci); } Criterion c = new SpecificCriterion(name, valueCount, minVal, maxVal, isHomogeneous, weight); c.Value = values; loCriteria.Add(c); } return(new Participant(id, loCriteria)); }
public List <Participant> ReadParticipantsFromFile(string file) { List <Participant> loEntries = new List <Participant>(); try { using (StreamReader reader = new StreamReader(file)) { String critBefore = ""; int pIDbefore = -1; Criterion c = null; List <Criterion> criteria = new List <Criterion>(); if (!reader.EndOfStream) { reader.ReadLine(); // throw away the header } while (!reader.EndOfStream) { String line = reader.ReadLine(); if (line.Length == 0) { continue; } String[] l = line.Split(seperator); int id = int.Parse(l[0]); string crit = l[1]; float minVal = float.Parse(l[2]); float maxVal = float.Parse(l[3]); bool isHom = bool.Parse(l[4]); float weight = float.Parse(l[5]); int valCount = int.Parse(l[6]); int valNo = int.Parse(l[7]); float val = float.Parse(l[8]); if (!pIDbefore.Equals(id)) { criteria = new List <Criterion>(); // create new reference critBefore = ""; Participant p = new Participant(criteria); // use the referenceing for all coming criteria loEntries.Add(p); pIDbefore = id; } if (!critBefore.Equals(crit)) { c = new SpecificCriterion(crit, valCount, minVal, maxVal, isHom, weight); criteria.Add(c); critBefore = crit; } c.Value[valNo] = val; } reader.Close(); } } catch (Exception) { throw new Exception("TextFileparticipantReaderWriter.readEntriesFromFile: seems not posible to open file!!!:"); } return(loEntries); }