Exemplo n.º 1
0
        protected override void Load(ContainerBuilder builder)
        {
            if (_process == null)
            {
                return;
            }

            // Connections
            foreach (var connection in _process.Connections.Where(c => c.Provider == "file"))
            {
                // Schema Reader
                builder.Register <ISchemaReader>(ctx => {
                    /* file and excel are different, have to load the content and check it to determine schema */
                    var fileInfo = new FileInfo(Path.IsPathRooted(connection.File) ? connection.File : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, connection.File));
                    var context  = ctx.ResolveNamed <IConnectionContext>(connection.Key);
                    var cfg      = new FileInspection(context, fileInfo, 100).Create();
                    var process  = ctx.Resolve <Process>(new NamedParameter("cfg", cfg));

                    foreach (var warning in process.Warnings())
                    {
                        context.Warn(warning);
                    }

                    if (process.Errors().Any())
                    {
                        foreach (var error in process.Errors())
                        {
                            context.Error(error);
                        }
                        return(new NullSchemaReader());
                    }

                    return(new SchemaReader(context, new RunTimeRunner(context), process));
                }).Named <ISchemaReader>(connection.Key);
            }

            // entity input
            foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Connection).Provider == "file"))
            {
                // input version detector
                builder.RegisterType <NullVersionDetector>().Named <IInputVersionDetector>(entity.Key);

                // input read
                builder.Register <IRead>(ctx => {
                    var input      = ctx.ResolveNamed <InputContext>(entity.Key);
                    var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity));

                    switch (input.Connection.Provider)
                    {
                    case "file":
                        if (input.Connection.Delimiter == string.Empty &&
                            input.Entity.Fields.Count(f => f.Input) == 1)
                        {
                            return(new FileReader(input, rowFactory));
                        }
                        return(new DelimitedFileReader(input, rowFactory));

                    default:
                        return(new NullReader(input, false));
                    }
                }).Named <IRead>(entity.Key);
            }

            // Entity Output
            if (_process.Output().Provider == "file")
            {
                // PROCESS OUTPUT CONTROLLER
                builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>();

                foreach (var entity in _process.Entities)
                {
                    // ENTITY OUTPUT CONTROLLER
                    builder.Register <IOutputController>(ctx => new NullOutputController()).Named <IOutputController>(entity.Key);

                    // ENTITY WRITER
                    builder.Register <IWrite>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);

                        switch (output.Connection.Provider)
                        {
                        case "file":
                            return(new DelimitedFileWriter(output, output.Connection.File));

                        default:
                            return(new NullWriter(output));
                        }
                    }).Named <IWrite>(entity.Key);
                }
            }
        }
