RunMySql.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Xml;
namespace Tomcat
{
public class RunMySql
{
/// <summary>
/// Function to start MySql exe
/// </summary>
/// <param name="mysqlLocation"></param>
/// <param name="mysqlPort"></param>
public void StartMySql(string tomcatLocation, string mysqlPort)
{
string response;
// Call the RunCommand function to change the port in web.xml
//response = RunCommand(Environment.GetEnvironmentVariable("RoleRoot") + @"\approot\setupPhp.bat", mysqlLocation, mysqlPort, Environment.GetEnvironmentVariable("RoleRoot") + @"\approot");
// Call the StartMySqlProcess to start the mysql process
response = RunMySqlProcess(tomcatLocation, mysqlPort);
//setting the webxml Configpath
// string serverConfigPath = tomcatLocation + @"webapps\mysql\WEB-INF\web.xml";
// Trace.WriteLine(serverConfigPath, "Information");
//Calling ConfigTomcatPort method to configure the port in web.xml
// ConfigMySqlPort(serverConfigPath, mysqlPort);
}
/// <summary>
/// Function to start mysql Process
/// </summary>
/// <param name="mysqlLocation"></param>
/// <returns></returns>
private string RunMySqlProcess(string tomcatLocation,string mysqlPort)
{
// This is a sample worker implementation. Replace with your logic.
Trace.WriteLine("PHP entry point called", "Information");
// initiating stream reader to get the output details
// StreamReader sr;
// string variable to store the output details
string returnDetails;
// Run MySqlcgi
Process mysqlProc = new Process();
try
{
mysqlProc.StartInfo.UseShellExecute = false;
mysqlProc.StartInfo.RedirectStandardOutput = false;
// setting the localsource path tomcatlocation to the environment variable catalina_home
//mysqlProc.StartInfo.EnvironmentVariables.Remove("XXXX");
//mysqlProc.StartInfo.EnvironmentVariables.Add("XXXX", "");
string mysqlini = tomcatLocation+@"mysql\my.ini" ;
// setting the file name bin\startup.bat in tomcatlocation of localresourcepath
// mysqlProc.StartInfo.Arguments = String.Format("{0} {1} {2} {3}", "-b", mysqlPort, "-c", mysqlini);
mysqlProc.StartInfo.FileName = tomcatLocation + @"mysql\bin\mysqld.exe";
Trace.WriteLine(mysqlProc.StartInfo.FileName, "Information");
// mysqlProc.EnableRaisingEvents = false;
// starting process
mysqlProc.Start();
// getting the process output
// sr = mysqlProc.StandardOutput;
// storing the output in the string variable
// returnDetails = sr.ReadToEnd();
// Logging the output details
// Trace.TraceInformation("Information", returnDetails);
returnDetails = null;
}
catch (Exception ex)
{
returnDetails = ex.Message;
// Logging the exceptiom
Trace.TraceError(ex.Message);
}
return returnDetails;
}
}
}