Exemplo n.º 1
0
        public static void Test2(RegexValuesList regexValuesList, string text, bool contiguous = false)
        {
            Trace.WriteLine("Input     : {0}", text);
            //FindText findText = regexValuesList.Find(text);
            FindText_v2 findText = regexValuesList.Find(text);

            if (!findText.Success)
            {
                Trace.WriteLine("Result           : not found");
                return;
            }
            while (findText.Success)
            {
                Trace.Write($"found \"{findText.Text}\" position {findText.Match.Index + 1} length {findText.Match.Length}");
                NamedValues <ZValue> values = findText.GetValues();
                if (values.Count > 0)
                {
                    Trace.Write(" values");
                    foreach (KeyValuePair <string, ZValue> value in findText.GetValues())
                    {
                        Trace.Write($" \"{value.Key}\" = \"{value.Value}\"");
                    }
                }
                if (findText.Attributes.Count > 0)
                {
                    Trace.Write(" attributes");
                    foreach (KeyValuePair <string, string> attribute in findText.Attributes)
                    {
                        Trace.Write($" \"{attribute.Key}\" = \"{attribute.Value}\"");
                    }
                }
                Trace.WriteLine();
                findText.FindNext(contiguous);
            }
        }
Exemplo n.º 2
0
        public IEnumerable <TextData> Read(IEnumerable <string> files)
        {
            foreach (string file in files)
            {
                int lineNumber = 1;
                //Trace.WriteLine($"read file \"{file}\"");
                foreach (string line in zFile.ReadLines(file))
                {
                    FindText_v2 findText = _regexList.Find(line, contiguous: _contiguousSearch);
                    // Values = findText.GetValues()
                    yield return(new TextData {
                        File = file, Filename = zPath.GetFileName(file), ColumnNumber = findText.Success ? findText.MatchIndex + 1 : 0,
                        LineNumber = lineNumber, Length = findText.MatchLength, Line = line, Values = findText.GetRegexValues()
                    });

                    while (findText.FindNext(contiguous: _contiguousSearch))
                    {
                        // Values = findText.GetValues()
                        yield return(new TextData {
                            File = file, Filename = zPath.GetFileName(file), ColumnNumber = findText.Success ? findText.MatchIndex + 1 : 0,
                            LineNumber = lineNumber, Length = findText.MatchLength, Line = line, Values = findText.GetRegexValues()
                        });
                    }
                    lineNumber++;
                }
            }
        }
Exemplo n.º 3
0
        //public static void Test_FindInFile_01(string file)
        //{
        //    //RegexValuesList regexList = new RegexValuesList(XmlConfig.CurrentConfig.GetElements("QuestionInfos/QuestionInfo"), compileRegex: true);
        //    RegexValuesList regexList = QuestionRun.GetQuestionRegexValuesList();
        //    foreach (string line in zFile.ReadLines(file))
        //    {
        //        string line2 = line.Trim();
        //        if (line2 == "")
        //            continue;
        //        Trace.WriteLine($"read : \"{line2}\"");
        //        FindText findText = regexList.Find(line2);
        //        if (findText.Found)
        //        {
        //            foreach (KeyValuePair<string, ZValue> namedValue in findText.matchValues.GetValues())
        //                Trace.WriteLine($"  found : {namedValue.Key} = \"{namedValue.Value}\"");
        //        }
        //        else
        //        {
        //            Trace.WriteLine($"  unknow text");
        //        }
        //    }
        //}

        public static void Test_Find_02(string text, RegexValuesList regexList)
        {
            Trace.WriteLine($"text : \"{text}\"");
            FindText_v2 findText = regexList.Find(text);

            if (findText.Success)
            {
                //MatchValues matchValues = findText.matchValues;
                while (findText.Success)
                {
                    Trace.WriteLine();
                    Trace.WriteLine($"  found : index {findText.Match.Index} length {findText.Match.Length}");
                    foreach (KeyValuePair <string, ZValue> namedValue in findText.GetValues())
                    {
                        Trace.WriteLine($"        : {namedValue.Key} = \"{namedValue.Value}\"");
                    }
                    //matchValues = matchValues.Next();
                    findText.Next();
                }
            }
            else
            {
                Trace.WriteLine($"  unknow text");
            }
        }
Exemplo n.º 4
0
        public static NamedValues <ZValue> Test_Find_01(string text, RegexValuesList regexList)
        {
            Trace.WriteLine($"text : \"{text}\"");
            //RegexValuesList regexList = new RegexValuesList(XmlConfig.CurrentConfig.GetElements("QuestionInfos/QuestionInfo"), compileRegex: true);
            //FindText findText = QuestionRun.GetQuestionRegexValuesList().Find(text);
            FindText_v2 findText = regexList.Find(text);

            Trace.WriteLine($"found : {findText.Success}");
            return(findText.GetAllValues());
        }
