protected override void OnRunWorkerCompleted(RunWorkerCompletedEventArgs e) { base.OnRunWorkerCompleted(e); // Check to see if the background process was cancelled. if (e.Cancelled || cancelUIRun) { DeleteTmpFile(); HttpWebRequest cancelRequest = HttpWebRequest.Create(PathMaker.GetValidationServer() + "PathRunnerRequestHandler.jsp?Action=StopWalkingClientTag&ClientTag=" + guid) as HttpWebRequest; //HttpWebRequest cancelRequest = HttpWebRequest.Create(Strings.SERVERNAME + "PathRunnerRequestHandler.jsp?Action=StopWalkingClientTag&ClientTag=" + guid) as HttpWebRequest; HttpWebResponse cancelResponse = null; try { cancelResponse = cancelRequest.GetResponse() as HttpWebResponse; } catch (WebException) { // usually because we aren't connected which has already been reported on the original request, ignore } finally { if (cancelResponse != null) cancelResponse.Close(); } guid = Guid.Empty; cancelUIRun = false; } else { guid = Guid.Empty; //Change html special characters htmlResults = WebUtility.HtmlDecode(htmlResults); htmlResults = htmlResults.Replace("<br>", "\n"); htmlResults = htmlResults.TrimStart('\r','\n'); if (htmlResults.Length > 0) { if (htmlResults.Contains("SaveFile.jsp?filename=")) { string[] splitLine = Regex.Split(htmlResults, "\r\n\n"); string tmpline = splitLine.Last(); int start = tmpline.LastIndexOf("SaveFile.jsp?filename=") + 21; int end = tmpline.LastIndexOf("debug.zip") + 9; if (end == -1) end = tmpline.Length; filename = tmpline.Substring(start + 1, end - start - 1); GetSaveFile(); //Remove last line that has zip file information so it doesn't show up in output string newhtml = string.Empty; for (int x=0; x < splitLine.Length - 1; x++) { if (x < splitLine.Length - 2) newhtml += splitLine[x] + "\r\n\n"; else { //don't add line return for last line, it causes a blank line in grid newhtml += splitLine[x]; } } htmlResults = newhtml; } DeleteTmpFile(); } else htmlResults = "No results returned from PathMaker"; } if (htmlResults.Length > 0) { ValidateResultsForm UISpecResults = new ValidateResultsForm(htmlResults, validationData.visioControl, Strings.UISPECRESULTSFORM); UISpecResults.Show(); } }
protected override void OnRunWorkerCompleted(RunWorkerCompletedEventArgs e) { base.OnRunWorkerCompleted(e); // Check to see if the background process was cancelled. if (e.Cancelled || cancelUIRun) { DeleteTmpFile(); HttpWebRequest cancelRequest = HttpWebRequest.Create(PathMaker.GetValidationServer() + "PathRunnerRequestHandler.jsp?Action=StopWalkingClientTag&ClientTag=" + guid) as HttpWebRequest; //HttpWebRequest cancelRequest = HttpWebRequest.Create(Strings.SERVERNAME + "PathRunnerRequestHandler.jsp?Action=StopWalkingClientTag&ClientTag=" + guid) as HttpWebRequest; HttpWebResponse cancelResponse = null; try { cancelResponse = cancelRequest.GetResponse() as HttpWebResponse; } catch (WebException) { // usually because we aren't connected which has already been reported on the original request, ignore } finally { if (cancelResponse != null) { cancelResponse.Close(); } } guid = Guid.Empty; cancelUIRun = false; } else { guid = Guid.Empty; //Change html special characters htmlResults = WebUtility.HtmlDecode(htmlResults); htmlResults = htmlResults.Replace("<br>", "\n"); htmlResults = htmlResults.TrimStart('\r', '\n'); if (htmlResults.Length > 0) { if (htmlResults.Contains("SaveFile.jsp?filename=")) { string[] splitLine = Regex.Split(htmlResults, "\r\n\n"); string tmpline = splitLine.Last(); int start = tmpline.LastIndexOf("SaveFile.jsp?filename=") + 21; int end = tmpline.LastIndexOf("debug.zip") + 9; if (end == -1) { end = tmpline.Length; } filename = tmpline.Substring(start + 1, end - start - 1); GetSaveFile(); //Remove last line that has zip file information so it doesn't show up in output string newhtml = string.Empty; for (int x = 0; x < splitLine.Length - 1; x++) { if (x < splitLine.Length - 2) { newhtml += splitLine[x] + "\r\n\n"; } else { //don't add line return for last line, it causes a blank line in grid newhtml += splitLine[x]; } } htmlResults = newhtml; } DeleteTmpFile(); } else { htmlResults = "No results returned from PathMaker"; } } if (htmlResults.Length > 0) { ValidateResultsForm UISpecResults = new ValidateResultsForm(htmlResults, validationData.visioControl, Strings.UISPECRESULTSFORM); UISpecResults.Show(); } }
private static bool ImportUserInterfaceSpecWorker(Object arg, ProgressBarForm progressBarForm) { ParamCache paramCache = arg as ParamCache; int total = 0; int progress = 0; int WordingCol = 0; int PromptCol = 0; Rows x; List<string> notProcessedList = new List<string>(); string notFoundText = string.Empty; string STATE = "State: "; string shapeName = string.Empty; string fieldSeparator = "[\r\a\t]"; object saveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges; object originalFormat = Type.Missing; object routeDocument = Type.Missing; Dictionary<string, string> promptIdToStateNameMap = new Dictionary<string, string>(); Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application(); try { // Set up the open file dialog and let the user select the file to open. if (openFileDialog == null) { openFileDialog = new OpenFileDialog(); openFileDialog.Title = Common.GetResourceString(Strings.OpenUISpecTitleRes); openFileDialog.Filter = Common.GetResourceString(Strings.OpenUISpecFilterRes); openFileDialog.FilterIndex = 1; } openFileDialog.InitialDirectory = PathMaker.getCurrentFileDirectory(paramCache.visioControl); if (openFileDialog.ShowDialog() == DialogResult.OK) { // The user selected a valid file name and hit OK. Get the // file name from the dialog and open the file. paramCache.currentFileName = openFileDialog.FileName; if (wordApp == null) { Common.ErrorMessage("Couldn't start Word - make sure it's installed"); return false; } Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(paramCache.currentFileName, ReadOnly: true, Visible: false); doc.Activate(); // just show we're moving a little earlier progressBarForm.SetProgressPercentage(1, 100); total = doc.Revisions.Count; //turn off show changes, otherwise it be included in revised text //doc.ActiveWindow.View.ShowInsertionsAndDeletions = false; notProcessedList.Clear(); PromptChangesList recordingList = new PromptChangesList(); foreach (Revision arev in doc.Revisions) { progress++; try { if (arev.Range.Information[WdInformation.wdWithInTable]) { x = arev.Range.Rows; notFoundText = Regex.Replace((STATE + arev.Range.Tables[1].Cell(1, 1).Range.Text + "\n\t" + x.First.Range.Text), fieldSeparator, " ").Trim() + "\r\n\n"; string tempStateName = arev.Range.Tables[1].Cell(1, 1).Range.Text.Replace("\r\a", string.Empty).Trim();//JDK added to help with unprocessed edits processing //TODO Make sure import and export consistant in the cols. shapeName = arev.Range.Tables[1].Cell(1, 2).Range.Text.Replace("\r\a", string.Empty).Trim(); ; if (shapeName.Equals(Strings.Interaction)) { WordingCol = 1; PromptCol = 2; //notFoundText = Regex.Replace((STATE + arev.Range.Tables[1].Cell(1, 1).Range.Text + "\n\t\t\t" + x.First.Range.Text), fieldSeparator, " ").Trim() + "\r\n\n"; } else if (shapeName.Equals(Strings.PlayPrompt)) { WordingCol = 0; PromptCol = 1; //notFoundText = Regex.Replace((STATE + arev.Range.Tables[1].Cell(1, 1).Range.Text + "\n\t\t\t" + x.First.Range.Text), fieldSeparator, " ").Trim() + "\r\n\n"; } else if (shapeName.Equals("Version")) { WordingCol = 0; PromptCol = 0; if (notFoundText.Trim().Length >= 18) { notFoundText = Regex.Replace((STATE + "Revision History \n\t" + x.First.Range.Text), fieldSeparator, " ").Trim() + "\r\n\n"; notProcessedList.Add(notFoundText); } continue; } else { WordingCol = 0; PromptCol = 0; notProcessedList.Add(notFoundText); continue; } string[] lines = Regex.Split(x.First.Range.Text, "\r\a"); if (lines[WordingCol] != "" && lines[PromptCol] != "") { recordingList.AddPromptRecording(lines[PromptCol], lines[WordingCol]); promptIdToStateNameMap.Add(lines[PromptCol].Trim(), tempStateName); } else { if (!notProcessedList.Contains(notFoundText)) notProcessedList.Add(notFoundText); } } else { if (!notProcessedList.Contains(arev.Range.Sentences.First.Text.Trim() + "\r\n\n")) notProcessedList.Add(arev.Range.Sentences.First.Text.Trim() + "\r\n\n"); } progressBarForm.SetProgressPercentage(progress, total); if (progressBarForm.Cancelled) { ((_Application)wordApp).Quit(false); System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp); wordApp = null; return false; } } catch { if (!notProcessedList.Contains(notFoundText)) notProcessedList.Add(notFoundText); } } Common.ApplyPromptRecordingList(recordingList); //Process not process records to display string unprocessed = string.Empty; for (int y = 0; y < notProcessedList.Count; y++) { unprocessed += notProcessedList[y].ToString(); } Dictionary<string, string> unprocessChangeList = recordingList.getUnusedPromptChanges(); if (unprocessChangeList.Count > 0) { //JDK - use this to get more context to display - tempStateName foreach (KeyValuePair<string, string> pair in unprocessChangeList) { if (promptIdToStateNameMap.ContainsKey(pair.Key)) { //grab tempStateName out of dictionary for the "id" string tempStateName = ""; if (promptIdToStateNameMap.TryGetValue(pair.Key, out tempStateName)) { unprocessed += STATE + tempStateName + " \n\t\t" + pair.Value + " " + pair.Key + "\r\n\n"; } else { unprocessed += STATE + "UNKOWN STATE NAME \n\t\t" + pair.Value + " " + pair.Key + "\r\n\n"; } } else { unprocessed += pair.Value + " " + pair.Key + "\r\n\n"; } } } if (total == 0) unprocessed += "No changes found \r\n\n"; if (unprocessed.Length > 0) { ValidateResultsForm frm = new ValidateResultsForm(unprocessed, paramCache.visioControl, Strings.UISPECTIMPORTRESULTS); frm.Text = "Changes Requiring Manual Updates"; frm.Name = Strings.UISPECTIMPORTRESULTS; frm.Show(); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { if (wordApp != null) { // Quit without saving changes. try { wordApp.Documents.Close(ref saveChanges, ref originalFormat, ref routeDocument); }catch { //do nothing not open } ((_Application)wordApp).Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp); wordApp = null; } } progressBarForm.SetProgressPercentage(total, total); System.Windows.Forms.Application.DoEvents(); return true; }