Beispiel #1
0
        public async Task <IActionResult> Put(int id, TaskModel model)
        {
            Domain.Entities.Task result = await this.mediator.Send(new UpdateTaskCommand(id, model.Name, model.TypeId, model.Location.Id ?? 0, model.Duration, model.Date, model.DueDate, model.Notes));

            if (result == null)
            {
                result = await this.mediator.Send(
                    new CreateTaskCommand(model.Name,
                                          model.TypeId,
                                          model.Duration,
                                          model.Date,
                                          model.DueDate,
                                          model.Location.Street,
                                          model.Location.Door,
                                          model.Location.Floor,
                                          model.Location.ZipCode,
                                          model.Location.City,
                                          model.Location.Country,
                                          model.Location.Latitude,
                                          model.Location.Longitude,
                                          model.Location.Alias,
                                          model.Location.Tags,
                                          model.Notes));

                model = this.mapper.Map(result);

                return(CreatedAtRoute(RouteNames.TaskResource.GetById, new { id = model.Id }, model));
            }

            model = this.mapper.Map(result);

            return(Ok(model));
        }
        public void Register()
        {
            Domain.Entities.Task scanRunningTask = DbContext.Task.FirstOrDefault(t => t.Name.StartsWith(ScanRunningTaskName));
            if (scanRunningTask == null)
            {
                scanRunningTask = new Domain.Entities.Task
                {
                    ApplicationName  = "DotnetSpider.Enterprise",
                    Cron             = $"0/15 * * * *",
                    IsEnabled        = true,
                    IsDeleted        = true,
                    Developers       = "DotnetSpider",
                    Owners           = "DotnetSpider",
                    Arguments        = "",
                    NodeCount        = 1,
                    NodeRunningCount = 0,
                    Name             = ScanRunningTaskName,
                    Version          = "0001",
                    NodeType         = 1
                };
                DbContext.Task.Add(scanRunningTask);
                DbContext.SaveChanges();
            }
            var taskId = scanRunningTask.Id.ToString();
            var job    = new SchedulerJobDto
            {
                Id   = taskId,
                Name = scanRunningTask.Name,
                Cron = "0/15 * * * *",
                Url  = string.Format(Configuration.SchedulerCallback, taskId),
                Data = JsonConvert.SerializeObject(new { TaskId = taskId })
            };

            _schedulerAppService.Create(job);
        }
Beispiel #3
0
        public async Task <IActionResult> Create()
        {
            var id = User.Claims.Where(c => c.Type == "Id").Select(c => c.Value).SingleOrDefault();

            if (String.IsNullOrEmpty(id))
            {
                return(Unauthorized());
            }
            Guid actorId = new Guid(id);

            try
            {
                using (var reader = new StreamReader(Request.Body))
                {
                    var body = await reader.ReadToEndAsync();

                    Domain.Entities.Task task = JsonSerializer.Deserialize <Domain.Entities.Task>(body);
                    task.CreatedById = actorId;
                    await _tasksService.Create(task, actorId);

                    return(Ok());
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message + " \nInner exception" + e.InnerException));
            }
        }
Beispiel #4
0
        private static void InitData(ApplicationDbContext context)
        {
            var random = new Random();

            for (int i = 0; i < 100; ++i)
            {
                Domain.Entities.Task task = new Domain.Entities.Task
                {
                    ApplicationName  = "dotnet",
                    Cron             = $"* * * {i} *",
                    IsEnabled        = true,
                    Developers       = "沈威",
                    Owners           = "刘菲",
                    Arguments        = "-a:1,2",
                    NodeCount        = 1,
                    NodeRunningCount = 0,
                    Analysts         = "刘菲",
                    Name             = $"360指数采集",
                    Version          = "abcd",
                    NodeType         = 1
                };
                context.Task.Add(task);
            }
            context.SaveChanges();
        }
Beispiel #5
0
        protected override void Seed(DbContexts.ToDoContext context)
        {
            var task = new Task {
                Name = "Wash clothes"
            };

            context.Task.AddOrUpdate(task);
        }
