Ejemplo n.º 1
0
        protected override void Load(ContainerBuilder builder)
        {
            // Cfg-Net Setup for Cfg
            builder.RegisterType <FileReader>().As <IReader>();
            builder.Register(ctx => _logger ?? new NLogPipelineLogger(ProcessName)).As <IPipelineLogger>().SingleInstance();
            builder.Register((ctx, p) => _jr ?? p.TypedAs <Request>()).As <Request>();

            builder.Register((ctx, p) => {
                var entityName = ctx.Resolve <Request>(p).FileInfo.Name;
                return(new PipelineContext(
                           ctx.Resolve <IPipelineLogger>(),
                           new Process {
                    Name = ProcessName
                },
                           new Entity {
                    Name = entityName, Alias = entityName, Key = entityName
                }
                           ));
            }).As <IContext>().InstancePerLifetimeScope();

            builder.Register((ctx, p) => {
                var request = ctx.Resolve <Request>(p);
                var cfg     = new Cfg(request.Configuration, ctx.Resolve <IReader>());

                // modify the input provider based on the file name requested
                var input  = cfg.Input();
                input.File = request.FileInfo.FullName;
                if (request.Extension.StartsWith(".xls", StringComparison.OrdinalIgnoreCase))
                {
                    input.Provider = "excel";
                }

                // modify the output connection
                var output = cfg.Output();
                if (!string.IsNullOrEmpty(request.Provider) && Constants.AdoProviderSet().Contains(request.Provider))
                {
                    output.Provider = request.Provider;
                }

                SetOption(() => request.Server, option => { output.Server = option; });
                SetOption(() => request.Database, option => { output.Database = option; });
                SetOption(() => request.DatabaseFile, option => { output.File = option; });
                SetOption(() => request.View, option => { output.Table = option; });
                SetOption(() => request.Schema, option => { output.Schema = option; });
                SetOption(() => request.User, option => { output.User = option; });
                SetOption(() => request.Password, option => { output.Password = option; });
                SetOption(() => request.Port, option => { output.Port = option; });

                // modify the types if provided from command line
                if (request.Types == null || !request.Types.Any(t => Constants.TypeSet().Contains(t)))
                {
                    return(cfg);
                }

                var context = ctx.Resolve <IContext>();
                context.Debug(() => "Manually over-riding types.");
                cfg.Input().Types.Clear();
                foreach (var type in request.Types.Where(type => Constants.TypeSet().Contains(type)))
                {
                    cfg.Input().Types.Add(new TflType(type));
                    context.Debug(() => $"Inspecting for type: {type}.");
                }
                return(cfg);
            }).As <Cfg>().InstancePerLifetimeScope();

            builder.Register((ctx, p) => {
                var process = new Process();
                if (p.Any())
                {
                    process.Load(p.Named <string>("cfg"));
                }
                return(process);
            }).As <Process>();
        }
Ejemplo n.º 2
0
        private void CreateMenu()
        {
            // OPEN
            _context.Debug(() => "Creating Menu.");

            var open = new Command {
                MenuText = "&Open", ToolBarText = "Open", Shortcut = Application.Instance.CommonModifier | Keys.O
            };

            open.Executed += OpenOnExecuted;

            // QUIT
            var quit = new Command {
                MenuText = "&Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q
            };

            quit.Executed += (sender, e) => Application.Instance.Quit();

            if (Platform.Supports <MenuBar>())
            {
                var fileMenu = new ButtonMenuItem {
                    Text = "&File", Items = { open }
                };
                var connectionMenu = new ButtonMenuItem {
                    Text = "&Connections", Items = { }
                };
                var typeMenu = new ButtonMenuItem {
                    Text = "&Types", Items = { }
                };

                if (Platform.Supports <CheckMenuItem>())
                {
                    var types = new[] { "bool", "byte", "short", "int", "long", "single", "double", "decimal", "datetime", "guid" };
                    foreach (var type in types)
                    {
                        typeMenu.Items.Add(new CheckMenuItem {
                            Text = type, Checked = _cfg.Input().Types.Any(t => t.Type.StartsWith(type))
                        });
                    }
                    typeMenu.Items.Add(new CheckMenuItem {
                        Text = "string", Checked = true, Enabled = false
                    });
                }

                if (Platform.Supports <RadioMenuItem>())
                {
                    var controller = new RadioMenuItem {
                        Text = "output", Checked = true
                    };
                    connectionMenu.Items.Add(new RadioMenuItem(controller)
                    {
                        Text = "output", Checked = true
                    });
                    connectionMenu.Items.AddSeparator();
                    foreach (var c in _cfg.Connections.Where(c => !c.Name.In("input", "output")))
                    {
                        connectionMenu.Items.Add(new RadioMenuItem(controller)
                        {
                            Text = c.Name, Checked = false
                        });
                    }
                }

                Menu = new MenuBar {
                    Items    = { fileMenu, connectionMenu, typeMenu },
                    QuitItem = quit
                };
            }
        }