Exemplo n.º 1
0
        public List <FileFormattingError> Validate()
        {
            List <FileFormattingError> fileFormatErrorList = new List <FileFormattingError>();

            if (!string.IsNullOrEmpty(this.TextData))
            {
                List <string> questionList = paperParser.GetQuestionList();

                for (int i = 0; i <= questionList.Count - 1; i++)
                {
                    logger.AppendLog("Question - " + (i + 1));
                    if (!(questionList[i].Equals("\n") ||
                          questionList[i].Equals(string.Empty)))
                    {
                        List <string> formatErrorList = new List <string>();

                        FormatError formatError = ValidateOptionStartTag(questionList[i]);
                        if (formatError != FormatError.None)
                        {
                            formatErrorList.Add(formatError.ToString());
                        }

                        formatError = ValidateOptionEnd(questionList[i]);
                        if (formatError != FormatError.None)
                        {
                            formatErrorList.Add(formatError.ToString());
                        }

                        formatError = ValidateQuestionAttributes(questionList[i]);
                        if (formatError != FormatError.None)
                        {
                            formatErrorList.Add(formatError.ToString());
                        }

                        if (formatErrorList.Count > 0)
                        {
                            fileFormatErrorList.Add(new FileFormattingError(i, formatErrorList));
                        }
                        else
                        {
                            logger.AppendLog("Correct format");
                        }

                        logger.AppendLog(string.Empty);
                    }
                }
            }
            else
            {
                throw new Exception("Empty file.");
            }

            return(fileFormatErrorList);
        }