Exemple #1
0
        //----------------------------------------------------------------------------------------
        public ActionResult Logs(LogViewFilters filters)
        {
            ViewBag.AppsName = new SelectList(logService.GetAppsName().AsEnumerable());

            LogViewModel result = logService.GetLogs(filters);

            return View(result);
        }
Exemple #2
0
        //----------------------------------------------------------------------------------------
        public static MvcHtmlString TableColumnHeader(this HtmlHelper html, LogViewFilters viewFilters, string propertyName, string linkText, string addThAttrs)
        {
            string action = Convert.ToString(html.ViewContext.Controller.ValueProvider.GetValue("action").RawValue);
            var filters = viewFilters.SetOrderBy(propertyName);

            var routeValue = new RouteValueDictionary();

            routeValue["Page"] = filters.PageInt;
            routeValue["DateFrom"] = filters.DateFrom;
            routeValue["DateTo"] = filters.DateTo;
            routeValue["SearchStr"] = filters.SearchStr;
            routeValue["OrderBy"] = filters.OrderBy;
            routeValue["App"] = filters.App;

            for (int i = 0; i < viewFilters.Level.Count; ++i)
                routeValue["Level[" + i + "]"] = viewFilters.Level[i];

            string link = html.ActionLink(linkText, action, routeValue).ToHtmlString();

            string colClass = viewFilters.GetColumnClass(propertyName);
            return new MvcHtmlString(string.Format(@"<th class=""{0}"" {2}>{1}</th>", colClass, link, addThAttrs));
        }
Exemple #3
0
 public LogViewModel(LogViewFilters filters, IEnumerable<LogItem> entries)
 {
     _filters = filters;
     _entries = entries.ToPagedList(filters.PageInt, Settings.Default.pageSize);
 }
Exemple #4
0
 public static MvcHtmlString TableColumnHeader(this HtmlHelper html, LogViewFilters viewParams, string propertyName, string linkText)
 {
     return TableColumnHeader(html, viewParams, propertyName, linkText, string.Empty);
 }
Exemple #5
0
        //----------------------------------------------------------------------------------------
        /// <summary>
        /// Получение журнала сообщений
        /// </summary>
        /// <param name="filters"></param>
        /// <returns></returns>
        public LogViewModel GetLogs(LogViewFilters filters)
        {
            var filter = new List<Expression<Func<LogItem, bool>>>();

            // получаем даты из класса фильтра
            DateTime? dateFrom = filters.ToDate(filters.DateFrom);
            DateTime? dateTo = filters.ToDate(filters.DateTo);

            // фильтрация по приложению
            if (!String.IsNullOrWhiteSpace(filters.App))
                filter.Add(c => c.domain == filters.App);

            // фильтрация по начальной дате
            if (dateFrom.HasValue)
                filter.Add(c => c.timestamp >= new BsonDateTime(dateFrom.Value));

            // фильтрация по конечной дате
            if (dateTo.HasValue)
                filter.Add(c => c.timestamp < new BsonDateTime(dateTo.Value.AddDays(1)));

            // фильтрация по уровню сообщений
            if (filters.Level != null && filters.Level.Count > 0)
                filter.Add(c => filters.Level.Contains(c.level));

            // фильтрация тексту
            // TODO подумать по каким полям искать
            if (!String.IsNullOrWhiteSpace(filters.SearchStr))
            {
                List<string> listSearch = filters.SearchStr.Split(',').Select(x => x.Trim().ToUpper()).ToList();

                foreach (string strSearch in listSearch)
                {
                    string str = strSearch;
                    filter.Add((s => s.userName.ToUpper().Contains(str)
                                     || s.loggerName.ToUpper().Contains(str)
                                     || s.machineName.ToUpper().Contains(str)
                                     || s.className.ToUpper().Contains(str)
                                     || s.method.ToUpper().Contains(str)
                                     || s.fileName.ToUpper().Contains(str)
                                     || s.domain.ToUpper().Contains(str)
                                     || s.message.ToUpper().Contains(str)));
                }
            }

            // сортировка
            Func<IQueryable<LogItem>, IOrderedQueryable<LogItem>> orderBy = item => item.OrderByDescending(x => x.timestamp);

            if (filters.HasOrderBy)
            {
                switch (filters.OrderByColumn.ToLower())
                {
                    case "datetime":
                        if (filters.OrderByDescending != null && filters.OrderByDescending.Value)
                            orderBy = item => item.OrderByDescending(x => x.timestamp);
                        else
                            orderBy = item => item.OrderBy(x => x.timestamp);
                        break;

                    case "level":
                        if (filters.OrderByDescending != null && filters.OrderByDescending.Value)
                            orderBy = item => item.OrderByDescending(x => x.level);
                        else
                            orderBy = item => item.OrderBy(x => x.level);
                        break;

                    case "app":
                        if (filters.OrderByDescending != null && filters.OrderByDescending.Value)
                            orderBy = item => item.OrderByDescending(x => x.domain);
                        else
                            orderBy = item => item.OrderBy(x => x.domain);
                        break;

                    case "thread":
                        if (filters.OrderByDescending != null && filters.OrderByDescending.Value)
                            orderBy = item => item.OrderByDescending(x => x.thread);
                        else
                            orderBy = item => item.OrderBy(x => x.thread);
                        break;

                    case "logger":
                        if (filters.OrderByDescending != null && filters.OrderByDescending.Value)
                            orderBy = item => item.OrderByDescending(x => x.loggerName);
                        else
                            orderBy = item => item.OrderBy(x => x.loggerName);
                        break;

                    case "user":
                        if (filters.OrderByDescending != null && filters.OrderByDescending.Value)
                            orderBy = item => item.OrderByDescending(x => x.userName);
                        else
                            orderBy = item => item.OrderBy(x => x.userName);
                        break;

                    case "machine":
                        if (filters.OrderByDescending != null && filters.OrderByDescending.Value)
                            orderBy = item => item.OrderByDescending(x => x.machineName);
                        else
                            orderBy = item => item.OrderBy(x => x.machineName);
                        break;
                }
            }

            var query = _logger.Get(filter, orderBy);

            return new LogViewModel(filters, query);
        }