Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CalDAV.NET/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ private async Task<ICalendar> 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")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thank you for your pull request.

Can you explain to me why you did remove the content value check? And is there a reason why you did comment it instead of removing the lines?

// {
// return null;
// }

var calendar = await Calendar.Deserialize(resource, uri, _client);

Expand Down
6 changes: 4 additions & 2 deletions CalDAV.NET/Interfaces/ICalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ public interface ICalendar
/// <param name="start">Start date and time of the event</param>
/// <param name="end">End date and time of the event</param>
/// <param name="location">Location of the event</param>
/// <param name="description">Description of the event</param>
/// <returns>New created event</returns>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="summary" /> is null</exception>
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 = "");

/// <summary>
/// Delete a given event from the calendar.
Expand All @@ -100,4 +102,4 @@ public interface ICalendar
/// <returns>True if all changes could be applied, otherwise false.</returns>
Task<IEnumerable<SaveChangesStatus>> SaveChangesAsync();
}
}
}
7 changes: 6 additions & 1 deletion CalDAV.NET/Interfaces/IEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ public interface IEvent
/// </summary>
string Summary { get; set; }

/// <summary>
/// Get or set the description of the event.
/// </summary>
string Description { get; set; }

// TODO: Add alarm
// TODO: Add missing properties like transparent, class, categories etc.
}
}
}
27 changes: 17 additions & 10 deletions CalDAV.NET/Internal/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace CalDAV.NET.Internal
{
internal class Calendar : ICalendar
public class Calendar : ICalendar
{
private static readonly Regex _hrefRegex = new Regex("<[^>]*(>|$)");

Expand All @@ -25,7 +25,9 @@ internal class Calendar : ICalendar
public string Method { get; private set; }
public string Color { get; private set; }

public IReadOnlyCollection<IEvent> Events => _events.Where(x => x.Status != EventState.Deleted).Select(x => x as IEvent).ToList();
public IReadOnlyCollection<IEvent> 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; }
Expand All @@ -42,23 +44,25 @@ private Calendar(CalDAVClient client)
_events = new List<Event>();
}

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)
{
throw new ArgumentNullException(nameof(summary));
}

var internalEvent = _calendar.Create<Ical.Net.CalendarComponents.CalendarEvent>();

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);

Expand All @@ -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));
}
Expand Down Expand Up @@ -141,7 +144,9 @@ internal static async Task<Calendar> 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;

Expand Down Expand Up @@ -212,7 +217,9 @@ private async Task<bool> DeleteEventAsync(IEvent calendarEvent)
private async Task<IEnumerable<Event>> 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"));
Expand Down Expand Up @@ -252,4 +259,4 @@ private string GetEventUrl(IEvent calendarEvent)
return $"{Uri}/{calendarEvent.Uid}.ics";
}
}
}
}
8 changes: 7 additions & 1 deletion CalDAV.NET/Internal/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public TimeSpan Duration
}
}

public string Description
{
get => _calendarEvent.Description;
set => _calendarEvent.Description = value;
}

public DateTime Stamp
{
get => _calendarEvent.DtStamp.Value;
Expand Down Expand Up @@ -125,4 +131,4 @@ private IDateTime SetDateTime(IDateTime target, DateTime value)
return target;
}
}
}
}