private ScheduledTaskDto createScheduletedTask(string taskType) { ScheduledTaskDto task = null; if (taskType == ScheduledTaskType.CUSTOM_EXPORT_ORDER) { task = new CustomExportOrderTaskDto(); } else if (taskType == ScheduledTaskType.GENERATE_PO) { task = new GeneratePoTaskDto(); } else if (taskType == ScheduledTaskType.MARKETPLACE_INVENTORY) { task = new MarketplaceInventoryTaskDto(); } else if (taskType == ScheduledTaskType.VENDOR_PRODUCT_FILE_INVENTORY) { task = new VendorProductFileInventoryTaskDto(); } else if (taskType == ScheduledTaskType.CUSTOM_EXPORT_PRODUCT) { task = new CustomExportProductTaskDto(); } else if (taskType == ScheduledTaskType.CUSTOM_IMPORT_ORDER) { task = new CustomImportOrderTaskDto(); } else { throw new ArgumentException("Unknown task type: " + task.TaskType); } return(task); }
private scheduledtask convertToDomainObject(ScheduledTaskDto taskModel) { scheduledtask task = null; if (taskModel is CustomExportOrderTaskDto) { task = Mapper.Map <customexportordertask>(taskModel as CustomExportOrderTaskDto); } else if (taskModel is GeneratePoTaskDto) { task = Mapper.Map <generatepotask>(taskModel as GeneratePoTaskDto); } else if (taskModel is MarketplaceInventoryTaskDto) { task = Mapper.Map <marketplaceinventorytask>(taskModel as MarketplaceInventoryTaskDto); } else if (taskModel is VendorProductFileInventoryTaskDto) { task = Mapper.Map <vendorproductfileinventorytask>(taskModel as VendorProductFileInventoryTaskDto); } else if (taskModel is CustomExportProductTaskDto) { task = Mapper.Map <customexportproducttask>(taskModel as CustomExportProductTaskDto); } else if (taskModel is CustomImportOrderTaskDto) { task = Mapper.Map <customimportordertask>(taskModel as CustomImportOrderTaskDto); } else { throw new InvalidCastException(string.Format("Unknown credential type \'{0}\' for casting!", task.TaskType)); } return(task); }
public async Task <IScheduledTask> Create(ScheduledTaskDto dto) { TareaProgramada tarea = TareasProgramadaFactory.CrearTareaProgramada(dto.Name, dto.Identifier, dto.Cron).WithTimeout(dto.Timeout); UpdateIsActive(tarea, dto.IsActive); return(await this.Repository.InsertAsync(tarea)); }
public bool UpdateScheduledTask(int id, ScheduledTaskDto model) { // get the curent scheduled task var existingTask = _context.scheduledtasks.FirstOrDefault(x => x.Id == id); // unbox to the correct object for scheduled task var updatedTask = convertToDomainObject(model); updatedTask.StartTime = model.StartTimeDate.TimeOfDay; updatedTask.ModifiedBy = model.ModifiedBy; updatedTask.Modified = DateTime.UtcNow; _context.Entry(existingTask).CurrentValues.SetValues(updatedTask); _context.SaveChanges(); return(true); }
public async Task <IScheduledTask> Update(ScheduledTaskDto dto) { TareaProgramada entity = await this.Repository.GetAsync(dto.Id); if (entity == null) { throw new DataException("No existe la tarea programada con id : " + dto.Id); } entity.ConCron(dto.Cron); entity.ConIdentificador(dto.Identifier); entity.ConNombre(dto.Name); entity.WithTimeout(dto.Timeout); UpdateIsActive(entity, dto.IsActive); return(await this.Repository.UpdateAsync(entity)); }
private ScheduledTaskDto convertToModel(scheduledtask task) { ScheduledTaskDto model = null; if (task is customexportordertask) { model = Mapper.Map <CustomExportOrderTaskDto>(task as customexportordertask); } else if (task is generatepotask) { model = Mapper.Map <GeneratePoTaskDto>(task as generatepotask); } else if (task is marketplaceinventorytask) { model = Mapper.Map <MarketplaceInventoryTaskDto>(task as marketplaceinventorytask); } else if (task is vendorproductfileinventorytask) { model = Mapper.Map <VendorProductFileInventoryTaskDto>(task as vendorproductfileinventorytask); } else if (task is customexportproducttask) { model = Mapper.Map <CustomExportProductTaskDto>(task as customexportproducttask); } else if (task is customimportordertask) { model = Mapper.Map <CustomImportOrderTaskDto>(task as customimportordertask); } else { throw new InvalidCastException(string.Format("Unknown credential type \'{0}\' for casting!", task.TaskType)); } // create the datetime object for the StartTime var today = DateTime.Now; model.StartTimeDate = new DateTime(today.Year, today.Month, today.Day, task.StartTime.Hours, task.StartTime.Minutes, task.StartTime.Seconds); return(model); }
public bool CreateScheduledTask(ScheduledTaskDto model) { try { // unbox the correct object type for the credential var task = convertToDomainObject(model); task.StartTime = model.StartTimeDate.TimeOfDay; task.CreatedBy = model.ModifiedBy; task.Created = DateTime.UtcNow; _context.scheduledtasks.Add(task); _context.SaveChanges(); model.Id = task.Id; } catch (DbEntityValidationException ex) { var errorMsg = EisHelper.ParseDbEntityValidationException(ex); return(false); } return(true); }
public async Task Create_ReturnsTareaProgramada() { //Configuramos el comportamiento esperado del repositorio. repository.Setup(x => x.InsertAsync(It.IsAny <TareaProgramada>())).Returns <TareaProgramada>(t => Task.FromResult(t)).Verifiable(); var dto = new ScheduledTaskDto() { Cron = "***?", Identifier = "tareaPrueba", Name = "Tarea de prueba", IsActive = true }; //Llamamos al código que queremos testear var result = await store.Create(dto); //Validamos el comportamiento del código. Assert.IsNotNull(result); Assert.AreEqual(dto.Cron, result.Cron); Assert.AreEqual(dto.Identifier, result.Identifier); Assert.AreEqual(dto.Name, result.Name); Assert.AreEqual(dto.IsActive, result.IsActive); repository.VerifyAll(); }