public static ActionResult TestSqlConnection(Session session) { try { if (session == null) { throw new ArgumentNullException("session"); } SetSessionProperty(session, "DATABASE_TEST_CONNECTION", "0"); string sConnectionString = GetConnectionString(session, false); using (var sqlConect = new SqlConnection(sConnectionString)) { sqlConect.Open(); } SetSessionProperty(session, "DATABASE_TEST_CONNECTION", "1"); MessageBox.Show(@"Test successful!", @"Test authentication", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "An Exception occured trying to connect.", ex, true); MessageBox.Show(ex.Message, @"Test authentication", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(ActionResult.Success); }
public static void UpdateCustomTableDataBasePaths(Session session, List <DataBasePathTO> listPaths, bool isCustomActionData) { try { Record record; Microsoft.Deployment.WindowsInstaller.View viewWI; if (listPaths == null || listPaths.Count < 0) { return; } if (session == null) { throw new ArgumentNullException("session"); } if (isCustomActionData) { if (session.CustomActionData.ContainsKey("DATABASE_PATHS")) { session.CustomActionData.Remove("DATABASE_PATHS"); session.CustomActionData.AddObject <List <DataBasePathTO> >("DATABASE_PATHS", listPaths); } else { session.CustomActionData.AddObject <List <DataBasePathTO> >("DATABASE_PATHS", listPaths); } } else { TableInfo info = session.Database.Tables["TABLE_DATABASE_PATHS"]; viewWI = session.Database.OpenView("SELECT * FROM TABLE_DATABASE_PATHS"); for (int i = 0; i < listPaths.Count; i++) { record = session.Database.CreateRecord(info.Columns.Count); record.FormatString = info.Columns.FormatString; record[1] = listPaths[i].Name; record[2] = listPaths[i].Description; record[3] = listPaths[i].Path; viewWI.Modify(ViewModifyMode.InsertTemporary, record); record.Dispose(); } viewWI.Close(); } } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception to update rows of CustomTable", ex, true); throw; } }
private static List <DataBasePathTO> GetCustomTableDataBasePaths(Session session, bool isCustomActionData) { try { List <DataBasePathTO> listPaths; if (isCustomActionData) { listPaths = session.CustomActionData.GetObject <List <DataBasePathTO> >("DATABASE_PATHS"); } else { listPaths = new List <DataBasePathTO>(); DataBasePathTO path; string sPath; using (Microsoft.Deployment.WindowsInstaller.View v = session.Database.OpenView ("SELECT * FROM `TABLE_DATABASE_PATHS`")) { if (v != null) { v.Execute(); for (Record r = v.Fetch(); r != null; r = v.Fetch()) { sPath = r.GetString(3); if (string.IsNullOrWhiteSpace(sPath)) { sPath = GetSessionProperty(session, "INSTALLLOCATION", isCustomActionData); } path = new DataBasePathTO() { Name = r.GetString(1), Description = r.GetString(2), Path = sPath }; listPaths.Add(path); r.Dispose(); } } } } if (listPaths == null || listPaths.Count == 0) { throw new InstallerException("No installation paths configured"); } return(listPaths); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception, GetCustomTableDataBasePaths", ex, true); throw; } }
/// <summary> /// Handles the event <seealso cref="CellClick" /> to present a dialog box to select folder. /// </summary> /// <param name="sender">object that fired the event .</param> /// <param name="e">Event <seealso cref="DataGridViewCellEventArgs" /> Arguments.</param> private void dgvPaths_CellClick(object sender, DataGridViewCellEventArgs e) { string path; if (e.RowIndex >= 0 && e.ColumnIndex == dgvPaths.Columns["dgvColPathDialog"].Index) { if (dgvPaths.Rows[e.RowIndex].Cells["dgvColPath"].Value == null || string.IsNullOrWhiteSpace(dgvPaths.Rows[e.RowIndex].Cells["dgvColPath"].Value.ToString())) { path = m_dirCurrent; } else { path = dgvPaths.Rows[e.RowIndex].Cells["dgvColPath"].Value.ToString(); } dgvPaths.Rows[e.RowIndex].Cells["dgvColPath"].Value = InstallUtilities.GetFolder(path); } }
public static ActionResult SetDefaultIPAdress(Session session) { try { string sHostName, sIP, sIPCurrent; sIPCurrent = GetSessionProperty(session, "DATABASE_MAILIP", false); if (string.IsNullOrWhiteSpace(sIPCurrent)) { sHostName = Dns.GetHostName(); sIP = Dns.GetHostEntry(sHostName).AddressList[0].ToString(); SetSessionProperty(session, "DATABASE_MAILIP", sIP); } return(ActionResult.Success); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception setting Default IP", ex, true); return(ActionResult.Failure); } }
public static ActionResult TestSqlConnection(Session session) { try { if (session == null) { throw new ArgumentNullException("session"); } SetSessionProperty(session, "DATABASE_TEST_CONNECTION", "0"); string sConnectionString = GetConnectionString(session, false); using (SqlConnection sqlConect = new SqlConnection(sConnectionString)) { sqlConect.Open(); } SetSessionProperty(session, "DATABASE_TEST_CONNECTION", "1"); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception when performing test connection to the database server.", ex, true); MessageBox.Show(ex.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(ActionResult.Success); }
private static List <FeactureInstallTO> GetFeactureScriptDataBase(Session session, List <string> listFeactureNames) { string sFileName = string.Empty; try { List <FeactureInstallTO> listF; string sLevel = session["INSTALLLEVEL"]; listF = new List <FeactureInstallTO>(); FeactureInstallTO f; int i; string sQuery = "SELECT `Feature`.`Feature`, `Feature`.`Title`, `Feature`.`Display`, " + " `Component`.`Directory_`, `File`.`FileName` " + " FROM `FeatureComponents`, `Feature`, `Component`, `File` " + " WHERE `FeatureComponents`.`Feature_` = `Feature`.`Feature` " + " AND `FeatureComponents`.`Component_` = `Component`.`Component` " + " AND `File`.`Component_` = `Component`.`Component` " + " AND `Feature`.`RuntimeLevel` > 0 AND `Feature`.`Level` > 0 " + // " AND `Feature`.`Level` <= " + sLevel + " ORDER BY `Feature`.`Display`"; using (Microsoft.Deployment.WindowsInstaller.View v = session.Database.OpenView(sQuery)) { if (v != null) { v.Execute(); //var str = string.Empty; //foreach (var fea in listFeactureNames) // str += fea.ToString(); //MessageBox.Show(str); //str = string.Empty ; //var frm = new FeatureList( session,v,listFeactureNames); //frm.ShowDialog(); for (Record r = v.Fetch(); r != null; r = v.Fetch()) { if (listFeactureNames.Contains(r.GetString("Feature")) && r.GetString("FileName").ToUpper().EndsWith(".SQL")) { i = r.GetString("FileName").IndexOf("|"); if (i > 0) { sFileName = r.GetString("FileName").Substring(i + 1); } else { sFileName = r.GetString("FileName"); } f = new FeactureInstallTO() { Feature = r.GetString("Feature"), Title = r.GetString("Title"), DisplayOrder = r.GetInteger("Display"), FileName = sFileName, DirectoryPath = session.GetTargetPath(r.GetString("Directory_")) }; listF.Add(f); } r.Dispose(); } } } return(listF); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Fail to Read Feature Script", ex, true); throw; } }
public static ActionResult SwhowPathInstall(Session session) { try { bool isCustomActionData = false; List <DataBasePathTO> listPaths; List <FeactureInstallTO> listFeactureScripts; List <string> listFeactureNames = new List <string>(); InstallUtilities.WriteLogInstall(session, "Starting SwhowPathInstall ...", null, true); if (session == null) { throw new ArgumentNullException("session"); } listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); CustomActionData data = new CustomActionData(); data.AddObject <List <DataBasePathTO> >("DATABASE_PATHS", listPaths); SetCustomActionData(session, "INSTALLLOCATION", data); SetCustomActionData(session, "DATABASE_SERVERNAME", data); SetCustomActionData(session, "DATABASE_NAME", data); SetCustomActionData(session, "DATABASE_WINDOWSAUTHENTICATION", data); SetCustomActionData(session, "DATABASE_AUTHENTICATEDATABASE", data); SetCustomActionData(session, "DATABASE_EXECUTESCRIPTS", data); SetCustomActionData(session, "DATABASE_USERNAME", data); SetCustomActionData(session, "DATABASE_PASSWORD", data); //SetCustomActionData(session, "DATABASE_PROXYPASSWORD", data); //SetCustomActionData(session, "DATABASE_MAILPROFILENAME", data); //SetCustomActionData(session, "DATABASE_MAILBOX", data); //SetCustomActionData(session, "DATABASE_MAILIP", data); //SetCustomActionData(session, "DATABASE_OPERATORNAMENAME", data); //SetCustomActionData(session, "DATABASE_OPERATORMAILBOX", data); //SetCustomActionData(session, "DATABASE_PROXYWINDOWSUSER", data); foreach (FeatureInfo fi in session.Features) { if (fi.RequestState == InstallState.Local || fi.RequestState == InstallState.Source || fi.RequestState == InstallState.Default) { listFeactureNames.Add(fi.Name); InstallUtilities.WriteLogInstall(session, "FEATURE fi.Name: " + fi.Name + ", fi.CurrentState: " + fi.CurrentState + ", fi.RequestState:" + fi.RequestState, null, false); } } listFeactureScripts = GetFeactureScriptDataBase(session, listFeactureNames); data.AddObject <List <FeactureInstallTO> >("DATABASE_FEACTURESCRIPTS", listFeactureScripts); //session["CUSTOMACTIONDATA_PROPERTIES"] = data.ToString(); session.DoAction("CA_DataBaseExecuteScripts", data); return(ActionResult.Success); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception to establish routes database installation", ex, true); return(ActionResult.Failure); } }
private static bool ExecuteSQLScript(Session session, string path, string fileName, bool usingTransaction, bool isCustomActionData) { bool bOK = true; string sCommandText = "", sScript = null, sMessage; SqlCommand command = new SqlCommand(); SqlConnection cnx; try { InstallUtilities.WriteLogInstall(session, string.Format("Begin ExecuteSQL, Path: {0}, Filename: {1} ...", path, fileName), null, false); sScript = GetSQLScriptFromFile(path, fileName).Trim(); sScript = ReplaceVariables(session, sScript, isCustomActionData); if (string.IsNullOrWhiteSpace(sScript)) { return(true); } cnx = GetConnection(session, isCustomActionData); command.CommandType = System.Data.CommandType.Text; command.CommandTimeout = 0; command.Connection = cnx; string[] splits = new string[] { "GO\n", "GO\r\n", "GO\t", "GO \r\n", "GO \n", "GO \r\n", "GO \n", "GO \n", "GO \r\n", "GO \r\n" }; string[] sSQL = sScript.Split(splits, StringSplitOptions.RemoveEmptyEntries); if (usingTransaction) { using (TransactionScope scope = new TransactionScope()) { foreach (string s in sSQL) { sCommandText = s.Trim(); if (sCommandText.EndsWith("GO", StringComparison.OrdinalIgnoreCase)) { sCommandText = sCommandText.Substring(0, sCommandText.Length - 2); } if (string.IsNullOrWhiteSpace(sCommandText)) { continue; } command.CommandText = sCommandText; command.ExecuteNonQuery(); } scope.Complete(); } } else { foreach (string s in sSQL) { sCommandText = s.Trim(); if (sCommandText.EndsWith("GO", StringComparison.OrdinalIgnoreCase)) { sCommandText = sCommandText.Substring(0, sCommandText.Length - 2); } if (string.IsNullOrWhiteSpace(sCommandText)) { continue; } command.CommandText = sCommandText; command.ExecuteNonQuery(); } } } catch (Exception ex) { bOK = false; sMessage = "Exception when running script: " + Path.Combine(path, fileName); InstallUtilities.WriteLogInstall(session, sMessage, ex, true); InstallUtilities.WriteLogInstall(session, "COMMAND EXECUTED:", null, false); InstallUtilities.WriteLogInstall(session, sCommandText, null, false); sCommandText = sCommandText.Length > 1000 ? sCommandText.Substring(0, 1000) + " ..." : sCommandText; sCommandText = sMessage + Environment.NewLine + Environment.NewLine + " Exception: " + ex.Message + Environment.NewLine + Environment.NewLine + sCommandText; MessageBox.Show(sCommandText + ex.Message, "Fail to execute sql", MessageBoxButtons.OK, MessageBoxIcon.Error); if (MessageBox.Show("Do you want to continue running the following script?" + Environment.NewLine + Environment.NewLine + "If No installation will be aborted. ", " Continue Installation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { bOK = true; } else { throw new InstallerException(sMessage + ". " + ex.Message); } } finally { command.Dispose(); } return(bOK); }
public static ActionResult ExecuteSQLScripts(Session session) { try { MessageResult iResult; string sInstallLocation, sServidor, sBaseDatos, sMensaje; int iTotalTicks, iTickIncrement = 1; bool isCustomActionData = true; if (session == null) { throw new ArgumentNullException("session"); } sInstallLocation = GetSessionProperty(session, "INSTALLLOCATION", isCustomActionData); sServidor = GetSessionProperty(session, "DATABASE_SERVERNAME", isCustomActionData); sBaseDatos = GetSessionProperty(session, "DATABASE_NAME", isCustomActionData); List <DataBasePathTO> listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); List <FeactureInstallTO> listF = session.CustomActionData.GetObject <List <FeactureInstallTO> >("DATABASE_FEACTURESCRIPTS"); iTotalTicks = listF.Count; InstallUtilities.WriteLogInstall(session, "Starting ExecuteSQLScripts ...", null, true); iResult = InstallProgress.ResetProgress(session, iTotalTicks); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } sMensaje = "SQL Server: " + sServidor; iResult = InstallProgress.DisplayStatusActionStart(session, sMensaje, sMensaje, "[1] / [2]: [3]"); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } iResult = InstallProgress.NumberOfTicksPerActionData(session, iTickIncrement, true); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } for (int i = 0; i < listF.Count; i++) { ExecuteSQLScript(session, listF[i].DirectoryPath, listF[i].FileName, isCustomActionData); iResult = InstallProgress.DisplayActionData3(session, (i + 1).ToString(), iTotalTicks.ToString(), InstallUtilities.Right(Path.Combine(listF[i].DirectoryPath, listF[i].FileName), 200)); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } } return(ActionResult.Success); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception raised when execute database script", ex, true); MessageBox.Show(ex.Message, "Error of scripts execution (ExecuteSQLScripts(Session session))", MessageBoxButtons.OK, MessageBoxIcon.Error); return(ActionResult.Failure); } }
/// <summary> /// Update the data stored in Session.CustomActionData with details <paramref name="listPaths" />. /// </summary> /// <param name="session">Windows Installer Session.</param> /// <param name="listPaths">Paths installation database.</param> /// <param name="isCustomActionData"> /// <para> /// <c>true</c>: Indicates return the value stored in session.CustomActionData[propertyName]. Useful for deferred /// action. /// </para> /// <para><c>false</c>: Indicates return the value stored in session[propertyName]. Useful for immediate action.</para> /// </param> public static void UpdateCustomTableDataBasePaths(Session session, List <DataBasePathTO> listPaths, bool isCustomActionData) { try { Record record; View viewWI; if (listPaths == null || listPaths.Count < 0) { return; } if (session == null) { throw new ArgumentNullException("session"); } if (isCustomActionData) { if (session.CustomActionData.ContainsKey("DATABASE_PATHS")) { session.CustomActionData.Remove("DATABASE_PATHS"); session.CustomActionData.AddObject("DATABASE_PATHS", listPaths); } else { session.CustomActionData.AddObject("DATABASE_PATHS", listPaths); } } else { //TableInfo info = session.Database.Tables["TABLE_DATABASE_PATHS"]; //for (int i = 0; i < listPaths.Count; i++) //{ // record = session.Database.CreateRecord(info.Columns.Count); // record.FormatString = info.Columns.FormatString; // record.SetString(1, listPaths[i].Name); // record.SetString(2, listPaths[i].Description); // record.SetString(3, listPaths[i].Path); // session.Database.Execute(info.SqlInsertString + " TEMPORARY", record); //} // Otro metodo //viewWI = session.Database.OpenView("DELETE FROM `TABLE_DATABASE_PATHS`"); //viewWI.Execute(); //viewWI.Close(); TableInfo info = session.Database.Tables["TABLE_DATABASE_PATHS"]; viewWI = session.Database.OpenView("SELECT * FROM TABLE_DATABASE_PATHS"); //viewWI.Execute(); for (int i = 0; i < listPaths.Count; i++) { // record = session.Database.CreateRecord(3); record = session.Database.CreateRecord(info.Columns.Count); record.FormatString = info.Columns.FormatString; //record.SetString(1, listPaths[i].Name); //record.SetString(2, listPaths[i].Description); //record.SetString(3, listPaths[i].Path); record[1] = listPaths[i].Name; record[2] = listPaths[i].Description; record[3] = listPaths[i].Path; // viewWI.Modify(ViewModifyMode.Replace, record); viewWI.Modify(ViewModifyMode.InsertTemporary, record); record.Dispose(); } viewWI.Close(); } } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception when updating rows CustomTable", ex, true); throw; } }
/// <summary> /// Returns data from the MSI tables: `FeatureComponents`, `Feature`, `Component`, `File`. /// We filter to just get the files that end in (*.SQL). /// </summary> /// <param name="session">Windows Installer Session.</param> /// <param name="listFeatureNames">List list with names to be installed.</param> /// <returns>Returns scripts database files to be installed.</returns> private static List <FeatureInstallTO> GetFeatureScriptDataBase(Session session, List <string> listFeatureNames) { try { List <FeatureInstallTO> listFeatures; string sLevel = session["INSTALLLEVEL"]; listFeatures = new List <FeatureInstallTO>(); FeatureInstallTO f; int i; string sFileName; string sQuery = "SELECT `Feature`.`Feature`, `Feature`.`Title`, `Feature`.`Display`, " + " `Component`.`Directory_`, `File`.`FileName` " + " FROM `FeatureComponents`, `Feature`, `Component`, `File` " + " WHERE `FeatureComponents`.`Feature_` = `Feature`.`Feature` " + " AND `FeatureComponents`.`Component_` = `Component`.`Component` " + " AND `File`.`Component_` = `Component`.`Component` " + " AND `Feature`.`RuntimeLevel` > 0 AND `Feature`.`Level` > 0 " + // " AND `Feature`.`Level` <= " + sLevel + " ORDER BY `Feature`.`Display`"; using (View v = session.Database.OpenView(sQuery)) { if (v != null) { v.Execute(); for (Record r = v.Fetch(); r != null; r = v.Fetch()) { if (listFeatureNames.Contains(r.GetString("Feature")) && r.GetString("FileName").ToUpper().EndsWith(".SQL")) { i = r.GetString("FileName").IndexOf("|", StringComparison.Ordinal); if (i > 0) { sFileName = r.GetString("FileName").Substring(i + 1); } else { sFileName = r.GetString("FileName"); } f = new FeatureInstallTO { Feature = r.GetString("Feature"), Title = r.GetString("Title"), DisplayOrder = r.GetInteger("Display"), FileName = sFileName, DirectoryPath = session.GetTargetPath(r.GetString("Directory_")) }; listFeatures.Add(f); } r.Dispose(); } } } return(listFeatures); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception, ReadFeactureScriptDataBase", ex, true); throw; } }
public static ActionResult ExecuteSQLScripts(Session session) { try { // Active message only for debugging developing // MessageBox.Show ( " ExecuteSQLScripts : To debug in VS Net, on the Debug menu, ' Attach to process ' // Msiexec.exe and rundll32.exe " DEBUG : ExecuteSQLScripts " , MessageBoxButtons.OK , MessageBoxIcon.Information ); MessageResult iResult; string sInstallLocation, sServer, sDatabase, sMessage; int iTotalTicks, iTickIncrement = 1; bool isCustomActionData = true; if (session == null) { throw new ArgumentNullException("session"); } sInstallLocation = GetSessionProperty(session, "INSTALLLOCATION", isCustomActionData); sServer = GetSessionProperty(session, "DATABASE_SERVERNAME", isCustomActionData); sDatabase = GetSessionProperty(session, "DATABASE_NAME", isCustomActionData); List <DataBasePathTO> listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); var listF = session.CustomActionData.GetObject <List <FeatureInstallTO> >("DATABASE_FEACTURESCRIPTS"); iTotalTicks = listF.Count; InstallUtilities.WriteLogInstall(session, "Initialised ExecuteSQLScripts ...", null, true); iResult = InstallProgress.ResetProgress(session, iTotalTicks); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } sMessage = "Executed Script on SQL Server: " + sServer; iResult = InstallProgress.DisplayStatusActionStart(session, sMessage, sMessage, "[1] / [2]: [3]"); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } iResult = InstallProgress.NumberOfTicksPerActionData(session, iTickIncrement, true); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } for (int i = 0; i < listF.Count; i++) { ExecuteSQLScript(session, listF[i].DirectoryPath, listF[i].FileName, isCustomActionData); iResult = InstallProgress.DisplayActionData3(session, (i + 1).ToString(), iTotalTicks.ToString(), InstallUtilities.Right(Path.Combine(listF[i].DirectoryPath, listF[i].FileName), 200)); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } } return(ActionResult.Success); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, @"Exception executing script against the database", ex, true); MessageBox.Show(ex.Message, @"Error while executing scripts", MessageBoxButtons.OK, MessageBoxIcon.Error); return(ActionResult.Failure); } }
public static ActionResult SwhowPathInstall(Session session) { try { // Active message only for debugging developing // MessageBox.Show("SwhowPathInstall: For debugging , the Debug menu, ' Attach to process ' ate processes : msiexec.exe y rundll32.exe.", // "Depurar: SwhowPathInstall", MessageBoxButtons.OK, MessageBoxIcon.Information); bool isCustomActionData = false; List <DataBasePathTO> listPaths; List <FeatureInstallTO> listFeactureScripts; var listFeactureNames = new List <string>(); InstallUtilities.WriteLogInstall(session, "Initialised SwhowPathInstall ...", null, true); if (session == null) { throw new ArgumentNullException("session"); } // Setup Routes taken from CustomTable Id = " TABLE_DATABASE_PATHS " and set default route listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); // Open the user form to change installation paths database . var frmA = new frmPaths(listPaths); if (frmA.ShowDialog() != DialogResult.OK) { throw new InstallerException("Configuración de rutas de instalación no realizada"); } // / Prepare CustomActionData for deferred CustomAction var data = new CustomActionData(); // Update CustomTable Id = " TABLE_DATABASE_PATHS " with modified routes // UpdateCustomTableDataBasePaths (session , listPaths , isCustomActionData ); // Prepare list of paths to be sent to CustomActionData for deferred CustomAction data.AddObject("DATABASE_PATHS", listPaths); // Add the route list as a session property // Data.Add ( " DATABASE_PATHS " JsonConvert.SerializeObject ( listPaths ) ) ; // To retrieve the serialized property // List <DataBasePathTO> JsonConvert.DeserializeObject listPaths = < List <DataBasePathTO> > ( session.CustomActionData [" DATABASE_PATHS "] ); // Prepare properties to be sent to CustomActionData for deferred CustomAction SetCustomActionData(session, "INSTALLLOCATION", data); SetCustomActionData(session, "DATABASE_SERVERNAME", data); SetCustomActionData(session, "DATABASE_NAME", data); SetCustomActionData(session, "DATABASE_WINDOWSAUTHENTICATION", data); SetCustomActionData(session, "DATABASE_AUTHENTICATEDATABASE", data); SetCustomActionData(session, "DATABASE_EXECUTESCRIPTS", data); SetCustomActionData(session, "DATABASE_USERNAME", data); SetCustomActionData(session, "DATABASE_PASSWORD", data); SetCustomActionData(session, "DATABASE_PROXYPASSWORD", data); SetCustomActionData(session, "DATABASE_MAILPROFILENAME", data); SetCustomActionData(session, "DATABASE_MAILBOX", data); SetCustomActionData(session, "DATABASE_MAILIP", data); SetCustomActionData(session, "DATABASE_OPERATORNAMENAME", data); SetCustomActionData(session, "DATABASE_OPERATORMAILBOX", data); SetCustomActionData(session, "DATABASE_PROXYWINDOWSUSER", data); // / Database Scripts to be installed, taken from the MSI Feature using sql files * . foreach (FeatureInfo fi in session.Features) { if (fi.RequestState == InstallState.Local || fi.RequestState == InstallState.Source || fi.RequestState == InstallState.Default) { listFeactureNames.Add(fi.Name); InstallUtilities.WriteLogInstall(session, "FEATURE fi.Name: " + fi.Name + ", fi.CurrentState: " + fi.CurrentState + ", fi.RequestState:" + fi.RequestState, null, false); } } listFeactureScripts = GetFeatureScriptDataBase(session, listFeactureNames); data.AddObject("DATABASE_FEACTURESCRIPTS", listFeactureScripts); // Add all the properties in a single variable //session["CUSTOMACTIONDATA_PROPERTIES"] = data.ToString(); // Schedule deferred actions session.DoAction("CA_DataBaseExecuteScripts", data); return(ActionResult.Success); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception to establish installation paths for database.", ex, true); return(ActionResult.Failure); } }
public static ActionResult ExecuteSQLScripts(Session session) { var data = new CustomActionData(); try { // Active message only for debugging developing // MessageBox.Show("SwhowPathInstall: For debugging , the Debug menu, ' Attach to process ' ate processes : msiexec.exe y rundll32.exe.", // "Depurar: SwhowPathInstall", MessageBoxButtons.OK, MessageBoxIcon.Information); //bool isCustomActionData = false; //List<DataBasePathTO> listPaths; List <FeatureInstallTO> listFeactureScripts; var listFeactureNames = new List <string>(); InstallUtilities.WriteLogInstall(session, "Initialised SwhowPathInstall ...", null, true); if (session == null) { throw new ArgumentNullException("session"); } // Setup Routes taken from CustomTable Id = " TABLE_DATABASE_PATHS " and set default route //listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); // Open the user form to change installation paths database . /* * var frmA = new frmPaths(listPaths); * if (frmA.ShowDialog() != DialogResult.OK) * { * MessageBox.Show("Error"); * throw new InstallerException("Configuración de rutas de instalación no realizada"); * } */ // / Prepare CustomActionData for deferred CustomAction // Update CustomTable Id = " TABLE_DATABASE_PATHS " with modified routes // UpdateCustomTableDataBasePaths (session , listPaths , isCustomActionData ); // Prepare list of paths to be sent to CustomActionData for deferred CustomAction //data.AddObject("DATABASE_PATHS", listPaths); // Add the route list as a session property // Data.Add ( " DATABASE_PATHS " JsonConvert.SerializeObject ( listPaths ) ) ; // To retrieve the serialized property // List <DataBasePathTO> JsonConvert.DeserializeObject listPaths = < List <DataBasePathTO> > ( session.CustomActionData [" DATABASE_PATHS "] ); // Prepare properties to be sent to CustomActionData for deferred CustomAction SetCustomActionData(session, "INSTALLLOCATION", data); SetCustomActionData(session, "DATABASE_SERVERNAME", data); SetCustomActionData(session, "DATABASE_NAME", data); SetCustomActionData(session, "DATABASE_WINDOWSAUTHENTICATION", data); SetCustomActionData(session, "DATABASE_AUTHENTICATEDATABASE", data); SetCustomActionData(session, "DATABASE_EXECUTESCRIPTS", data); SetCustomActionData(session, "DATABASE_USERNAME", data); SetCustomActionData(session, "DATABASE_PASSWORD", data); SetCustomActionData(session, "DATABASE_PROXYPASSWORD", data); SetCustomActionData(session, "DATABASE_MAILPROFILENAME", data); SetCustomActionData(session, "DATABASE_MAILBOX", data); SetCustomActionData(session, "DATABASE_MAILIP", data); SetCustomActionData(session, "DATABASE_OPERATORNAMENAME", data); SetCustomActionData(session, "DATABASE_OPERATORMAILBOX", data); SetCustomActionData(session, "DATABASE_PROXYWINDOWSUSER", data); // / Database Scripts to be installed, taken from the MSI Feature using sql files * . foreach (FeatureInfo fi in session.Features) { if (fi.RequestState == InstallState.Local || fi.RequestState == InstallState.Source || fi.RequestState == InstallState.Default) { listFeactureNames.Add(fi.Name); InstallUtilities.WriteLogInstall(session, "FEATURE fi.Name: " + fi.Name + ", fi.CurrentState: " + fi.CurrentState + ", fi.RequestState:" + fi.RequestState, null, false); } } listFeactureScripts = GetFeatureScriptDataBase(session, listFeactureNames); data.AddObject("DATABASE_FEACTURESCRIPTS", listFeactureScripts); // Add all the properties in a single variable //session["CUSTOMACTIONDATA_PROPERTIES"] = data.ToString(); // Schedule deferred actions //session.DoAction("CA_DataBaseExecuteScripts", data); //return ActionResult.Success; } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception to establish installation paths for database.", ex, true); return(ActionResult.Failure); } try { // Active message only for debugging developing // MessageBox.Show ( " ExecuteSQLScripts : To debug in VS Net, on the Debug menu, ' Attach to process ' // Msiexec.exe and rundll32.exe " DEBUG : ExecuteSQLScripts " , MessageBoxButtons.OK , MessageBoxIcon.Information ); MessageResult iResult; string sInstallLocation, sServer, sDatabase, sMessage; int iTotalTicks, iTickIncrement = 1; bool isCustomActionData = true; if (session == null) { throw new ArgumentNullException("session"); } // sInstallLocation = GetSessionProperty(session, "INSTALLLOCATION", isCustomActionData); sServer = GetSessionProperty(session, "DATABASE_SERVERNAME", false); //PRESET TO STANDARD DATABASE NAME //sDatabase = GetSessionProperty(session, "DATABASE_NAME", isCustomActionData); //List<DataBasePathTO> listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); var listF = data.GetObject <List <FeatureInstallTO> >("DATABASE_FEACTURESCRIPTS"); iTotalTicks = listF.Count; InstallUtilities.WriteLogInstall(session, "Initialised ExecuteSQLScripts ...", null, true); iResult = InstallProgress.ResetProgress(session, iTotalTicks); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } sMessage = "Executed Script on SQL Server: " + sServer; iResult = InstallProgress.DisplayStatusActionStart(session, sMessage, sMessage, "[1] / [2]: [3]"); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } iResult = InstallProgress.NumberOfTicksPerActionData(session, iTickIncrement, true); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } for (int i = 0; i < listF.Count; i++) { ExecuteSQLScript(session, listF[i].DirectoryPath, listF[i].FileName, isCustomActionData); iResult = InstallProgress.DisplayActionData3(session, (i + 1).ToString(), iTotalTicks.ToString(), InstallUtilities.Right(Path.Combine(listF[i].DirectoryPath, listF[i].FileName), 200)); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } } } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, @"Exception executing script against the database", ex, true); MessageBox.Show(ex.Message, @"Error while executing scripts", MessageBoxButtons.OK, MessageBoxIcon.Error); return(ActionResult.Failure); } return(ActionResult.Success); }