Пример #1
0
        public void Execute(IEnumerable <DataRow> rows, ISampler <DataRow> sampler, JsonWriter writer)
        {
            rows = rows ?? new List <DataRow>();
            sampler.Build(rows);
            var sampled = sampler.GetResult();

            writer.WriteStartObject();
            writer.WritePropertyName("total-rows");
            writer.WriteValue(rows.Count());
            if (sampler.GetIsSampled())
            {
                writer.WritePropertyName("sampled-rows");
                writer.WriteValue(rows.Count() - sampler.GetExcludedRowCount());
            }

            if (sampled.Count() > 0)
            {
                writer.WritePropertyName("table");
                writer.WriteStartObject();

                writer.WritePropertyName("columns");
                writer.WriteStartArray();
                var formatters = new List <CellFormatter>();

                foreach (DataColumn column in sampled.ElementAt(0).Table.Columns)
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("position");
                    writer.WriteValue(column.Ordinal);
                    writer.WritePropertyName("name");
                    writer.WriteValue(column.ColumnName);

                    var cpFormatter = new ColumnPropertiesFormatter();
                    writer.WritePropertyName("role");
                    writer.WriteValue(cpFormatter.GetRoleText((ColumnRole)(column.ExtendedProperties["NBi::Role"] ?? ColumnRole.Key)));
                    writer.WritePropertyName("type");
                    writer.WriteValue(cpFormatter.GetTypeText((ColumnType)(column.ExtendedProperties["NBi::Type"] ?? ColumnType.Text)));
                    formatters.Add(new CellFormatterFactory().GetObject((ColumnType)(column.ExtendedProperties["NBi::Type"] ?? ColumnType.Text)));
                    var tolerance = (Tolerance)(column.ExtendedProperties["NBi::Tolerance"]);
                    if (!Tolerance.IsNullOrNone(tolerance))
                    {
                        writer.WritePropertyName("tolerance");
                        writer.WriteValue(cpFormatter.GetToleranceText(tolerance).Trim());
                    }
                    var rounding = (Rounding)(column.ExtendedProperties["NBi::Rounding"]);
                    if (rounding != null)
                    {
                        writer.WritePropertyName("rounding");
                        writer.WriteValue(cpFormatter.GetRoundingText(rounding));
                    }
                    writer.WriteEndObject();
                }
                writer.WriteEndArray(); //columns

                BuildRows(sampled, formatters, writer);

                writer.WriteEndObject(); //table
            }
            writer.WriteEndObject();
        }
Пример #2
0
        protected virtual void RenderColumns(IEnumerable <ExtendedMetadata> extendedMetadatas, JsonWriter writer)
        {
            writer.WritePropertyName("columns");
            writer.WriteStartArray();
            foreach (var extendedMetadata in extendedMetadatas)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("position");
                writer.WriteValue(extendedMetadata.Ordinal);
                writer.WritePropertyName("name");
                writer.WriteValue(extendedMetadata.Name);

                var cpFormatter = new ColumnPropertiesFormatter();
                writer.WritePropertyName("role");
                writer.WriteValue(cpFormatter.GetRoleText(extendedMetadata.Role));
                writer.WritePropertyName("type");
                writer.WriteValue(cpFormatter.GetTypeText(extendedMetadata.Type));
                if (!Tolerance.IsNullOrNone(extendedMetadata.Tolerance))
                {
                    writer.WritePropertyName("tolerance");
                    writer.WriteValue(cpFormatter.GetToleranceText(extendedMetadata.Tolerance).Trim());
                }
                if (extendedMetadata.Rounding != null)
                {
                    writer.WritePropertyName("rounding");
                    writer.WriteValue(cpFormatter.GetRoundingText(extendedMetadata.Rounding));
                }
                writer.WriteEndObject();
            }
            writer.WriteEndArray(); //columns
        }
Пример #3
0
        public void Execute(IEnumerable <DataRow> rows, ISampler <DataRow> sampler, IEnumerable <ColumnMetadata> metadata, JsonWriter writer)
        {
            rows = rows ?? new List <DataRow>();
            sampler.Build(rows);
            var sampled = sampler.GetResult();

            writer.WriteStartObject();
            writer.WritePropertyName("total-rows");
            writer.WriteValue(rows.Count());
            if (sampler.GetIsSampled())
            {
                writer.WritePropertyName("sampled-rows");
                writer.WriteValue(rows.Count() - sampler.GetExcludedRowCount());
            }

            if (sampled.Count() > 0)
            {
                writer.WritePropertyName("table");
                writer.WriteStartObject();

                writer.WritePropertyName("columns");
                writer.WriteStartArray();
                var formatters = new List <IPresenter>();

                var columns = sampled.ElementAt(0).Table.Columns;
                for (var i = 0; i < columns.Count; i++)
                {
                    var meta = metadata.ElementAt(i);

                    writer.WriteStartObject();
                    writer.WritePropertyName("position");
                    writer.WriteValue(columns[i].Ordinal);
                    writer.WritePropertyName("name");
                    writer.WriteValue(columns[i].ColumnName);

                    var cpFormatter = new ColumnPropertiesFormatter();
                    writer.WritePropertyName("role");
                    writer.WriteValue(cpFormatter.GetRoleText(meta.Role));
                    writer.WritePropertyName("type");
                    writer.WriteValue(cpFormatter.GetTypeText(meta.Type));
                    if (!Tolerance.IsNullOrNone(meta.Tolerance))
                    {
                        writer.WritePropertyName("tolerance");
                        writer.WriteValue(cpFormatter.GetToleranceText(meta.Tolerance).Trim());
                    }
                    if (meta.Rounding != null)
                    {
                        writer.WritePropertyName("rounding");
                        writer.WriteValue(cpFormatter.GetRoundingText(meta.Rounding));
                    }

                    formatters.Add(new PresenterFactory().Instantiate(metadata.ElementAt(i).Type));
                    writer.WriteEndObject();
                }
                writer.WriteEndArray(); //columns

                BuildRows(sampled, formatters, writer);

                writer.WriteEndObject(); //table
            }
            writer.WriteEndObject();
        }