Exemplo n.º 5
0
        private string FindSpecial(string title)
        {
            //FindText findSpecial = _printTitleManager.FindSpecial.Find(title);
            FindText_v2 findSpecial = _printTitleManager.FindSpecial.Find(title);

            if (findSpecial.Success)
            {
                _special = true;
                //_specialMatch = findSpecial.matchValues;
                //title = findSpecial.matchValues.Replace(" $$special$$ ");
                title = findSpecial.Replace(" $$special$$ ");
            }
            return(title);
        }
Exemplo n.º 6
0
 private void _FindPrint()
 {
     if (_titleInfo.FormatedTitle != "")
     {
         _findPrint = _findPrintManager.FindPrintList.Find(_titleInfo.FormatedTitle);
     }
     else if (_titleInfo.Date != null && _titleInfo.RemainText != "")
     {
         // pour fichier du monde 20150829_QUO.pdf formatedTitle=""
         _findPrint = _findPrintManager.FindPrintList.Find(_titleInfo.RemainText);
     }
     else
     {
         _findPrint = new FindText_v2();   // not found
     }
 }
Exemplo n.º 7
0
        private BonusDirectoryInfo GetBonusDirectoryInfo(string directory)
        {
            //FindText findText = _bonusDirectories.Find(zPath.GetFileName(directory));
            FindText_v2 findText = _bonusDirectories.Find(zPath.GetFileName(directory));

            if (findText.Success)
            {
                string bonusDirectory = findText.GetAttribute("directory");
                return(new BonusDirectoryInfo {
                    IsBonusDirectory = true, Directory = bonusDirectory
                });
            }
            else
            {
                return new BonusDirectoryInfo {
                           IsBonusDirectory = false
                }
            };
        }
Exemplo n.º 8
0
        public static void Test_FindInFile_01(string file, RegexValuesList regexList)
        {
            //RegexValuesList regexList = QuestionRun.GetResponseRegexValuesList();
            int lineNumber = 0;

            foreach (string line in zFile.ReadLines(file))
            {
                //string line2 = line.Trim();
                //if (line2 == "")
                //    continue;

                lineNumber++;
                if (line == "")
                {
                    continue;
                }

                Trace.WriteLine();
                Trace.WriteLine($"read : line {lineNumber} \"{line}\"");
                FindText_v2 findText = regexList.Find(line);
                if (findText.Success)
                {
                    //MatchValues matchValues = findText.matchValues;
                    while (findText.Success)
                    {
                        Trace.WriteLine();
                        Trace.WriteLine($"  found : index {findText.Match.Index} length {findText.Match.Length}");
                        foreach (KeyValuePair <string, ZValue> namedValue in findText.GetValues())
                        {
                            Trace.WriteLine($"        : {namedValue.Key} = \"{namedValue.Value}\"");
                        }
                        //matchValues = matchValues.Next();
                        findText.Next();
                    }
                }
                else
                {
                    Trace.WriteLine($"  unknow text");
                }
            }
        }
Exemplo n.º 9
0
        public static void Test(RegexValuesList regexValuesList, string text)
        {
            Trace.WriteLine("Input     : {0}", text);
            //FindText findText = regexValuesList.Find(text);
            FindText_v2 findText = regexValuesList.Find(text);

            if (!findText.Success)
            {
                Trace.WriteLine("Result           : not found");
            }
            else
            {
                Trace.WriteLine("Result           : found");
                Trace.WriteLine("  Text           : \"{0}\"", findText.Text);
                Trace.WriteLine("  Key            : \"{0}\"", findText.Key);
                Trace.WriteLine("  Name           : \"{0}\"", findText.Name);
                Trace.WriteLine("  Pattern        : \"{0}\"", findText.Pattern);

                Trace.WriteLine("  Attributes     : {0}", findText.Attributes.Count);
                foreach (KeyValuePair <string, string> attribute in findText.Attributes)
                {
                    Trace.WriteLine("    Attribute  : \"{0}\" = \"{1}\"", attribute.Key, attribute.Value);
                }

                NamedValues <ZValue> values = findText.GetValues();
                Trace.WriteLine("  GetValues()    : {0}", values.Count);
                foreach (KeyValuePair <string, ZValue> value in values)
                {
                    Trace.WriteLine("    Value      : \"{0}\" = \"{1}\"", value.Key, value.Value);
                }

                values = findText.GetAllValues();
                Trace.WriteLine("  GetAllValues() : {0}", values.Count);
                foreach (KeyValuePair <string, ZValue> value in values)
                {
                    Trace.WriteLine("    AllValue   : \"{0}\" = {1}", value.Key, value.Value);
                }
            }
        }
