internal static void Reset() { s_gd = null; ANARecord.Reset(); ANAAnalysis.Reset(); }
/// <summary> /// Do whatever it takes to convert the input this processor knows about. /// </summary> public void Convert() { using (ANAConverterDlg dlg = new ANAConverterDlg()) { dlg.ShowDialog(); if (dlg.DialogResult == DialogResult.OK) { string outputPathname = null; string parametersPathname = null; try { parametersPathname = dlg.ParametersPathname; string anaPathname = dlg.ANAPathname; using (StreamReader reader = new StreamReader(anaPathname)) // Client to catch any exception. { ANARecord record = null; string line = reader.ReadLine(); ANARecord.SetParameters(parametersPathname); ANAObject.DataLayer = m_gd; // Sanity checks. if (line == null) { ThrowFileLoadException(reader, anaPathname, "ANA File is empty"); } while (!line.StartsWith("\\a")) { line = line.Trim(); if ((line != "") || ((line = reader.ReadLine()) == null)) { ThrowFileLoadException(reader, anaPathname, "Does not appear to be an ANA file."); } } while (line != null) { switch (line.Split()[0]) { case "\\a": { if (record != null) { record.Convert(); } record = new ANARecord(line.Substring(3)); break; } case "\\w": { record.ProcessWLine(line.Substring(3)); break; } case "\\u": { record.ProcessOtherLine(LineType.kUnderlyingForm, line.Substring(3)); break; } case "\\d": { record.ProcessOtherLine(LineType.kDecomposition, line.Substring(3)); break; } case "\\cat": { record.ProcessOtherLine(LineType.kCategory, line.Substring(5)); break; } default: // Eat this line. break; } line = reader.ReadLine(); } Debug.Assert(record != null); record.Convert(); // Process last record. } // Main processing. PositionAnalyzer anal = new PositionAnalyzer(); anal.Process(m_gd); // Do any post-analysis processing here, if needed. // End of any optional post-processing. // Save, so it can be transformed. outputPathname = GetOutputPathname(anaPathname); m_gd.SaveData(outputPathname); // Transform. XslCompiledTransform trans = new XslCompiledTransform(); try { trans.Load(XSLPathname); } catch { MessageBox.Show("Could not load the XSL file.", "Information"); return; } string htmlOutput = Path.GetTempFileName() + ".html"; try { trans.Transform(outputPathname, htmlOutput); } catch { MessageBox.Show("Could not transform the input file.", "Information"); return; } Process.Start(htmlOutput); } finally { if (parametersPathname != null && File.Exists(parametersPathname)) { File.Delete(parametersPathname); } if (outputPathname != null && File.Exists(outputPathname)) { File.Delete(outputPathname); } } } } // Reset m_gd, in case it gets called for another file. m_gd = GAFAWSData.Create(); }
/// <summary> /// Do whatever it takes to convert the input this processor knows about. /// </summary> public void Convert() { using (ANAConverterDlg dlg = new ANAConverterDlg()) { dlg.ShowDialog(); if (dlg.DialogResult == DialogResult.OK) { string outputPathname = null; string parametersPathname = null; try { parametersPathname = dlg.ParametersPathname; string anaPathname = dlg.ANAPathname; using (StreamReader reader = new StreamReader(anaPathname)) // Client to catch any exception. { ANARecord record = null; string line = reader.ReadLine(); ANARecord.SetParameters(parametersPathname); ANAObject.DataLayer = m_gd; // Sanity checks. if (line == null) ThrowFileLoadException(reader, anaPathname, "ANA File is empty"); while (!line.StartsWith("\\a")) { line = line.Trim(); if ((line != "") || ((line = reader.ReadLine()) == null)) ThrowFileLoadException(reader, anaPathname, "Does not appear to be an ANA file."); } while (line != null) { switch (line.Split()[0]) { case "\\a": { if (record != null) record.Convert(); record = new ANARecord(line.Substring(3)); break; } case "\\w": { record.ProcessWLine(line.Substring(3)); break; } case "\\u": { record.ProcessOtherLine(LineType.kUnderlyingForm, line.Substring(3)); break; } case "\\d": { record.ProcessOtherLine(LineType.kDecomposition, line.Substring(3)); break; } case "\\cat": { record.ProcessOtherLine(LineType.kCategory, line.Substring(5)); break; } default: // Eat this line. break; } line = reader.ReadLine(); } Debug.Assert(record != null); record.Convert(); // Process last record. } // Main processing. PositionAnalyzer anal = new PositionAnalyzer(); anal.Process(m_gd); // Do any post-analysis processing here, if needed. // End of any optional post-processing. // Save, so it can be transformed. outputPathname = GetOutputPathname(anaPathname); m_gd.SaveData(outputPathname); // Transform. XslCompiledTransform trans = new XslCompiledTransform(); try { trans.Load(XSLPathname); } catch { MessageBox.Show("Could not load the XSL file.", "Information"); return; } string htmlOutput = Path.GetTempFileName() + ".html"; try { trans.Transform(outputPathname, htmlOutput); } catch { MessageBox.Show("Could not transform the input file.", "Information"); return; } Process.Start(htmlOutput); } finally { if (parametersPathname != null && File.Exists(parametersPathname)) File.Delete(parametersPathname); if (outputPathname != null && File.Exists(outputPathname)) File.Delete(outputPathname); } } } // Reset m_gd, in case it gets called for another file. m_gd = GAFAWSData.Create(); }