Esempio n. 1
0
        public PaginationQueryDto Find(PaginationQueryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException($"{nameof(input)} should not be null.");
            }
            input.Validate();
            PaginationQueryDto output;

            Expression <Func <Core.Entities.Task, bool> > where = t => !t.IsDeleted;

            var keyword = input.GetFilterValue("keyword");

            if (!string.IsNullOrWhiteSpace(keyword))
            {
                where = where.AndAlso(t => t.Name.Contains(keyword));
            }

            var isRunning = input.GetFilterValue("isrunning");

            if (!string.IsNullOrWhiteSpace(isRunning))
            {
                if ("true" == isRunning.ToLower())
                {
                    where = where.AndAlso(t => t.IsRunning);
                }
                else
                {
                    where = where.AndAlso(t => !t.IsRunning);
                }
            }

            switch (input.Sort)
            {
            case "name":
            {
                output = DbContext.Task.PageList(input, where, t => t.Name);
                break;
            }

            case "nodecount":
            {
                output = DbContext.Task.PageList(input, where, t => t.NodeCount);
                break;
            }

            default:
            {
                output = DbContext.Task.PageList(input, where, t => t.CreationTime);
                break;
            }
            }
            output.Result = Mapper.Map <List <TaskDto> >(output.Result);
            return(output);
        }
Esempio n. 2
0
        public PaginationQueryDto QueryRunning(PaginationQueryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException($"{nameof(input)} should not be null.");
            }
            PaginationQueryDto output = DbContext.Task.PageList <Core.Entities.Task, string, string>(input, d => d.IsRunning, d => d.Id);

            output.Result = Mapper.Map <List <TaskDto> >(output.Result);
            return(output);
        }
Esempio n. 3
0
        public static PaginationQueryOutput PageList <TEntity, TKey, TOrdery>(this DbSet <TEntity> dbSet,
                                                                              PaginationQueryInput input,
                                                                              Expression <Func <TEntity, bool> > where       = null,
                                                                              Expression <Func <TEntity, TOrdery> > orderyBy = null) where TEntity : class, IEntity <TKey>
        {
            PaginationQueryOutput output   = new PaginationQueryOutput();
            IQueryable <TEntity>  entities = dbSet.AsQueryable();

            if (where != null)
            {
                entities = entities.Where(where);
            }

            output.Total = entities.Count();

            if (orderyBy == null)
            {
                if (input.SortByDesc)
                {
                    entities = entities.OrderByDescending(e => e.Id).Skip((input.Page.Value - 1) * input.Size.Value)
                               .Take(input.Size.Value);
                }
                else
                {
                    entities = entities.Skip((input.Page.Value - 1) * input.Size.Value).Take(input.Size.Value);
                }
            }
            else
            {
                if (input.SortByDesc)
                {
                    entities = entities.OrderByDescending(orderyBy).Skip((input.Page.Value - 1) * input.Size.Value)
                               .Take(input.Size.Value);
                }
                else
                {
                    entities = entities.OrderBy(orderyBy).Skip((input.Page.Value - 1) * input.Size.Value)
                               .Take(input.Size.Value);
                }
            }

            output.Page   = input.Page.Value;
            output.Size   = input.Size.Value;
            output.Result = output.Total == 0 ? new List <TEntity>() : entities.ToList();
            return(output);
        }
Esempio n. 4
0
        public PaginationQueryDto Find(PaginationQueryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException($"{nameof(input)} should not be null.");
            }
            var output = new PaginationQueryDto
            {
                Page = input.Page.Value,
                Size = input.Size.Value
            };
            var taskId            = long.Parse(input.GetFilterValue("taskid"));
            var taskHistoryOutput = DbContext.TaskHistory.PageList(input, a => a.TaskId == taskId, t => t.CreationTime);

            output.Total = taskHistoryOutput.Total;
            var taskHistories = (List <Domain.Entities.TaskHistory>)taskHistoryOutput.Result;
            List <Domain.Entities.TaskStatus> statuses;

            if (taskHistories.Count > 0)
            {
                var identities = taskHistories.Select(r => r.Identity);
                statuses = DbContext.TaskStatus.Where(a => identities.Contains(a.Identity)).ToList();
            }
            else
            {
                statuses = new List <Domain.Entities.TaskStatus>(0);
            }

            var result        = new List <PaginationQueryTaskHistoryDto>(taskHistories.Count);
            var statusOutputs = Mapper.Map <List <TaskStatusDto> >(statuses);

            foreach (var item in taskHistories)
            {
                result.Add(new PaginationQueryTaskHistoryDto
                {
                    Identity     = item.Identity,
                    CreationTime = item.CreationTime.ToString("yyyy/MM/dd HH:mm:ss"),
                    Statuses     = statusOutputs.Where(a => a.Identity == item.Identity).ToList()
                });
            }
            output.Result = result;

            return(output);
        }