Beispiel #6
0
 public Domain.Entities.Task GetById(string id)
 {
     Domain.Entities.Task task = null;
     using (var dbConnection = _connectionFactory.GetConnection)
     {
         string sQuery = "SELECT * FROM Tasks"
                         + " WHERE Id = @Id";
         task = dbConnection.Query <Domain.Entities.Task>(sQuery, new { Id = id }).FirstOrDefault();
     }
     return(task);
 }
Beispiel #7
0
        public async System.Threading.Tasks.Task Update(Specification <Domain.Entities.Task> spec, Action <Domain.Entities.Task> func, Guid actorId)
        {
            Domain.Entities.Task task = await _tasksRepository.ReadOne(spec);

            if (await _policyService.IsAllowedToTaskCRUD(new GetProjectParticipationByKeySpec(task.ProjectId, actorId)))
            {
                await _tasksRepository.Update(spec, func);

                await _tasksRepository.Update(spec, t => t.UpdatedAt = DateTime.UtcNow);
            }
        }
Beispiel #8
0
        public async Task <IActionResult> Get(int id)
        {
            Domain.Entities.Task result = await this.mediator.Send(new GetTaskByIdQuery(id));

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(this.mapper.Map(result)));
        }
 public async Task <KeyValuePair <bool, string> > UpdateTask(Domain.Entities.Task taskObject)
 {
     lock (lockQuantity)
     {
         var response = _taskRepo.Update(taskObject);
         if (response > 0)
         {
             _updateTimes++;
         }
         return(new KeyValuePair <bool, string>(true, ""));
     }
 }
Beispiel #10
0
        public async System.Threading.Tasks.Task AddAssignee(Specification <Domain.Entities.Task> spec, Guid assigneeId, Guid actorId)
        {
            Domain.Entities.Task task = await _tasksRepository.ReadOne(spec);

            if (await _policyService.IsAllowedToTaskCRUD(new GetProjectParticipationByKeySpec(task.ProjectId, actorId)))
            {
                await _partisipationsRepository.Create(new TaskParticipation()
                {
                    TaskId = task.Id, UserId = assigneeId
                });

                await _tasksRepository.Update(spec, t => t.UpdatedAt = DateTime.UtcNow);
            }
        }
Beispiel #11
0
        public async Task <int> Handle(CreateTaskCommand request, CancellationToken cancellationToken)
        {
            var entity = new Domain.Entities.Task
            {
                EmployeeId = request.EmployeeId,
                Title      = request.Title,
                State      = TaskState.New,
                Priority   = PriorityLevel.Critical
            };

            _context.Tasks.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(entity.Id);
        }
Beispiel #12
0
        public async System.Threading.Tasks.Task Move(Specification <Domain.Entities.Task> spec, int index, Guid statusId, Guid actorId)
        {
            spec.Includes = t => t.Include(t => t.Project).ThenInclude(p => p.Statuses).ThenInclude(s => s.Tasks);
            Domain.Entities.Task task = await _tasksRepository.ReadOne(spec);

            Project project = task.Project;

            if (task.StatusId == statusId)
            {
                var status = await _statusesRepository.ReadOne(new GetByIdSpecification <Status>(statusId) { Includes = s => s.Include(s => s.Tasks) });

                var tasks = status.Tasks.OrderBy(t => t.Index).ToList();

                tasks.RemoveAt(task.Index);
                tasks.Insert(index, task);

                for (int i = 0; i < tasks.Count; i++)
                {
                    await _tasksRepository.Update(new GetByIdSpecification <Domain.Entities.Task>(tasks[i].Id), t => t.Index = i);
                }
            }
            else
            {
                var newStatus = await _statusesRepository.ReadOne(new GetByIdSpecification <Status>(statusId));

                var oldStatus = await _statusesRepository.ReadOne(new GetByIdSpecification <Status>(task.StatusId));

                var newTasks = newStatus.Tasks.OrderBy(t => t.Index).ToList();
                var oldTasks = oldStatus.Tasks.OrderBy(t => t.Index).ToList();

                await _tasksRepository.Update(new GetByIdSpecification <Domain.Entities.Task>(task.Id), t => t.StatusId = statusId);

                oldTasks.RemoveAt(task.Index);
                newTasks.Insert(index, task);

                for (int i = 0; i < newTasks.Count; i++)
                {
                    await _tasksRepository.Update(new GetByIdSpecification <Domain.Entities.Task>(newTasks[i].Id), t => t.Index = i);
                }

                for (int i = 0; i < oldTasks.Count; i++)
                {
                    await _tasksRepository.Update(new GetByIdSpecification <Domain.Entities.Task>(oldTasks[i].Id), t => t.Index = i);
                }
            }
        }
