Exemple #1
0
        public ActionResult GetLogRowProperties(Guid componentId, Guid logRowId)
        {
            var componentRepository = CurrentAccountDbContext.GetComponentRepository();

            componentRepository.GetById(componentId);
            var logRepository = CurrentAccountDbContext.GetLogRepository();
            var log           = logRepository.Find(logRowId, componentId);
            var model         = GetLogRowPropertiesModel(log);

            return(PartialView(model));
        }
Exemple #2
0
        /// <summary>
        /// Поиск следующей записи по тексту
        /// </summary>
        public JsonResult FindNextRecord(LogFiltersModel filters)
        {
            if (!filters.ComponentId.HasValue)
            {
                return(null);
            }

            var levels = GetFilterLevels(filters.LogLevel);

            var logRepository = CurrentAccountDbContext.GetLogRepository();

            DateTime date;
            int      order;

            if (filters.Id.HasValue)
            {
                var currentRecord = logRepository.Find(filters.Id.Value, filters.ComponentId.Value);
                date  = currentRecord.Date;
                order = currentRecord.Order;
            }
            else
            {
                date  = filters.Date ?? Now();
                order = 0;
            }

            var logSearchResult = logRepository.FindNextRecordByText(filters.Text, filters.ComponentId.Value, date, order, levels, filters.Context, SearchIterationRecordCount);

            if (!logSearchResult.Found)
            {
                if (logSearchResult.Record == null)
                {
                    return(GetSuccessJsonResponse(new
                    {
                        found = false,
                        message = "Далее записей с таким текстом не найдено",
                        id = (Guid?)null
                    }));
                }

                return(GetSuccessJsonResponse(new
                {
                    found = false,
                    id = logSearchResult.Record.Id.ToString(),
                    date = DateTimeHelper.GetRussianDateTime(logSearchResult.Record.Date)
                }));
            }

            return(GetSuccessJsonResponse(new
            {
                found = true,
                id = logSearchResult.Record.Id.ToString()
            }));
        }
Exemple #3
0
        public PartialViewResult Center(LogFiltersModel filters)
        {
            if (!filters.ComponentId.HasValue)
            {
                return(null);
            }

            if (!filters.Id.HasValue)
            {
                return(null);
            }

            var levels = GetFilterLevels(filters.LogLevel);

            var logRepository = CurrentAccountDbContext.GetLogRepository();
            var logRecord     = logRepository.Find(filters.Id.Value, filters.ComponentId.Value);

            var previousRecords      = logRepository.GetPreviousRecords(filters.ComponentId.Value, logRecord.Date, logRecord.Order, levels, filters.Context, OutputRecordCount / 2);
            var previousRecordsModel = RecordsToModel(previousRecords);

            var nextRecords      = logRepository.GetNextRecords(filters.ComponentId.Value, logRecord.Date, logRecord.Order, levels, filters.Context, OutputRecordCount - previousRecordsModel.Length - 1);
            var nextRecordsModel = RecordsToModel(nextRecords);

            var logRecordModel = RecordsToModel(new[] { logRecord }.AsQueryable());

            var model = new LogPartialModel()
            {
                Filters           = filters,
                Items             = previousRecordsModel.Concat(logRecordModel).Concat(nextRecordsModel).ToArray(),
                ScrollToId        = logRecord.Id,
                OutputRecordCount = OutputRecordCount
            };

            FillRecordLinks(model);

            if (!string.IsNullOrEmpty(filters.Text))
            {
                var textLowercase = filters.Text.ToLower();
                if (!logRecord.Message.ToLower().Contains(textLowercase) && logRecord.Parameters.Any(t => t.Name.ToLower().Contains(textLowercase) || t.Value.ToLower().Contains(textLowercase)))
                {
                    model.ExpandedProperties      = GetLogRowPropertiesModel(logRecord);
                    model.ExpandedProperties.Text = filters.Text;
                }
            }

            return(PartialView("Partial", model));
        }