Exemplo n.º 2
0
        protected override void Load(ContainerBuilder builder)
        {
            if (!builder.Properties.ContainsKey("Process"))
            {
                return;
            }

            var p = (Process)builder.Properties["Process"];

            // FILES

            // connections
            foreach (var connection in p.Connections.Where(c => c.Provider == "file"))
            {
                // Schema Reader
                builder.Register <ISchemaReader>(ctx => {
                    /* file and excel are different, have to load the content and check it to determine schema */
                    var context = ctx.ResolveNamed <IConnectionContext>(connection.Key);
                    var cfg     = new FileInspection(context, FileUtility.Find(connection.File), 100).Create();
                    var process = new Process(cfg);

                    foreach (var warning in process.Warnings())
                    {
                        context.Warn(warning);
                    }

                    if (process.Errors().Any())
                    {
                        foreach (var error in process.Errors())
                        {
                            context.Error(error);
                        }
                        return(new NullSchemaReader());
                    }

                    return(new FileSchemaReader(process, new InputContext(new PipelineContext(ctx.Resolve <IPipelineLogger>(), process, process.Entities.First()))));
                }).Named <ISchemaReader>(connection.Key);
            }

            // entity input
            foreach (var entity in p.Entities.Where(e => p.Connections.First(c => c.Name == e.Input).Provider == "file"))
            {
                // input version detector
                builder.RegisterType <NullInputProvider>().Named <IInputProvider>(entity.Key);

                // input read
                builder.Register <IRead>(ctx => {
                    var input      = ctx.ResolveNamed <InputContext>(entity.Key);
                    var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity));

                    if (input.Connection.Delimiter == string.Empty && input.Entity.Fields.Count(f => f.Input) == 1)
                    {
                        return(new FileReader(input, rowFactory));
                    }
                    return(new DelimitedFileReader(input, rowFactory));
                }).Named <IRead>(entity.Key);
            }

            // Entity Output
            if (p.GetOutputConnection().Provider == "file")
            {
                // PROCESS OUTPUT CONTROLLER
                builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>();

                foreach (var entity in p.Entities)
                {
                    // ENTITY OUTPUT CONTROLLER
                    builder.Register <IOutputController>(ctx => {
                        var output      = ctx.ResolveNamed <OutputContext>(entity.Key);
                        var fileInfo    = new FileInfo(Path.Combine(output.Connection.Folder, output.Connection.File ?? output.Entity.OutputTableName(output.Process.Name)));
                        var folder      = Path.GetDirectoryName(fileInfo.FullName);
                        var init        = p.Mode == "init" || (folder != null && !Directory.Exists(folder));
                        var initializer = init ? (IInitializer) new FileInitializer(output) : new NullInitializer();
                        return(new FileOutputController(output, initializer, new NullInputProvider(), new NullOutputProvider()));
                    }).Named <IOutputController>(entity.Key);

                    // ENTITY WRITER
                    builder.Register <IWrite>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);

                        switch (output.Connection.Provider)
                        {
                        case "file":
                            if (output.Connection.Delimiter == string.Empty)
                            {
                                return(new FileStreamWriter(output));
                            }
                            else
                            {
                                return(new DelimitedFileWriter(output));
                            }

                        default:
                            return(new NullWriter(output));
                        }
                    }).Named <IWrite>(entity.Key);
                }
            }

            // FOLDERS
            foreach (var connection in p.Connections.Where(c => c.Provider == "folder"))
            {
                builder.Register <ISchemaReader>(ctx => new NullSchemaReader()).Named <ISchemaReader>(connection.Key);
            }

            // enitity input
            foreach (var entity in p.Entities.Where(e => p.Connections.First(c => c.Name == e.Input).Provider == "folder"))
            {
                // input version detector
                builder.RegisterType <NullInputProvider>().Named <IInputProvider>(entity.Key);

                builder.Register <IRead>(ctx => {
                    var input      = ctx.ResolveNamed <InputContext>(entity.Key);
                    var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity));

                    switch (input.Connection.Provider)
                    {
                    case "folder":
                        return(new FolderReader(input, rowFactory));

                    default:
                        return(new NullReader(input, false));
                    }
                }).Named <IRead>(entity.Key);
            }

            if (p.GetOutputConnection().Provider == "folder")
            {
                // PROCESS OUTPUT CONTROLLER
                builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>();

                foreach (var entity in p.Entities)
                {
                    // todo
                }
            }
        }
Exemplo n.º 3
0
        protected override void Load(ContainerBuilder builder)
        {
            if (_process == null)
            {
                return;
            }

            // Connections
            foreach (var connection in _process.Connections.Where(c => c.Provider == "file"))
            {
                // Schema Reader
                builder.Register <ISchemaReader>(ctx => {
                    /* file and excel are different, have to load the content and check it to determine schema */
                    var fileInfo = new FileInfo(Path.IsPathRooted(connection.File) ? connection.File : ctx.Resolve <IAppDataFolder>().Combine(Common.FileFolder, connection.File));
                    var context  = ctx.ResolveNamed <IConnectionContext>(connection.Key);
                    var cfg      = new FileInspection(context, fileInfo, 100).Create();
                    var process  = ctx.Resolve <Process>();
                    process.Load(cfg);

                    foreach (var warning in process.Warnings())
                    {
                        context.Warn(warning);
                    }

                    if (process.Errors().Any())
                    {
                        foreach (var error in process.Errors())
                        {
                            context.Error(error);
                        }
                        return(new NullSchemaReader());
                    }

                    return(new SchemaReader(context, new RunTimeRunner(context, ctx.Resolve <IAppDataFolder>(), ctx.Resolve <ITemplateProcessor>(), ctx.Resolve <INotifier>()), process));
                }).Named <ISchemaReader>(connection.Key);
            }

            // entity input
            foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Connection).Provider == "file"))
            {
                // input version detector
                builder.RegisterType <NullInputProvider>().Named <IInputProvider>(entity.Key);

                // input read
                builder.Register <IRead>(ctx => {
                    var input      = ctx.ResolveNamed <InputContext>(entity.Key);
                    var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity));

                    switch (input.Connection.Provider)
                    {
                    case "file":

                        if (input.Connection.Delimiter == string.Empty &&
                            input.Entity.Fields.Count(f => f.Input) == 1)
                        {
                            return(new FileReader(input, rowFactory));
                        }

                        return(new DelimitedFileReader(input, rowFactory));

                    default:
                        return(new NullReader(input, false));
                    }
                }).Named <IRead>(entity.Key);
            }

            // Entity Output
            if (_process.Output().Provider == "file")
            {
                // PROCESS OUTPUT CONTROLLER
                builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>();

                foreach (var e in _process.Entities)
                {
                    var entity = e;

                    // ENTITY OUTPUT CONTROLLER
                    builder.Register <IOutputController>(ctx => new NullOutputController()).Named <IOutputController>(entity.Key);

                    // ENTITY WRITER
                    builder.Register(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);

                        switch (output.Connection.Provider)
                        {
                        case "filehelpers":
                        case "file":
                            if (output.Connection.File.StartsWith("~"))
                            {
                                if (output.Connection.File.StartsWith("~/App_Data", System.StringComparison.OrdinalIgnoreCase))
                                {
                                    output.Connection.File = _appDataFolder.MapPath(output.Connection.File);
                                }
                                else
                                {
                                    output.Connection.File = _appDataFolder.MapPath(Path.Combine("~/App_Data/", output.Connection.File.Trim('~', '/')));
                                }
                            }
                            return(output.Connection.Stream ? (IWrite) new DelimitedFileStreamWriter(output, HttpContext.Current.Response.OutputStream) : new DelimitedFileWriter(output));

                        default:
                            return(new NullWriter(output));
                        }
                    }).Named <IWrite>(entity.Key);
                }
            }
        }
