using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Win32.TaskScheduler; namespace BodyshopPartner.Utils { public static class ScheduledTaskConfig { private static string workingDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); public static void RegisterPaintScale() { try { Microsoft.Win32.TaskScheduler.Task existingTask = TaskService.Instance.FindTask("ImEX Online Partner - Paint Scale Connection Export"); if (existingTask != null) { TaskService.Instance.RootFolder.DeleteTask("ImEX Online Partner - Paint Scale Connection Export"); } Microsoft.Win32.TaskScheduler.Task newTask = TaskService.Instance.AddTask("ImEX Online Partner - Paint Scale Connection Export", QuickTriggerType.Hourly, "powershell.exe", @"-ExecutionPolicy Bypass -File " + AppMetaData.globalScriptsPath + @"\PaintScaleExport.ps1"); newTask.Run(); } catch (Exception ex) { logger.Error(ex, "Error when trying to register scheduled task."); } } public static void RegisterArms() { try { Microsoft.Win32.TaskScheduler.Task existingTask = TaskService.Instance.FindTask("ImEX Online Partner - ARMS"); if (existingTask != null) { TaskService.Instance.RootFolder.DeleteTask("ImEX Online Partner - ARMS"); } Microsoft.Win32.TaskScheduler.Task newTask = TaskService.Instance.AddTask("ImEX Online Partner - ARMS", QuickTriggerType.Daily, "powershell.exe", @"-ExecutionPolicy Bypass -File " + AppMetaData.globalScriptsPath + @"\ArmsExport.ps1"); newTask.Run(); } catch (Exception ex) { logger.Error(ex, "Error when trying to register scheduled task."); } } } }