public void Execute(bool isNormalExecution = true) { try { bool blnsqlerr = false; var _rootpath = Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Resources"); string script = Path.Combine(_rootpath, scriptName + ".ps1"); string scriptText = File.ReadAllText(script); StringBuilder sb = new StringBuilder(); var powershell = new PowerShellHelper(); var runspace = powershell.CreateRunSpace(Application.ExecutablePath, scriptName); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); Command myCommand = new Command(scriptText, true); var sqlWindowsAuthParam = new CommandParameter(null, "w"); var sqlServerParam = new CommandParameter(null, FormElements.Credential.SqlInstanceName); var sqlUserName = new CommandParameter(null, FormElements.Credential.SqlUserName); var sqlPwd = new CommandParameter(null, FormElements.Credential.SqlPassword); if (string.IsNullOrEmpty(FormElements.Credential.SqlDatabaseName)) { myCommand.Parameters.Add(new CommandParameter(null, FormElements.Credential.SqlDatabaseName)); } else { myCommand.Parameters.Add(new CommandParameter(null, "master")); } if (FormElements.Credential.SqlAuthMode != "w") { sqlWindowsAuthParam = new CommandParameter(null, "network"); } myCommand.Parameters.Add(sqlWindowsAuthParam); myCommand.Parameters.Add(sqlServerParam); myCommand.Parameters.Add(sqlUserName); myCommand.Parameters.Add(sqlPwd); foreach (var item in FormElements.SQLServer) { if (chklstApp.CheckedIndices.Contains(item.id)) { var param5 = new CommandParameter(null, 1); myCommand.Parameters.Add(param5); } else { var param5 = new CommandParameter(null, 0); myCommand.Parameters.Add(param5); } } pipeline.Commands.Add(myCommand); Collection <PSObject> results = pipeline.Invoke(); var errors = pipeline.Error; // CSV or Error file Generation code var generateCSV = new Csvhelper(); generateCSV.WriteOutput(Application.ExecutablePath, scriptName, results, pipeline, this.timeStamp, out blnsqlerr); // CSV or Error file Generation code if (blnsqlerr) { //MessageBox.Show("Error Occured.for more detail kindly check SQL Log!!\r\n", "Error Message"); //return; } else { if (isNormalExecution) { var profileHelper = new ProfileHelper(); profileHelper.SetProfileData <SQLServerModel>(Application.ExecutablePath, scriptName, FormElements, chklstApp); } } // Profilecreation(); runspace.Close(); //DialogResult dialogResult = MessageBox.Show("SQL Server scripts executed successfully.Do you want to execute next script?", "Success", MessageBoxButtons.YesNo); //if (dialogResult == DialogResult.Yes) //{ // //do something // SSRSConfiguration objfrm = new SSRSConfiguration(); // objfrm.Show(); // this.Close(); //} //else if (dialogResult == DialogResult.No) //{ // SQLServer objfrm = new SQLServer(); // objfrm.Show(); // this.Close(); //} if (isNormalExecution) { SQLServerlogs frmsql = new SQLServerlogs(); DialogResult dr = frmsql.ShowDialog(this); if (dr == DialogResult.Cancel) { //frmapplog.Close(); } else if (dr == DialogResult.OK) { //textBox1.Text = frm2.getText(); //frmapplog.Close(); this.Enabled = true; SSRSConfiguration objfrm = new SSRSConfiguration(); objfrm.Show(); this.Close(); } } } catch (Exception ex) { MessageBox.Show("Error Occured.for more detail kindly check SQL Server Log!!\r\n" + "\r\n" + ex.Message.ToString(), "Error Message"); } }
public void Execute(bool isNormalExecution = true) { try { bool blneventerr = false; var _rootpath = Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Resources"); string script = Path.Combine(_rootpath, scriptName + ".ps1"); string scriptText = File.ReadAllText(script); StringBuilder sb = new StringBuilder(); var powershell = new PowerShellHelper(); var runspace = powershell.CreateRunSpace(Application.ExecutablePath, cmbevent.SelectedValue.ToString()); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); Command myCommand = new Command(scriptText, true); if (txtsource.Text.Trim() != string.Empty) { var sourceFilter = new CommandParameter(null, txtsource.Text); myCommand.Parameters.Add(sourceFilter); } else { var sourceFilter = new CommandParameter(null, " "); myCommand.Parameters.Add(sourceFilter); } if (txtmessage.Text.Trim() != string.Empty) { var messageFilter = new CommandParameter(null, txtmessage.Text); myCommand.Parameters.Add(messageFilter); } else { var messageFilter = new CommandParameter(null, " "); myCommand.Parameters.Add(messageFilter); } pipeline.Commands.Add(myCommand); Collection <PSObject> results = pipeline.Invoke(); var errors = pipeline.Error; // CSV or Error file Generation code var generateCSV = new Csvhelper(); generateCSV.WriteOutput(Application.ExecutablePath, scriptName, results, pipeline, this.timeStamp, out blneventerr); // CSV or Error file Generation code if (blneventerr) { //MessageBox.Show("Error Occured.for more detail kindly check Event Log!!\r\n", "Error Message"); //return; } runspace.Close(); Console.WriteLine(sb.ToString()); //DialogResult dialogResult = MessageBox.Show("Selected event log executed successfully.Do you want to complete?", "Success", MessageBoxButtons.YesNo); //if (dialogResult == DialogResult.Yes) //{ // //do something // Complete objfrm = new Complete(); // objfrm.Show(); // this.Close(); //} //else if (dialogResult == DialogResult.No) //{ // EventLog objfrm = new EventLog(); // objfrm.Show(); // this.Close(); //} if (isNormalExecution) { Eventlogs frmevntlog = new Eventlogs(); DialogResult dr = frmevntlog.ShowDialog(this); if (dr == DialogResult.Cancel) { //frmapplog.Close(); } else if (dr == DialogResult.OK) { //textBox1.Text = frm2.getText(); //frmapplog.Close(); this.Enabled = true; Complete objfrm = new Complete(); objfrm.Show(); this.Close(); } } } catch (Exception ex) { MessageBox.Show("Error Occured.for more detail kindly check Event Log!!\r\n" + "\r\n" + ex.Message.ToString(), "Error Message"); } }
public void Execute(bool isNormalExecution = true) { try { bool blnapperr = false; //do the code when bgv completes its work var _rootpath = Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Resources"); string script = Path.Combine(_rootpath, scriptName + ".ps1"); string scriptText = File.ReadAllText(script); StringBuilder sb = new StringBuilder(); var powershell = new PowerShellHelper(); var runspace = powershell.CreateRunSpace(Application.ExecutablePath, scriptName); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); Command myCommand = new Command(scriptText, true); var hostName = new CommandParameter(null, FormElements.Credential.MachineHostName); var port = new CommandParameter(null, FormElements.Credential.MachinePortNumber); var sqlWindowsAuthParam = new CommandParameter(null, FormElements.Credential.SqlAuthMode); var sqlServerParam = new CommandParameter(null, FormElements.Credential.SqlInstanceName); var sqlUserName = new CommandParameter(null, FormElements.Credential.SqlUserName); var sqlPwd = new CommandParameter(null, FormElements.Credential.SqlPassword); myCommand.Parameters.Add(hostName); myCommand.Parameters.Add(port); if (FormElements.Credential.SqlAuthMode != "w") { sqlWindowsAuthParam = new CommandParameter(null, "network"); } myCommand.Parameters.Add(sqlWindowsAuthParam); myCommand.Parameters.Add(sqlServerParam); myCommand.Parameters.Add(sqlUserName); myCommand.Parameters.Add(sqlPwd); foreach (var item in FormElements.ApplicationInformation) { if (chklstApp.CheckedIndices.Contains(item.id)) { var param5 = new CommandParameter(null, 1); myCommand.Parameters.Add(param5); } else { var param5 = new CommandParameter(null, 0); myCommand.Parameters.Add(param5); } } pipeline.Commands.Add(myCommand); Collection <PSObject> results = pipeline.Invoke(); var errors = pipeline.Error; // CSV or Error file Generation code var generateCSV = new Csvhelper(); generateCSV.WriteOutput(Application.ExecutablePath, scriptName, results, pipeline, this.timeStamp, out blnapperr); // CSV or Error file Generation code if (blnapperr) { //MessageBox.Show("Error Occured.for more detail kindly check Application Log!!\r\n", "Error Message"); //return; } else { var profileHelper = new ProfileHelper(); profileHelper.SetBaseClassValues(FormElements); if (isNormalExecution) { profileHelper.SetProfileData <ApplicationModel>(Application.ExecutablePath, scriptName, FormElements, chklstApp); } } runspace.Close(); if (isNormalExecution) { Applicationlogs frmapplog = new Applicationlogs(); DialogResult dr = frmapplog.ShowDialog(this); if (dr == DialogResult.Cancel) { //this.Enabled = true; //ApplicationInformation objapp = new ApplicationInformation(); //objapp.Show(); //this.Close(); //frmapplog.Close(); } else if (dr == DialogResult.OK) { this.Enabled = true; IISInformation objfrm = new IISInformation(); objfrm.Show(); this.Close(); } } } catch (Exception ex) { MessageBox.Show("Error Occured.for more detail kindly check Application Log!!\r\n" + "\r\n" + ex.Message.ToString(), "Error Message"); } }
public void Execute(bool isNormalExecution = true) { try { bool blniiserr = false; var _rootpath = Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Resources"); string script = Path.Combine(_rootpath, scriptName + ".ps1"); string scriptText = File.ReadAllText(script); StringBuilder sb = new StringBuilder(); var powershell = new PowerShellHelper(); var runspace = powershell.CreateRunSpace(Application.ExecutablePath, scriptName); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); Command myCommand = new Command(scriptText, true); foreach (var item in FormElements.IISInformation) { if (chklstApp.CheckedIndices.Contains(item.id)) { var param5 = new CommandParameter(null, 1); myCommand.Parameters.Add(param5); } else { var param5 = new CommandParameter(null, 0); myCommand.Parameters.Add(param5); } } pipeline.Commands.Add(myCommand); Collection <PSObject> results = pipeline.Invoke(); var errors = pipeline.Error; // CSV or Error file Generation code var generateCSV = new Csvhelper(); generateCSV.WriteOutput(Application.ExecutablePath, scriptName, results, pipeline, this.timeStamp, out blniiserr); // CSV or Error file Generation code //Profilecreation(); if (blniiserr) { // MessageBox.Show("Error Occured.for more detail kindly check iis Log!!\r\n", "Error Message"); // return; } else { if (isNormalExecution) { var profileHelper = new ProfileHelper(); profileHelper.SetProfileData <IISInformationModel>(Application.ExecutablePath, scriptName, FormElements, chklstApp); } } runspace.Close(); //DialogResult dialogResult = MessageBox.Show("IIS scripts executed successfully.Do you want to execute next script?", "Success", MessageBoxButtons.YesNo); //if (dialogResult == DialogResult.Yes) //{ // //do something // SQLServerDiagnostics objfrm = new SQLServerDiagnostics(); // objfrm.Show(); // this.Close(); //} //else if (dialogResult == DialogResult.No) //{ // IISInformation objfrm = new IISInformation(); // objfrm.Show(); // this.Close(); //} if (isNormalExecution) { IISInformationlogs frmiislogs = new IISInformationlogs(); DialogResult dr = frmiislogs.ShowDialog(this); if (dr == DialogResult.Cancel) { } else if (dr == DialogResult.OK) { this.Enabled = true; SQLServerDiagnostics objfrm = new SQLServerDiagnostics(); objfrm.Show(); this.Close(); } } } catch (Exception ex) { MessageBox.Show("Error Occured.for more detail kindly check IIS Log!!\r\n" + "\r\n" + ex.Message.ToString(), "Error Message"); } }