62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
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");
|
|
if (existingTask != null)
|
|
{
|
|
TaskService.Instance.RootFolder.DeleteTask("ImEX Online Partner - Paint Scale Connection");
|
|
}
|
|
Microsoft.Win32.TaskScheduler.Task newTask = TaskService.Instance.AddTask("ImEX Online Partner - Paint Scale Connection", QuickTriggerType.Hourly, "powershell.exe", @"-ExecutionPolicy Bypass -File " + workingDirectory + @"\Utils\Scripts\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 " + workingDirectory + @"\Utils\Scripts\ArmsExport.ps1");
|
|
newTask.Run();
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex, "Error when trying to register scheduled task.");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|