Ejemplo n.º 1
0
        /// <summary>
        /// Gets CalDAV items.
        /// </summary>
        /// <param name="itemPath">Relative path requested.</param>
        /// <param name="context">Instance of <see cref="DavContext"/> class.</param>
        /// <returns>Object implementing various calendar items or null if no object corresponding to path is found.</returns>
        public static async Task <IHierarchyItemAsync> GetCalDavItemAsync(DavContext context, string itemPath)
        {
            // If this is [DAVLocation]/calendars - return folder that contains all calendars.
            if (itemPath.Equals(CalendarsRootFolder.CalendarsRootFolderPath.Trim('/'), System.StringComparison.InvariantCultureIgnoreCase))
            {
                return(new CalendarsRootFolder(context));
            }

            string[] segments = itemPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            // If URL ends with .ics - return calendar file, which contains event or to-do.
            if (itemPath.EndsWith(CalendarFile.Extension, System.StringComparison.InvariantCultureIgnoreCase))
            {
                string uid = EncodeUtil.DecodeUrlPart(Path.GetFileNameWithoutExtension(segments.Last()));
                return((await CalendarFile.LoadByUidsAsync(context, new[] { uid }, PropsToLoad.All)).FirstOrDefault());
            }

            // If this is [DAVLocation]/calendars/[CalendarFolderId]/ return calendar.
            if (itemPath.StartsWith(CalendarsRootFolder.CalendarsRootFolderPath.Trim('/'), System.StringComparison.InvariantCultureIgnoreCase))
            {
                Guid calendarFolderId;
                if (Guid.TryParse(EncodeUtil.DecodeUrlPart(segments.Last()), out calendarFolderId))

                {
                    return(await CalendarFolder.LoadByIdAsync(context, calendarFolderId));
                }
            }

            return(null);
        }
 /// <summary>
 /// Creates a new calendar.
 /// </summary>
 /// <param name="name">Name of the new calendar.</param>
 public async Task CreateFolderAsync(string name)
 {
     await CalendarFolder.CreateCalendarFolderAsync(Context, name, "");
 }
 /// <summary>
 /// Retrieves children of this folder.
 /// </summary>
 /// <param name="propNames">Properties requested by client application for each child.</param>
 /// <param name="offset">The number of children to skip before returning the remaining items. Start listing from from next item.</param>
 /// <param name="nResults">The number of items to return.</param>
 /// <param name="orderProps">List of order properties requested by the client.</param>
 /// <returns>Children of this folder.</returns>
 public override async Task <PageResults> GetChildrenAsync(IList <PropertyName> propNames, long?offset, long?nResults, IList <OrderProperty> orderProps)
 {
     // Here we list calendars from back-end storage.
     // You can filter calendars if requied and return only calendars that user has access to.
     return(new PageResults((await CalendarFolder.LoadAllAsync(Context)).OrderBy(x => x.Name), null));
 }