Esempio n. 5
0
        public PaginationQueryDto Find(PaginationQueryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException($"{nameof(input)} should not be null.");
            }

            var identity = input.GetFilterValue("identity")?.Trim();

            if (string.IsNullOrWhiteSpace(identity))
            {
                return(new PaginationQueryDto {
                    Page = input.Page.Value, Size = input.Size.Value, Total = 0, Result = null
                });
            }

            Expression <Func <Core.Entities.TaskLog, bool> > where = t => t.Identity == identity;

            var nodeId = input.GetFilterValue("nodeid")?.Trim();

            if (!string.IsNullOrWhiteSpace(nodeId))
            {
                where = where.AndAlso(t => t.NodeId == nodeId);
            }

            var logType = input.GetFilterValue("logtype");

            if (!string.IsNullOrWhiteSpace(logType) && "all" != logType.Trim().ToLower())
            {
                where = where.AndAlso(t => t.Level.ToLower() == logType.ToLower());
            }
            var output = DbContext.TaskLog.PageList(input, where, t => t.Logged);

            output.Result = Mapper.Map <List <TaskLogOutput> >(output.Result);
            return(output);
        }
Esempio n. 6
0
        /// <summary>
        /// 搜索节点
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PaginationQueryDto Query(PaginationQueryInput input)
        {
            if (input == null)
            {
                throw new DotnetSpiderHubException($"{nameof(input)} should not be null.");
            }

            PaginationQueryDto output;

            switch (input.Sort?.ToLower())
            {
            case "enable":
            {
                output = DbContext.Node.PageList <Core.Entities.Node, long, bool>(input, null, d => d.IsEnable);
                break;
            }

            case "nodeid":
            {
                output = DbContext.Node.PageList <Core.Entities.Node, long, string>(input, null, d => d.NodeId);
                break;
            }

            case "createtime":
            {
                output = DbContext.Node.PageList <Core.Entities.Node, long, DateTime>(input, null, d => d.CreationTime);
                break;
            }

            case "type":
            {
                output = DbContext.Node.PageList <Core.Entities.Node, long, string>(input, null, d => d.Type);
                break;
            }

            default:
            {
                output = DbContext.Node.PageList <Core.Entities.Node, long, bool>(input, null, d => d.IsOnline);
                break;
            }
            }

            List <NodeDto> nodeOutputs = new List <NodeDto>();
            var            nodes       = (List <Core.Entities.Node>)output.Result;

            foreach (var node in nodes)
            {
                var nodeOutput = new NodeDto();
                nodeOutput.CreationTime = node.CreationTime;
                nodeOutput.IsEnable     = node.IsEnable;
                nodeOutput.NodeId       = node.NodeId;
                nodeOutput.IsOnline     = IsOnlineNode(node);

                if (nodeOutput.IsOnline)
                {
                    var lastHeartbeat = DbContext.NodeHeartbeat.OrderByDescending(t => t.Id)
                                        .FirstOrDefault(h => h.NodeId == node.NodeId);
                    nodeOutput.CPULoad      = lastHeartbeat.CpuLoad;
                    nodeOutput.FreeMemory   = lastHeartbeat.FreeMemory;
                    nodeOutput.Ip           = lastHeartbeat.Ip;
                    nodeOutput.Os           = lastHeartbeat.Os;
                    nodeOutput.ProcessCount = lastHeartbeat.ProcessCount;
                    nodeOutput.Type         = lastHeartbeat.Type;
                    nodeOutput.CPUCoreCount = lastHeartbeat.CpuCoreCount;
                    nodeOutput.TotalMemory  = lastHeartbeat.TotalMemory;
                    nodeOutput.Version      = lastHeartbeat.Version;
                }
                else
                {
                    nodeOutput.CPULoad      = 0;
                    nodeOutput.FreeMemory   = 0;
                    nodeOutput.Ip           = "unkonw";
                    nodeOutput.Os           = "unkonw";
                    nodeOutput.ProcessCount = 0;
                    nodeOutput.CPUCoreCount = 0;
                    nodeOutput.TotalMemory  = 0;
                    nodeOutput.Type         = "default";
                    nodeOutput.Version      = "unkonw";
                }

                nodeOutputs.Add(nodeOutput);
            }

            output.Result = nodeOutputs;
            return(output);
        }
Esempio n. 7
0
 public IActionResult Find(PaginationQueryInput input)
 {
     return(Success(_logAppService.Find(input)));
 }
Esempio n. 8
0
 public IActionResult Find([FromQuery] PaginationQueryInput input)
 {
     return(Success(_taskStatusAppService.Find(input)));
 }
Esempio n. 9
0
 public IActionResult Find([FromQuery] PaginationQueryInput input)
 {
     return(Success(_nodeAppService.Query(input)));
 }
        public IActionResult Find([FromQuery] PaginationQueryInput input)
        {
            var result = _taskAppService.Find(input);

            return(Success(result));
        }
Esempio n. 11
0
        public IActionResult Query([FromQuery] PaginationQueryInput input)
        {
            var output = _dbContext.Client.PageList <Client, int, DateTimeOffset>(input, null, d => d.CreationTime);

            return(new JsonResult(new ApiResult(ApiResult.SuccessCode, null, output)));
        }
