Пример #1
0
 private void SaveResponseQuestion(ResponseReader.ResponseQuestion responseQuestion)
 {
     //if (_trace)
     //    Trace.WriteLine($"save question \"{responseQuestion.QuestionNumber}\"");
     foreach (ResponseReader.ResponseQuestion responseQuestion2 in _responseQuestions)
     {
         if (Math.Abs(responseQuestion.Position - responseQuestion2.Position) <= 2)
         {
             throw new PBFileException($"missing response for \"{responseQuestion.Year} - question no {responseQuestion.QuestionNumber}\", line {responseQuestion.SourceLineNumber} file \"{responseQuestion.SourceFilename}\"", responseQuestion.SourceFile, responseQuestion.SourceLineNumber);
         }
     }
     _responseQuestions.Add(responseQuestion);
 }
Пример #2
0
 private ResponseReader.ResponseQuestion ResponseCreateResponseQuestion(QuestionDataQuestionNumber value)
 {
     //if (_responseQuestion != null)
     //{
     //    SaveResponseQuestion(_responseQuestion);
     //}
     ResponseReader.ResponseQuestion responseQuestion = new ResponseReader.ResponseQuestion(value.QuestionNumber, value.ColumnIndex, value.Length)
     {
         SourceFile = GetSubPath(value.File), SourceFilename = value.Filename, SourceLineNumber = value.LineNumber
     };
     responseQuestion.Year = GetYear(responseQuestion.Position);
     if (responseQuestion.Year == 0)
     {
         throw new PBFileException($"year not found, line {value.LineNumber} column {value.ColumnIndex + 1} file \"{value.Filename}\"", value.File, value.LineNumber);
     }
     return(responseQuestion);
 }
Пример #3
0
 //private Response SetResponse(ZValue value, int index, int length, ResponseQuestion responseQuestion)
 private Response_v2 SetResponse(QuestionDataResponse value, ResponseReader.ResponseQuestion responseQuestion)
 {
     //ResponseReader.ResponseQuestion responseQuestion;
     //if (_responseQuestion != null)
     //    responseQuestion = _responseQuestion;
     //else
     if (responseQuestion == null)
     {
         //responseQuestion = GetResponseQuestion(GetMiddlePosition(value.ColumnIndex, value.Length));
         responseQuestion = GetResponseQuestion(value);
     }
     //if (_trace)
     //    Trace.WriteLine($"set response \"{value}\" question {responseQuestion.QuestionNumber} index {index} length {length}");
     responseQuestion.FoundResponse = true;
     // $$pb remove responseQuestion from list
     return(new Response_v2 {
         Category = _responseCategory, Year = responseQuestion.Year, QuestionNumber = responseQuestion.QuestionNumber, Responses = value.Responses,
         SourceFile = responseQuestion.SourceFile, SourceLine = responseQuestion.SourceLineNumber
     });
 }
Пример #4
0
        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();
        }
Пример #5
0
        private QuestionResponse_v2 ReadResponse(QuestionData value)
        {
            Response_v2 response = null;

            if (_responseQuestion != null && value.Type != QuestionDataType.Response)
            {
                if (_trace)
                {
                    //Trace.WriteLine($"save response question (line {value.LineNumber} \"{value.Filename}\")");
                    Trace.WriteLine($"save response question : {_responseQuestion.Year} - {_responseQuestion.QuestionNumber}");
                }
                SaveResponseQuestion(_responseQuestion);
                _responseQuestion = null;
            }
            switch (value.Type)
            {
            case QuestionDataType.EmptyLine:
                if (_emptyLineCount == _responseMaxEmptyLine && _responseYears.Count > 0)
                {
                    _responseEnd = true;
                }
                break;

            case QuestionDataType.ResponseCategory:
                _responseCategory = ((QuestionDataResponseCategory)value).Category;
                if (_trace)
                {
                    Trace.WriteLine($"response category : {_responseCategory} (line {value.LineNumber} \"{value.Filename}\")");
                }
                ControlRemindResponseQuestions();
                _responseYears         = new List <ResponseReader.ResponseYear>();
                _responseQuestionBlock = false;
                break;

            case QuestionDataType.ResponseYear:
                QuestionDataResponseYear responseYear = (QuestionDataResponseYear)value;
                if (_responseQuestionBlock)
                {
                    throw new PBException($"wrong response year position, line {responseYear.LineNumber} column {responseYear.ColumnIndex + 1} file \"{responseYear.Filename}\"");
                }
                if (_trace)
                {
                    Trace.WriteLine($"response year : {responseYear.Year} (line {value.LineNumber} \"{value.Filename}\")");
                }
                ResponseAddYear(responseYear);
                break;

            case QuestionDataType.QuestionNumber:
                //responseQuestion = NewQuestion(namedValue.Value.Value, namedValue.Value.Index, namedValue.Value.Length, responseQuestion);
                QuestionDataQuestionNumber questionNumber = (QuestionDataQuestionNumber)value;
                if (_trace)
                {
                    Trace.WriteLine($"response question : {questionNumber.QuestionNumber} (line {value.LineNumber} \"{value.Filename}\")");
                }
                _responseQuestion      = ResponseCreateResponseQuestion(questionNumber);
                _responseQuestionBlock = true;
                break;

            case QuestionDataType.Response:
                QuestionDataResponse responseValue = (QuestionDataResponse)value;
                if (_responseQuestion != null && _responseQuestion.SourceLineNumber != responseValue.LineNumber)
                {
                    SaveResponseQuestion(_responseQuestion);
                    _responseQuestion = null;
                }
                response = SetResponse(responseValue, _responseQuestion);
                if (_trace)
                {
                    Trace.WriteLine($"response : {response.Responses} question {response.Year} - {response.QuestionNumber} (line {value.LineNumber} \"{value.Filename}\")");
                }
                _responseQuestion = null;
                break;
            }
            ControlResponseQuestions();
            return(response);
        }