コード例 #1
0
 public void ExecuteNonAsync(ParamsLoader loader, ParamsDB paramsDB = null)
 {
     try
     {
         Task.Run(() => Execute(loader, paramsDB));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #2
0
 public async Task ExecuteAsync(ParamsLoader loader, ParamsDB paramsDB = null)
 {
     try
     {
         await Task.Run(() => Execute(loader, paramsDB));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #3
0
 public Task TaskExecute(ParamsLoader loader, ParamsDB paramsDB = null)
 {
     try
     {
         return(new Task(() =>
         {
             Execute(loader, paramsDB);
         }
                         ));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
コード例 #4
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();
            }
        }