Пример #1
0
        // 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));
        }
Пример #2
0
        // GET: WindowsTasks/Delete/5
        public async Task <IActionResult> Delete(string taskName)
        {
            if (taskName == null)
            {
                return(NotFound());
            }

            //todo: make this async
            AM_TaskScheduler.TaskSchedulerManager tm = new AM_TaskScheduler.TaskSchedulerManager();
            tm.DeleteTask(taskName);
            return(RedirectToAction(nameof(Index)));
        }
Пример #3
0
        public IActionResult TriggerTask(string id, bool substring)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                //string server, string username, string domain, string password, string folder, string description, string cronString
                AM_TaskScheduler.TaskSchedulerManager tm = new AM_TaskScheduler.TaskSchedulerManager();
                tm.TriggerTask(id, substring);
            }
            catch (Exception eX)
            {
                throw new Exception($"Failed to trigger Task {id}. Error: {eX.Message}");
            }
            return(RedirectToAction("Details", "WindowsTasks", new { id = id }));
        }
Пример #4
0
        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"));
        }