Пример #1
0
        public bool ShowDialog()
        {
            var win = new Window(_prompt)
            {
                X = 0,
                Y = 0,

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width  = Dim.Fill(),
                Height = Dim.Fill()
            };

            //////////////////////////////////////////////// Username //////////////////////

            var lbluser = new Label("Username:"******"Password:"******"Database Type")
            {
                X       = 0,
                Y       = Pos.Bottom(lblPassword),
                Width   = 10,
                Height  = 1,
                Clicked = () =>
                {
                    if (_activator.SelectEnum("Database Type", typeof(DatabaseType), out Enum chosen))
                    {
                        DatabaseType = (DatabaseType)chosen;
                    }
                }
            };

            //////////////////////////////////////////////// Server  //////////////////////

            var lblServer = new Label("Server:")
            {
                X      = 0,
                Y      = Pos.Bottom(btnDatabaseType),
                Height = 1,
            };

            var tbServer = new TextField(string.Empty)
            {
                X     = Pos.Right(lblServer),
                Y     = Pos.Bottom(btnDatabaseType),
                Width = Dim.Fill()
            };

            tbServer.Changed += (s, e) => Server = ((TextField)s).Text.ToString();


            //////////////////////////////////////////////// Database  //////////////////////

            var lblDatabase = new Label("Database:")
            {
                X      = 0,
                Y      = Pos.Bottom(lblServer),
                Height = 1,
            };

            var tbDatabase = new TextField(string.Empty)
            {
                X     = Pos.Right(lblDatabase),
                Y     = Pos.Bottom(lblServer),
                Width = Dim.Fill() - 20
            };

            tbDatabase.Changed += (s, e) => Database = ((TextField)s).Text.ToString();

            var btnCreateDatabase = new Button("Create Database")
            {
                X       = Pos.Right(tbDatabase),
                Y       = Pos.Bottom(lblServer),
                Width   = 15,
                Height  = 0,
                Clicked = CreateDatabase
            };

            //////////////////////////////////////////////// Schema  //////////////////////

            var lblSchema = new Label("Schema:")
            {
                X      = 0,
                Y      = Pos.Bottom(lblDatabase),
                Height = 1,
            };

            var tbSchema = new TextField(string.Empty)
            {
                X     = Pos.Right(lblSchema),
                Y     = Pos.Bottom(lblDatabase),
                Width = Dim.Fill()
            };

            tbSchema.Changed += (s, e) => Schema = ((TextField)s).Text.ToString();


            //////////////////////////////////////////////// Table  //////////////////////

            CbIsView = new CheckBox("Is View")
            {
                X     = 0,
                Y     = Pos.Bottom(lblSchema),
                Width = Dim.Fill()
            };

            var lblTable = new Label("Table:")
            {
                X      = 0,
                Y      = Pos.Bottom(CbIsView),
                Height = 1,
            };

            var tbTable = new TextField(string.Empty)
            {
                X     = Pos.Right(lblTable),
                Y     = Pos.Bottom(CbIsView),
                Width = Dim.Fill()
            };


            tbTable.Changed += (s, e) => Table = ((TextField)s).Text.ToString();

            win.Add(lbluser);
            win.Add(tbuser);
            win.Add(lblPassword);
            win.Add(tbPassword);
            win.Add(btnDatabaseType);
            win.Add(lblServer);
            win.Add(tbServer);
            win.Add(lblDatabase);
            win.Add(tbDatabase);
            win.Add(btnCreateDatabase);

            if (_showTableComponents)
            {
                win.Add(lblSchema);
                win.Add(tbSchema);
                win.Add(CbIsView);
                win.Add(lblTable);
                win.Add(tbTable);
            }



            var btnOk = new Button(_okText, true)
            {
                X       = 0,
                Y       = _showTableComponents ? Pos.Bottom(lblTable) : Pos.Bottom(lblDatabase),
                Width   = 5,
                Height  = 1,
                Clicked = () =>
                {
                    OkClicked = true;
                    Application.RequestStop();
                }
            };

            var btnCancel = new Button("Cancel", true)
            {
                X       = Pos.Right(btnOk) + 10,
                Y       = _showTableComponents ? Pos.Bottom(lblTable) : Pos.Bottom(lblDatabase),
                Width   = 5,
                Height  = 1,
                Clicked = Application.RequestStop
            };

            win.Add(btnOk);
            win.Add(btnCancel);

            Application.Run(win);

            return(OkClicked);
        }
