Exemple #1
0
        public static ViewLayout ReadXml(XmlReader reader)
        {
            var viewLayout = new ViewLayout(reader.GetAttribute("name"));

            if (reader.IsEmptyElement)
            {
                reader.ReadElementString("layout");
                return(viewLayout);
            }
            reader.Read();
            var columnFormats = new List <Tuple <ColumnId, ColumnFormat> >();
            var rowTransforms = new List <IRowTransform>();

            while (true)
            {
                if (reader.IsStartElement("columnFormat"))
                {
                    var columnFormat = ColumnFormat.EMPTY;

                    var strWidth = reader.GetAttribute("width");
                    if (strWidth != null)
                    {
                        columnFormat = columnFormat.ChangeWidth(int.Parse(strWidth));
                    }
                    columnFormat = columnFormat.ChangeFormat(reader.GetAttribute("format"));
                    columnFormats.Add(Tuple.Create(ColumnId.ParsePersistedString(reader.GetAttribute("column")), columnFormat));
                    if (reader.IsEmptyElement)
                    {
                        reader.ReadElementString("columnFormat");
                    }
                    else
                    {
                        reader.Skip();
                    }
                }
                else if (reader.IsStartElement("pivot"))
                {
                    rowTransforms.Add(PivotSpec.ReadXml(reader));
                }
                else if (reader.IsStartElement("rowFilter"))
                {
                    rowTransforms.Add(RowFilter.ReadXml(reader));
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    reader.ReadEndElement();
                    break;
                }
                else
                {
                    reader.Skip();
                }
            }
            viewLayout.ColumnFormats = ImmutableList.ValueOf(columnFormats);
            viewLayout.RowTransforms = ImmutableList.ValueOf(rowTransforms);
            return(viewLayout);
        }
Exemple #2
0
        public static PivotSpec ReadXml(XmlReader reader)
        {
            var pivotSpec = new PivotSpec();

            if (reader.IsEmptyElement)
            {
                reader.ReadElementString("pivot");
                return(pivotSpec);
            }
            var rowHeaders    = new List <Column>();
            var columnHeaders = new List <Column>();
            var values        = new List <AggregateColumn>();

            reader.Read();
            while (true)
            {
                if (reader.IsStartElement("rowHeader"))
                {
                    rowHeaders.Add(new Column(ColumnId.ParsePersistedString(reader.GetAttribute("sourceColumn")))
                                   .ChangeCaption(reader.GetAttribute("caption")));
                    ReadEndElement(reader, "rowHeader");
                }
                else if (reader.IsStartElement("columnHeader"))
                {
                    columnHeaders.Add(new Column(ColumnId.ParsePersistedString(reader.GetAttribute("sourceColumn"))));
                    ReadEndElement(reader, "columnHeader");
                }
                else if (reader.IsStartElement("value"))
                {
                    values.Add((AggregateColumn) new AggregateColumn(
                                   ColumnId.ParsePersistedString(reader.GetAttribute("sourceColumn")),
                                   AggregateOperation.FromName(reader.GetAttribute("op")))
                               .ChangeCaption(reader.GetAttribute("caption")));
                    ReadEndElement(reader, "value");
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    reader.ReadEndElement();
                    break;
                }
                else
                {
                    reader.Skip();
                }
            }
            pivotSpec.RowHeaders    = ImmutableList.ValueOf(rowHeaders);
            pivotSpec.ColumnHeaders = ImmutableList.ValueOf(columnHeaders);
            pivotSpec.Values        = ImmutableList.ValueOf(values);
            return(pivotSpec);
        }