Beispiel #1
0
        public GetAlarmItemsResult GetAlarmItems(AlarmStatus status, MongodbAdminConfigurationItem admin, int pageSize, int pageIndex)
        {
            try
            {
                var databases = admin.MongodbAdminDatabaseConfigurationItems.Values.Select(b => b.DatabasePrefix).Distinct().ToList();
                var tables    = admin.MongodbAdminDatabaseConfigurationItems.Values.SelectMany(b => b.MongodbAdminTableConfigurationItems).Select(c => c.Value.TableName).Distinct().ToList();

                GetAlarmItemsResult r = new GetAlarmItemsResult();
                var dbContextFactory  = LocalServiceLocator.GetService <IDbContextFactory>();
                using (var context = dbContextFactory.CreateContext <AlarmDbContext>())
                {
                    var q = context.AlarmItems.Where(_ => _.AlarmStatusId == (int)status);
                    if (!databases.Contains("*"))
                    {
                        q = q.Where(_ => databases.Contains(_.AlarmDatabaseName));
                    }
                    if (!tables.Contains("*"))
                    {
                        q = q.Where(_ => tables.Contains(_.AlarmTableName));
                    }
                    r.Count = q.Count();
                    r.Data  = q.OrderByDescending(_ => _.OpenTime)
                              .Skip(pageIndex * pageSize).Take(pageSize).ToList();
                    return(r);
                }
            }
            catch (Exception ex)
            {
                ex.Handle("GetAlarmItems");
                throw;
            }
        }
Beispiel #2
0
        public GetAlarmItemsResult GetAlarmItems(AlarmStatus status, MongodbAdminConfigurationItem admin, int pageSize, int pageIndex)
        {
            try
            {
                var databases = admin.MongodbAdminDatabaseConfigurationItems.Values.Select(b => b.DatabasePrefix).Distinct().ToList();
                var tables = admin.MongodbAdminDatabaseConfigurationItems.Values.SelectMany(b => b.MongodbAdminTableConfigurationItems).Select(c => c.Value.TableName).Distinct().ToList();

                GetAlarmItemsResult r = new GetAlarmItemsResult();
                var dbContextFactory = LocalServiceLocator.GetService<IDbContextFactory>();
                using (var context = dbContextFactory.CreateContext<AlarmDbContext>())
                {
                    var q = context.AlarmItems.Where(_ => _.AlarmStatusId == (int)status);
                    if (!databases.Contains("*"))
                        q = q.Where(_ => databases.Contains(_.AlarmDatabaseName));
                    if (!tables.Contains("*"))
                        q = q.Where(_ => tables.Contains(_.AlarmTableName));
                    r.Count = q.Count();
                    r.Data = q.OrderByDescending(_ => _.OpenTime)
                        .Skip(pageIndex * pageSize).Take(pageSize).ToList();
                    return r;
                }
            }
            catch (Exception ex)
            {
                ex.Handle("GetAlarmItems");
                throw;
            }
        }