public static IEnumerable <TextData> Test_ReadQuestionFiles(string directory, int limit = 0) { directory = zPath.Combine(XmlConfig.CurrentConfig.GetExplicit("CardDirectory"), directory); //TextDataReader textDataReader = new TextDataReader(QuestionsManager.GetScanFiles(directory, limit)); TextDataReader textDataReader = new TextDataReader(); textDataReader.SetRegexList(CreateQuestionRegexValuesList()); //return textDataReader.Read(QuestionsManager.GetScanFiles(zPath.Combine(directory, @"data\scan"), limit)); int pageNumber = 1; foreach (TextData textData in textDataReader.Read(QuestionsManager.GetScanFiles(zPath.Combine(directory, @"data\scan"), limit))) { yield return(textData); if (textData.Values.ContainsKey("pageNumber")) { pageNumber++; } if (textData.Values.ContainsKey("responses") && pageNumber > 1) { textDataReader.SetRegexList(CreateResponseRegexValuesList()); textDataReader.ContiguousSearch = true; } } }
public static IEnumerable <QuestionData> Test_ReadQuestionFilesAsQuestionData_v2(string directory, int limit = 0) { directory = zPath.Combine(XmlConfig.CurrentConfig.GetExplicit("CardDirectory"), directory); //TextDataReader textDataReader = new TextDataReader(QuestionsManager.GetScanFiles(directory, limit)); TextDataReader textDataReader = new TextDataReader(); textDataReader.SetRegexList(CreateQuestionRegexValuesList()); foreach (QuestionData value in textDataReader.Read(QuestionsManager.GetScanFiles(zPath.Combine(directory, @"data\scan"), limit)).Select(textData => QuestionData.CreateQuestionData(textData))) { if (value.Type == QuestionDataType.Responses) { //Trace.WriteLine("read responses"); textDataReader.SetRegexList(CreateResponseRegexValuesList()); textDataReader.ContiguousSearch = true; } yield return(value); } }
/// <summary> /// Converts a NodeContainerFormat into an ARC container. /// </summary> /// <param name="source">The source format.</param> /// <returns>The binary format.</returns> public BinaryFormat Convert(NodeContainerFormat source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var files = new List <Node>(); var tags = new Dictionary <string, Dictionary <string, int> >(); var totalSize = 0; foreach (Node node in Navigator.IterateNodes(source.Root, NavigationMode.DepthFirst)) { if (node.IsContainer) { continue; } if (node.Name.EndsWith(".arcinfo", StringComparison.InvariantCulture)) { string path = node.Path.Replace(".arcinfo", string.Empty); var dict = new Dictionary <string, int>(); var reader = new TextDataReader(node.Stream); while (!node.Stream.EndOfStream) { string line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) { continue; } string[] split = line.Split('='); dict.Add(split[0], int.Parse(split[1], NumberStyles.Integer, CultureInfo.InvariantCulture)); } tags.Add(path, dict); } else { files.Add(node); totalSize += (int)node.Stream.Length; } } var header = new ArcHeader { MagicId = "TGP0", Version = 3, CompressionType = 0, FileCount = files.Count, OriginalSize = totalSize, }; Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); DataStream outputStream = DataStreamFactory.FromMemory(); var writer = new DataWriter(outputStream) { DefaultEncoding = Encoding.GetEncoding(1252), Endianness = EndiannessMode.LittleEndian, }; writer.WriteOfType(header); var currentOffset = 0; foreach (Node node in files) { string path = node.Path.Substring(source.Root.Path.Length + 1).Replace("/", "\\"); var size = (int)node.Stream.Length; writer.Write(path, 0x60, false); writer.Write(currentOffset); writer.Write(size); if (tags.ContainsKey(node.Path)) { writer.Write(tags[node.Path]["Unknown1"]); writer.Write(tags[node.Path]["Unknown2"]); } else { writer.Write(0); writer.Write(0); } currentOffset += size; } foreach (Node node in files) { node.Stream.WriteTo(outputStream); } return(new BinaryFormat(outputStream)); }
public static IEnumerable <TextData> Test_Anki_01(string directory, int limit = 0) { TextDataReader textDataReader = new TextDataReader(CreateAnkiRegexValuesList(), GetScanFiles(directory, limit)); return(textDataReader.Read()); }
public IEnumerable <QuestionResponse_v2> Read(IEnumerable <string> files, string baseDirectory = null) { _lastValueType = null; _dontSetLastValueType = false; _emptyLineCount = 0; _questionYear = null; _questionType = QuestionType.None; _question = null; _questionTmp = null; _associationQuestion = null; _sendCurrentQuestion = false; _responseYears = null; _responseQuestions = null; _responseCategory = null; _responseQuestionBlock = false; _responseQuestion = null; _responseEnd = false; _baseDirectory = baseDirectory; TextDataReader textDataReader = new TextDataReader(); textDataReader.SetRegexList(_questionRegexValuesList); bool readResponse = false; //int emptyLineCount = 0; int pageNumber = 1; foreach (QuestionData value in textDataReader.Read(files).Select(textData => QuestionData.CreateQuestionData(textData))) { if (value.Type != QuestionDataType.EmptyLine) { _emptyLineCount = 0; } else { _emptyLineCount++; } _sendCurrentQuestion = false; _dontSetLastValueType = false; switch (value.Type) { case QuestionDataType.Responses: if (pageNumber >= _minPageForResponses) { if (_trace) { Trace.WriteLine($"start read response (line {value.LineNumber} \"{value.Filename}\")"); } textDataReader.SetRegexList(_responseRegexValuesList); textDataReader.ContiguousSearch = true; _sendCurrentQuestion = true; readResponse = true; _responseYears = new List <ResponseReader.ResponseYear>(); _responseQuestions = new List <ResponseReader.ResponseQuestion>(); _responseQuestionBlock = false; } break; case QuestionDataType.PageNumber: pageNumber++; _sendCurrentQuestion = true; break; default: //throw new PBFileException($"unknow value type {value.Type} line {value.LineNumber} file \"{value.Filename}\"", value.File, value.LineNumber); if (!readResponse) { ReadQuestion(value); } else { QuestionResponse_v2 response = ReadResponse(value); if (response != null) { yield return(response); } } break; } if (_sendCurrentQuestion) { if (_question != null) { yield return(GetQuestion()); } _question = _questionTmp; _questionTmp = null; } //if (readResponse) // break; if (!_dontSetLastValueType) { _lastValueType = value.Type; } if (_responseEnd) { break; } } if (_question != null) { yield return(GetQuestion()); } ControlRemindResponseQuestions(); }