Exemplo n.º 10
0
        public IEnumerable <Question> Read(IEnumerable <string> files, string baseDirectory = null)
        {
            //Trace.WriteLine("read questions files");

            if (_maxLinesPerQuestion == -1)
            {
                throw new PBException("undefined MaxLinesPerQuestion");
            }
            if (_maxLinesPerChoice == -1)
            {
                throw new PBException("undefined MaxLinesPerResponse");
            }

            _baseDirectory = baseDirectory;

            foreach (string file in files)
            {
                _file     = file;
                _filename = zPath.GetFileName(_file);
                //_year = null;
                //_questionType = QuestionType.None;
                _lastValueType = QuestionValueType.None;
                _question      = null;
                _lineNumber    = 0;
                int emptyLineCount = 0;
                _endOfPage = false;

                if (_trace)
                {
                    Trace.WriteLine($"read question file \"{file}\"");
                }

                foreach (string line in zFile.ReadLines(file))
                {
                    _lineNumber++;
                    string line2 = line.Trim();
                    if (line2 == "")
                    {
                        //if (_lastValueType == QuestionValueType.Response)
                        if (_lastValueType == QuestionValueType.Response || (_associationQuestion != null && _associationQuestion.Complete && _lastValueType == QuestionValueType.Question))
                        {
                            if (_question != null)
                            {
                                //if (!_newVersion)
                                //    yield return new Question { Year = _question.Year, Type = _question.Type, Number = _question.Number, QuestionText = _question.QuestionText, Choices = _question.Choices.ToArray(),
                                //        SourceFile = _question.SourceFile, SourceLine = _question.SourceLine };
                                //else
                                yield return(GetQuestion());

                                _question = null;
                            }
                            else if (_associationQuestion != null)
                            {
                                _associationQuestion.Complete = true;
                            }
                            _lastValueType = QuestionValueType.None;
                        }

                        if (++emptyLineCount == _maxEmptyLine)
                        {
                            _endOfPage = true;
                        }

                        continue;
                    }

                    emptyLineCount = 0;

                    //FindText_v2 findText = _regexList.Find(line2);
                    FindText_v2 findText = _regexList.Find(line);
                    if (findText.Success)
                    {
                        bool          newQuestion = false;
                        QuestionTmp   question    = null;
                        QuestionValue value       = GetQuestionValue(findText.GetValues());
                        if (_trace)
                        {
                            Trace.WriteLine($"  line {_lineNumber} - {value}");
                        }
                        switch (value.Type)
                        {
                        case QuestionValueType.Year:
                            newQuestion          = true;
                            _year                = ((QuestionValueYear)value).Year;
                            _associationQuestion = null;
                            break;

                        case QuestionValueType.QuestionType:
                            newQuestion          = true;
                            _questionType        = ((QuestionValueQuestionType)value).QuestionType;
                            _associationQuestion = null;
                            break;

                        case QuestionValueType.QuestionNumber:
                            newQuestion = true;
                            if (_year == null)
                            {
                                throw new PBFileException($"unknow year, line {_lineNumber} file \"{_filename}\"", _file, _lineNumber);
                            }
                            //string sourceFile = _file;
                            //if (baseDirectory != null && sourceFile.StartsWith(baseDirectory))
                            //{
                            //    int l = baseDirectory.Length;
                            //    if (sourceFile[l] == '\\')
                            //        l++;
                            //    sourceFile = sourceFile.Substring(l);
                            //}
                            question = new QuestionTmp {
                                Year = (int)_year, Type = _questionType, Number = ((QuestionValueQuestionNumber)value).QuestionNumber,
                                QuestionLineCount = 0, SourceFile = GetSubPath(_file), SourceLine = _lineNumber
                            };
                            if (_associationQuestion != null)
                            {
                                _associationQuestion.Complete = true;
                            }
                            break;

                        case QuestionValueType.Response:
                            //if (_question == null)
                            //    throw new PBFileException($"unknow question, line {_lineNumber} file \"{_filename}\"", _file, _lineNumber);
                            //AddResponse(_question, (QuestionValueResponse)value);
                            AddResponse((QuestionValueResponse)value);
                            break;

                        case QuestionValueType.None:
                            _TraceUnknowValue(line2);
                            break;

                        default:
                            throw new PBFileException($"wrong value \"{line2}\" line {_lineNumber} file \"{_filename}\"", _file, _lineNumber);
                        }
                        if (newQuestion)
                        {
                            if (_question != null)
                            {
                                //yield return new Question { Year = _question.Year, Type = _question.Type, Number = _question.Number, QuestionText = _question.QuestionText, Responses = _question.Responses.ToArray() };
                                yield return(GetQuestion());
                            }
                            _question = question;
                        }
                        _lastValueType = value.Type;
                    }
                    else
                    {
                        if (_trace)
                        {
                            Trace.WriteLine($"  line {_lineNumber} - text - {line2}");
                        }
                        switch (_lastValueType)
                        {
                        case QuestionValueType.QuestionNumber:
                            _question.QuestionText = line2;
                            _question.QuestionLineCount++;
                            _lastValueType = QuestionValueType.Question;
                            break;

                        case QuestionValueType.Question:
                            //if (_question.QuestionLineCount > _maxLinesPerQuestion - 1)
                            //    throw new PBFileException($"to many lines for question \"{line2}\" line {_lineNumber} file \"{_filename}\"", _file, _lineNumber);
                            //_question.QuestionText += " " + line2;
                            //_question.QuestionLineCount++;
                            AddQuestion(line2);
                            break;

                        case QuestionValueType.Response:
                            //if (_question.ResponseLineCount > 1)
                            //    throw new PBFileException($"to many lines for response \"{line2}\" line {_lineNumber} file \"{_filename}\"", _file, _lineNumber);
                            //int i = _question.Responses.Count - 1;
                            //_question.Responses[i] += " " + line2;
                            //_question.ResponseLineCount++;
                            AddResponse(line2);
                            break;

                        case QuestionValueType.None:
                            _TraceUnknowValue(line2);
                            break;

                        default:
                            if (_lastValueType == QuestionValueType.QuestionType && _questionType == QuestionType.Association && _manageAssociationQuestion)
                            {
                                _associationQuestion = new QuestionAssociationTmp {
                                    Type = QuestionType.Association, QuestionText = line2, QuestionLineCount = 1, Complete = false
                                };
                                _lastValueType = QuestionValueType.Question;
                            }
                            //else if (_year != null)
                            //    throw new PBFileException($"wrong value \"{line2}\" line {_lineNumber} file \"{_filename}\"", _file, _lineNumber);
                            else
                            {
                                _TraceUnknowValue(line2);
                            }
                            break;
                        }
                    }
                }
                if (_question != null)
                {
                    //yield return new Question { Year = _question.Year, Type = _question.Type, Number = _question.Number, QuestionText = _question.QuestionText, Responses = _question.Responses.ToArray() };
                    yield return(GetQuestion());
                }
            }
        }
