示例#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>
        /// Returns a list of calendar files that correspont to the specified list of item paths.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method is called by the Engine during <b>calendar-multiget</b> call.
        /// </para>
        /// <para>
        /// For each item from the <b>pathList</b> parameter return an item that corresponds to path or <b>null</b> if the item is not found.
        /// </para>
        /// </remarks>
        /// <param name="pathList">Calendar files path list.</param>
        /// <param name="propNames">
        /// Properties requested by the client. You can use this as a hint about what properties will be called by
        /// the Engine for each item that are returned from this method.
        /// </param>
        /// <returns>List of calendar files. Returns <b>null</b> for any item that is not found.</returns>
        public async Task <IEnumerable <ICalendarFileAsync> > MultiGetAsync(IEnumerable <string> pathList, IEnumerable <PropertyName> propNames)
        {
            // Get list of UIDs from path list.
            IEnumerable <string> uids = pathList.Select(a => System.IO.Path.GetFileNameWithoutExtension(a));

            return(await CalendarFile.LoadByUidsAsync(Context, uids, PropsToLoad.All));
        }