Exemplo n.º 1
0
        void Execute(ParamsLoader loader, ParamsDB paramsDB)
        {
            string Credentials, ComandoStartNewWindow, FileNameSystem;

            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                FileNameSystem = "/bin/bash";
            }
            else
            {
                FileNameSystem = "cmd.exe";
            }
            if (paramsDB != null)
            {
                Credentials     = paramsDB.GetCredentials();
                CriarNovaJanela = paramsDB.CriarNovaJanela;
            }
            else
            {
                Credentials = GetCredentials();
            }
            if (CriarNovaJanela && Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                ComandoStartNewWindow = "start ";
            }
            else
            {
                ComandoStartNewWindow = "";
            }

            if (!Directory.Exists(loader.DirWorkControl))
            {
                Directory.CreateDirectory(loader.DirWorkControl);
                throw new Exception($@"Insert control file in path:\n{loader.DirWorkControl}");
            }
            var LogDir = $"{loader.DirWorkControl}\\LOG";
            var BadDir = $"{loader.DirWorkControl}\\BAD";

            if (!Directory.Exists(LogDir) || !Directory.Exists(BadDir))
            {
                Directory.CreateDirectory(LogDir);
                Directory.CreateDirectory(BadDir);
            }
            using (Process process = new Process())
            {
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.WorkingDirectory       = loader.DirWorkControl;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.FileName = FileNameSystem;

                process.StartInfo.CreateNoWindow = !CriarNovaJanela;

                process.Start();
                ProcessID = process.Id;
                string[] log             = loader.FileUpload.Split(new string[] { ".txt", ".csv", @"\", "." }, StringSplitOptions.RemoveEmptyEntries);
                string   NomeSemExtensao = log[log.Length - 1];
                string   ProcPar         = $@"{ComandoStartNewWindow}{PathClient}SQLLDR.exe {Credentials} control={loader.FileControl} log=.\LOG\{NomeSemExtensao}.log bad=.\BAD\{NomeSemExtensao}.bad data={loader.FileUpload}";
                //process.StandardInput.WriteLine("@echo on");
                process.StandardInput.WriteLine(ProcPar);
                process.StandardInput.Flush();
                process.StandardInput.Close();
                if (loader.Debug)
                {
                    DebugEventParams.Invoke(ProcPar + Environment.NewLine);
                }
                while (!process.StandardOutput.EndOfStream)
                {
                    DebugEventParams.Invoke(process.StandardOutput.ReadLine() + Environment.NewLine);
                }

                process.WaitForExit();
            }
        }
Exemplo n.º 2
0
        void Execute(ParamsScript script, ParamsDB paramsDB)
        {
            string Credentials, ComandoStartNewWindow, FileNameSystem;

            if (CriarNovaJanela && Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                ComandoStartNewWindow = "start ";
            }
            else
            {
                ComandoStartNewWindow = "";
            }
            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                FileNameSystem = "/bin/bash";
            }
            else
            {
                FileNameSystem = "cmd.exe";
            }

            if (paramsDB != null)
            {
                Credentials     = paramsDB.GetCredentials();
                CriarNovaJanela = paramsDB.CriarNovaJanela;
            }
            else
            {
                Credentials = GetCredentials();
            }
            if (CriarNovaJanela && Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                ComandoStartNewWindow = "start ";
            }
            else
            {
                ComandoStartNewWindow = "";
            }
            if (!Directory.Exists(script.ScriptDir))
            {
                Directory.CreateDirectory(script.ScriptDir);
                throw new Exception($@"Insert script file in path:\n{script.ScriptDir}");
            }
            using (Process process = new Process())
            {
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.WorkingDirectory       = script.ScriptDir;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.FileName = FileNameSystem;

                process.StartInfo.CreateNoWindow = !CriarNovaJanela;

                process.Start();
                ProcessID = process.Id;
                string ProcPar = $@"{ComandoStartNewWindow}{PathClient}sqlplus.exe {Credentials} @{script.ScriptName} {script.Parameters}";
                process.StandardInput.WriteLine(ProcPar);
                process.StandardInput.Flush();
                process.StandardInput.Close();

                if (script.Debug)
                {
                    DebugEventParams.Invoke(ProcPar + Environment.NewLine);
                }
                while (!process.StandardOutput.EndOfStream)
                {
                    DebugEventParams.Invoke(process.StandardOutput.ReadLine() + Environment.NewLine);
                }
                process.WaitForExit();
            }
        }