Пример #1
0
        public void Load(string filename)
        {
            var parser = new QuestionParser();

            try
            {
                using (var reader = new StreamReader(filename, Encoding.UTF8))
                {
                    var parseResult = parser.Parse(reader);
                    foreach (var ex in parseResult.Errors)
                    {
                        App.Log.WriteException(ex, false);
                    }
                    _questions = parseResult.Questions;
                }
            }
            catch (Exception ex)
            {
                var msg = new StringBuilder();
                msg.AppendLine("Я чё-то не понял!");
                msg.AppendFormat("Файл {0}:", Path.GetFileName(filename)).AppendLine();
                msg.AppendLine(ex.Message);
                msg.AppendLine();
                msg.Append("Как-то так...");
                throw new ApplicationException(msg.ToString());
            }

            Name = Path.GetFileNameWithoutExtension(filename);

            if (_questions.Count == 0)
            {
                throw new ApplicationException("Вопросов-то в файле нет!");
            }
        }
Пример #2
0
        public void Load(string filename)
        {
            var parser = new QuestionParser();
            try
            {
                using (var reader = new StreamReader(filename, Encoding.UTF8))
                {
                    var parseResult = parser.Parse(reader);
                    foreach (var ex in parseResult.Errors)
                        App.Log.WriteException(ex, false);
                    _questions = parseResult.Questions;
                }
            }
            catch (Exception ex)
            {
                var msg = new StringBuilder();
                msg.AppendLine("Я чё-то не понял!");
                msg.AppendFormat("Файл {0}:", Path.GetFileName(filename)).AppendLine();
                msg.AppendLine(ex.Message);
                msg.AppendLine();
                msg.Append("Как-то так...");
                throw new ApplicationException(msg.ToString());
            }

            Name = Path.GetFileNameWithoutExtension(filename);

            if (_questions.Count == 0)
            {
                throw new ApplicationException("Вопросов-то в файле нет!");
            }
        }