Exemplo n.º 1
0
        public IPagedList<LogEntity> SeachLog(LogsSearchSettings logsSearchSettings)
        {
            using (IUnitOfWork uow = _UnitFactory.GetUnit(this))
            {
                uow.BeginTransaction();
                IEnumerable<LogEntity> query = uow.Query<LogEntity>().Where(x=>logsSearchSettings.Applications.Contains(x.ApplictionId));

                if (!String.IsNullOrWhiteSpace(logsSearchSettings.SerchMessage))
                {
                    query = query.Where(p =>(logsSearchSettings.SerchMessage != null && p.Message != null && p.Message.ToLower().Contains(logsSearchSettings.SerchMessage)));

                }

                if (logsSearchSettings.SortBy == SortDirection.ASC)
                {
                    switch (logsSearchSettings.OrderBy)
                    {
                        case LogsFields.SourceDate:
                            query = query.OrderBy(l => l.SourceDate);
                            break;
                        case LogsFields.Message:
                            query = query.OrderBy(l => l.Message);
                            break;
                        case LogsFields.Level:
                            query = query.OrderBy(l => l.Level);
                            break;
                    }
                }
                else
                {
                    switch (logsSearchSettings.OrderBy)
                    {
                        case LogsFields.SourceDate:
                            query = query.OrderByDescending(l => l.SourceDate);
                            break;
                        case LogsFields.Message:
                            query = query.OrderByDescending(l => l.Message);
                            break;
                        case LogsFields.Level:
                            query = query.OrderByDescending(l => l.Level);
                            break;
                    }
                }

                query = query.Skip((logsSearchSettings.PageNumber - 1) * logsSearchSettings.PageSize);
                query = query.Take(logsSearchSettings.PageSize);

                IPagedList<LogEntity> result = new StaticPagedList<LogEntity>(query, logsSearchSettings.PageNumber, logsSearchSettings.PageSize, 1000);

                return result;
            }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            string username = Membership.GetUser().UserName;
            List<Guid> apps = UserHelper.GetAppsIdsForUser(username);
            LogsSearchSettings logSearch = new LogsSearchSettings()
            {
                Applications = apps,
                PageNumber = 1,
                PageSize = 10

            };
            IPagedList<LogEntity> lastestLog = RepositoryContext.Current.Logs.SeachLog(logSearch);

            DashboardModel dm = new DashboardModel();
            dm.ErrorCount = RepositoryContext.Current.Logs.CountByLevel(StandardLogLevels.ERROR );
            dm.InfoCount = RepositoryContext.Current.Logs.CountByLevel(StandardLogLevels.ERROR);
            dm.LogCount = RepositoryContext.Current.Logs.CountByLevel(StandardLogLevels.ALL_LEVELS);
            dm.WarnCount = RepositoryContext.Current.Logs.CountByLevel(StandardLogLevels.WARNING);

            dm.LastTen = ConversionHelper.ConvertLogEntityToMessage(lastestLog.ToList());
                dm.QueueLoad = LogQueue.Current.QueueLoad;
                dm.AppLastTen = new List<MessagesListModel>();

            IPagedList<LogEntity> logOfCurrentApp;
                foreach (ApplicationEntity app in UserHelper.GetAppsForUser(username))
                {

                        logSearch = new LogsSearchSettings()
                        {
                            PageNumber = 1,
                            PageSize = 10

                        };
                     logSearch.Applications.Add(app.IdApplication);
                     logOfCurrentApp = RepositoryContext.Current.Logs.SeachLog(logSearch);
                    MessagesListModel list = new MessagesListModel();
                    list.ApplicationName = app.ApplicationName;
                    list.IdApplication = app.IdApplication;

                    list.Messages= ConversionHelper.ConvertLogEntityToMessage(logOfCurrentApp.ToList());
                    dm.AppLastTen.Add(list);

                }

                return View(dm);
        }