Exemple #4
0
        /// <summary>
        /// Детализация по компоненту - лог
        /// </summary>
        public ActionResult ComponentDetailsLog(Guid id, LogLevel?level, int?count)
        {
            level = level ?? LogLevel.Trace;
            count = count ?? 10;
            const int maxCount = 500;

            if (count > maxCount)
            {
                count = maxCount;
            }

            var model = new ComponentDetailsLogModel()
            {
                ComponentId = id,
                Level       = level.Value,
                Count       = count.Value
            };
            var levels = new[]
            {
                LogLevel.Trace,
                LogLevel.Debug,
                LogLevel.Info,
                LogLevel.Warning,
                LogLevel.Error,
                LogLevel.Fatal
            };
            var levelFilter = levels.Where(x => x >= level.Value).ToArray();

            var messages = CurrentAccountDbContext.GetLogRepository()
                           .GetLastRecords(id, null, levelFilter, null, count.Value)
                           .ToArray();

            model.Messages = messages
                             .OrderBy(x => x.Date)
                             .ThenBy(x => x.Order)
                             .Select(x => new ComponentDetailsLogModel.LogMessage()
            {
                Id            = x.Id,
                Level         = x.Level,
                Message       = x.Message,
                Time          = x.Date,
                HasProperties = x.ParametersCount > 0
            }).ToArray();

            return(PartialView(model));
        }
Exemple #5
0
        /// <summary>
        /// Подгружаемая часть с блоком N предыдущих записей
        /// </summary>
        public PartialViewResult GetPreviousRecords(DateTime toDate, int order, LogFiltersModel filters)
        {
            if (!filters.ComponentId.HasValue)
            {
                return(null);
            }

            var levels = GetFilterLevels(filters.LogLevel);

            var logRepository = CurrentAccountDbContext.GetLogRepository();
            var records       = logRepository.GetPreviousRecords(filters.ComponentId.Value, toDate, order, levels, filters.Context, OutputRecordCount);

            var model = new LogPartialModel()
            {
                Filters           = filters,
                Items             = RecordsToModel(records),
                OutputRecordCount = OutputRecordCount
            };

            // Рассчитаем ссылку на предыдущие записи
            if (model.Items.Length > 0)
            {
                var firstRecord = model.Items[0];
                model.Previous = new LogPartialModel.DateAndOrderModel()
                {
                    Date  = firstRecord.Date,
                    Order = firstRecord.Order
                };
            }
            else
            {
                model.Previous          = null;
                model.NoPreviousRecords = true;
            }

            model.Next      = null;
            model.MarkAsNew = true;

            if (model.Items.Length > 0)
            {
                model.ScrollToId = model.Items.Last().Id;
            }

            return(PartialView("Partial", model));
        }
Exemple #6
0
        public ActionResult GetLogFile(Guid componentId, Guid id, Guid fileId)
        {
            var componentRepository = CurrentAccountDbContext.GetComponentRepository();

            componentRepository.GetById(componentId);
            var repository = CurrentAccountDbContext.GetLogRepository();
            var row        = repository.Find(id, componentId);
            var file       = row.Parameters.SingleOrDefault(x => x.Id == fileId);

            if (file == null)
            {
                throw new HttpException(404, "Файл не найден");
            }
            var contentType = GuiHelper.GetContentType(file.Name);
            var bytes       = Convert.FromBase64String(file.Value);

            return(File(bytes, contentType, file.Name));
        }
Exemple #7
0
        /// <summary>
        /// Подгружаемая часть лога, не для режима следующие N / предыдущие N
        /// </summary>
        public PartialViewResult Partial(LogFiltersModel filters)
        {
            if (!filters.ComponentId.HasValue)
            {
                return(null);
            }

            // Если явно указана запись, отобразим как при поиске, с центрированием
            if (filters.Id.HasValue)
            {
                return(Center(filters));
            }

            var levels = GetFilterLevels(filters.LogLevel);

            IQueryable <Log> records;
            var logRepository = CurrentAccountDbContext.GetLogRepository();

            if (filters.Date.HasValue)
            {
                records = logRepository.GetFirstRecords(filters.ComponentId.Value, filters.Date, levels, filters.Context, OutputRecordCount);
            }
            else
            {
                records = logRepository.GetLastRecords(filters.ComponentId.Value, null, levels, filters.Context, OutputRecordCount);
            }

            var model = new LogPartialModel()
            {
                Filters           = filters,
                Items             = RecordsToModel(records),
                OutputRecordCount = OutputRecordCount
            };

            // Если показываем записи с конца, то прокрутим до последней записи
            if (!filters.Date.HasValue && model.Items.Length > 0)
            {
                model.ScrollToId = model.Items.Last().Id;
            }

            FillRecordLinks(model);

            return(PartialView(model));
        }