/// <summary> /// Executes the specified file path. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="solutionName">Name of the solution.</param> /// <param name="package">The package.</param> /// <param name="outputDelegate">The output delegate.</param> static void Execute(string filePath, string solutionName, string package, WriteOutputDelegate outputDelegate) { try { var xDocument = XDocument.Load(filePath, LoadOptions.None); var solutions = ConfigurationHelper.LoadSolutions(xDocument); var selectedSolution = solutions.Find((x) => { return x.Name.Equals(solutionName, StringComparison.OrdinalIgnoreCase); }); XElement xmlToRun = null; if (selectedSolution != null) { package = package.SafeToString(); if (package.Equals("full", StringComparison.OrdinalIgnoreCase)) { xmlToRun = selectedSolution.FullXml; } else if (package.StartsWith("incremental-", StringComparison.OrdinalIgnoreCase)) { var pieces = package.Split('-'); if (pieces.Length > 2) { var fromVersion = pieces[1]; var toVersion = pieces[2]; xmlToRun = selectedSolution.IncrementalXml.ToList().Find((x) => { return x.GetAttributeValue("BaseVersion").Equals(fromVersion.SafeToString(), StringComparison.OrdinalIgnoreCase) && x.GetAttributeValue("TargetVersion").Equals(toVersion.SafeToString(), StringComparison.OrdinalIgnoreCase); }); } } if (xmlToRun != null) { SqlExecutor sqlExecutor = new SqlExecutor(outputDelegate, selectedSolution.ConnectionSetting, xmlToRun); sqlExecutor.Execute(solutionName); } else { outputDelegate("No matched SQL package to run."); } } else { } } catch (Exception ex) { outputDelegate(ex.Message); } finally { outputDelegate("Execution is ended at " + DateTime.Now + Environment.NewLine); } }
/// <summary> /// Executes the task. /// </summary> private void ExecuteTask(object formObject) { ExecutionForm form = formObject as ExecutionForm; if (form != null) { form.Invoke(new WriteOutputDelegate(WriteOutput), "-----------------------------------" + Environment.NewLine); form.Invoke(new WriteOutputDelegate(WriteOutput), "Execution is started at " + DateTime.Now.ToString(dateTimeFormat) + Environment.NewLine); try { SqlExecutor sqlExecutor = new SqlExecutor(form.WriteOutputLine, form.solution.ConnectionSetting, form.runningXml); sqlExecutor.Execute(form.solution.Name); form.Invoke(new Action(SetButtonAsCompleted)); } catch (ThreadAbortException taex) { Thread.ResetAbort(); form.Invoke(new WriteOutputDelegate(WriteOutput), "Execution is aborted."); form.Invoke(new Action(SetButtonAsCompleted)); } catch (Exception ex) { WriteOutput(ex.Message); } finally { form.workThread = null; form.Invoke(new WriteOutputDelegate(WriteOutput), "Execution is ended at " + DateTime.Now.ToString(dateTimeFormat) + Environment.NewLine); form.Invoke(new WriteOutputDelegate(WriteOutput), "-----------------------------------" + Environment.NewLine); } } }