Esempio n. 12
0
        public PaginationQueryLogDto Find(PaginationQueryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException($"{nameof(input)} should not be null.");
            }
            var result = new PaginationQueryLogDto
            {
                Page    = input.Page.Value,
                Size    = input.Size.Value,
                Columns = new List <string>(),
                Values  = new List <List <string> >()
            };
            var identity = input.GetFilterValue("identity")?.Trim();

            if (string.IsNullOrWhiteSpace(identity))
            {
                return(result);
            }
            var client     = new MongoClient(Configuration.LogMongoConnectionString);
            var database   = client.GetDatabase("dotnetspider");
            var collection = database.GetCollection <BsonDocument>(identity);

            var queryBson = new BsonDocument();
            var nodeId    = input.GetFilterValue("nodeid")?.Trim();

            if (!string.IsNullOrWhiteSpace(nodeId))
            {
                queryBson.Add("NodeId", nodeId);
            }
            var logType = input.GetFilterValue("logtype");

            if (!string.IsNullOrWhiteSpace(logType) && "all" != logType.Trim().ToLower())
            {
                queryBson.Add("Level", logType);
            }

            var list = collection.Find(queryBson).Skip((input.Page - 1) * input.Size).Limit(input.Size).Sort(Builders <BsonDocument> .Sort.Descending("_id")).ToList();

            result.Total = collection.Find(queryBson).Count();

            if (list.Count > 0)
            {
                var head = list.First();
                foreach (var hi in head.Elements)
                {
                    if (hi.Name == "_id" || hi.Name.ToLower() == "identity")
                    {
                        continue;
                    }
                    result.Columns.Add(hi.Name);
                }
                foreach (var item in list)
                {
                    var vlist = new List <string>();
                    foreach (var v in item.Elements.Where(a => a.Name != "_id" && a.Name.ToLower() != "identity"))
                    {
                        vlist.Add(v.Value is BsonNull ? string.Empty : v.Value.ToString());
                    }
                    result.Values.Add(vlist);
                }
            }
            return(result);
        }
        public PaginationQueryDto Find(PaginationQueryInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException($"{nameof(input)} should not be null.");
            }
            PaginationQueryDto output;

            Expression <Func <Core.Entities.TaskStatus, bool> > where = null;
            var status  = input.GetFilterValue("status")?.ToLower().Trim();
            var keyword = input.GetFilterValue("keyword")?.ToLower().Trim();
            List <Core.Entities.Task> tasks;
            List <long> taskIds;
            List <Core.Entities.TaskStatus> taskStatuses;

            if (string.IsNullOrWhiteSpace(keyword))
            {
                if (!string.IsNullOrEmpty(status) && "all" != status)
                {
                    where = d => d.Status.ToLower() == status;
                }
                output       = DbContext.TaskStatus.PageList(input, where, d => d.Id);
                taskStatuses = (List <Core.Entities.TaskStatus>)output.Result;
                taskIds      = taskStatuses.Select(t => t.TaskId).ToList();
                var ids = taskIds;
                tasks = DbContext.Task.Where(t => ids.Contains(t.Id)).ToList();
            }
            else
            {
                tasks   = DbContext.Task.Where(t => t.Name.ToLower().Contains(keyword)).ToList();
                taskIds = tasks.Select(t => t.Id).ToList();
                if (!string.IsNullOrEmpty(status) && "all" != status)
                {
                    var ids = taskIds;
                    where = d => d.Status.ToLower() == status && ids.Contains(d.TaskId);
                }
                else
                {
                    var ids = taskIds;
                    where = d => ids.Contains(d.TaskId);
                }
                output       = DbContext.TaskStatus.PageList(input, where, d => d.Id);
                taskStatuses = (List <Core.Entities.TaskStatus>)output.Result;
            }
            var taskStatusOutputs = new List <TaskStatusDto>();

            foreach (var taskStatus in taskStatuses)
            {
                var taskStatusOutput = new TaskStatusDto();
                taskStatusOutput.Name                 = tasks.FirstOrDefault(t => t.Id == taskStatus.TaskId)?.Name;
                taskStatusOutput.AvgDownloadSpeed     = taskStatus.AvgDownloadSpeed;
                taskStatusOutput.AvgPipelineSpeed     = taskStatus.AvgDownloadSpeed;
                taskStatusOutput.AvgProcessorSpeed    = taskStatus.AvgDownloadSpeed;
                taskStatusOutput.Error                = taskStatus.Error;
                taskStatusOutput.Identity             = taskStatus.Identity;
                taskStatusOutput.LastModificationTime = taskStatus.LastModificationTime?.ToString("yyyy/MM/dd HH:mm:ss");
                taskStatusOutput.Left                 = taskStatus.Left;
                taskStatusOutput.NodeId               = taskStatus.NodeId;
                taskStatusOutput.Status               = taskStatus.Status;
                taskStatusOutput.Success              = taskStatus.Success;
                taskStatusOutput.TaskId               = taskStatus.TaskId;
                taskStatusOutput.Thread               = taskStatus.Thread;
                taskStatusOutput.Total                = taskStatus.Total;
                taskStatusOutputs.Add(taskStatusOutput);
            }
            output.Result = taskStatusOutputs;
            return(output);
        }