Beispiel #13
0
        public async Task <IActionResult> CreateTask([FromBody] Domain.Entities.Task task)
        {
            var validation = task.CheckTaskInformation();

            if (!validation.IsValid)
            {
                return(BadRequest(validation.Errors.Select(x => x.ErrorMessage)));
            }

            var wasCreated = await _taskApp.InsertTasks(task);

            if (wasCreated.Key)
            {
                return(Ok());
            }

            return(StatusCode(400, new { data = wasCreated.Value }));
        }
        public async Task <KeyValuePair <bool, string> > InsertTasks(Domain.Entities.Task taskObject)
        {
            var isUnique = await CheckUniquenessName(taskObject.Name);

            if (!isUnique)
            {
                return(new KeyValuePair <bool, string>(false, "task name already exisist"));
            }

            lock (lockQuantity)
            {
                var response = _taskRepo.Insert(taskObject);
                if (response > 0)
                {
                    _createTimes++;
                }
                return(new KeyValuePair <bool, string>(true, ""));
            }
        }
        public void GetById_NotOK()
        {
            var moqId       = new Random().Next();
            var dummyObject = new Domain.Entities.Task
            {
                Id        = moqId,
                Name      = "Test Name",
                Status    = Domain.Aggregation.TaskStatus.Open,
                TimeStamp = DateTime.Now
            };

            var moqRepo = new Mock <ITaskRepository>();

            moqRepo.Setup(x => x.GetByID(moqId)).Returns(dummyObject);

            var instance = new TasksApplication(moqRepo.Object);
            var result   = instance.GetTaskById(0).GetAwaiter().GetResult();

            Assert.NotNull(instance);
            Assert.Null(result);
        }
Beispiel #16
0
        public bool UpdateTask(Domain.Entities.Task task)
        {
            var query = @"UPDATE [Tasks] SET [LastMessageId] = @LastMessageId, [ConversationId] = @ConversationId, [UpdatedTime] = @UpdatedTime WHERE Id = @Id";
            var param = new DynamicParameters();

            param.Add("@Id", task.id);
            param.Add("@ConversationId", task.ConversationId);
            param.Add("@LastMessageId", task.LastMessageId);
            param.Add("@UdpatedTime", DateTime.UtcNow);
            int rowsAffected;

            using (var connection = _connectionFactory.GetConnection)
            {
                rowsAffected = SqlMapper.Execute(connection, query, param, commandType: CommandType.Text);
            }
            // CacheBase.cacheDeleteCacheSame(new List<string>() {task.id });
            if (rowsAffected > 0)
            {
                return(true);
            }
            return(false);
        }
