private void button_MergeDB_RunFailed_Click(object sender, RoutedEventArgs e) { textBox_MergeDB_Output.Text = string.Empty; ToggleMergeRunButton(false); ToggleMergeOpenFileButton(false); ToggleCheckBoxes(false); var connString = BillingToolBoxSettings.Default.ConnectionString.Replace("Provider=SQLOLEDB.1;", string.Empty); connString = connString.Replace("Initial Catalog=master;", string.Format("Initial Catalog={0};", comboBox_MergeDB_Databases.SelectedItem)); var badSQLFiles2 = new List<string>(); Task.Factory.StartNew(() => { try { SetLabelText("Running DB files...\r\n"); var connection = new SqlConnection(connString); var server = new Server(new ServerConnection(connection)); foreach (var badSqlFile in badSQLFiles) { var fileInfo = new FileInfo(badSqlFile); var sqlScriptWorker = new SQLScriptWorker(); var workerThread = new Thread(() => sqlScriptWorker.RunScript(fileInfo, server)); workerThread.Start(); while (sqlScriptWorker.statusMessage == string.Empty) { Thread.Sleep(1); } workerThread.Join(); WriteToMergeDBOutput(sqlScriptWorker.statusMessage); if (sqlScriptWorker.statusMessage.StartsWith("Error")) badSQLFiles2.Add(fileInfo.FullName); } WriteToMergeDBOutput("\r\n\r\nMerge finished."); } catch (Exception ex) { this.Dispatcher.Invoke((Action)(() => { Tools.ShowErrorPopUpModal(ex.Message); Log.WriteToLog(ex.Message); })); } finally { badSQLFiles = new List<string>(); foreach (var badSqlFile in badSQLFiles2) { badSQLFiles.Add(badSqlFile); } ToggleMergeRunButton(true); ToggleCheckBoxes(true); ParseErrors(); } }); }
private void RunMerge() { ToggleMergeRunButton(false); ToggleMergeOpenFileButton(false); ToggleMergeRunFailedButton(false); ToggleCheckBoxes(false); ToggleFolderButton(false); var getLatest = checkBox_MergeDB_GetLatest.IsChecked; var force = (checkBox_MergeDB_ForceGet.IsChecked == true) ? " /force " : string.Empty; var connString = BillingToolBoxSettings.Default.ConnectionString.Replace("Provider=SQLOLEDB.1;", string.Empty); connString = connString.Replace("Initial Catalog=master;", string.Format("Initial Catalog={0};", comboBox_MergeDB_Databases.SelectedItem)); badSQLFiles = new List<string>(); Task.Factory.StartNew(() => { try { if (getLatest == true) { SetLabelText("Getting latest..."); var p = new Process(); p.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.EXE"; p.StartInfo.Arguments = string.Format("get \"{0}\"{1}/recursive", BillingToolBoxSettings.Default.BDD_Directory, force); WriteToMergeDBOutput(string.Format("Running: {0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments)); p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.OutputDataReceived += new DataReceivedEventHandler(MergeDBOutputHandler); p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); p.WaitForExit(); WriteToMergeDBOutput("Finished getting latest.\r\n"); } SetLabelText("Running DB files..."); foreach (var path in BillingToolBoxSettings.Default.MergeFolders) { var directory = Path.Combine(BillingToolBoxSettings.Default.BDD_Directory, path); var titleString = "Running Files in: " + directory; var spacer = "".PadRight(titleString.Length + 1, '-'); WriteToMergeDBOutput(string.Format("{0}\r\n{1}\r\n{0}", spacer, titleString)); var di = new DirectoryInfo(directory); var files = di.GetFiles("*.sql", SearchOption.AllDirectories); var connection = new SqlConnection(connString); var server = new Server(new ServerConnection(connection)); foreach (var fileInfo in files) { var sqlScriptWorker = new SQLScriptWorker(); var workerThread = new Thread(() => sqlScriptWorker.RunScript(fileInfo, server)); workerThread.Start(); while (sqlScriptWorker.statusMessage == string.Empty) { Thread.Sleep(1); } workerThread.Join(); WriteToMergeDBOutput(sqlScriptWorker.statusMessage); if (sqlScriptWorker.statusMessage.StartsWith("Error")) badSQLFiles.Add(fileInfo.FullName); } } WriteToMergeDBOutput("\r\n\r\nMerge finished."); } catch (Exception ex) { Dispatcher.Invoke((Action)(() => { Tools.ShowErrorPopUpModal(ex.Message); Log.WriteToLog(ex.Message); })); } finally { ToggleMergeRunButton(true); ToggleCheckBoxes(true); ToggleFolderButton(true); ParseErrors(); } }); }