/// <summary> /// Gets CardDAV items. /// </summary> /// <param name="path">Relative path requested.</param> /// <param name="context">Instance of <see cref="DavContext"/> class.</param> /// <returns>Object implementing various business card items or null if no object corresponding to path is found.</returns> public static async Task <IHierarchyItemAsync> GetCardDavItemAsync(DavContext context, string path) { // If this is [DAVLocation]/addressbooks - return folder that contains all addressbooks. if (path.Equals(AddressbooksRootFolder.AddressbooksRootFolderPath.Trim('/'), System.StringComparison.InvariantCultureIgnoreCase)) { return(new AddressbooksRootFolder(context)); } string[] segments = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); // If URL ends with .vcf - return address book file, which contains vCard. if (path.EndsWith(CardFile.Extension, System.StringComparison.InvariantCultureIgnoreCase)) { string fileName = EncodeUtil.DecodeUrlPart(System.IO.Path.GetFileNameWithoutExtension(segments.Last())); return((await CardFile.LoadByFileNamesAsync(context, new[] { fileName }, PropsToLoad.All)).FirstOrDefault()); } // If this is [DAVLocation]/addressbooks/[AddressbookFolderId]/ return address book. if (path.StartsWith(AddressbooksRootFolder.AddressbooksRootFolderPath.Trim('/'), System.StringComparison.InvariantCultureIgnoreCase)) { Guid addressbookFolderId; if (Guid.TryParse(EncodeUtil.DecodeUrlPart(segments.Last()), out addressbookFolderId)) { return(await AddressbookFolder.LoadByIdAsync(context, addressbookFolderId)); } } return(null); }
/// <summary> /// Creates a new address book. /// </summary> /// <param name="name">Name of the new address book.</param> public async Task CreateFolderAsync(string name) { await AddressbookFolder.CreateAddressbookFolderAsync(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 addressbooks from back-end storage. // You can filter addressbooks if requied and return only addressbooks that user has access to. return(new PageResults((await AddressbookFolder.LoadAllAsync(Context)).OrderBy(x => x.Name), null)); }