Exemple #1
0
        private string _GenerateContext(Schema Schema)
        {
            var t_FileGenerator = new MultipleStatement(
                new List <IFileComponentGenerator>
            {
                new FunctionDef($"New-StorageContext",
                                new List <PowershellVariableDef> {
                    new PowershellVariableDef {
                        DataType = "System.Data.SqlClient.SqlConnection", Name = "Con"
                    }
                },
                                new List <IFileComponentGenerator>
                {
                    new Statement("$_CONTEXT = New-Object -TypeName psobject"),
                    new Statement("$_CONTEXT | Add-Member -MemberType NoteProperty -Name Connection -Value $Con"),
                    new MultipleStatement
                    (
                        Schema.Tables.Select
                        (
                            T => new Statement($"$_CONTEXT | Add-Member -MemberType NoteProperty -Name {T.Name} -Value $(New-{T.Name}DTORepository($Con))")
                        )
                        .ToList <IFileComponentGenerator>()
                    ),
                    new Statement("return $_CONTEXT;")
                })
            });

            return(t_FileGenerator.Generate());
        }
Exemple #2
0
        private string _GenerateRepo(Table Table)
        {
            var t_File = new MultipleStatement(new List <IFileComponentGenerator>
            {
                new FunctionDef($"New-{Table.Name}DTORepository",
                                new List <PowershellVariableDef> {
                    new PowershellVariableDef {
                        DataType = "System.Data.SQLite.SQLiteConnection", Name = "Con"
                    }
                },
                                new List <IFileComponentGenerator>
                {
                    _GenerateRead(Table),
                    new Statement("$_REPO = New-Object -TypeName psobject"),
                    new Statement("$_REPO | Add-Member -MemberType NoteProperty -Name Connection -Value $Con"),
                    new Statement("$_REPO | Add-Member -MemberType ScriptMethod -Name Read -Value $_READ"),
                    new Statement("return $_REPO;")
                })
            });

            return(t_File.Generate());
        }