Пример #2
0
        public CommandInvoker(IBasicActivateItems basicActivator)
        {
            _basicActivator    = basicActivator;
            _repositoryLocator = basicActivator.RepositoryLocator;

            _argumentDelegates = _basicActivator.GetDelegates();


            AddDelegate(typeof(ICatalogueRepository), true, (p) => _repositoryLocator.CatalogueRepository);
            AddDelegate(typeof(IDataExportRepository), true, (p) => _repositoryLocator.DataExportRepository);
            AddDelegate(typeof(IBasicActivateItems), true, (p) => _basicActivator);
            AddDelegate(typeof(IRDMPPlatformRepositoryServiceLocator), true, (p) => _repositoryLocator);
            AddDelegate(typeof(DirectoryInfo), false, (p) => _basicActivator.SelectDirectory($"Enter Directory for '{p.Name}'"));
            AddDelegate(typeof(FileInfo), false, (p) => _basicActivator.SelectFile($"Enter File for '{p.Name}'"));

            AddDelegate(typeof(string), false, (p) =>

                        _basicActivator.TypeText("Value needed for parameter", p.Name, 1000, null, out string result, false)
                ? result
                : throw new OperationCanceledException());

            AddDelegate(typeof(Type), false, (p) =>
                        _basicActivator.SelectType($"Type needed for {p.Name} ", p.DemandIfAny?.TypeOf, out Type chosen)
                    ? chosen
                    : throw new OperationCanceledException());

            AddDelegate(typeof(DiscoveredDatabase), false, (p) => _basicActivator.SelectDatabase(true, "Value needed for parameter " + p.Name));
            AddDelegate(typeof(DiscoveredTable), false, (p) => _basicActivator.SelectTable(true, "Value needed for parameter " + p.Name));

            AddDelegate(typeof(DatabaseEntity), false, (p) => _basicActivator.SelectOne(p.Name, GetAllObjectsOfType(p.Type)));
            AddDelegate(typeof(IMightBeDeprecated), false, SelectOne <IMightBeDeprecated>);
            AddDelegate(typeof(IDisableable), false, SelectOne <IDisableable>);
            AddDelegate(typeof(INamed), false, SelectOne <INamed>);
            AddDelegate(typeof(IDeleteable), false, SelectOne <IDeleteable>);

            AddDelegate(typeof(Enum), false, (p) => _basicActivator.SelectEnum("Value needed for parameter " + p.Name, p.Type, out Enum chosen)?chosen:null);


            _argumentDelegates.Add(new CommandInvokerArrayDelegate(typeof(IMapsDirectlyToDatabaseTable), false, (p) =>
            {
                IMapsDirectlyToDatabaseTable[] available = GetAllObjectsOfType(p.Type.GetElementType());
                return(_basicActivator.SelectMany(p.Name, p.Type.GetElementType(), available));
            }));


            AddDelegate(typeof(ICheckable), false,
                        (p) => _basicActivator.SelectOne(p.Name,
                                                         _basicActivator.GetAll <ICheckable>()
                                                         .Where(p.Type.IsInstanceOfType)
                                                         .Cast <IMapsDirectlyToDatabaseTable>()
                                                         .ToArray())
                        );

            AddDelegate(typeof(IPatcher), false, (p) =>
            {
                if (!_basicActivator.SelectType("Select Patcher (if any)", typeof(IPatcher), out Type patcherType))
                {
                    throw new OperationCanceledException();
                }

                if (patcherType == null)
                {
                    return(null);
                }

                try
                {
                    return(Activator.CreateInstance(patcherType));
                }
                catch (Exception e)
                {
                    throw new Exception($"Failed to call/find blank constructor of IPatcher Type '{patcherType}'", e);
                }
            }
                        );

            _argumentDelegates.Add(new CommandInvokerValueTypeDelegate((p) =>
                                                                       _basicActivator.SelectValueType(p.Name, p.Type, null, out object chosen)
                    ? chosen
                    : throw new OperationCanceledException()));
        }
        public bool ShowDialog()
        {
            var win = new Window(_prompt)
            {
                X = 0,
                Y = 0,

                // By using Dim.Fill(), it will automatically resize without manual intervention
                Width       = Dim.Fill(),
                Height      = Dim.Fill(),
                Modal       = true,
                ColorScheme = ConsoleMainWindow.ColorScheme
            };

            //////////////////////////////////////////////// Username //////////////////////

            var lbluser = new Label("Username:"******"Password:"******"Use Credentials")
            {
                X = Pos.Right(tbPassword),
                Y = Pos.Bottom(lbluser),
            };

            btnPickCredentials.Clicked += BtnPickCredentials_Clicked;
            win.Add(btnPickCredentials);



            //////////////////////// Database Type /////////////

            var btnDatabaseType = new Button($"Database Type ({DatabaseType})")
            {
                X      = 0,
                Y      = Pos.Bottom(lblPassword),
                Height = 1
            };

            win.Add(btnDatabaseType);

            btnDatabaseType.Clicked += () =>
            {
                if (_activator.SelectEnum("Database Type", typeof(DatabaseType), out Enum chosen))
                {
                    DatabaseType         = (DatabaseType)chosen;
                    btnDatabaseType.Text = $"Database Type ({chosen})";
                    win.SetNeedsDisplay();
                }
            };

            //////////////////////////////////////////////// Server  //////////////////////

            var lblServer = new Label("Server:")
            {
                X      = 0,
                Y      = Pos.Bottom(btnDatabaseType),
                Height = 1,
            };

            win.Add(lblServer);

            var tbServer = new TextField(string.Empty)
            {
                X     = Pos.Right(lblServer),
                Y     = Pos.Bottom(btnDatabaseType),
                Width = 17
            };

            tbServer.TextChanged += (s) => Server = tbServer.Text.ToString();

            win.Add(tbServer);

            //////////////////////////////////////////////// Database  //////////////////////

            var lblDatabase = new Label("Database:")
            {
                X      = 0,
                Y      = Pos.Bottom(lblServer),
                Height = 1,
            };

            win.Add(lblDatabase);

            var tbDatabase = new TextField(string.Empty)
            {
                X     = Pos.Right(lblDatabase),
                Y     = Pos.Bottom(lblServer),
                Width = 15
            };

            win.Add(tbDatabase);
            tbDatabase.TextChanged += (s) => Database = tbDatabase.Text.ToString();

            var btnCreateDatabase = new Button("Create Da_tabase")
            {
                X = Pos.Right(tbDatabase) + 1,
                Y = Pos.Bottom(lblServer)
            };

            btnCreateDatabase.Clicked += CreateDatabase;
            win.Add(btnCreateDatabase);

            //////////////////////////////////////////////// Schema  //////////////////////

            var lblSchema = new Label("Schema:")
            {
                X      = 0,
                Y      = Pos.Bottom(lblDatabase),
                Height = 1
            };

            var tbSchema = new TextField(string.Empty)
            {
                X     = Pos.Right(lblSchema),
                Y     = Pos.Bottom(lblDatabase),
                Width = Dim.Fill()
            };

            tbSchema.TextChanged += (s) => Schema = tbSchema.Text.ToString();


            //////////////////////////////////////////////// Table  //////////////////////

            CbIsView = new CheckBox("Is View")
            {
                X = 0,
                Y = Pos.Bottom(lblSchema),
            };

            CbIsTableValuedFunc = new CheckBox("Is Func")
            {
                X = Pos.Right(CbIsView) + 5,
                Y = Pos.Bottom(lblSchema),
            };


            var lblTable = new Label("Table:")
            {
                X      = 0,
                Y      = Pos.Bottom(CbIsView),
                Height = 1,
            };

            var tbTable = new TextField(string.Empty)
            {
                X     = Pos.Right(lblTable),
                Y     = Pos.Bottom(CbIsView),
                Width = Dim.Fill()
            };

            tbTable.TextChanged += (s) => Table = tbTable.Text.ToString();


            if (_showTableComponents)
            {
                win.Add(lblSchema);
                win.Add(tbSchema);
                win.Add(CbIsView);
                win.Add(CbIsTableValuedFunc);
                win.Add(lblTable);
                win.Add(tbTable);
            }

            var btnOk = new Button(_okText, true)
            {
                X      = 0,
                Y      = _showTableComponents ? Pos.Bottom(lblTable) : Pos.Bottom(lblDatabase),
                Height = 1
            };

            btnOk.Clicked += () =>
            {
                OkClicked = true;
                Application.RequestStop();
            };

            var btnCancel = new Button("Cancel", true)
            {
                X      = Pos.Right(btnOk) + 10,
                Y      = _showTableComponents ? Pos.Bottom(lblTable) : Pos.Bottom(lblDatabase),
                Height = 1
            };

            btnCancel.Clicked += () => Application.RequestStop();

            win.Add(btnOk);
            win.Add(btnCancel);

            Application.Run(win);

            return(OkClicked);
        }
