예제 #1
0
        public LogControll(string path)
        {
            SetLogFilePath(path);

            _exceptionBodyTemplatesDict = new Dictionary <string, ExceptionBodyTemplate>();


            #region Создание тестового шаблона
            ExceptionBodyTemplate exceptionBodyTemplate = new ExceptionBodyTemplate("Тест_1");
            exceptionBodyTemplate.AddTemplatePart(TemplatePartCreator.CreateTemplatePart("ExceptionStart", "EXCEPTION", null, 1));
            exceptionBodyTemplate.AddTemplatePart(TemplatePartCreator.CreateTemplatePart("MachineName", "MachineName", null, 1));
            exceptionBodyTemplate.AddTemplatePart(TemplatePartCreator.CreateTemplatePart("Exception Type", "Exception Type", null, 1));
            exceptionBodyTemplate.AddTemplatePart(TemplatePartCreator.CreateTemplatePart("Message", "Message: ", null, 1));
            exceptionBodyTemplate.AddTemplatePart(TemplatePartCreator.CreateTemplatePart("Server stack trace", "Server stack trace", " "));

            _exceptionBodyTemplatesDict.Add(exceptionBodyTemplate.TemplateName, exceptionBodyTemplate);
            #endregion
        }
예제 #2
0
        private Dictionary <string, List <ExceptionInfo> > extractTemplateObjects(string fileString, string copyFileString)
        {
            ///Надо ли делать проверку на пути к файлам

            //Список ошибок, разложеный по имени шаблона, применяемого для их считывания
            Dictionary <string, List <ExceptionInfo> > exceptionInfosDic = new Dictionary <string, List <ExceptionInfo> >();

            //Первые части шаблонов
            Dictionary <string, IReadingTemplatePart> FirstTemplatePartsDic;

            //считываемый на данный момент шаблон
            ExceptionBodyTemplate readingExceptionBodyTemplate = null;
            //считывается ли сейчас шаблон
            bool exceptionBodyTemplateIsReading = false;
            //считываемая на данный момент часть шаблона
            IReadingTemplatePart readingTemplatePart = null;

            //Объект, содержащий в себе список Шаблонов Частей Шаблона и их текстовое содержание
            ExceptionInfo exceptionInfo = null;

            FirstTemplatePartsDic = getFirstsTemplateParts();

            using (StreamReader streamReader = new StreamReader(copyFileString))
            {
                while (!streamReader.EndOfStream)
                {
                    fileString = streamReader.ReadLine();

                    #region Поиск совбадения первой части шаблона

                    //если шаблон ещё не считывается
                    if (!exceptionBodyTemplateIsReading)
                    {
                        exceptionInfo = new ExceptionInfo();

                        //для каждой части из списка первых частей шаблонов
                        foreach (var templatePart in FirstTemplatePartsDic)
                        {
                            //Проверка на совпадение с улсовием первой Части шаблона
                            if (templatePart.Value.CheckConditionMatch(fileString))
                            {
                                exceptionBodyTemplateIsReading = true;

                                //нахождение шаблона, первая часть которого начала считываться
                                readingExceptionBodyTemplate = _exceptionBodyTemplatesDict[templatePart.Key];

                                exceptionInfo.ExcceptionBodyTemplate = readingExceptionBodyTemplate;

                                readingTemplatePart = templatePart.Value;
                                break;
                            }
                        }
                    }
                    #endregion

                    #region Чтение шаблона
                    else
                    {
                        LinkedListNode <IReadingTemplatePart> FirstNode = readingExceptionBodyTemplate.TemplatePartsLinkedList.First;
                        //while (exceptionBodyTemplateIsReading)
                        //{
                        //    if (readingTemplatePart.IsReading)
                        //    {
                        //        readingTemplatePart.LineProcessing(fileString, ref exceptionInfo);
                        //    }
                        //    else
                        //    {
                        //        //конец считывания ЧАСТИ шаблона
                        //        if (readingExceptionBodyTemplate.TemplatePartsLinkedList.GetEnumerator().MoveNext())
                        //        {
                        //        }
                        //        else
                        //        {
                        //            //зафигачить Null-ы или обновить значения во всех необходимых переменных
                        //            exceptionBodyTemplateIsReading = false;
                        //            exceptionInfosDic.ContainsKey(readingExceptionBodyTemplate.TemplateName) ? exceptionInfosDic[readingExceptionBodyTemplate.TemplateName].Add(readingExceptionBodyTemplate);
                        //        }
                        //    }
                        //}
                    }
                    #endregion
                }
            }

            return(exceptionInfosDic);
        }