Exemplo n.º 4
0
        protected override void Load(ContainerBuilder builder)
        {
            if (_process == null)
            {
                return;
            }

            // Connections
            foreach (var connection in _process.Connections.Where(c => c.Provider == "file"))
            {
                // Schema Reader
                builder.Register <ISchemaReader>(ctx => {
                    /* file and excel are different, have to load the content and check it to determine schema */
                    var fileInfo = new FileInfo(Path.IsPathRooted(connection.File) ? connection.File : _appDataFolder.Combine(Common.FileFolder, connection.File));
                    var context  = ctx.ResolveNamed <IConnectionContext>(connection.Key);
                    var cfg      = new FileInspection(context, fileInfo, 100).Create();
                    var process  = ctx.Resolve <Process>();
                    process.Load(cfg);

                    foreach (var warning in process.Warnings())
                    {
                        context.Warn(warning);
                    }

                    if (process.Errors().Any())
                    {
                        foreach (var error in process.Errors())
                        {
                            context.Error(error);
                        }
                        return(new NullSchemaReader());
                    }

                    return(new SchemaReader(context, new RunTimeRunner(context, _appDataFolder, _templateProcessor), process));
                }).Named <ISchemaReader>(connection.Key);
            }

            // entity input
            foreach (var entity in _process.Entities.Where(e => _process.Connections.First(c => c.Name == e.Connection).Provider == "file"))
            {
                // input version detector
                builder.RegisterType <NullVersionDetector>().Named <IInputVersionDetector>(entity.Key);

                // input read
                builder.Register <IRead>(ctx => {
                    var input      = ctx.ResolveNamed <InputContext>(entity.Key);
                    var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity));

                    switch (input.Connection.Provider)
                    {
                    case "file":

                        if (input.Connection.Delimiter == string.Empty &&
                            input.Entity.Fields.Count(f => f.Input) == 1)
                        {
                            return(new FileReader(input, rowFactory));
                        }

                        IRowCondition condition = new NullRowCondition();
                        if (input.Entity.Filter.Any())
                        {
                            var expression = input.Entity.Filter.First().Expression;
                            if (ctx.IsRegisteredWithName <IParser>("js") && ctx.ResolveNamed <IParser>("js").Parse(expression, input.Error))
                            {
                                condition = ctx.Resolve <IRowCondition>(new TypedParameter(typeof(InputContext), input), new TypedParameter(typeof(string), input.Entity.Filter.First().Expression));
                            }
                            else
                            {
                                input.Error("Your {0} script is not parsing or registered. It is not filtering.", input.Entity.Alias);
                            }
                        }
                        return(new DelimitedFileReader(input, rowFactory, condition));

                    default:
                        return(new NullReader(input, false));
                    }
                }).Named <IRead>(entity.Key);
            }

            // Entity Output
            if (_process.Output().Provider == "file")
            {
                // PROCESS OUTPUT CONTROLLER
                builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>();

                foreach (var e in _process.Entities)
                {
                    var entity = e;

                    // ENTITY OUTPUT CONTROLLER
                    builder.Register <IOutputController>(ctx => new NullOutputController()).Named <IOutputController>(entity.Key);

                    // ENTITY WRITER
                    builder.Register <IWrite>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);

                        switch (output.Connection.Provider)
                        {
                        case "file":
                            return(new DelimitedFileStreamWriter(output, HttpContext.Current.Response.OutputStream));

                        default:
                            return(new NullWriter(output));
                        }
                    }).Named <IWrite>(entity.Key);
                }
            }
        }