Exemplo n.º 11
0
        //private PrintTitleInfo _GetPrintTitleInfo_v1(string title)
        //{
        //    PrintTitleInfo titleInfo = new PrintTitleInfo();
        //    titleInfo.originalTitle = title;
        //    string titleStructure = title;

        //    FindText findSpecial = _findSpecial.Find(titleStructure);
        //    if (findSpecial.found)
        //    {
        //        titleInfo.special = true;
        //        titleInfo.specialMatch = findSpecial.matchValues;
        //        titleStructure = findSpecial.matchValues.Replace(" $$special$$ ");
        //    }

        //    FindNumber findNumber = _findNumber.Find(titleStructure);
        //    if (findNumber.found)
        //    {
        //        titleInfo.number = findNumber.number;
        //        titleInfo.numberMatch = findNumber.matchValues;
        //        titleStructure = findNumber.matchValues.Replace(" $$number$$ ");
        //    }

        //    FindDate findDate = _findDateManager_v1.Find(titleStructure);
        //    if (findDate.found)
        //    {
        //        titleInfo.date = findDate.date;
        //        titleInfo.dateType = findDate.dateType;
        //        titleInfo.dateMatch = findDate.matchValues;
        //        titleStructure = findDate.matchValues.Replace(" $$date$$ ");
        //    }
        //    titleInfo.dateOtherMatchList = findDate.matchValuesList;

        //    Match match = __rgSpecialLabel.Match(titleStructure);
        //    if (match.Success)
        //    {
        //        titleInfo.specialText = match.Groups[1].Value.Trim(__trimChars);
        //        titleInfo.specialText = GetFormatedText(titleInfo.specialText);
        //        titleStructure = match.zReplace(titleStructure, "");
        //    }

        //    int i = titleStructure.IndexOf("$$");
        //    if (i != -1)
        //    {
        //        titleInfo.title = titleStructure.Substring(0, i).Trim(__trimChars);
        //        titleStructure = titleStructure.Substring(i);
        //    }
        //    else
        //        titleInfo.title = titleStructure;

        //    titleInfo.titleStructure = titleStructure;
        //    titleInfo.formatedTitle = GetFormatedText(titleInfo.title);
        //    titleInfo.name = GetName(titleInfo.formatedTitle);
        //    titleInfo.remainText = __rgTitleStructureName.Replace(titleStructure, "").Trim(__trimChars);

        //    titleInfo.file = GetFile(titleInfo);

        //    return titleInfo;
        //}

        /// not used
        //private PrintTitleInfo _GetPrintTitleInfo_v2(string title)
        //{
        //    PrintTitleRequest titleRequest = new PrintTitleRequest();

        //    titleRequest.originalTitle = title;

        //    PrintSplitedTitle splitedTitle = SplitTitle(title);

        //    FindText findSpecial = _findSpecial.Find(splitedTitle.titlePart1);
        //    if (findSpecial.found)
        //    {
        //        titleRequest.special = true;
        //        splitedTitle.titlePart1 = findSpecial.matchValues.Replace(" $$special$$ ");
        //    }

        //    FindNumber findNumber = _findNumber.Find(splitedTitle.titlePart1);
        //    if (findNumber.found)
        //    {
        //        titleRequest.number = findNumber.number;
        //        splitedTitle.titlePart1 = findNumber.matchValues.Replace(" $$number$$ ");
        //    }

        //    FindDate findDate = _findDateManager_new.Find(splitedTitle.titlePart2);
        //    if (findDate.found)
        //    {
        //        titleRequest.date = findDate.date;
        //        titleRequest.dateType = findDate.dateType;
        //        splitedTitle.titlePart2 = findDate.matchValues.Replace(" $$date$$ ");
        //    }

        //    Match match = __rgSpecialLabel.Match(splitedTitle.titlePart1);
        //    if (match.Success)
        //    {
        //        titleRequest.specialText = match.Groups[1].Value.Trim(__trimChars);
        //        titleRequest.specialText = GetFormatedText(titleRequest.specialText);
        //        splitedTitle.titlePart1 = match.zReplace(splitedTitle.titlePart1, "");
        //    }

        //    //Trace.WriteLine("titleRequest :");
        //    //Trace.WriteLine(titleRequest.zToJson());
        //    //Trace.WriteLine("splitedTitle :");
        //    //Trace.WriteLine(splitedTitle.zToJson());

        //    string concatenatedTitle = splitedTitle.titlePart1;
        //    if (!string.IsNullOrEmpty(splitedTitle.realTitlePart2))
        //        concatenatedTitle += " - " + splitedTitle.realTitlePart2;
        //    int i = concatenatedTitle.IndexOf("$$");
        //    if (i != -1)
        //    {
        //        titleRequest.title = concatenatedTitle.Substring(0, i).Trim(__trimChars);
        //        concatenatedTitle = concatenatedTitle.Substring(i);
        //    }
        //    else
        //    {
        //        titleRequest.title = concatenatedTitle;
        //        concatenatedTitle = null;
        //    }

        //    titleRequest.titleStructure = concatenatedTitle;
        //    titleRequest.formatedTitle = GetFormatedText(titleRequest.title);
        //    titleRequest.name = GetName(titleRequest.formatedTitle);
        //    if (concatenatedTitle != null)
        //        titleRequest.remainText = __rgTitleStructureName.Replace(concatenatedTitle, "").Trim(__trimChars);

        //    titleRequest.file = GetFile(titleRequest);

        //    PrintTitleInfo titleInfo = new PrintTitleInfo
        //        {
        //            originalTitle = titleRequest.originalTitle,
        //            title = titleRequest.title,
        //            formatedTitle = titleRequest.formatedTitle,
        //            name = titleRequest.name,
        //            special = titleRequest.special,
        //            specialText = titleRequest.specialText,
        //            number = titleRequest.number,
        //            date = titleRequest.date,
        //            dateType = titleRequest.dateType,
        //            titleStructure = titleRequest.titleStructure,
        //            remainText = titleRequest.remainText,
        //            file = titleRequest.file
        //        };
        //    return titleInfo;
        //}

        /// new split
        private PrintTitleInfo _GetPrintTitleInfo(string title, bool splitTitle, Date?expectedDate)
        {
            // pourquoi split :
            //     "Le Parisien + Votre été du dimanche 24 août 2014"                               date = "été du dimanche 24 août 2014"
            //     "Le Parisien + Votre été du dimanche 24 août 2014"                               date = "été du dimanche 24 août 2014"
            //     "Le Parisien + Votre été (la France en fête) du dimanche 20 juillet 2014"        date = "été"
            //     "Le Monde + Eco&Entreprise + journal de 1994 du mardi 08 avril 2014"             date = "de 1994"
            //     "Le Monde de l'Image 84  - 2013"                                                 date not found
            //     "Le Monde de L'Intelligence 29 - Février-Mars 2013"                              date not found
            //     "Le Monde des Sciences 7 - Février-Mars 2013"                                    date = "7 - Février-Mars 2013"

            PrintTitleRequest titleRequest = new PrintTitleRequest();

            titleRequest.OriginalTitle = title;

            title = ReplaceCharacters(title);

            // new le 11/08/2015
            //title = GetFormatedText(title);

            bool foundDate = false;

            if (splitTitle)
            {
                // split d'abord avec "du" puis avec "-"
                int i1 = title.LastIndexOf(" du ", StringComparison.InvariantCultureIgnoreCase);
                int i2 = title.LastIndexOf("- ");
                int i3 = Math.Max(i1, i2);
                if (i3 != -1)
                {
                    string title1 = title.Substring(0, i3);
                    string title2 = title.Substring(i3);

                    FindDate findDate = _findDateManager.Find(title2, expectedDate);
                    if (findDate.Found)
                    {
                        titleRequest.Date      = findDate.Date;
                        titleRequest.DateType  = findDate.DateType;
                        titleRequest.DateMatch = findDate.matchValues;
                        title2    = findDate.matchValues.Replace(" $$date$$ ");
                        title     = title1 + title2;
                        foundDate = true;
                    }
                    //titleRequest.DateOtherMatchList = findDate.matchValuesList;
                }

                if (!foundDate)
                {
                    // puis split avec "-"
                    i3 = Math.Min(i1, i2);
                    i3 = title.IndexOf("- ");
                    if (i3 != -1)
                    {
                        // attention i + 1 pour garder un espace en début de chaine
                        //return new PrintSplitedTitle(title.Substring(0, i), title.Substring(i + 1));

                        string title1 = title.Substring(0, i3);
                        string title2 = title.Substring(i3);

                        FindDate findDate = _findDateManager.Find(title2, expectedDate);
                        if (findDate.Found)
                        {
                            titleRequest.Date      = findDate.Date;
                            titleRequest.DateType  = findDate.DateType;
                            titleRequest.DateMatch = findDate.matchValues;
                            title2    = findDate.matchValues.Replace(" $$date$$ ");
                            title     = title1 + title2;
                            foundDate = true;
                        }
                        //titleRequest.DateOtherMatchList = findDate.matchValuesList;
                    }
                }
            }

            //FindText findSpecial = _findSpecial.Find(title);
            FindText_v2 findSpecial = _findSpecial.Find(title);

            if (findSpecial.Success)
            {
                titleRequest.Special = true;
                //titleRequest.SpecialMatch = findSpecial.matchValues;
                //title = findSpecial.matchValues.Replace(" $$special$$ ");
                title = findSpecial.Replace(" $$special$$ ");
            }

            FindNumber findNumber = _findNumberManager.Find(title);

            if (findNumber.found)
            {
                titleRequest.Number      = findNumber.number;
                titleRequest.NumberMatch = findNumber.matchValues;
                title = findNumber.matchValues.Replace(" $$number$$ ");
            }

            if (!foundDate)
            {
                FindDate findDate = _findDateManager.Find(title, expectedDate);
                //Trace.WriteLine("PrintTitleManager._GetPrintTitleInfo() : _findDateManager.Find(\"{0}\")", title);
                //Trace.WriteLine(findDate.zToJson());
                if (findDate.Found)
                {
                    titleRequest.Date      = findDate.Date;
                    titleRequest.DateType  = findDate.DateType;
                    titleRequest.DateMatch = findDate.matchValues;
                    title = findDate.matchValues.Replace(" $$date$$ ");
                }
                //titleRequest.DateOtherMatchList = findDate.matchValuesList;
            }

            Match match = __rgSpecialLabel.Match(title);

            if (match.Success)
            {
                titleRequest.SpecialText = match.Groups[1].Value.Trim(__trimChars);
                titleRequest.SpecialText = GetFormatedText(titleRequest.SpecialText);
                title = match.zReplace(title, "");
            }

            //Trace.WriteLine("titleRequest :");
            //Trace.WriteLine(titleRequest.zToJson());
            //Trace.WriteLine("splitedTitle :");
            //Trace.WriteLine(splitedTitle.zToJson());

            //string concatenatedTitle = splitedTitle.titlePart1;
            //if (!string.IsNullOrEmpty(splitedTitle.realTitlePart2))
            //    concatenatedTitle += " - " + splitedTitle.realTitlePart2;
            int i = title.IndexOf("$$");

            if (i != -1)
            {
                titleRequest.Title = title.Substring(0, i).Trim(__trimChars);
                title = title.Substring(i);
            }
            else
            {
                titleRequest.Title = title;
                title = null;
            }

            titleRequest.TitleStructure = title;
            titleRequest.FormatedTitle  = GetFormatedText(titleRequest.Title);
            titleRequest.Name           = GetName(titleRequest.FormatedTitle);
            if (title != null)
            {
                titleRequest.RemainText = __rgTitleStructureName.Replace(title, "").Trim(__trimChars);
            }

            //titleRequest.File = GetFile(titleRequest);

            PrintTitleInfo titleInfo = new PrintTitleInfo
            {
                OriginalTitle = titleRequest.OriginalTitle,
                Title         = titleRequest.Title,
                FormatedTitle = titleRequest.FormatedTitle,
                Name          = titleRequest.Name,
                Special       = titleRequest.Special,
                //SpecialMatch = titleRequest.SpecialMatch,
                SpecialText = titleRequest.SpecialText,
                Number      = titleRequest.Number,
                NumberMatch = titleRequest.NumberMatch,
                Date        = titleRequest.Date,
                DateType    = titleRequest.DateType,
                DateMatch   = titleRequest.DateMatch,
                //DateOtherMatchList = titleRequest.DateOtherMatchList,
                TitleStructure = titleRequest.TitleStructure,
                RemainText     = titleRequest.RemainText,
                //File = titleRequest.File
            };

            return(titleInfo);
        }