Пример #4
0
        public CommandInvoker(IBasicActivateItems basicActivator)
        {
            _basicActivator    = basicActivator;
            _repositoryLocator = basicActivator.RepositoryLocator;

            _argumentDelegates = _basicActivator.GetDelegates();


            AddDelegate(typeof(ICatalogueRepository), true, (p) => _repositoryLocator.CatalogueRepository);
            AddDelegate(typeof(IDataExportRepository), true, (p) => _repositoryLocator.DataExportRepository);
            AddDelegate(typeof(IBasicActivateItems), true, (p) => _basicActivator);
            AddDelegate(typeof(IRDMPPlatformRepositoryServiceLocator), true, (p) => _repositoryLocator);
            AddDelegate(typeof(DirectoryInfo), false, (p) => _basicActivator.SelectDirectory($"Enter Directory for '{p.Name}'"));
            AddDelegate(typeof(FileInfo), false, (p) => _basicActivator.SelectFile($"Enter File for '{p.Name}'"));

            // Is the Global Check Notifier the best here?
            AddDelegate(typeof(ICheckNotifier), true, (p) => _basicActivator.GlobalErrorCheckNotifier);

            AddDelegate(typeof(string), false, (p) =>

                        _basicActivator.TypeText("Value needed for parameter", GetPromptFor(p), 1000, null, out string result, false)
                ? result
                : throw new OperationCanceledException());

            AddDelegate(typeof(Type), false, (p) =>
                        _basicActivator.SelectType($"Type needed for {p.Name} ", p.DemandIfAny?.TypeOf, out Type chosen)
                    ? chosen
                    : throw new OperationCanceledException());

            AddDelegate(typeof(DiscoveredDatabase), false, (p) => _basicActivator.SelectDatabase(true, GetPromptFor(p)));
            AddDelegate(typeof(DiscoveredTable), false, (p) => _basicActivator.SelectTable(true, GetPromptFor(p)));

            AddDelegate(typeof(DatabaseEntity), false, (p) => _basicActivator.SelectOne(GetPromptFor(p), GetAllObjectsOfType(p.Type)));
            AddDelegate(typeof(IPipeline), false, SelectPipeline);
            AddDelegate(typeof(IMightBeDeprecated), false, SelectOne <IMightBeDeprecated>);
            AddDelegate(typeof(IDisableable), false, SelectOne <IDisableable>);
            AddDelegate(typeof(INamed), false, SelectOne <INamed>);
            AddDelegate(typeof(IDeleteable[]), false, SelectMany <IDeleteable>);
            AddDelegate(typeof(IDeleteable), false, SelectOne <IDeleteable>);
            AddDelegate(typeof(ILoggedActivityRootObject), false, SelectOne <ILoggedActivityRootObject>);
            AddDelegate(typeof(ICollectSqlParameters), false, SelectOne <ICollectSqlParameters>);
            AddDelegate(typeof(IRootFilterContainerHost), false, SelectOne <IRootFilterContainerHost>);

            AddDelegate(typeof(Enum), false, (p) => _basicActivator.SelectEnum(GetPromptFor(p), p.Type, out Enum chosen)?chosen:null);


            _argumentDelegates.Add(new CommandInvokerArrayDelegate(typeof(IMapsDirectlyToDatabaseTable), false, (p) =>
            {
                IMapsDirectlyToDatabaseTable[] available = GetAllObjectsOfType(p.Type.GetElementType());
                var result = _basicActivator.SelectMany(GetPromptFor(p), p.Type.GetElementType(), available);

                if (result == null)
                {
                    return(null);
                }

                var typedArray = Array.CreateInstance(p.Type.GetElementType(), result.Length);
                for (int i = 0; i < typedArray.Length; i++)
                {
                    typedArray.SetValue(result[i], i);
                }

                return(typedArray);
            }));


            AddDelegate(typeof(ICheckable), false,
                        (p) => _basicActivator.SelectOne(GetPromptFor(p),
                                                         _basicActivator.GetAll <ICheckable>()
                                                         .Where(p.Type.IsInstanceOfType)
                                                         .Cast <IMapsDirectlyToDatabaseTable>()
                                                         .ToArray())
                        );

            AddDelegate(typeof(IPatcher), false, (p) =>
            {
                if (!_basicActivator.SelectType("Select Patcher (if any)", typeof(IPatcher), out Type patcherType))
                {
                    throw new OperationCanceledException();
                }

                if (patcherType == null)
                {
                    return(null);
                }

                try
                {
                    return(Activator.CreateInstance(patcherType));
                }
                catch (Exception e)
                {
                    throw new Exception($"Failed to call/find blank constructor of IPatcher Type '{patcherType}'", e);
                }
            }
                        );

            _argumentDelegates.Add(new CommandInvokerValueTypeDelegate((p) =>
                                                                       _basicActivator.SelectValueType(GetPromptFor(p), p.Type, null, out object chosen)
                    ? chosen
                    : throw new OperationCanceledException()));
        }