Esempio n. 1
0
        private IEnumerable <IExecutable> ProcessCreator(BasicScope scope)
        {
            yield return(new DeleteFile(scope.Topic, "DeleteFile")
            {
                FileName = OutputFileName,
            });

            yield return(ProcessBuilder.Fluent
                         .ReadFromExcel(new EpPlusExcelReader(scope.Topic, "Reader")
            {
                FileName = SourceFileName,
                SheetName = "People",
                ColumnConfiguration = new List <ReaderColumnConfiguration>()
                {
                    new ReaderColumnConfiguration("Name", new StringConverter(CultureInfo.InvariantCulture)),
                    new ReaderColumnConfiguration("Age", new IntConverterAuto(CultureInfo.InvariantCulture)),
                },
            })
                         .WriteRowToExcelSimple(new EpPlusSimpleRowWriterMutator(scope.Topic, "Writer")
            {
                FileName = OutputFileName,
                SheetName = "output",
                ColumnConfiguration = new List <ColumnCopyConfiguration>()
                {
                    new ColumnCopyConfiguration("Name", "Contact name"),
                    new ColumnCopyConfiguration("Age", "Contact age"),
                },
                Finalize = (package, state) => state.LastWorksheet.Cells.AutoFitColumns(),
            })
                         .ProcessBuilder.Result);
        }
Esempio n. 2
0
        private IEnumerable <IExecutable> ReCreateDatabaseProcess(BasicScope scope, DatabaseDefinition definition)
        {
            yield return(new CustomAction(scope.Topic, nameof(ReCreateDatabaseProcess))
            {
                Then = proc =>
                {
                    System.Data.SqlClient.SqlConnection.ClearAllPools();

                    proc.Context.Log(LogSeverity.Information, proc, "opening connection to {DatabaseName}", "master");
                    using var connection = DbProviderFactories.GetFactory(TestConnectionString.ProviderName).CreateConnection();
                    connection.ConnectionString = "Data Source=(local);Initial Catalog=\"master\";Integrated Security=SSPI;Connection Timeout=5";
                    connection.Open();

                    try
                    {
                        proc.Context.Log(LogSeverity.Information, proc, "dropping {DatabaseName}", DatabaseName);
                        using var dropCommand = connection.CreateCommand();
                        dropCommand.CommandText = "ALTER DATABASE [" + DatabaseName + "] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE IF EXISTS [" + DatabaseName + "]";
                        dropCommand.ExecuteNonQuery();
                    }
                    catch (Exception)
                    {
                    }

                    proc.Context.Log(LogSeverity.Information, proc, "creating {DatabaseName}", DatabaseName);
                    using var createCommand = connection.CreateCommand();
                    createCommand.CommandText = "CREATE DATABASE [" + DatabaseName + "];";
                    createCommand.ExecuteNonQuery();

                    var dbToolsContext = new Context()
                    {
                        Settings = Helper.GetDefaultSettings(MsSqlVersion.MsSql2016),
                        Logger = new DbTools.Common.Logger.Logger(),
                    };

                    var generator = new MsSql2016Generator(dbToolsContext);
                    var executer = new MsSql2016Executer(TestConnectionString, generator);
                    var creator = new DatabaseCreator(definition, executer);
                    creator.CreateTables();
                }
            });
Esempio n. 3
0
        private IEnumerable <IExecutable> ProcessCreator(BasicScope scope)
        {
            yield return(new DeleteFile(scope.Topic, "DeleteFile")
            {
                FileName = OutputFileName,
            });

            yield return(ProcessBuilder.Fluent
                         .ReadFromExcel(new EpPlusExcelReader(scope.Topic, "PeopleReader")
            {
                FileName = SourceFileName,
                SheetName = "People",
                ColumnConfiguration = new List <ReaderColumnConfiguration>()
                {
                    new ReaderColumnConfiguration("ID", new IntConverterAuto(CultureInfo.InvariantCulture)),
                    new ReaderColumnConfiguration("Name", new StringConverter(CultureInfo.InvariantCulture)),
                },
            })
                         .Join(new JoinMutator(scope.Topic, "JoinContact")
            {
                NoMatchAction = new NoMatchAction(MatchMode.Remove),
                LookupBuilder = new RowLookupBuilder()
                {
                    Process = ProcessBuilder.Fluent
                              .ReadFromExcel(new EpPlusExcelReader(scope.Topic, "ReadContacts")
                    {
                        FileName = SourceFileName,
                        SheetName = "Contact",
                        ColumnConfiguration = new List <ReaderColumnConfiguration>()
                        {
                            new ReaderColumnConfiguration("PeopleID", new IntConverterAuto(CultureInfo.InvariantCulture)),
                            new ReaderColumnConfiguration("MethodTypeID", new StringConverter(CultureInfo.InvariantCulture)),
                            new ReaderColumnConfiguration("Value", new StringConverter(CultureInfo.InvariantCulture)),
                        },
                    })
                              .RemoveRow(new RemoveRowMutator(scope.Topic, "RemoveInvalidContacts")
                    {
                        If = row => row.IsNullOrEmpty("Value"),
                    })
                              .ProcessBuilder.Result,
                    KeyGenerator = row => row.GetAs <int>("PeopleID").ToString("D", CultureInfo.InvariantCulture),
                },
                RowKeyGenerator = row => row.GetAs <int>("ID").ToString("D", CultureInfo.InvariantCulture),
                ColumnConfiguration = new List <ColumnCopyConfiguration>()
                {
                    new ColumnCopyConfiguration("MethodTypeID"),
                    new ColumnCopyConfiguration("Value", "ContactValue"),
                },
            })
                         .Join(new JoinMutator(scope.Topic, "JoinContactMethod")
            {
                NoMatchAction = new NoMatchAction(MatchMode.Remove),
                LookupBuilder = new RowLookupBuilder()
                {
                    Process = new EpPlusExcelReader(scope.Topic, "ReadContactMethod")
                    {
                        FileName = SourceFileName,
                        SheetName = "ContactMethod",
                        ColumnConfiguration = new List <ReaderColumnConfiguration>()
                        {
                            new ReaderColumnConfiguration("ID", new StringConverter(CultureInfo.InvariantCulture)),     // used for "RightKey"
                            new ReaderColumnConfiguration("Name", new StringConverter(CultureInfo.InvariantCulture)),   // will be renamed to "ContactMethod"
                        },
                    },
                    KeyGenerator = row => row.GetAs <string>("ID"),
                },
                RowKeyGenerator = row => row.GetAs <string>("MethodTypeID"),
                ColumnConfiguration = new List <ColumnCopyConfiguration>()
                {
                    new ColumnCopyConfiguration("Name", "ContactMethod"),
                },
            })
                         .WriteRowToExcelSimple(new EpPlusSimpleRowWriterMutator(scope.Topic, "Writer")
            {
                FileName = OutputFileName,
                SheetName = "output",
                ColumnConfiguration = new List <ColumnCopyConfiguration>()
                {
                    new ColumnCopyConfiguration("Name", "Contact name"),
                    new ColumnCopyConfiguration("ContactMethod", "Contact method"),
                    new ColumnCopyConfiguration("ContactValue", "Value"),
                },
                Finalize = (package, state) => state.LastWorksheet.Cells.AutoFitColumns(),
            })
                         .ProcessBuilder.Result);
        }
Esempio n. 4
0
 public BasicScopeProcessFailedEventArgs(BasicScope scope, IJob process)
 {
     Scope   = scope;
     Process = process;
 }