Add period to Windows scheduled task
This commit is contained in:
parent
c7fb317e05
commit
b9d95acd04
@ -12,6 +12,8 @@ import java.nio.file.Path;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.LocalDateTime;
|
||||
import javafx.util.Pair;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@ -39,12 +41,15 @@ public class WindowsScheduler {
|
||||
rootElement.setAttribute("xmlns", "http://schemas.microsoft.com/windows/2004/02/mit/task");
|
||||
doc.appendChild(rootElement);
|
||||
|
||||
LocalDateTime scheduleDateTime = station.getScheduleStartDate().atTime(station.getScheduleStartTime());
|
||||
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
|
||||
// RegistrationInfo element
|
||||
Element registrationInfo = doc.createElement("RegistrationInfo");
|
||||
rootElement.appendChild(registrationInfo);
|
||||
|
||||
Element date = doc.createElement("Date");
|
||||
date.appendChild(doc.createTextNode("2025-01-22T22:09:01.6765321"));
|
||||
date.appendChild(doc.createTextNode(scheduleDateTime.format(dateFormatter)));
|
||||
registrationInfo.appendChild(date);
|
||||
|
||||
Element author = doc.createElement("Author");
|
||||
@ -63,7 +68,7 @@ public class WindowsScheduler {
|
||||
triggers.appendChild(calendarTrigger);
|
||||
|
||||
Element startBoundary = doc.createElement("StartBoundary");
|
||||
startBoundary.appendChild(doc.createTextNode("2025-01-22T22:08:06"));
|
||||
startBoundary.appendChild(doc.createTextNode(scheduleDateTime.format(dateFormatter)));
|
||||
calendarTrigger.appendChild(startBoundary);
|
||||
|
||||
Element enabled = doc.createElement("Enabled");
|
||||
@ -74,12 +79,46 @@ public class WindowsScheduler {
|
||||
randomDelay.appendChild(doc.createTextNode("PT1H"));
|
||||
calendarTrigger.appendChild(randomDelay);
|
||||
|
||||
switch(station.getMessagePeriod()) {
|
||||
case DAILY:
|
||||
{
|
||||
Element scheduleByDay = doc.createElement("ScheduleByDay");
|
||||
calendarTrigger.appendChild(scheduleByDay);
|
||||
|
||||
Element daysInterval = doc.createElement("DaysInterval");
|
||||
daysInterval.appendChild(doc.createTextNode("1"));
|
||||
scheduleByDay.appendChild(daysInterval);
|
||||
}
|
||||
break;
|
||||
case WEEKLY:
|
||||
{
|
||||
Element scheduleByDay = doc.createElement("ScheduleByDay");
|
||||
calendarTrigger.appendChild(scheduleByDay);
|
||||
Element daysInterval = doc.createElement("DaysInterval");
|
||||
daysInterval.appendChild(doc.createTextNode("7"));
|
||||
scheduleByDay.appendChild(daysInterval);
|
||||
}
|
||||
break;
|
||||
case MONTHLY:
|
||||
Element scheduleByMonth = doc.createElement("ScheduleByMonth");
|
||||
calendarTrigger.appendChild(scheduleByMonth);
|
||||
Element daysOfMonth = doc.createElement("DaysOfMonth");
|
||||
scheduleByMonth.appendChild(daysOfMonth);
|
||||
Element day = doc.createElement("Day");
|
||||
day.appendChild(doc.createTextNode(String.valueOf(station.getScheduleStartDate().getDayOfMonth())));
|
||||
daysOfMonth.appendChild(day);
|
||||
|
||||
Element months = doc.createElement("Months");
|
||||
String[] monthNames = {
|
||||
"January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"
|
||||
};
|
||||
for (String monthName : monthNames) {
|
||||
Element month = doc.createElement(monthName);
|
||||
months.appendChild(month);
|
||||
}
|
||||
scheduleByMonth.appendChild(months);
|
||||
break;
|
||||
}
|
||||
|
||||
// Principals element
|
||||
Element principals = doc.createElement("Principals");
|
||||
|
Loading…
x
Reference in New Issue
Block a user