Beispiel #17
0
        public bool CreateTask(Domain.Entities.Task task)
        {
            var query = @"INSERT INTO Tasks([Id],[ConversationId],[Type],[CreatedTime]) VALUES(@Id, @ConversationId, @Type, @CreatedTime)";
            var param = new DynamicParameters();

            param.Add("@Id", task.id);
            param.Add("@ConversationId", task.ConversationId);
            param.Add("@Type", task.Type);
            param.Add("@CreatedTime", task.created_time);
            int rowsAffected;

            using (var connection = _connectionFactory.GetConnection)
            {
                rowsAffected = SqlMapper.Execute(connection, query, param, commandType: CommandType.Text);
            }
            //CacheBase.cacheDeleteCacheSame(new List<string>() {task.id });
            if (rowsAffected > 0)
            {
                return(true);
            }
            return(false);
        }
        private string PushTask(Domain.Entities.Task task)
        {
            var nodes = _nodeAppService.GetAvailable(task.Os, task.NodeType, task.NodeCount);

            if (nodes.Count == 0)
            {
                // TODO LOG
                return(null);
            }

            var identity = Guid.NewGuid().ToString("N");
            var messages = new List <CreateMessageInput>();

            foreach (var node in nodes)
            {
                var arguments = string.Concat(task.Arguments, task.IsSingle ? " -tid:" : " ", task.Id, task.IsSingle ? " -i:" : " ", identity);
                var msg       = new CreateMessageInput
                {
                    TaskId          = task.Id,
                    ApplicationName = task.ApplicationName,
                    Name            = Domain.Entities.Message.RunMessageName,
                    NodeId          = node.NodeId,
                    Version         = task.Version,
                    Arguments       = arguments
                };
                messages.Add(msg);
            }
            _messageAppService.Create(messages);

            var taskHistory = new AddTaskHistoryInput
            {
                Identity = identity,
                NodeIds  = string.Join("|", nodes.Select(a => a.NodeId)),
                TaskId   = task.Id
            };

            _taskHistoryAppService.Add(taskHistory);
            return(identity);
        }
Beispiel #19
0
        public async Task <IActionResult> UpdateTask(int id, [FromBody] Domain.Entities.Task task)
        {
            var validation = task.CheckTaskInformation();

            if (!validation.IsValid)
            {
                return(BadRequest(validation.Errors.Select(x => x.ErrorMessage)));
            }

            if (task.Id == 0)
            {
                task.Id = id;
            }

            var response = await _taskApp.UpdateTask(task);

            if (response.Key)
            {
                return(Ok());
            }

            return(StatusCode(400, new { data = response.Value }));
        }
        public void UpateTask()
        {
            var expectResponse = new KeyValuePair <bool, string>(true, "");
            var moqId          = new Random().Next();
            var moqName        = "Test Name";
            var dummyObject    = new Domain.Entities.Task
            {
                Id        = moqId,
                Name      = moqName,
                Status    = Domain.Aggregation.TaskStatus.Open,
                TimeStamp = DateTime.Now
            };

            var moqRepo = new Mock <ITaskRepository>();

            moqRepo.Setup(x => x.Update(dummyObject)).Returns(1);

            var instance = new TasksApplication(moqRepo.Object);
            var result   = instance.UpdateTask(dummyObject).GetAwaiter().GetResult();

            Assert.NotNull(instance);
            Assert.True(result.Key);
        }
 public void Update(Domain.Entities.Task task)
 {
     _context.Entry(task).State = EntityState.Modified;
     _context.SaveChanges();
 }
Beispiel #22
0
 public void Update(Domain.Entities.Task entity)
 {
     throw new NotImplementedException();
 }
Beispiel #23
0
 public async System.Threading.Tasks.Task Create(Domain.Entities.Task task, Guid actorId)
 {
     task.CreatedAt = DateTime.UtcNow;
     await _tasksRepository.Create(task);
 }
Beispiel #24
0
        public static void ExitTask(INodeAppService nodeAppService, IMessageAppService messageAppService, Domain.Entities.Task task, ILogger logger = null)
        {
            var runningNodes = nodeAppService.GetAllOnline();

            var messages = new List <CreateMessageInput>();

            foreach (var status in runningNodes)
            {
                var msg = new CreateMessageInput
                {
                    ApplicationName = "NULL",
                    TaskId          = task.Id,
                    Name            = Domain.Entities.Message.CanleMessageName,
                    NodeId          = status.NodeId
                };
                logger?.LogWarning($"Add CANCLE message: {JsonConvert.SerializeObject(msg)}.");
                messages.Add(msg);
            }
            messageAppService.Create(messages);

            task.IsRunning        = false;
            task.NodeRunningCount = 0;
        }
 public void Create(Domain.Entities.Task task)
 {
     _context.Tasks.Add(task);
     _context.SaveChanges();
 }