public override void InitializeRelatedTables(DataProcessor processor, TableDataBuilder table) { if (!InlineFields) { var tables = processor.TableMap.Tables; var current = tables.FirstOrDefault(t => t.Name == TableName) as TableDataBuilder; if (current != null) { if (!current.Schema.FieldsAreEqual(LookupTableBuilder.Schema) || current.GetType() != LookupTableBuilder.GetType()) { throw new InvalidOperationException("Lookup tables with the same name must have the same schema and type to be shared"); } LookupTableBuilder.Schema.ClearRelations(); LookupTableBuilder = current; } else { //Insert dimension tables in the start, since it is referenced by other tables tables.Insert(0, LookupTableBuilder); } table.Schema.Associate(LookupTableBuilder.Schema, table.Schema.Fields.Where(f => Fields.Contains(f)).ToArray(), LookupTableBuilder.Schema.Keys.Select(fp => fp.Value), true); } //Initialize realted tables in field mappers foreach (var fm in FieldMappers) { fm.InitializeRelatedTables(processor, InlineFields ? table : LookupTableBuilder); } base.InitializeRelatedTables(processor, table); }
public void Initialize(DataProcessor processor, TableDataBuilder parentTable) { foreach (var mapper in TableMappers) { mapper.Initialize(processor, parentTable); } }
public static void View(CremaDataTable dataTable, TextWriter writer) { var columns = GetColumns(); var tableDataBuilder = new TableDataBuilder(columns); var count = 0; var rows = ViewProperties.Sort == string.Empty ? dataTable.Select(ViewProperties.Expression) : dataTable.Select(ViewProperties.Expression, ViewProperties.Sort); foreach (var item in rows) { var items = columns.Select(i => $"{item[i]}").ToArray(); if (ViewProperties.Limit >= 0 && ViewProperties.Limit <= count) { break; } tableDataBuilder.Add(items); count++; } writer.WriteLine(); writer.PrintTableData(tableDataBuilder.Data, true); writer.WriteLine(); string[] GetColumns() { var query = from item in dataTable.Columns where item.IsKey || StringUtility.GlobMany(item.ColumnName, ViewProperties.Columns) select item.ColumnName; if (ColumnLimit <= 0) { return(query.ToArray()); } return(query.Take(ColumnLimit).ToArray()); } }
public void Info(Guid domainID) { var domain = this.GetDomain(domainID); var authentication = this.CommandContext.GetAuthentication(this); var metaData = domain.Dispatcher.Invoke(() => domain.GetMetaData(authentication)); var domainInfo = metaData.DomainInfo; var dataBaseName = this.cremaHost.Dispatcher.Invoke(() => this.cremaHost.DataBases[domainInfo.DataBaseID].Name); var items = new Dictionary <string, object> { { $"{nameof(domainInfo.DomainID)}", domainInfo.DomainID }, { $"{nameof(domainInfo.DataBaseID)}", domainInfo.DataBaseID }, { $"DataBaseName", dataBaseName }, { $"{nameof(domainInfo.DomainType)}", domainInfo.DomainType }, { $"{nameof(domainInfo.ItemType)}", domainInfo.ItemType }, { $"{nameof(domainInfo.ItemPath)}", domainInfo.ItemPath }, { $"{nameof(domainInfo.CreationInfo)}", domainInfo.CreationInfo.ToLocalValue() }, { $"{nameof(domainInfo.ModificationInfo)}", domainInfo.ModificationInfo.ToLocalValue() }, { $"UserList", string.Empty }, }; this.Out.WriteLine(); this.Out.Print <object>(items); var tableDataBuilder = new TableDataBuilder(nameof(DomainUserInfo.UserID), nameof(DomainUserInfo.UserName), nameof(DomainUserState), nameof(DomainUserInfo.AccessType)); foreach (var item in metaData.Users) { tableDataBuilder.Add(item.DomainUserInfo.UserID, item.DomainUserInfo.UserName, item.DomainUserState, item.DomainUserInfo.AccessType); } this.Out.PrintTableData(tableDataBuilder.Data, true); this.Out.WriteLine(); }
public void ViewCategory(string categoryPath, long revision = -1) { var category = this.GetCategory(categoryPath); var builderList = new List <TableDataBuilder>(); var authentication = this.CommandContext.GetAuthentication(this); category.Dispatcher.Invoke(() => { var dataSet = category.GetDataSet(authentication, revision); foreach (var item in dataSet.Types) { builderList.Add(BuildTableData(item)); } }); foreach (var item in builderList) { this.Out.Print(item); } TableDataBuilder BuildTableData(CremaDataType dataType) { var builder = new TableDataBuilder(CremaSchema.Name, CremaSchema.Value, CremaSchema.Comment); foreach (var item in dataType.Members) { builder.Add(item.Name, item.Value, item.Comment); } return(builder); } }
public void TestTableDataBuilderFieldOrder() { var fields = new[] { new Field { FieldType = FieldType.Key, ValueType = typeof(int), Name = "0" }, new Field { FieldType = FieldType.Fact, ValueType = typeof(int), Name = "1" }, new Field { FieldType = FieldType.Dimension, ValueType = typeof(int), Name = "2" }, new Field { FieldType = FieldType.Label, ValueType = typeof(int), Name = "3" }, new Field { FieldType = FieldType.Key, ValueType = typeof(int), Name = "4" }, new Field { FieldType = FieldType.Fact, ValueType = typeof(int), Name = "5" }, new Field { FieldType = FieldType.Dimension, ValueType = typeof(int), Name = "6" } }; var builder = new TableDataBuilder("Test", fields.Select(f => new StaticFieldMapper(f, 0))); Assert.IsTrue( builder.Schema.Fields.SequenceEqual(new[] { fields[0], fields[4], fields[2], fields[3], fields[6], fields[1], fields[5] })); }
public void TestTableDataBuilderDefaultValues() { var fields = new[] { new Field { FieldType = FieldType.Key, ValueType = typeof(int), Name = "0" }, new Field { FieldType = FieldType.Key, ValueType = typeof(int?), Name = "1" }, new Field { FieldType = FieldType.Key, ValueType = typeof(string), Name = "2" }, new Field { FieldType = FieldType.Key, ValueType = typeof(DateTime), Name = "3" }, new Field { FieldType = FieldType.Key, ValueType = typeof(DateTime?), Name = "4" }, }; var builder = new TableDataBuilder("Test", fields.Select(f => new StaticFieldMapper(f, 0))); var row = builder.CreateEmptyRow(); Assert.IsTrue( row.SequenceEqual(new object[] { 0, null, null, default(DateTime), null })); }
public override void InitializeRelatedTables(DataProcessor processor, TableDataBuilder table) { foreach (var fm in FieldMappers.SelectMany(fms => fms)) { fm.InitializeRelatedTables(processor, table); } }
protected override IEnumerable <Field> CreateFields() { _iterator = new FieldMapperIterator(FieldMappers); if (!InlineFields) { LookupTableBuilder = CreateLookupBuilder(); if (LookupTableBuilder.Schema.Keys.Length == 0) { LookupTableBuilder.AddHashKey(HashKeyFactory); } } return(GetFields(InlineFields ? FieldTarget.Inline : FieldTarget.KeyReference).ToArray()); }
public virtual void Initialize(DataProcessor processor, TableDataBuilder parentTable) { Builders = new List <BuilderInfo>(); foreach (var def in TableDefinitions) { var fieldMappers = def.FieldMappers.ToArray(); foreach (var mapper in fieldMappers) { mapper.Initialize(processor); } var builder = fieldMappers.Length == 0 ? null : new TableDataBuilder(def.Name, fieldMappers); var builderInfo = new BuilderInfo(builder); if (builder != null) { if (parentTable != null) { builder.LinkParentTable(parentTable); } builder.EnsureKey(KeyFactory.Default); processor.TableMap.Tables.Add(builderInfo.Builder); } foreach (var fieldMapper in fieldMappers) { fieldMapper.InitializeRelatedTables(processor, builderInfo.Builder); } if (def.TableMappers != null) { foreach (var childTable in def.TableMappers) { builderInfo.Children.Add(childTable); childTable.Initialize(processor, builder ?? parentTable); } } Builders.Add(builderInfo); } }
public void View(string typeName, long revision = -1) { var type = this.GetType(typeName); var tableData = type.Dispatcher.Invoke(() => { var authentication = this.CommandContext.GetAuthentication(this); var dataSet = type.GetDataSet(authentication, revision); var dataType = dataSet.Types[type.Name, type.Category.Path]; var tableDataBuilder = new TableDataBuilder(CremaSchema.Name, CremaSchema.Value, CremaSchema.Comment); foreach (var item in dataType.Members) { tableDataBuilder.Add(item.Name, item.Value, item.Comment); } return(tableDataBuilder); }); this.Out.Print(tableData); }
public void List(string filter = "") { var items = this.GetLogList(); if (DetailProperties.IsDetail == true) { var tableData = new TableDataBuilder(nameof(ILogService.Name), nameof(ILogService.Verbose), nameof(ILogService.FileName)); foreach (var item in this.GetLogList()) { tableData.Add(item.Name, item.Verbose, item.FileName); } this.Out.PrintTableData(tableData.Data, true); } else { foreach (var item in this.GetLogList()) { this.Out.WriteLine(item.Name); } } }
public void ColumnList(string tableName) { var table = this.GetTable(tableName); var tableInfo = table.Dispatcher.Invoke(() => table.TableInfo); var headerList = new List <string>(new string[] { "IsKey", CremaSchema.Name, "DataType", CremaSchema.Comment, }); if (ColumnInfoProperties.ID == true || ColumnInfoProperties.All) { headerList.Add(nameof(ColumnInfoProperties.ID)); } if (ColumnInfoProperties.AllowNull == true || ColumnInfoProperties.All) { headerList.Add(nameof(ColumnInfoProperties.AllowNull)); } if (ColumnInfoProperties.ReadOnly == true || ColumnInfoProperties.All) { headerList.Add(nameof(ColumnInfoProperties.ReadOnly)); } if (ColumnInfoProperties.Unique == true || ColumnInfoProperties.All) { headerList.Add(nameof(ColumnInfoProperties.Unique)); } if (ColumnInfoProperties.AutoIncrement == true || ColumnInfoProperties.All) { headerList.Add(nameof(ColumnInfoProperties.AutoIncrement)); } if (ColumnInfoProperties.Tags == true || ColumnInfoProperties.All) { headerList.Add(nameof(ColumnInfoProperties.Tags)); } if (ColumnInfoProperties.DefaultValue == true || ColumnInfoProperties.All) { headerList.Add(nameof(ColumnInfoProperties.DefaultValue)); } if (ColumnInfoProperties.SignatureDate == true || ColumnInfoProperties.All) { headerList.Add(nameof(Data.ColumnInfo.CreationInfo)); headerList.Add(nameof(Data.ColumnInfo.ModificationInfo)); } var tableDataBuilder = new TableDataBuilder(headerList.ToArray()); foreach (var item in tableInfo.Columns) { var objectList = new List <object>(new object[] { item.IsKey ? "O" : string.Empty, item.Name, item.DataType, item.Comment }); if (ColumnInfoProperties.ID == true || ColumnInfoProperties.All) { objectList.Add(item.ID); } if (ColumnInfoProperties.AllowNull == true || ColumnInfoProperties.All) { objectList.Add(item.AllowNull); } if (ColumnInfoProperties.ReadOnly == true || ColumnInfoProperties.All) { objectList.Add(item.ReadOnly); } if (ColumnInfoProperties.Unique == true || ColumnInfoProperties.All) { objectList.Add(item.IsUnique); } if (ColumnInfoProperties.AutoIncrement == true || ColumnInfoProperties.All) { objectList.Add(item.AutoIncrement); } if (ColumnInfoProperties.Tags == true || ColumnInfoProperties.All) { objectList.Add(item.DerivedTags); } if (ColumnInfoProperties.DefaultValue == true || ColumnInfoProperties.All) { objectList.Add(item.DefaultValue); } if (ColumnInfoProperties.SignatureDate == true || ColumnInfoProperties.All) { objectList.Add(item.CreationInfo); objectList.Add(item.ModificationInfo); } tableDataBuilder.Add(objectList.ToArray()); } this.Out.PrintTableData(tableDataBuilder.Data, true); this.Out.WriteLine(); }
public BuilderInfo(TableDataBuilder builder) { Builder = builder; Children = new List <ITableMapper>(); }
public virtual void InitializeRelatedTables(DataProcessor processor, TableDataBuilder table) { }