Exemplo n.º 5
0
        protected override void Load(ContainerBuilder builder)
        {
            if (_process == null && !builder.Properties.ContainsKey("Process"))
            {
                return;
            }

            var p = _process ?? (Process)builder.Properties["Process"];

            // connections
            foreach (var connection in p.Connections.Where(c => c.Provider == "file"))
            {
                // Schema Reader
                builder.Register <ISchemaReader>(ctx => {
                    var context = ctx.ResolveNamed <IConnectionContext>(connection.Key);
                    var cfg     = new FileInspection(context, FileUtility.Find(connection.File), connection.Sample).Create();
                    var process = new Process(cfg);

                    foreach (var warning in process.Warnings())
                    {
                        context.Warn(warning);
                    }

                    if (process.Errors().Any())
                    {
                        foreach (var error in process.Errors())
                        {
                            context.Error(error);
                        }
                        return(new NullSchemaReader());
                    }

                    var input      = new InputContext(new PipelineContext(ctx.Resolve <IPipelineLogger>(), process, process.Entities.First()));
                    var rowFactory = new RowFactory(input.RowCapacity, input.Entity.IsMaster, false);
                    var reader     = new CsvHelperReader(input, rowFactory);

                    return(new FileSchemaReader(process, input, reader));
                }).Named <ISchemaReader>(connection.Key);
            }

            // entity input
            foreach (var entity in p.Entities.Where(e => p.Connections.First(c => c.Name == e.Input).Provider == "file"))
            {
                // input version detector
                builder.RegisterType <NullInputProvider>().Named <IInputProvider>(entity.Key);

                // input read
                builder.Register <IRead>(ctx => {
                    var input      = ctx.ResolveNamed <InputContext>(entity.Key);
                    var rowFactory = ctx.ResolveNamed <IRowFactory>(entity.Key, new NamedParameter("capacity", input.RowCapacity));

                    if (input.Connection.Delimiter == string.Empty && input.Entity.Fields.Count(f => f.Input) == 1)
                    {
                        return(new FileReader(input, rowFactory));
                    }
                    return(new CsvHelperReader(input, rowFactory));
                }).Named <IRead>(entity.Key);
            }

            // Entity Output
            if (p.GetOutputConnection().Provider == "file")
            {
                // PROCESS OUTPUT CONTROLLER
                builder.Register <IOutputController>(ctx => new NullOutputController()).As <IOutputController>();

                foreach (var entity in p.Entities)
                {
                    // ENTITY OUTPUT CONTROLLER
                    builder.Register <IOutputController>(ctx => {
                        var output      = ctx.ResolveNamed <OutputContext>(entity.Key);
                        var fileInfo    = new FileInfo(Path.Combine(output.Connection.Folder, output.Connection.File ?? output.Entity.OutputTableName(output.Process.Name)));
                        var folder      = Path.GetDirectoryName(fileInfo.FullName);
                        var init        = p.Mode == "init" || (folder != null && !Directory.Exists(folder));
                        var initializer = init ? (IInitializer) new FileInitializer(output) : new NullInitializer();
                        return(new FileOutputController(output, initializer, new NullInputProvider(), new NullOutputProvider()));
                    }).Named <IOutputController>(entity.Key);

                    // ENTITY WRITER
                    builder.Register <IWrite>(ctx => {
                        var output = ctx.ResolveNamed <OutputContext>(entity.Key);

                        switch (output.Connection.Provider)
                        {
                        case "file":
                            if (output.Connection.Delimiter == string.Empty)
                            {
                                output.Error("A delimiter is required for a file output.");
                                return(new NullWriter(output, true));
                            }
                            else
                            {
                                if (output.Connection.Stream && _streamWriter != null)
                                {
                                    if (output.Connection.Synchronous)
                                    {
                                        return(new CsvHelperStreamWriterSync(output, _streamWriter));
                                    }
                                    else
                                    {
                                        return(new CsvHelperStreamWriter(output, _streamWriter));
                                    }
                                }
                                else
                                {
                                    var fileInfo     = new FileInfo(Path.Combine(output.Connection.Folder, output.Connection.File ?? output.Entity.OutputTableName(output.Process.Name)));
                                    var streamWriter = new StreamWriter(System.IO.File.OpenWrite(fileInfo.FullName));
                                    return(output.Connection.Synchronous ? (IWrite) new CsvHelperStreamWriterSync(output, streamWriter) : new CsvHelperStreamWriter(output, streamWriter));
                                }
                            }

                        default:
                            return(new NullWriter(output, true));
                        }
                    }).Named <IWrite>(entity.Key);
                }
            }
        }
Exemplo n.º 6
0
 public Prompt()
 {
     inspection = new FileInspection();
     scanFiles  = new List <ScanFile>();
     yamlReader = new YamlReader();
 }