예제 #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!Model.Exists)
            {
                WriteObject($"{Ansi.Color.Foreground.LightRed}Model file {Model?.FullName} not found.{Ansi.Color.Foreground.Default}");
                return;
            }
            WriteObject($"Checking model: {Model.FullName}");

            string modelBim = File.ReadAllText(Model.FullName);

            TabModel.Database database = TabModel.JsonSerializer.DeserializeDatabase(modelBim);

            // Create the schema
            if (!SchemaBuilder.CheckModel(
                    database.Model,
                    out List <TabModel.Table> unsupportedTables,
                    out List <TabModel.Measure> unsupportedMeasures,
                    out List <TabModel.Relationship> unsupportedRelationships))
            {
                void DumpUnsupportedElement <T>(List <T> unsupportedList, string name)
                {
                    if (unsupportedList.Count > 0)
                    {
                        WriteObject($"{Ansi.Color.Foreground.LightYellow}{unsupportedList.Count} {name} are not supported:{Ansi.Color.Foreground.Default}");
                        foreach (var item in unsupportedList)
                        {
                            string itemName =
                                (item is TabModel.Table) ? (item as TabModel.Table).Name
                                : (item is TabModel.Measure) ? (item as TabModel.Measure).Name
                                : (item is TabModel.SingleColumnRelationship sr) ? $"'{sr.FromTable.Name}'[{sr.FromColumn.Name}]{sr.CardinalityText()}'{sr.ToTable.Name}'[{sr.ToColumn.Name}] ({sr.CrossFilteringBehavior})"
                                : item.ToString();
                            WriteObject($"  {Ansi.Color.Foreground.Yellow}{itemName}{Ansi.Color.Foreground.Default}");
                        }
                    }
                }

                DumpUnsupportedElement(unsupportedTables, "tables");
                DumpUnsupportedElement(unsupportedMeasures, "measures");
                DumpUnsupportedElement(unsupportedRelationships, "relationships");

                WriteObject($"{Ansi.Color.Foreground.LightRed}Model has unsupported objects.{Ansi.Color.Foreground.Default}");
            }
            else
            {
                WriteObject($"{Ansi.Color.Foreground.LightGreen}Model validated.{Ansi.Color.Foreground.Default}");
            }
        }
예제 #2
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            WriteObject($"{Ansi.Color.Foreground.LightCyan}** GENERATE model **{Ansi.Color.Foreground.Default}");
            if (!Model.Exists)
            {
                WriteObject($"{Ansi.Color.Foreground.LightRed}Model file {Model?.FullName} not found.{Ansi.Color.Foreground.Default}");
                return;
            }
            WriteObject($"Loading model: {Model.FullName}");

            string modelBim = File.ReadAllText(Model.FullName);

            TabModel.Database database = TabModel.JsonSerializer.DeserializeDatabase(modelBim);

            // Create the schema
            if (!SchemaBuilder.CheckModel(
                    database.Model,
                    out List <TabModel.Table> unsupportedTables,
                    out List <TabModel.Measure> unsupportedMeasures,
                    out List <TabModel.Relationship> unsupportedRelationships))
            {
                if (unsupportedMeasures.Count > 0)
                {
                    WriteObject($"{Ansi.Color.Foreground.LightYellow}Removing {unsupportedMeasures.Count} unsupported measures.{Ansi.Color.Foreground.Default}");
                    foreach (TabModel.Measure m in unsupportedMeasures)
                    {
                        WriteObject($"  {Ansi.Color.Foreground.Yellow}{m.Name}{Ansi.Color.Foreground.Default}");
                        m.Table.Measures.Remove(m);
                    }
                }

                if (unsupportedRelationships.Count > 0)
                {
                    WriteObject($"{Ansi.Color.Foreground.LightYellow}Removing {unsupportedRelationships.Count} unsupported relationships.{Ansi.Color.Foreground.Default}");
                    foreach (TabModel.Relationship r in unsupportedRelationships)
                    {
                        string relationshipDescription = (r is TabModel.SingleColumnRelationship sr)
                                ? $"*** SKIP *** '{sr.FromTable.Name}'[{sr.FromColumn.Name}]{sr.CardinalityText()}'{sr.ToTable.Name}'[{sr.ToColumn.Name}] ({sr.CrossFilteringBehavior})"
                                : $"*** SKIP *** '{r.FromTable.Name}'-->'{r.ToTable.Name}' ({r.CrossFilteringBehavior})";
                        WriteObject($"  {Ansi.Color.Foreground.Yellow}{relationshipDescription}{Ansi.Color.Foreground.Default}");
                        database.Model.Relationships.Remove(r);
                    }
                }

                if (unsupportedTables.Count > 0)
                {
                    WriteObject($"{Ansi.Color.Foreground.LightYellow}Removing {unsupportedTables.Count} unsupported tables.{Ansi.Color.Foreground.Default}");
                    foreach (TabModel.Table t in unsupportedTables)
                    {
                        WriteObject($"  {Ansi.Color.Foreground.Yellow}{t.Name}{Ansi.Color.Foreground.Default}");
                        database.Model.Tables.Remove(t);
                    }
                }

                WriteObject($"{Ansi.Color.Foreground.LightCyan}Prepared model compatible with Push Dataset.{Ansi.Color.Foreground.Default}");
            }
            else
            {
                WriteObject($"{Ansi.Color.Foreground.LightGreen}Copying model compatible with Push Dataset.{Ansi.Color.Foreground.Default}");
            }

            string modelCompatibleBim = TabModel.JsonSerializer.SerializeDatabase(database);

            WriteObject($"Saving model: {Out.FullName}");
            File.WriteAllText(Out.FullName, modelCompatibleBim);
        }