Esempio n. 1
0
        private void buttonSendFiles_Click(object sender, EventArgs e)
        {
            OpenFileDialog fdlg = new OpenFileDialog();

            fdlg.Multiselect = true;
            fdlg.ShowDialog();
            List <string> result = fdlg.FileNames.ToList();

            if (result.Count > 0)
            {
                string form1Text = this.Text;

                this.Text = form1Text + " - sending...";
                try
                {
                    ExecutorFactory.CreateExecutor(new DBExecutor(), string.Empty).SendFiles(result, this.textBoxKey.Text.ToString());
                    MessageBox.Show("Files sent successfully");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Files were not sent!" + ex.ToString());
                }
                this.Text = form1Text;
            }
        }
Esempio n. 2
0
        private void createJson(bool sendFiles = false)
        {
            string saveFolder;

            if (sendFiles)
            {
                saveFolder = Path.GetTempPath();
            }
            else
            {
                FolderBrowserDialog fbd    = new FolderBrowserDialog();
                DialogResult        result = fbd.ShowDialog();

                // export cancelled - do nothing
                if (result != DialogResult.OK)
                {
                    return;
                }

                saveFolder = fbd.SelectedPath;
            }
            try
            {
                this.SaveDialogSettings();
                DBExecutor dbExecutor = new DBExecutor();
                this.BuildConnectionString(dbExecutor);

                // create filesystem configuration file, Executor will use this
                if (checkboxUseFS.Checked)
                {
                    CreateFileSystemCfgFile();
                }

                string myName = this.textBoxUserName.Text;
                Guid   myKey;
                if (!Guid.TryParse(this.textBoxKey.Text, out myKey))
                {
                    throw new SQLDepException("Invalid or missing API key. Get one in your dashboard on SQLdep website.");
                }

                string sqlDialect = this.GetDatabaseTypeName(this.comboBoxDatabase.SelectedIndex);

                Executor executor       = ExecutorFactory.CreateExecutor(dbExecutor, sqlDialect);
                string   filename       = "DBexport_" + executor.runId + "_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".json";
                string   exportFileName = Path.Combine(saveFolder, filename);

                this.AsyncExecutor       = new AsyncExecutor(myName, myKey, sqlDialect, exportFileName, executor, checkboxUseFS.Checked, sendFiles);
                this.AsyncExecutorThread = new Thread(AsyncExecutor.Run);
                this.AsyncExecutorThread.Start();
                //new Thread(this.ShowProgress).Start();
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                Logger.Log(msg);
                MessageBox.Show(msg);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Executes each of the given scripts against the specified database.
        /// </summary>
        /// <param name="connectionInfo">The database connection information.</param>
        /// <param name="scripts">The list of scripts or xml data to execute.</param>
        public virtual void Execute(IConnectionSettings connectionInfo, IList <IScriptFile> scripts)
        {
            Throw.If(connectionInfo, "connectionInfo").IsNull();
            Throw.If(scripts, "scripts").IsNull();

            IDatabase db = DatabaseConnectionFactory.CreateDbConnection(connectionInfo);

            foreach (IScriptFile curScript in scripts)
            {
                // I'm betting there's a pattern for this
                // new AbstractExecutor.Execute(db, curScript);
                IExecutor executor = ExecutorFactory.CreateExecutor(db, curScript);
                executor.Execute(db, curScript);
            }
        }
Esempio n. 4
0
    public void CreateExecutor_ThrowsIfTypeIsNotAValidReturnType(string methodName)
    {
        // Arrange
        var methodInfo = typeof(TestPageModel).GetMethod(methodName);
        var handler    = new HandlerMethodDescriptor()
        {
            MethodInfo = methodInfo,
            Parameters = CreateParameters(methodInfo),
        };

        // Act & Assert
        var ex = Assert.Throws <InvalidOperationException>(() => ExecutorFactory.CreateExecutor(handler));

        Assert.Equal($"Unsupported handler method return type '{methodInfo.ReturnType}'.", ex.Message);
    }
Esempio n. 5
0
    private static PageHandlerExecutorDelegate[] GetHandlerExecutors(CompiledPageActionDescriptor actionDescriptor)
    {
        if (actionDescriptor.HandlerMethods == null || actionDescriptor.HandlerMethods.Count == 0)
        {
            return(Array.Empty <PageHandlerExecutorDelegate>());
        }

        var results = new PageHandlerExecutorDelegate[actionDescriptor.HandlerMethods.Count];

        for (var i = 0; i < actionDescriptor.HandlerMethods.Count; i++)
        {
            results[i] = ExecutorFactory.CreateExecutor(actionDescriptor.HandlerMethods[i]);
        }

        return(results);
    }
Esempio n. 6
0
    public async Task CreateExecutor_ForMethodReturningConcreteSubtypeOfIActionResult()
    {
        // Arrange
        var handler = new HandlerMethodDescriptor()
        {
            MethodInfo = typeof(TestPage).GetMethod(nameof(TestPage.ConcreteActionResult)),
            Parameters = new HandlerParameterDescriptor[0],
        };

        // Act
        var executor = ExecutorFactory.CreateExecutor(handler);

        // Assert
        Assert.NotNull(executor);
        var actionResultTask = executor(new TestPage(), null);
        var actionResult     = await actionResultTask;

        Assert.IsType <ViewResult>(actionResult);
    }
Esempio n. 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            // only one execution at time is allowed, do nothing now
            if (this.AsyncExecutor != null)
            {
                return;
            }

            FolderBrowserDialog fbd    = new FolderBrowserDialog();
            DialogResult        result = fbd.ShowDialog();

            try
            {
                this.SaveDialogSettings();
                DBExecutor dbExecutor = new DBExecutor();
                this.BuildConnectionString(dbExecutor);

                string myName = this.textBoxUserName.Text.ToString();
                Guid   myKey;
                if (!Guid.TryParse(this.textBoxKey.Text.ToString(), out myKey))
                {
                    throw new Exception("Invalid or missing API key! Get one at https://www.sqldep.com/browser/upload/api");
                }

                string sqlDialect = this.GetDatabaseTypeName(this.comboBoxDatabase.SelectedIndex);


                List <string> failedDbs = new List <string>();
                Executor      executor  = ExecutorFactory.CreateExecutor(dbExecutor, sqlDialect);

                string exportFileName = fbd.SelectedPath + "\\DBexport_" + executor.runId + "_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".json";

                this.AsyncExecutor       = new AsyncExecutor(myName, myKey, sqlDialect, exportFileName, executor);
                this.AsyncExecutorThread = new Thread(AsyncExecutor.Run);
                this.AsyncExecutorThread.Start();
                new Thread(this.ShowProgress).Start();
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                MessageBox.Show(msg);
            }
        }
Esempio n. 8
0
    public async Task CreateExecutor_ForTaskOfIActionResultReturningMethod()
    {
        // Arrange
        var methodInfo = typeof(TestPage).GetMethod(nameof(TestPage.GenericTaskHandler));
        var handler    = new HandlerMethodDescriptor()
        {
            MethodInfo = methodInfo,
            Parameters = CreateParameters(methodInfo),
        };

        // Act
        var executor = ExecutorFactory.CreateExecutor(handler);

        // Assert
        Assert.NotNull(executor);
        var actionResultTask = executor(new TestPage(), null);
        var actionResult     = await actionResultTask;

        Assert.IsType <EmptyResult>(actionResult);
    }
Esempio n. 9
0
        public void RegisterService(object service, bool isOverride)
        {
            var originalAsmName       = new AssemblyName("NTSock" + service.GetType().FullName);
            var assemblyBuilderHelper = new AssemblyBuilderHelper(originalAsmName.Name + ".dll");

            servicesLock.EnterWriteLock();
            try
            {
                var serviceType = service.GetType();
                var methods     = serviceType.GetMethods();
                if (methods != null)
                {
                    for (var i = 0; i < methods.Length; i++)
                    {
                        var method = methods[i];
                        if (method.GetCustomAttributes(typeof(ServiceMethodAttribute), false).Length == 0)
                        {
                            continue;
                        }
                        var executor = ExecutorFactory.CreateExecutor(service, method, i, assemblyBuilderHelper);
                        if (methodMaps.ContainsKey(executor.ExecutorKey))
                        {
                            if (!isOverride)
                            {
                                throw new ArgumentException("Cannot override an existing service.");
                            }
                            methodMaps.Remove(executor.ExecutorKey);
                        }
                        methodMaps.Add(executor.ExecutorKey, executor);
                    }
                    ExecutorFactory.CreateProxy(service, assemblyBuilderHelper);
                }
#if DEBUG
                assemblyBuilderHelper.Save();
#endif
            }
            finally
            {
                servicesLock.ExitWriteLock();
            }
        }
Esempio n. 10
0
    public async Task CreateExecutor_ForActionResultReturningMethod_WithParameters()
    {
        // Arrange
        var methodInfo = typeof(TestPage).GetMethod(nameof(TestPage.ActionResultReturnHandlerWithParameters));
        var handler    = new HandlerMethodDescriptor()
        {
            MethodInfo = methodInfo,
            Parameters = CreateParameters(methodInfo),
        };

        // Act
        var executor = ExecutorFactory.CreateExecutor(handler);

        // Assert
        Assert.NotNull(executor);
        var actionResultTask = executor(new TestPage(), CreateArguments(methodInfo));
        var actionResult     = await actionResultTask;
        var contentResult    = Assert.IsType <ContentResult>(actionResult);

        Assert.Equal("Hello 0", contentResult.Content);
    }
Esempio n. 11
0
    public async Task CreateExecutor_ForVoidReturningMethod()
    {
        // Arrange
        var handler = new HandlerMethodDescriptor()
        {
            MethodInfo = typeof(TestPage).GetMethod(nameof(TestPage.VoidReturningHandler)),
            Parameters = new HandlerParameterDescriptor[0],
        };

        var page = new TestPage();

        // Act
        var executor = ExecutorFactory.CreateExecutor(handler);

        // Assert
        Assert.NotNull(executor);
        var actionResultTask = executor(page, null);
        var actionResult     = await actionResultTask;

        Assert.Null(actionResult);
        Assert.True(page.SideEffects);
    }
Esempio n. 12
0
 public void RegisterService(string serviceName, object service, bool isOverride)
 {
     servicesLock.EnterWriteLock();
     try
     {
         if (methodMaps.ContainsKey(serviceName))
         {
             if (!isOverride)
             {
                 throw new ArgumentException("Cannot add service: " + serviceName);
             }
             methodMaps.Remove(serviceName);
         }
         var serviceType = service.GetType();
         var methods     = serviceType.GetMethods();
         if (methods != null)
         {
             foreach (var method in methods)
             {
                 var builder    = new StringBuilder(serviceName + " " + method.Name + " ");
                 var parameters = method.GetParameters();
                 if (parameters.Length > 0)
                 {
                     foreach (ParameterInfo parameter in parameters)
                     {
                         builder.Append(parameter.ParameterType + " ");
                     }
                 }
                 var executor = ExecutorFactory.CreateExecutor(service, method);
                 methodMaps.Add(builder.ToString().Trim(), executor);
             }
         }
     }
     finally
     {
         servicesLock.ExitWriteLock();
     }
 }
Esempio n. 13
0
        static int Main(string[] args)
        {
            string dbType           = string.Empty;
            string auth_type        = "sql_auth";
            string server           = string.Empty;
            string port             = string.Empty;
            string database         = string.Empty;
            string loginName        = string.Empty;
            string loginpassword    = string.Empty;
            string customSqlSetName = string.Empty;
            string exportFileName   = string.Empty;
            string sMyKey           = string.Empty;
            string sendFile         = string.Empty;
            string help             = string.Empty;
            string driverName       = string.Empty;
            Guid   myKey;

            var p = new OptionSet()
            {
                { "dbType=", "database type MsSQL(mssql)/Oracle(oracle)", v => dbType = v },
                { "a|auth=", "authorization SQL(default: sql_auth)/Windows (win_auth)", v => { if (v != null)
                                                                                               {
                                                                                                   auth_type = v;
                                                                                               }
                  } },
                { "s|server=", "server", v => server = v },
                { "p|port=", "port", v => { if (v != null)
                                            {
                                                port = v;
                                            }
                  } },
                { "d|database=", "database (SID for Oracle)", v => database = v },
                { "u|user="******"loginName", v => { if (v != null)
                                                 {
                                                     loginName = v;
                                                 }
                  } },
                { "pwd|password="******"loginpassword", v => { if (v != null)
                                                           {
                                                               loginpassword = v;
                                                           }
                  } },
                { "n|name=", "name of export", v => customSqlSetName = v },
                { "f|file=", "output file", v => exportFileName = v },
                { "k|key=", "api key (Guid)", v => sMyKey = v },
                { "h|help", "show help", v => help = "set" },
                { "driver", "driver name", v => driverName = v },
                { "send=", "SEND or SENDONLY, default do not send", v => sendFile = v.ToUpper() },
            };

            try
            {
                p.Parse(args);

                if (help.Equals("set") || (args.Length == 0))
                {
                    ShowHelp(p);
                }
                else
                {
                    myKey = Guid.Parse(sMyKey);

                    DBExecutor dbExecutor = new DBExecutor();

                    bool runDb  = (sendFile != "SENDONLY");
                    bool sendIt = (sendFile == "SEND" || sendFile == "SENDONLY");

                    string connectString = dbExecutor.BuildConnectionString(dbType, string.Empty, auth_type, server, port, database, loginName, loginpassword, driverName, DBExecutor.UseDriver.DEFAULT);
                    dbExecutor.ConnectString = connectString;
                    if (runDb)
                    {
                        dbExecutor.Connect();
                    }

                    Executor executor = ExecutorFactory.CreateExecutor(dbExecutor, dbType);

                    if (runDb)
                    {
                        executor.Run(customSqlSetName, myKey, dbType, exportFileName);
                    }

                    if (sendIt)
                    {
                        List <string> sendFiles = new List <string>();

                        FileAttributes fileattr;
                        foreach (var item in exportFileName.Split(','))
                        {
                            fileattr = File.GetAttributes(item);

                            if ((fileattr & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                // add whole directory content
                                foreach (string fileName in Directory.EnumerateFiles(item, "*.*"))
                                {
                                    // skip inner directories
                                    fileattr = File.GetAttributes(fileName);

                                    if ((fileattr & FileAttributes.Directory) == 0)
                                    {
                                        sendFiles.Add(fileName);
                                    }
                                }
                            }
                            else
                            {
                                sendFiles.Add(item);
                            }
                        }

                        executor.SendFiles(sendFiles, sMyKey);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(-1);
            }
            return(0); // standard success
        }
Esempio n. 14
0
        static int Main(string[] args)
        {
            Arguments arguments = new Arguments();

            var p = new OptionSet()
            {
                { "dbType=", "database type: mssql|oracle|greenplum|postgres|redshift|snowflake", v => arguments.dbType = v },
                { "a|auth=", "authorization SQL(default: sql_auth)/ Windows(win_auth)", v => { if (v != null)
                                                                                               {
                                                                                                   arguments.auth_type = v;
                                                                                               }
                  } },
                { "s|server=", "server", v => arguments.server = v },
                { "acc|account=", "account", v => arguments.account = v },
                { "p|port=", "port", v => { if (v != null)
                                            {
                                                arguments.port = v;
                                            }
                  } },
                { "d|database=", "database (SID for Oracle)", v => arguments.database = v },
                { "u|user="******"loginName", v => { if (v != null)
                                                 {
                                                     arguments.loginName = v;
                                                 }
                  } },
                { "pwd|password="******"loginpassword", v => { if (v != null)
                                                           {
                                                               arguments.loginpassword = v;
                                                           }
                  } },
                { "n|name=", "batch name for the web dashboard", v => arguments.customSqlSetName = v },
                { "f|file=", "output file", v => arguments.exportFileName = v },
                { "k|key=", "api key (Guid)", v => arguments.sMyKey = v },
                { "h|help", "show help", v => arguments.help = "set" },
                { "driver", "driver name", v => arguments.driverName = v },
                { "send=", "SEND or SENDONLY, default do not send", v => arguments.sendFile = v.ToUpper() },
                { "use-filesystem", "Use this option to use FS. file_system.conf must be configured!", v => arguments.useFS = true },
                { "warehouse", "Warehouse (Snowflake only)", v => arguments.warehouse = v },
                { "role", "Role (Snowflake only)", v => arguments.role = v },
            };

            try
            {
                p.Parse(args);

                if (arguments.help.Equals("set") || (args.Length == 0))
                {
                    ShowHelp(p);
                }
                else
                {
                    arguments.myKey = Guid.Parse(arguments.sMyKey);

                    DBExecutor dbExecutor = new DBExecutor();

                    bool   runDb         = (arguments.sendFile != "SENDONLY");
                    bool   sendIt        = (arguments.sendFile == "SEND" || arguments.sendFile == "SENDONLY");
                    string connectString = dbExecutor.BuildConnectionString(arguments, DBExecutor.UseDriver.DEFAULT);
                    dbExecutor.ConnectString = connectString;

                    Executor executor = ExecutorFactory.CreateExecutor(dbExecutor, arguments.dbType);

                    if (runDb)
                    {
                        executor.Run(arguments.customSqlSetName, arguments.myKey, arguments.dbType, arguments.exportFileName, arguments.useFS);
                    }

                    if (sendIt)
                    {
                        List <string> sendFiles = new List <string>();

                        FileAttributes fileattr;
                        foreach (var item in arguments.exportFileName.Split(','))
                        {
                            fileattr = File.GetAttributes(item);

                            if ((fileattr & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                // add whole directory content
                                foreach (string fileName in Directory.EnumerateFiles(item, "*.*"))
                                {
                                    // skip inner directories
                                    fileattr = File.GetAttributes(fileName);

                                    if ((fileattr & FileAttributes.Directory) == 0)
                                    {
                                        sendFiles.Add(fileName);
                                    }
                                }
                            }
                            else
                            {
                                sendFiles.Add(item);
                            }
                        }

                        executor.SendFiles(sendFiles, arguments.sMyKey);
                    }
                }
            }
            catch (Exception e)
            {
                string exMessage = e.Message;
                if (e.InnerException != null)
                {
                    exMessage += "\nInner exception: " + e.InnerException.Message;
                }
                Logger.Exception(exMessage);
                return(-1);
            }
            return(0); // standard success
        }