Пример #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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }