in src/PatchOrchestrationApplication/NodeAgentNTService/src/Manager/ServiceSettings.cs [135:232]
private void ParseWUFrequency()
{
string[] arr = WUFrequency.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(str => str.Trim()).ToArray();
if(arr.Count() == 0)
{
throw new ArgumentException("Illegal WUFrequency Parameter : "+ WUFrequency);
}
this.Frequency = (Frequency)Enum.Parse(typeof(Frequency), arr[0]);
DateTime currentDateTime = DateTime.UtcNow;
switch (this.Frequency)
{
case Frequency.Monthly:
if (arr.Count() != 3)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}
if (arr[1].Trim().Equals("Last", StringComparison.InvariantCultureIgnoreCase))
{
this.IsLastDayOfMonth = true;
}
else
{
int dayOfMonth = (int) Convert.ChangeType(arr[1], typeof(int));
if (dayOfMonth > MaxSupportedDayOfMonth)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency + ". The day of month should be between 1 to 28.");
}
this.Date = new DateTime(currentDateTime.Year, currentDateTime.Month, dayOfMonth, 0, 0, 0);
this.Date = this.Date.Date + TimeSpan.Parse(arr[2]);
}
break;
case Frequency.MonthlyByWeekAndDay:
if (arr.Count() != 4)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}
this.WeekOfMonth = (int)Convert.ChangeType(arr[1], typeof(int));
this.DayOfWeek = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), arr[2]);
this.Time = TimeSpan.Parse(arr[3]);
if (this.WeekOfMonth < 1 || this.WeekOfMonth > 4)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency + ". The WeekOfMonth should be between 1 to 4.");
}
break;
case Frequency.Weekly:
if (arr.Count() != 3)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}
this.DayOfWeek = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), arr[1]);
this.Date = currentDateTime;
this.Date = this.Date.Date + TimeSpan.Parse(arr[2]);
break;
case Frequency.Daily:
if (arr.Count() != 2)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}
this.Date = currentDateTime;
this.Date = this.Date.Date + TimeSpan.Parse(arr[1]);
break;
case Frequency.Once:
if (arr.Count() != 3)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}
this.Date = DateTime.Parse(arr[1]);
this.Date = this.Date.Date + TimeSpan.Parse(arr[2]);
break;
case Frequency.None:
if (arr.Count() != 1)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}
break;
case Frequency.Hourly:
if (arr.Count() != 2)
{
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}
this.HourlyFrequencyInMinutes = (long)Convert.ChangeType(arr[1], typeof(long));
break;
default:
throw new ArgumentException("Illegal WUFrequency Parameter : " + WUFrequency);
}
}