Free cookie consent management tool by TermsFeed Policy Generator

Changeset 979


Ignore:
Timestamp:
12/11/08 20:44:09 (15 years ago)
Author:
cbahner
Message:

#318 implemented persistence mechanism for new data row model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/ChartDataRowsModel.cs

    r864 r979  
    131131
    132132    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    133       throw new NotImplementedException();
    134      
     133      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     134
     135      foreach (var row in rows) {
     136        XmlNode columnElement = document.CreateNode(XmlNodeType.Element, "row", null);
     137
     138        XmlAttribute idAttr = document.CreateAttribute("label");
     139        idAttr.Value = row.Label.ToString();
     140        columnElement.Attributes.Append(idAttr);
     141
     142        for (int i = 0; i < row.Count; i++) {
     143          if (i == 0) {
     144            columnElement.InnerText += row[i].ToString(CultureInfo.InvariantCulture.NumberFormat);
     145          } else {
     146            columnElement.InnerText += ";" + row[i].ToString(CultureInfo.InvariantCulture.NumberFormat);
     147          }
     148        }
     149        node.AppendChild(columnElement);
     150      }
     151      return node;   
    135152    }
    136153
    137154    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    138       throw new NotImplementedException();
     155      base.Populate(node, restoredObjects);
    139156
     157      foreach (XmlNode dataRow in node.ChildNodes) {
     158        XmlAttributeCollection attrs = dataRow.Attributes;
     159        XmlAttribute rowIdAttr = (XmlAttribute)attrs.GetNamedItem("label");
     160        string rowLabel = rowIdAttr.Value;
     161        DataRow row = new DataRow();
     162        row.Label = rowLabel;
     163
     164        string[] tokens = dataRow.InnerText.Split(';');
     165        double[] data = new double[tokens.Length];
     166        for (int i = 0; i < data.Length; i++) {
     167          if (tokens[i].Length != 0) {
     168            if (
     169              double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) ==
     170              false) {
     171              throw new FormatException("Can't parse " + tokens[i] + " as double value.");
     172            }
     173          }
     174        }
     175        row.AddValues(data);
     176
     177        AddDataRow(row);
     178      }
    140179    }
    141180  }
Note: See TracChangeset for help on using the changeset viewer.