Example #1
0
        public void Run(string inputFileName, string outputFileName)
        {
            string text       = " ";
            string sourceText = " ";

            try
            {
                using (StreamReader sr = new StreamReader(inputFileName, Encoding.UTF8))
                {
                    text = sr.ReadToEnd();
                }
                // удаление комментариев
                Directive.EraseComments(ref text);

                // производим импорт для всех файлов
                bool check = ImportAllFiles(ref text);
                sourceText = text;
                int pos = text.IndexOf("#");
                while (pos != -1)
                {
                    var dirName = GetCmdName(text, pos);
                    // вызов директивы
                    if (_dirs.ContainsKey(dirName))
                    {
                        _dirs[dirName].Run(this, ref text, ref pos);
                        pos = text.IndexOf("#"); // нахожу след. директиву
                    }
                    else
                    {
                        throw new Exception("Неожиданная встреча директивы: " + dirName);
                    }
                    //Console.WriteLine(text);
                    //Console.WriteLine("*****************");
                    //Console.ReadKey();
                }
                using (StreamWriter sw = new StreamWriter(outputFileName, false, Encoding.UTF8))
                {
                    sw.WriteLine(text.Trim('\n', ' ', '\r'));
                }
                Console.WriteLine("Успешное завершение работы");
            }
            catch (Exception e)
            {
                Console.WriteLine($"ИСКЛЮЧЕНИЕ: {e.Message}");
                Console.WriteLine($"Аварийное завершение программы! Был создан файл {outputFileName}_LOG.txt");
                using (StreamWriter sw = new StreamWriter($"{outputFileName}_LOG.txt"))
                {
                    sw.WriteLine(sourceText.Insert(sourceText.Length - 1, $"***[ Ошибка: {e.Message} ]***"));
                }
                return;
            }
        }