public void StandardTest(string testComment) { // now test this document var options = AsciiDocumentAnalysisOptions.GetDefaultSystemOptions(); var bytes = System.Text.Encoding.UTF8.GetBytes(AsciiText); var analysis = AsciiDocumentAnalysis.Analyze(null, new System.IO.MemoryStream(bytes), options); var separation = analysis.SeparationStrategy; Assert.AreEqual(MaxLines, LineList.Count, "Test does not produce expected number of lines"); for (int iLine = 0; iLine < MaxLines; ++iLine) { var expectedTokens = TokenList[iLine]; Assert.AreEqual(MaxColumns, expectedTokens.Count, string.Format("Test does not produce expected number of tokens in line {0}", iLine)); var currentTokens = separation.GetTokens(LineList[iLine]).ToArray(); Assert.AreEqual(MaxColumns, currentTokens.Length, string.Format("SeparationStrategy (of type {0}) returns too less or too many tokens in line {1}, ColumnMode={2}", separation.GetType(), iLine, testComment)); for (int iColumn = 0; iColumn < MaxColumns; ++iColumn) { var expectedToken = expectedTokens[iColumn].Trim(); var currentToken = currentTokens[iColumn].Trim(); Assert.AreEqual(expectedToken, currentToken, string.Format("Tokens are different in line {0}, column {1}, ColumnMode={2}, SeparationStrategy={3}", iLine, iColumn, testComment, separation.GetType())); } } var structure = analysis.RecognizedStructure; Assert.AreEqual(MaxColumns, structure.Count); for (int iColumn = 0; iColumn < MaxColumns; ++iColumn) { AsciiColumnInfo info = structure[iColumn]; Assert.AreEqual(AsciiColumnType.Int64, info.ColumnType); } }
public static void Test05_SingleCharTabGermanCulture2() { var GermanCulture = System.Globalization.CultureInfo.GetCultureInfo("de"); var rnd = new Random(); var stb = new StringBuilder(); var arr = new double[100, 2]; for (int i = 0; i < 100; ++i) { arr[i, 0] = Math.Round(rnd.NextDouble() * 10, 3); arr[i, 1] = Math.Round(rnd.NextDouble() * 10, 3); stb.Append(arr[i, 0].ToString(GermanCulture)); stb.Append("\t"); stb.Append(arr[i, 0].ToString(GermanCulture)); stb.AppendLine(); } // now test this document var options = AsciiDocumentAnalysisOptions.GetOptionsForCultures(System.Globalization.CultureInfo.InvariantCulture, GermanCulture); var bytes = System.Text.Encoding.UTF8.GetBytes(stb.ToString()); var analysis = AsciiDocumentAnalysis.Analyze(null, new System.IO.MemoryStream(bytes), options); var separation = analysis.SeparationStrategy; Assert.AreEqual(2, analysis.RecognizedStructure.Count); Assert.IsTrue(AsciiColumnType.Double == analysis.RecognizedStructure[0].ColumnType); Assert.IsTrue(AsciiColumnType.Double == analysis.RecognizedStructure[1].ColumnType); Assert.IsTrue("de" == analysis.NumberFormatCulture.TwoLetterISOLanguageName); }
private void ReadAnalysisOptionsAndAnalyze() { if (!_asciiDocumentAnalysisOptionsController.Apply(false)) { return; } _analysisOptions = (AsciiDocumentAnalysisOptions)_asciiDocumentAnalysisOptionsController.ModelObject; if (_asciiStreamData != null) { _asciiStreamData.Seek(0, System.IO.SeekOrigin.Begin); _doc = AsciiDocumentAnalysis.Analyze(_doc, _asciiStreamData, _analysisOptions); _asciiStreamData.Seek(0, System.IO.SeekOrigin.Begin); Initialize(true); // getting Gui elements filled with the result of the analysis } else if (_asciiStreamDataProvider != null) { using (var str = _asciiStreamDataProvider.GetStreamForAnalysis()) { if (str != null) { str.Seek(0, System.IO.SeekOrigin.Begin); _doc = AsciiDocumentAnalysis.Analyze(_doc, str, _analysisOptions); Initialize(true); // getting Gui elements filled with the result of the analysis } } } }
/// <summary> /// Shows the ASCII analysis dialog. /// </summary> /// <param name="fileName">Name of the file to analyze.</param> /// <param name="importOptions">On return, contains the ASCII import options the user has confirmed.</param> /// <param name="analysisOptions">Options that specify how many lines are analyzed, and what number formats and date/time formats will be tested.</param> /// <returns><c>True</c> if the user confirms this dialog (clicks OK). False if the user cancels this dialog.</returns> public static bool ShowAsciiImportOptionsDialog(string fileName, AsciiDocumentAnalysisOptions analysisOptions, out AsciiImportOptions importOptions) { importOptions = new AsciiImportOptions(); using (FileStream str = AsciiImporter.GetAsciiInputFileStream(fileName)) { importOptions = AsciiDocumentAnalysis.Analyze(new AsciiImportOptions(), str, analysisOptions); object[] args = new object[] { importOptions, str }; var controller = (Altaxo.Gui.IMVCAController)Current.Gui.GetControllerAndControl(args, typeof(Altaxo.Gui.IMVCAController), Gui.UseDocument.Directly); if (!Current.Gui.ShowDialog(controller, "Choose Ascii import options")) { return(false); } importOptions = (AsciiImportOptions)controller.ModelObject; return(true); } }