Exemplo n.º 12
0
        private void FindDayAndPrint()
        {
            if (!_findPrintManager.UseFindDay || _expectedDate == null || _titleInfo.FormatedTitle == "" || _date != null)
            {
                return;
            }

            if (__traceWarning)
            {
                Trace.WriteLine("  search day \"{0}\"", _titleInfo.FormatedTitle);
            }
            FindDay findDay = _findPrintManager.FindDayManager.Find(_titleInfo.FormatedTitle);

            while (findDay.Found)
            {
                int  day  = (int)findDay.Day;
                Date?date = zdate.GetDayInsideDateGap(day, (Date)_expectedDate, _findPrintManager.GapDayBefore, _findPrintManager.GapDayAfter);
                if (date != null)
                {
                    if (__traceWarning)
                    {
                        Trace.WriteLine("  day found {0} date {1} expected date {2}", day, date, _expectedDate);
                    }
                    //_dateMatch = findDay.MatchValues;
                    //title = findDay.MatchValues.Replace(" $$day$$ ");
                    //_foundDate = true;
                    string title = findDay.MatchValues.Replace("").Trim();
                    if (_dayTitle == null)
                    {
                        _dayTitle = title;
                        _date     = date;
                        _dateType = DateType.Day;
                    }
                    if (__traceWarning)
                    {
                        Trace.WriteLine("  search print \"{0}\"", title);
                    }
                    _findPrint = _findPrintManager.FindPrintList.Find(title);
                    if (_findPrint.Success)
                    {
                        _dayTitle = title;
                        _date     = date;
                        _dateType = DateType.Day;
                        break;
                    }
                }
                else if (__traceWarning)
                {
                    Trace.WriteLine("  wrong day found {0} expected date {1} in \"{2}\"", day, _expectedDate, _titleInfo.FormatedTitle);
                }
                findDay.FindNext();
            }

            //    if (_expectedDate != null && _printTitleManager.UseFindDay)
            //    {
            //        FindDay findDay = _printTitleManager.FindDayManager.Find(title);
            //        //Trace.WriteLine("FindDay \"{0}\" : found {1} day {2}", title, findDay.Found, findDay.Day);
            //        if (findDay.Found)
            //        {
            //            int day = (int)findDay.Day;
            //            Date? date = zdate.GetDayInsideDateGap(day, (Date)_expectedDate, _printTitleManager.GapDayBefore, _printTitleManager.GapDayAfter);
            //            if (date != null)
            //            {
            //                _date = date;
            //                _dateType = DateType.Day;
            //                _dateMatch = findDay.MatchValues;
            //                title = findDay.MatchValues.Replace(" $$day$$ ");
            //                _foundDate = true;
            //            }
            //            else
            //                Trace.WriteLine("  wrong day found {0} expected date {1} in \"{2}\"", day, _expectedDate, title);
            //        }
            //    }
            //    return title;
        }
