// GET: WindowsTasks/Details/5 public async Task <IActionResult> Details(string id, bool substring) { if (id == null) { return(NotFound()); } try { TaskSchedulerManager tsm = new TaskSchedulerManager(); var t = tsm.GetTask(id, substring); WindowsTasks task = new WindowsTasks(); task.Id = Guid.NewGuid(); //need to map this to something else from the task. look into docs task.Name = t.Name; task.Description = t.Definition.RegistrationInfo.Description; var triggerCount = t.Definition.Triggers.Count; if (triggerCount > 0) { task.TriggerType = t.Definition.Triggers.First().TriggerType.ToString(); //task.TriggerString = t.Definition.Triggers.First().Repetition.ToString(); //need to figure out what the trigger's schedule looks like and put it in here task.TriggerString = t.Definition.Triggers.First().ToString(); task.TriggerAction = t.Definition.Actions.First().ActionType.ToString(); task.ActionFilePath = t.Definition.Actions.First().ToString(); } task.LastRun = t.LastRunTime; task.CreatedByUser = t.Definition.RegistrationInfo.Author; return(View(task)); } catch (Exception ex) { throw new Exception($"Failed to retreive task: {id}. Error: {ex.Message}"); } }
// GET: WindowsTasks from system task registration, not database public async Task <IActionResult> Index() { //todo: make this async AM_TaskScheduler.TaskSchedulerManager tm = new AM_TaskScheduler.TaskSchedulerManager(); List <Task> tasks = tm.GetTasks(); List <WindowsTasks> windowsTasks = new List <WindowsTasks>(); foreach (var t in tasks) { WindowsTasks task = new WindowsTasks(); task.Id = Guid.NewGuid(); //need to map this to something else from the task. look into docs task.Name = t.Name; task.Description = t.Definition.RegistrationInfo.Description; var triggerCount = t.Definition.Triggers.Count; if (triggerCount > 0) { task.TriggerType = t.Definition.Triggers.First().TriggerType.ToString(); task.TriggerString = t.Definition.Triggers.First().Repetition.ToString(); //need to figure out what the trigger's schedule looks like and put it in here task.TriggerAction = t.Definition.Actions.First().ActionType.ToString(); } task.LastRun = t.LastRunTime; task.CreatedByUser = t.Definition.RegistrationInfo.Author; windowsTasks.Add(task); } // return View(await _context.WindowsTasks.ToListAsync()); return(View(windowsTasks)); }
public async Task <IActionResult> Create([Bind("Id,Description,TriggerType,TriggerString,TriggerAction,DateCreated,LastRun,CreatedByUser")] WindowsTasks windowsTasks) { if (ModelState.IsValid) { windowsTasks.Id = Guid.NewGuid(); _context.Add(windowsTasks); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(windowsTasks)); }
public IActionResult Edit(WindowsTasks task) { if (task.ActionFile.Length > 0) { // string filePath = $@"\\{localIP}\c$" + _folderPath; string filePath = "C:\\WAM\\Uploads\\" + task.ActionFile.FileName; using (var stream = new FileStream(filePath, FileMode.Create)) { task.ActionFile.CopyToAsync(stream); task.ActionFilePath = $@"\\{localIP}" + _folderPath + task.ActionFile.FileName; } } //string server, string username, string domain, string password, string folder, string description, string cronString AM_TaskScheduler.TaskSchedulerManager tm = new AM_TaskScheduler.TaskSchedulerManager(); WindowsTask mTasks = new WindowsTask(task); tm.UpdateTask(mTasks); return(RedirectToAction("Index")); }
// GET: WindowsTasks/Create public IActionResult Create() { WindowsTasks task = new WindowsTasks(); return(View(task)); }