2022-03-15 18:00:53 +00:00
|
|
|
// (c) Copyright Ascensio System SIA 2010-2022
|
|
|
|
//
|
|
|
|
// This program is a free software product.
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
|
|
|
|
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
|
|
|
|
// any third-party rights.
|
|
|
|
//
|
|
|
|
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
//
|
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
|
|
|
//
|
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
|
|
|
//
|
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
// trademark law for use of our trademarks.
|
|
|
|
//
|
|
|
|
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
|
|
|
|
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
namespace ASC.Web.Core.Calendars;
|
|
|
|
|
|
|
|
public abstract class BaseCalendar : ICalendar, ICloneable
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
protected BaseCalendar(AuthContext authContext, TimeZoneConverter timeZoneConverter)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
this.Context = new CalendarContext();
|
|
|
|
this.SharingOptions = new SharingOptions();
|
|
|
|
AuthContext = authContext;
|
|
|
|
TimeZoneConverter = timeZoneConverter;
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
#region ICalendar Members
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public virtual string Id { get; set; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public virtual string Name { get; set; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public virtual string Description { get; set; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public virtual Guid OwnerId { get; set; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public virtual EventAlertType EventAlertType { get; set; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public abstract List<IEvent> LoadEvents(Guid userId, DateTime utcStartDate, DateTime utcEndDate);
|
|
|
|
public abstract List<ITodo> LoadTodos(Guid userId, DateTime utcStartDate, DateTime utcEndDate);
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public virtual SharingOptions SharingOptions { get; set; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public virtual TimeZoneInfo TimeZone { get; set; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public virtual CalendarContext Context { get; set; }
|
|
|
|
protected AuthContext AuthContext { get; }
|
|
|
|
protected TimeZoneConverter TimeZoneConverter { get; }
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
#endregion
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
#region ICloneable Members
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public object Clone()
|
|
|
|
{
|
|
|
|
var cal = (BaseCalendar)this.MemberwiseClone();
|
|
|
|
cal.Context = (CalendarContext)this.Context.Clone();
|
|
|
|
cal.SharingOptions = (SharingOptions)this.SharingOptions.Clone();
|
|
|
|
return cal;
|
|
|
|
}
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
#endregion
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
#region IiCalFormatView Members
|
2019-06-07 08:59:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string ToiCalFormat()
|
|
|
|
{
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
|
sb.AppendLine("BEGIN:VCALENDAR");
|
|
|
|
sb.AppendLine("PRODID:TeamLab Calendar");
|
|
|
|
sb.AppendLine("VERSION:2.0");
|
|
|
|
|
|
|
|
sb.AppendLine("METHOD:PUBLISH");
|
|
|
|
sb.AppendLine("CALSCALE:GREGORIAN");
|
|
|
|
sb.AppendLine($"X-WR-CALNAME:{Name}");
|
|
|
|
sb.AppendLine($"X-WR-TIMEZONE:{TimeZoneConverter.WindowsTzId2OlsonTzId(TimeZone.Id)}");
|
|
|
|
//tz
|
|
|
|
sb.AppendLine("BEGIN:VTIMEZONE");
|
|
|
|
sb.AppendLine($"TZID:{TimeZoneConverter.WindowsTzId2OlsonTzId(TimeZone.Id)}");
|
|
|
|
sb.AppendLine("END:VTIMEZONE");
|
|
|
|
|
|
|
|
//events
|
|
|
|
foreach (var e in LoadEvents(AuthContext.CurrentAccount.ID, DateTime.MinValue, DateTime.MaxValue))
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
if (e is BaseEvent && e.GetType().GetCustomAttributes(typeof(AllDayLongUTCAttribute), true).Length == 0)
|
2019-06-07 08:59:07 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
(e as BaseEvent).TimeZone = TimeZone;
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
sb.AppendLine(e.ToiCalFormat());
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
sb.Append("END:VCALENDAR");
|
|
|
|
|
|
|
|
return sb.ToString();
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
#endregion
|
2019-06-07 08:59:07 +00:00
|
|
|
}
|