Exemplo n.º 13
0
        private IEnumerable <Response> _Read()
        {
            _filename          = zPath.GetFileName(_file);
            _lineNumber        = 0;
            _years             = new List <ResponseYear>();
            _responseQuestions = new List <ResponseQuestion>();
            bool questionBlock  = false;
            int  emptyLineCount = 0;

            Trace.WriteLine($"read response file \"{_filename}\"");
            foreach (string line in zFile.ReadLines(_file))
            {
                _lineNumber++;
                //string line2 = line.Trim();
                if (line == "")
                {
                    //if (++emptyLineCount == _maxEmptyLine)
                    if (++emptyLineCount == _maxEmptyLine && _years.Count > 0)
                    {
                        break;
                    }
                    //int _maxEmptyLine
                    //if (_responseQuestions.Count > 0)
                    //    throw new PBException($"missing response for {GetQuestionWithoutResponse().zToStringValues(", ")}, line {_lineNumber}");
                    continue;
                }

                emptyLineCount = 0;
                bool        verifyRemainText = true;
                FindText_v2 findText         = _regexList.Find(line, contiguous: true);
                if (findText.Success)
                {
                    //MatchValues matchValues = findText.matchValues;
                    //while (matchValues.Match.Success)
                    ResponseQuestion responseQuestion = null;
                    while (findText.Success)
                    {
                        //ResponseQuestion responseQuestion = null;
                        //foreach (KeyValuePair<string, ZValue> namedValue in findText.GetValues())
                        foreach (KeyValuePair <string, RegexValue <ZValue> > namedValue in findText.GetRegexValues())
                        {
                            switch (namedValue.Key.ToLower())
                            {
                            case "category":
                                if (!_manageCategory)
                                {
                                    throw new PBException($"manage category is not activated");
                                }
                                if (_trace)
                                {
                                    Trace.WriteLine($"new category \"{namedValue.Value.Value}\"");
                                }
                                _category     = (string)namedValue.Value.Value;
                                _years        = new List <ResponseYear>();
                                questionBlock = false;
                                break;

                            case "year":
                                //if (_responseQuestions.Count != 0)
                                if (questionBlock)
                                {
                                    throw new PBException($"wrong year position, line {_lineNumber} column {findText.MatchIndex + 1} file \"{_filename}\"");
                                }
                                //AddYear(namedValue.Value, findText.Match.Index, findText.Match.Length);
                                AddYear(namedValue.Value.Value, namedValue.Value.Index, namedValue.Value.Length);
                                //_years.Add(new ResponseYear(int.Parse((string)namedValue.Value), matchValues.Match.Index, matchValues.Match.Length));
                                break;

                            case "questionnumber":
                                //if (responseQuestion != null)
                                //    //_responseQuestions.Add(responseQuestion);
                                //    SaveQuestion(responseQuestion);
                                //responseQuestion = new ResponseQuestion(int.Parse((string)namedValue.Value), matchValues.Match.Index, matchValues.Match.Length);
                                //responseQuestion.Year = GetYear(responseQuestion.Position);
                                //responseQuestion = NewQuestion(namedValue.Value, findText.Match.Index, findText.Match.Length, responseQuestion);
                                responseQuestion = NewQuestion(namedValue.Value.Value, namedValue.Value.Index, namedValue.Value.Length, responseQuestion);
                                questionBlock    = true;
                                break;

                            case "characterresponsecodes":
                                //if (responseQuestion == null)
                                //    throw new PBException($"unknow question, line {_lineNumber} column {matchValues.Match.Index + 1}");
                                //if (namedValue.Value != null)
                                //{
                                //if (responseQuestion == null)
                                //    responseQuestion = GetResponseQuestion(GetMiddlePosition(matchValues.Match.Index, matchValues.Match.Length));
                                ////GetYear(GetMiddlePosition(matchValues.Match.Index, matchValues.Match.Length))
                                ////Responses = ((string)namedValue.Value).ToCharArray()
                                //yield return new Response { Year = responseQuestion.Year, QuestionNumber = responseQuestion.QuestionNumber, Responses = (string)namedValue.Value };
                                //responseQuestion.FoundResponse = true;
                                //yield return SetResponse(namedValue.Value, findText.Match.Index, findText.Match.Length, responseQuestion);
                                yield return(SetResponse(namedValue.Value.Value, namedValue.Value.Index, namedValue.Value.Length, responseQuestion));

                                responseQuestion = null;
                                //}
                                break;

                            case "numericresponsecodes":
                                yield return(SetResponse(ConvertNumericResponseCodes(namedValue.Value.Value), namedValue.Value.Index, namedValue.Value.Length, responseQuestion));

                                responseQuestion = null;
                                break;
                            }
                        }
                        //if (responseQuestion != null)
                        //    //_responseQuestions.Add(responseQuestion);
                        //    SaveQuestion(responseQuestion);
                        //matchValues = matchValues.Next();
                        //findText.Next();
                        findText.FindNext(contiguous: true);
                    }

                    // control text not found
                    //if (findText.MatchIndex + findText.MatchLength < line.Length)
                    //{
                    //    string textNotFound = line.Substring(findText.MatchIndex + findText.MatchLength).Trim();
                    //    if (textNotFound.Length > 0)
                    //        Trace.WriteLine($"warning remain text \"{textNotFound}\" line {_lineNumber} column {findText.MatchIndex + findText .MatchLength + 1}");
                    //}

                    if (responseQuestion != null)
                    {
                        //_responseQuestions.Add(responseQuestion);
                        SaveQuestion(responseQuestion);
                    }


                    bool questionWithoutResponse = false;
                    foreach (ResponseQuestion responseQuestion2 in _responseQuestions)
                    {
                        if (!responseQuestion2.FoundResponse)
                        {
                            questionWithoutResponse = true;
                            break;
                        }
                    }
                    if (!questionWithoutResponse)
                    {
                        _responseQuestions = new List <ResponseQuestion>();
                    }
                }
                else if (_acceptUnknowText)
                {
                    Trace.WriteLine($"  unknow text \"{line}\" line {_lineNumber} file \"{_filename}\"");
                    verifyRemainText = false;
                }

                // control text not found
                if (verifyRemainText && findText.MatchIndex + findText.MatchLength < line.Length)
                {
                    string textNotFound = line.Substring(findText.MatchIndex + findText.MatchLength).Trim();
                    if (textNotFound.Length > 0)
                    {
                        //Trace.WriteLine($"unknow text \"{textNotFound}\" line {_lineNumber} column {findText.MatchIndex + findText.MatchLength + 1} file \"{_filename}\"");
                        throw new PBException($"  unknow text \"{textNotFound}\" line {_lineNumber} column {findText.MatchIndex + findText.MatchLength + 1} file \"{_filename}\"");
                    }
                }
            }
            foreach (ResponseQuestion responseQuestion2 in _responseQuestions)
            {
                if (!responseQuestion2.FoundResponse)
                {
                    Trace.WriteLine($"no response for {responseQuestion2.Year} - question {responseQuestion2.QuestionNumber}");
                }
            }
        }