From 4f37ff61caf51e285e53bcc1ff5156d6eaf76cac Mon Sep 17 00:00:00 2001 From: kdj <935637782@QQ.COM> Date: Sun, 7 Jul 2024 13:05:46 +0800 Subject: [PATCH 1/3] add event description property --- CalDAV.NET/Client.cs | 8 ++++---- CalDAV.NET/Internal/Event.cs | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CalDAV.NET/Client.cs b/CalDAV.NET/Client.cs index 351b0d3..7d5bf4e 100644 --- a/CalDAV.NET/Client.cs +++ b/CalDAV.NET/Client.cs @@ -150,10 +150,10 @@ private async Task GetCalendarWithUriAsync(string uri) // check if resource really is a calendar var contentType = resource?.Properties.FirstOrDefault(x => x.Key.LocalName == "getcontenttype"); - if (contentType.HasValue == false || contentType.Value.Value != "text/calendar") - { - return null; - } + // if (contentType.HasValue == false || contentType.Value.Value != "text/calendar") + // { + // return null; + // } var calendar = await Calendar.Deserialize(resource, uri, _client); diff --git a/CalDAV.NET/Internal/Event.cs b/CalDAV.NET/Internal/Event.cs index 0c1631c..d6ed44d 100644 --- a/CalDAV.NET/Internal/Event.cs +++ b/CalDAV.NET/Internal/Event.cs @@ -39,6 +39,12 @@ public TimeSpan Duration } } + public string Description + { + get => _calendarEvent.Description; + set => _calendarEvent.Description = value; + } + public DateTime Stamp { get => _calendarEvent.DtStamp.Value; @@ -125,4 +131,4 @@ private IDateTime SetDateTime(IDateTime target, DateTime value) return target; } } -} +} \ No newline at end of file From bb6a19d362a48f6bdb12d3ce32e2327c51c27b8d Mon Sep 17 00:00:00 2001 From: kdj <935637782@QQ.COM> Date: Sun, 7 Jul 2024 13:05:46 +0800 Subject: [PATCH 2/3] add event description property --- CalDAV.NET/Client.cs | 8 ++++---- CalDAV.NET/Interfaces/IEvent.cs | 7 ++++++- CalDAV.NET/Internal/Event.cs | 8 +++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CalDAV.NET/Client.cs b/CalDAV.NET/Client.cs index 351b0d3..7d5bf4e 100644 --- a/CalDAV.NET/Client.cs +++ b/CalDAV.NET/Client.cs @@ -150,10 +150,10 @@ private async Task GetCalendarWithUriAsync(string uri) // check if resource really is a calendar var contentType = resource?.Properties.FirstOrDefault(x => x.Key.LocalName == "getcontenttype"); - if (contentType.HasValue == false || contentType.Value.Value != "text/calendar") - { - return null; - } + // if (contentType.HasValue == false || contentType.Value.Value != "text/calendar") + // { + // return null; + // } var calendar = await Calendar.Deserialize(resource, uri, _client); diff --git a/CalDAV.NET/Interfaces/IEvent.cs b/CalDAV.NET/Interfaces/IEvent.cs index ba19e69..6205157 100644 --- a/CalDAV.NET/Interfaces/IEvent.cs +++ b/CalDAV.NET/Interfaces/IEvent.cs @@ -49,7 +49,12 @@ public interface IEvent /// string Summary { get; set; } + /// + /// Get or set the description of the event. + /// + string Description { get; set; } + // TODO: Add alarm // TODO: Add missing properties like transparent, class, categories etc. } -} +} \ No newline at end of file diff --git a/CalDAV.NET/Internal/Event.cs b/CalDAV.NET/Internal/Event.cs index 0c1631c..d6ed44d 100644 --- a/CalDAV.NET/Internal/Event.cs +++ b/CalDAV.NET/Internal/Event.cs @@ -39,6 +39,12 @@ public TimeSpan Duration } } + public string Description + { + get => _calendarEvent.Description; + set => _calendarEvent.Description = value; + } + public DateTime Stamp { get => _calendarEvent.DtStamp.Value; @@ -125,4 +131,4 @@ private IDateTime SetDateTime(IDateTime target, DateTime value) return target; } } -} +} \ No newline at end of file From c09550462983aae6557968c952b5966b008d178c Mon Sep 17 00:00:00 2001 From: kdj <935637782@QQ.COM> Date: Mon, 8 Jul 2024 21:56:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CalDAV.NET/Interfaces/ICalendar.cs | 6 ++++-- CalDAV.NET/Internal/Calendar.cs | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CalDAV.NET/Interfaces/ICalendar.cs b/CalDAV.NET/Interfaces/ICalendar.cs index 7ccdb88..760e344 100644 --- a/CalDAV.NET/Interfaces/ICalendar.cs +++ b/CalDAV.NET/Interfaces/ICalendar.cs @@ -80,9 +80,11 @@ public interface ICalendar /// Start date and time of the event /// End date and time of the event /// Location of the event + /// Description of the event /// New created event /// Thrown if is null - IEvent CreateEvent(string summary, DateTime start, DateTime end = default(DateTime), string location = null); + IEvent CreateEvent(string summary, DateTime start, DateTime end = default(DateTime), string location = null, + string description = ""); /// /// Delete a given event from the calendar. @@ -100,4 +102,4 @@ public interface ICalendar /// True if all changes could be applied, otherwise false. Task> SaveChangesAsync(); } -} +} \ No newline at end of file diff --git a/CalDAV.NET/Internal/Calendar.cs b/CalDAV.NET/Internal/Calendar.cs index fca0f3d..f34f260 100644 --- a/CalDAV.NET/Internal/Calendar.cs +++ b/CalDAV.NET/Internal/Calendar.cs @@ -9,7 +9,7 @@ namespace CalDAV.NET.Internal { - internal class Calendar : ICalendar + public class Calendar : ICalendar { private static readonly Regex _hrefRegex = new Regex("<[^>]*(>|$)"); @@ -25,7 +25,9 @@ internal class Calendar : ICalendar public string Method { get; private set; } public string Color { get; private set; } - public IReadOnlyCollection Events => _events.Where(x => x.Status != EventState.Deleted).Select(x => x as IEvent).ToList(); + public IReadOnlyCollection Events => + _events.Where(x => x.Status != EventState.Deleted).Select(x => x as IEvent).ToList(); + public bool LocalChanges => _events.Any(x => x.Status != EventState.None); private string ETag { get; set; } @@ -42,7 +44,8 @@ private Calendar(CalDAVClient client) _events = new List(); } - public IEvent CreateEvent(string summary, DateTime start, DateTime end = default, string location = null) + public IEvent CreateEvent(string summary, DateTime start, DateTime end = default, string location = null, + string description = "") { if (summary == null) { @@ -50,15 +53,16 @@ public IEvent CreateEvent(string summary, DateTime start, DateTime end = default } var internalEvent = _calendar.Create(); - var calendarEvent = new Event(internalEvent) { Start = start, End = end != default ? end : start.AddHours(1), Summary = summary, Location = location, - Status = EventState.Created + Status = EventState.Created, + Description = description, }; + internalEvent.IsAllDay = false; _events.Add(calendarEvent); @@ -72,8 +76,7 @@ public void DeleteEvent(IEvent calendarEvent) throw new ArgumentNullException(nameof(calendarEvent)); } - var internalEvent = calendarEvent as Event; - if (internalEvent == null) + if (!(calendarEvent is Event internalEvent)) { throw new ArgumentException(nameof(calendarEvent)); } @@ -141,7 +144,9 @@ internal static async Task Deserialize(Resource resource, string uri, break; case "owner": - calendar.Owner = property.Value.Contains("href") ? _hrefRegex.Replace(property.Value, "") : property.Value; + calendar.Owner = property.Value.Contains("href") + ? _hrefRegex.Replace(property.Value, "") + : property.Value; break; @@ -212,7 +217,9 @@ private async Task DeleteEventAsync(IEvent calendarEvent) private async Task> GetEventsAsync() { // create body - var query = new XElement(Constants.CalNs + "calendar-query", new XAttribute(XNamespace.Xmlns + "d", Constants.DavNs), new XAttribute(XNamespace.Xmlns + "c", Constants.CalNs)); + var query = new XElement(Constants.CalNs + "calendar-query", + new XAttribute(XNamespace.Xmlns + "d", Constants.DavNs), + new XAttribute(XNamespace.Xmlns + "c", Constants.CalNs)); var prop = new XElement(Constants.DavNs + "prop"); prop.Add(new XElement(Constants.DavNs + "getetag")); @@ -252,4 +259,4 @@ private string GetEventUrl(IEvent calendarEvent) return $"{Uri}/{calendarEvent.Uid}.ics"; } } -} +} \ No newline at end of file