Files
duplicati/Duplicati.Library.RestAPI/Database/Schedule.cs
T

84 lines
3.4 KiB
C#
Raw Normal View History

2024-06-05 11:02:56 +02:00
// Copyright (C) 2024, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
2013-11-23 14:26:36 +01:00
using System;
using System.Linq;
2014-03-04 15:38:13 +01:00
using Duplicati.Server.Serialization.Interface;
2013-11-23 14:26:36 +01:00
namespace Duplicati.Server.Database
{
2014-03-04 15:38:13 +01:00
public class Schedule : ISchedule
2013-11-23 14:26:36 +01:00
{
public long ID { get; set; }
public string[] Tags { get; set; }
public DateTime Time { get; set; }
public string Repeat { get; set; }
public DateTime LastRun { get; set; }
public string Rule { get; set; }
2024-06-05 11:02:56 +02:00
2013-11-23 14:26:36 +01:00
public DayOfWeek[] AllowedDays
2024-06-05 11:02:56 +02:00
{
2013-11-23 14:26:36 +01:00
get
{
if (string.IsNullOrEmpty(this.Rule))
return null;
2024-06-05 11:02:56 +02:00
var days = (from n in this.Rule.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
where n.StartsWith("AllowedWeekDays=", StringComparison.OrdinalIgnoreCase)
select n.Substring("AllowedWeekDays=".Length).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
2013-11-23 14:26:36 +01:00
.FirstOrDefault();
2024-06-05 11:02:56 +02:00
2013-11-23 14:26:36 +01:00
if (days == null)
return null;
2019-04-16 21:35:02 -07:00
2024-06-05 11:02:56 +02:00
return (from n in days
2019-04-16 21:35:02 -07:00
where Enum.TryParse<DayOfWeek>(n, true, out _)
2013-11-23 14:26:36 +01:00
select (DayOfWeek)Enum.Parse(typeof(DayOfWeek), n, true))
.ToArray();
}
set
{
2024-06-05 11:02:56 +02:00
var parts =
string.IsNullOrEmpty(this.Rule) ?
2013-11-23 14:26:36 +01:00
new string[0] :
2024-06-05 11:02:56 +02:00
(from n in this.Rule.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
where !n.StartsWith("AllowedWeekDays=", StringComparison.OrdinalIgnoreCase)
select n);
2013-11-23 14:26:36 +01:00
if (value != null && value.Length != 0)
2014-03-05 15:29:14 +01:00
parts = parts.Union(new string[] {
2013-11-23 14:26:36 +01:00
"AllowedWeekDays=" +
string.Join(
",",
(from n in value
2014-03-05 15:29:14 +01:00
select Enum.GetName(typeof(DayOfWeek), n)).Distinct()
)
}).Distinct();
2024-06-05 11:02:56 +02:00
2013-11-23 14:26:36 +01:00
this.Rule = string.Join(";", parts);
}
}
}
}