public static ExecScript ExecScript() { return((Statement statement, ProgressBar bar, String ServerName, String serverUser, String serverPass) => { BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += (o, workerE) => { worker.ReportProgress(50); try { SSHCommander.RunCommand(ServerName, serverUser, serverPass, statement.ScriptToLaunch); } catch (Exception ex) { } worker.ReportProgress(50); }; worker.ProgressChanged += (o, e) => { bar.Value += e.ProgressPercentage; }; worker.RunWorkerCompleted += (o, e) => { bar.Value = 0; bar.Visibility = System.Windows.Visibility.Hidden; }; worker.RunWorkerAsync(); }); }
public static ExecScriptWithLog ExecScriptWithLog() { return((Statement statement, String tailPars, ProgressBar bar, TextBox txtBox, String ServerName, String serverUser, String serverPass) => { bar.Value = 0; BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += (o, workerE) => { String feedback = ""; worker.ReportProgress(50); try { feedback = SSHCommander.RunCommandWithFeedback(ServerName, serverUser, serverPass, statement.ScriptToLaunch + tailPars.ToSafeString()); worker.ReportProgress(10); workerE.Result = feedback; worker.ReportProgress(10); } catch (Exception ex) { } worker.ReportProgress(30); }; worker.ProgressChanged += (o, e) => { bar.Value += e.ProgressPercentage; }; worker.RunWorkerCompleted += (o, e) => { txtBox.Text = e.Result.ToSafeString(); Task.Factory.StartNew(() => { WriteFSLog()(e.Result.ToSafeString(), Path.Combine(Environment.CurrentDirectory, statement.ScriptToLaunch + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Millisecond.ToString() + ".log")); }); }; worker.RunWorkerAsync(); }); }