/// <summary> /// Called whan this file is being deleted. /// </summary> /// <param name="multistatus">Information about items that failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { await RequireHasTokenAsync(); fileSystemInfo.Delete(); await context.socketService.NotifyRefreshAsync(GetParentPath(Path)); }
/// <summary> /// Copies this file to another folder. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name in destination folder.</param> /// <param name="deep">Is not used.</param> /// <param name="multistatus">Container for errors with items other than this file.</param> public override async Task CopyToAsync( IItemCollectionAsync destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT); } if (!await destDavFolder.ClientHasTokenAsync()) { throw new LockedException("Doesn't have token for destination folder."); } DavHierarchyItem destItem = await destDavFolder.FindChildAsync(destName); if (destItem != null) { try { await destItem.DeleteAsync(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } await CopyThisItemAsync(destDavFolder, null, destName); await Context.socketService.NotifyRefreshAsync(destDavFolder.Path); }
/// <summary> /// Not supported. /// </summary> public void UpdateProperties( IList <PropertyValue> setProps, IList <PropertyName> delProps, MultistatusException multistatus) { throw new DavException("Cannot update properties of history resource.", DavStatus.NOT_ALLOWED); }
/// <summary> /// Called whan this folder is being deleted. /// </summary> /// <param name="multistatus">Information about items that failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { /* * if (await GetParentAsync() == null) * { * throw new DavException("Cannot delete root.", DavStatus.NOT_ALLOWED); * } */ bool allChildrenDeleted = true; foreach (IHierarchyItemAsync child in (await GetChildrenAsync(new PropertyName[0], null, null, new List <OrderProperty>())).Page) { try { await child.DeleteAsync(multistatus); } catch (DavException ex) { //continue the operation if a child failed to delete. Tell client about it by adding to multistatus. multistatus.AddInnerException(child.Path, ex); allChildrenDeleted = false; } } if (allChildrenDeleted) { dirInfo.Delete(); } }
public virtual async Task UpdatePropertiesAsync( IList <PropertyValue> setProps, IList <PropertyName> delProps, MultistatusException multistatus) { throw new NotImplementedException(); }
/// <summary> /// Copies this file to another folder. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name in destination folder.</param> /// <param name="deep">Is not used.</param> /// <param name="multistatus">Container for errors with items other than this file.</param> public override void CopyTo( IItemCollection destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT); } if (!destDavFolder.ClientHasToken()) { throw new LockedException("Doesn't have token for destination folder."); } DavHierarchyItem destItem = destDavFolder.FindChild(destName); if (destItem != null) { try { destItem.Delete(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } CopyThisItem(destDavFolder, null, destName); }
/// <summary> /// Called whan this folder is being deleted. /// </summary> /// <param name="multistatus">Information about items that failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { /* * if (await GetParentAsync() == null) * { * throw new DavException("Cannot delete root.", DavStatus.NOT_ALLOWED); * } */ await RequireHasTokenAsync(); bool allChildrenDeleted = true; foreach (IHierarchyItemAsync child in await GetChildrenAsync(new PropertyName[0])) { try { await child.DeleteAsync(multistatus); } catch (DavException ex) { //continue the operation if a child failed to delete. Tell client about it by adding to multistatus. multistatus.AddInnerException(child.Path, ex); allChildrenDeleted = false; } } if (allChildrenDeleted) { dirInfo.Delete(); await context.eventsService.NotifyDeleteAsync(Path); } }
/// <summary> /// Called whan this file is being deleted. /// </summary> /// <param name="multistatus">Information about items that failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { if (FileSystemInfoExtension.IsUsingFileSystemAttribute) { await fileSystemInfo.DeleteExtendedAttributes(); } fileSystemInfo.Delete(); }
/// <summary> /// Copies this folder to another folder with option to rename it. /// </summary> /// <param name="destFolder">Folder to copy this folder to.</param> /// <param name="destName">New name of this folder.</param> /// <param name="deep">Whether children shall be copied.</param> /// <param name="multistatus">Container for errors. We put here errors which occur with /// individual items being copied.</param> public override async Task CopyToAsync( IItemCollectionAsync destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist", DavStatus.CONFLICT); } if (!await destDavFolder.ClientHasTokenAsync()) { throw new LockedException("Doesn't have token for destination folder."); } if (isRecursive(destDavFolder)) { throw new DavException("Cannot copy folder to its subtree", DavStatus.FORBIDDEN); } IHierarchyItemAsync destItem = await destDavFolder.FindChildAsync(destName); if (destItem != null) { try { await destItem.DeleteAsync(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } DavFolder newDestFolder = await CopyThisItemAsync(destDavFolder, null, destName); // copy children if (deep) { foreach (IHierarchyItemAsync child in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { var dbchild = child as DavHierarchyItem; try { await dbchild.CopyToAsync(newDestFolder, child.Name, deep, multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); } } } await Context.socketService.NotifyRefreshAsync(newDestFolder.Path); }
/// <summary> /// Called whan this file is being deleted. /// </summary> /// <param name="multistatus">Information about items that failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { await RequireHasTokenAsync(); if (FileSystemInfoExtension.IsUsingFileSystemAttribute) { await fileSystemInfo.DeleteExtendedAttributes(); } fileSystemInfo.Delete(); await context.socketService.NotifyRefreshAsync(GetParentPath(Path)); }
/// <summary> /// Called when client application deletes this file. /// </summary> /// <param name="multistatus">Error description if case delate failed. Ignored by most clients.</param> public override async Task DeleteAsync(MultistatusException multistatus) { // Notify attendees that event is canceled if deletion is successful. string calendarObjectContent = File.ReadAllText(fileSystemInfo.FullName); await base.DeleteAsync(multistatus); IEnumerable <IComponent> calendars = new vFormatter().Deserialize(calendarObjectContent); ICalendar2 calendar = calendars.First() as ICalendar2; calendar.Method = calendar.CreateMethodProp(MethodType.Cancel); await iMipEventSchedulingTransport.NotifyAttendeesAsync(context, calendar); }
/// <summary> /// Called when this file is being deleted. /// </summary> /// <param name="multistatus">Information about items that failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { await RequireHasTokenAsync(); try { await context.DataLakeStoreService.DeleteItemAsync(Path); } catch (RequestFailedException ex) { throw new DataException($"Cannot delete item {Name}", ex); } await context.socketService.NotifyRefreshAsync(GetParentPath(Path)); }
/// <summary> /// Deletes this address book. /// </summary> /// <param name="multistatus"><see cref="MultistatusException"/> to populate with child files and folders failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { // Delete address book and all vCards associated with it. Check that user has permissions to delete. string sql = @"DELETE FROM [card_AddressbookFolder] WHERE [AddressbookFolderId]=@AddressbookFolderId AND [AddressbookFolderId] IN (SELECT [AddressbookFolderId] FROM [card_Access] WHERE [UserId]=@UserId AND [Owner] = 1)"; if (await Context.ExecuteNonQueryAsync(sql, "@UserId", Context.UserId , "@AddressbookFolderId", addressbookFolderId) < 1) { throw new DavException("Item not found or you do not have enough permissions to complete this operation.", DavStatus.FORBIDDEN); } }
/// <summary> /// Called when this folder is being deleted. /// </summary> /// <param name="multistatus">Information about items that failed to delete.</param> public override async Task DeleteAsync(MultistatusException multistatus) { /* * if (await GetParentAsync() == null) * { * throw new DavException("Cannot delete root.", DavStatus.NOT_ALLOWED); * } */ await RequireHasTokenAsync(); await context.DataLakeStoreService.DeleteItemAsync(Path); await context.socketService.NotifyDeleteAsync(Path); }
/// <summary> /// Adds, modifies and removes properties for this item. /// </summary> /// <param name="setProps">List of properties to be set.</param> /// <param name="delProps">List of property names to be removed. Properties that don't exist shall be skipped.</param> /// <param name="multistatus">Information about errors.</param> public override async Task UpdatePropertiesAsync( IList <PropertyValue> setProps, IList <PropertyName> delProps, MultistatusException multistatus) { foreach (PropertyValue p in setProps) { await SetPropertyAsync(p); // create or update property } foreach (PropertyName p in delProps) { await RemovePropertyAsync(p.Name, p.Namespace); } }
/// <summary> /// Deletes this file. /// </summary> /// <param name="multistatus">Is not used.</param> public override void Delete(MultistatusException multistatus) { DavFolder parent = GetParent(); if (parent == null) { throw new DavException("Parent is null.", DavStatus.CONFLICT); } if (!parent.ClientHasToken()) { throw new LockedException(); } if (!ClientHasToken()) { throw new LockedException(); } DeleteThisItem(parent); }
protected static async Task FindLocksDownAsync(IHierarchyItemAsync root, bool skipShared) { IFolderAsync folder = root as IFolderAsync; if (folder != null) { foreach (IHierarchyItemAsync child in (await folder.GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { DavHierarchyItem dbchild = child as DavHierarchyItem; if (await dbchild.ItemHasLockAsync(skipShared)) { MultistatusException mex = new MultistatusException(); mex.AddInnerException(dbchild.Path, new LockedException()); throw mex; } await FindLocksDownAsync(child, skipShared); } } }
/// <summary> /// Deletes this file. /// </summary> /// <param name="multistatus">Is not used.</param> public override async Task DeleteAsync(MultistatusException multistatus) { DavFolder parent = await GetParentAsync(); if (parent == null) { throw new DavException("Parent is null.", DavStatus.CONFLICT); } if (!await parent.ClientHasTokenAsync()) { throw new LockedException(); } if (!await ClientHasTokenAsync()) { throw new LockedException(); } await DeleteThisItemAsync(parent); await Context.socketService.NotifyRefreshAsync(parent.Path); }
protected static void FindLocksDown(IHierarchyItem root, bool skipShared) { IFolder folder = root as IFolder; if (folder != null) { foreach (IHierarchyItem child in folder.GetChildren(new PropertyName[0])) { DavHierarchyItem dbchild = child as DavHierarchyItem; if (dbchild.ItemHasLock(skipShared)) { MultistatusException mex = new MultistatusException(); mex.AddInnerException(dbchild.Path, new LockedException()); throw mex; } FindLocksDown(child, skipShared); } } }
/// <summary> /// Deletes this folder. /// </summary> /// <param name="multistatus">Container for errors. /// If some child file/folder fails to remove we report error in this container.</param> public override async Task DeleteAsync(MultistatusException multistatus) { DavFolder parent = await GetParentAsync(); if (parent == null) { throw new DavException("Cannot delete root.", DavStatus.CONFLICT); } if (!await parent.ClientHasTokenAsync()) { throw new LockedException(); } if (!await ClientHasTokenAsync()) { throw new LockedException(); } bool deletedAllChildren = true; foreach (IHierarchyItemAsync child in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { DavHierarchyItem dbchild = child as DavHierarchyItem; try { await dbchild.DeleteAsync(multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); deletedAllChildren = false; } } if (deletedAllChildren) { await DeleteThisItemAsync(parent); await Context.socketService.NotifyDeleteAsync(Path); } }
public virtual async Task UpdatePropertiesAsync( IList <PropertyValue> setProps, IList <PropertyName> delProps, MultistatusException multistatus) { await RequireHasTokenAsync(); foreach (PropertyValue p in setProps) { // Microsoft Mini-redirector may update file creation date, modification date and access time passing properties: // <Win32CreationTime xmlns="urn:schemas-microsoft-com:">Thu, 28 Mar 2013 20:15:34 GMT</Win32CreationTime> // <Win32LastModifiedTime xmlns="urn:schemas-microsoft-com:">Thu, 28 Mar 2013 20:36:24 GMT</Win32LastModifiedTime> // <Win32LastAccessTime xmlns="urn:schemas-microsoft-com:">Thu, 28 Mar 2013 20:36:24 GMT</Win32LastAccessTime> // In this case update creation and modified date in your storage or do not save this properties at all, otherwise // Windows Explorer will display creation and modification date from this props and it will differ from the values // in the Created and Modified fields in your storage if (p.QualifiedName.Namespace == "urn:schemas-microsoft-com:") { if (p.QualifiedName.Name == "Win32CreationTime") { await SetDbFieldAsync("Created", DateTime.Parse(p.Value, new System.Globalization.CultureInfo("en-US")).ToUniversalTime()); } else if (p.QualifiedName.Name == "Win32LastModifiedTime") { await SetDbFieldAsync("Modified", DateTime.Parse(p.Value, new System.Globalization.CultureInfo("en-US")).ToUniversalTime()); } } else { await SetPropertyAsync(p); // create or update property } } foreach (PropertyName p in delProps) { await RemovePropertyAsync(p.Name, p.Namespace); } // You should not update modification date/time here. Mac OS X Finder expects that properties update do not change the file modification date. await Context.socketService.NotifyUpdatedAsync(Path); }
/// <summary> /// Deletes this folder. /// </summary> /// <param name="multistatus">Container for errors. /// If some child file/folder fails to remove we report error in this container.</param> public override void Delete(MultistatusException multistatus) { DavFolder parent = GetParent(); if (parent == null) { throw new DavException("Cannot delete root.", DavStatus.CONFLICT); } if (!parent.ClientHasToken()) { throw new LockedException(); } if (!ClientHasToken()) { throw new LockedException(); } bool deletedAllChildren = true; foreach (IHierarchyItem child in GetChildren(new PropertyName[0])) { DavHierarchyItem dbchild = child as DavHierarchyItem; try { dbchild.Delete(multistatus); } catch (DavException ex) { multistatus.AddInnerException(dbchild.Path, ex); deletedAllChildren = false; } } if (deletedAllChildren) { DeleteThisItem(parent); } }
/// <summary> /// Moves this file to different folder and renames it. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New file name.</param> /// <param name="multistatus">Container for errors with items other than this file.</param> public override void MoveTo(IItemCollection destFolder, string destName, MultistatusException multistatus) { DavFolder destDavFolder = destFolder as DavFolder; if (destFolder == null) { throw new DavException("Destination folder doesn't exist.", DavStatus.CONFLICT); } DavFolder parent = GetParent(); if (parent == null) { throw new DavException("Cannot move root.", DavStatus.CONFLICT); } if (!ClientHasToken() || !destDavFolder.ClientHasToken() || !parent.ClientHasToken()) { throw new LockedException(); } DavHierarchyItem destItem = destDavFolder.FindChild(destName); if (destItem != null) { try { destItem.Delete(multistatus); } catch (DavException ex) { multistatus.AddInnerException(destItem.Path, ex); return; } } MoveThisItem(destDavFolder, destName, parent); }
/// <summary> /// Saves property values to extended attribute. /// </summary> /// <param name="setProps">Properties to be set.</param> /// <param name="delProps">Properties to be deleted.</param> /// <param name="multistatus">Information about properties that failed to create, update or delate.</param> public async Task UpdatePropertiesAsync(IList <PropertyValue> setProps, IList <PropertyName> delProps, MultistatusException multistatus) { await RequireHasTokenAsync(); List <PropertyValue> propertyValues = await GetPropertyValuesAsync(); foreach (PropertyValue propToSet in setProps) { // Microsoft Mini-redirector may update file creation date, modification date and access time passing properties: // <Win32CreationTime xmlns="urn:schemas-microsoft-com:">Thu, 28 Mar 2013 20:15:34 GMT</Win32CreationTime> // <Win32LastModifiedTime xmlns="urn:schemas-microsoft-com:">Thu, 28 Mar 2013 20:36:24 GMT</Win32LastModifiedTime> // <Win32LastAccessTime xmlns="urn:schemas-microsoft-com:">Thu, 28 Mar 2013 20:36:24 GMT</Win32LastAccessTime> // In this case update creation and modified date in your storage or do not save this properties at all, otherwise // Windows Explorer will display creation and modification date from this props and it will differ from the values // in the Created and Modified fields in your storage if (propToSet.QualifiedName.Namespace == "urn:schemas-microsoft-com:") { switch (propToSet.QualifiedName.Name) { case "Win32CreationTime": fileSystemInfo.CreationTimeUtc = DateTime.Parse(propToSet.Value, new System.Globalization.CultureInfo("en-US")).ToUniversalTime(); break; case "Win32LastModifiedTime": fileSystemInfo.LastWriteTimeUtc = DateTime.Parse(propToSet.Value, new System.Globalization.CultureInfo("en-US")).ToUniversalTime(); break; default: context.Logger.LogDebug(string.Format("Unspecified case: DavHierarchyItem.UpdateProperties {0} from {1} namesapce", propToSet.QualifiedName.Name, propToSet.QualifiedName.Namespace)); break; } } else { PropertyValue existingProp = propertyValues.FirstOrDefault(p => p.QualifiedName == propToSet.QualifiedName); if (existingProp != null) { existingProp.Value = propToSet.Value; } else { propertyValues.Add(propToSet); } } } propertyValues.RemoveAll(prop => delProps.Contains(prop.QualifiedName)); await fileSystemInfo.SetExtendedAttributeAsync(propertiesAttributeName, propertyValues); await context.socketService.NotifyRefreshAsync(GetParentPath(Path)); }
/// <summary> /// Deletes this item. /// </summary> /// <param name="multistatus">If some items fail to delete but operation in whole shall be continued, add /// information about the error into <paramref name="multistatus"/> using /// <see cref="MultistatusException.AddInnerException(string,ITHit.WebDAV.Server.DavException)"/>. /// </param> public abstract Task DeleteAsync(MultistatusException multistatus);
/// <summary> /// Moves this item to the destination folder under a new name. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">Name of the destination item.</param> /// <param name="multistatus">If some items fail to copy but operation in whole shall be continued, add /// information about the error into <paramref name="multistatus"/> using /// <see cref="MultistatusException.AddInnerException(string,ITHit.WebDAV.Server.DavException)"/>. /// </param> public abstract Task MoveToAsync(IItemCollectionAsync destFolder, string destName, MultistatusException multistatus);
/// <summary> /// Called when this folder is being moved or renamed. /// </summary> /// <param name="destFolder">Destination folder.</param> /// <param name="destName">New name of this folder.</param> /// <param name="multistatus">Information about child items that failed to move.</param> public override async Task MoveToAsync(IItemCollectionAsync destFolder, string destName, MultistatusException multistatus) { DavFolder targetFolder = destFolder as DavFolder; if (targetFolder == null) { throw new DavException("Target folder doesn't exist", DavStatus.CONFLICT); } if (IsRecursive(targetFolder)) { throw new DavException("Cannot move folder to its subtree.", DavStatus.FORBIDDEN); } string newDirPath = System.IO.Path.Combine(targetFolder.FullPath, destName); string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName); try { // Remove item with the same name at destination if it exists. IHierarchyItemAsync item = await context.GetHierarchyItemAsync(targetPath); if (item != null) { await item.DeleteAsync(multistatus); } await targetFolder.CreateFolderAsync(destName); } catch (DavException ex) { // Continue the operation but report error with destination path to client. multistatus.AddInnerException(targetPath, ex); return; } // Move child items. bool movedSuccessfully = true; IFolderAsync createdFolder = (IFolderAsync)await context.GetHierarchyItemAsync(targetPath); foreach (DavHierarchyItem item in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { try { await item.MoveToAsync(createdFolder, item.Name, multistatus); } catch (DavException ex) { // Continue the operation but report error with child item to client. multistatus.AddInnerException(item.Path, ex); movedSuccessfully = false; } } if (movedSuccessfully) { await DeleteAsync(multistatus); } }
/// <summary> /// Called when this folder is being copied. /// </summary> /// <param name="destFolder">Destination parent folder.</param> /// <param name="destName">New folder name.</param> /// <param name="deep">Whether children items shall be copied.</param> /// <param name="multistatus">Information about child items that failed to copy.</param> public override async Task CopyToAsync(IItemCollectionAsync destFolder, string destName, bool deep, MultistatusException multistatus) { DavFolder targetFolder = destFolder as DavFolder; if (targetFolder == null) { throw new DavException("Target folder doesn't exist", DavStatus.CONFLICT); } if (IsRecursive(targetFolder)) { throw new DavException("Cannot copy to subfolder", DavStatus.FORBIDDEN); } string newDirLocalPath = System.IO.Path.Combine(targetFolder.FullPath, destName); string targetPath = targetFolder.Path + EncodeUtil.EncodeUrlPart(destName); // Create folder at the destination. try { if (!Directory.Exists(newDirLocalPath)) { await targetFolder.CreateFolderAsync(destName); } } catch (DavException ex) { // Continue, but report error to client for the target item. multistatus.AddInnerException(targetPath, ex); } // Copy children. IFolderAsync createdFolder = (IFolderAsync)await context.GetHierarchyItemAsync(targetPath); foreach (DavHierarchyItem item in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page) { if (!deep && item is DavFolder) { continue; } try { await item.CopyToAsync(createdFolder, item.Name, deep, multistatus); } catch (DavException ex) { // If a child item failed to copy we continue but report error to client. multistatus.AddInnerException(item.Path, ex); } } }
/// <summary> /// Updates dead properties. /// </summary> /// <param name="setProps">Properties to set.</param> /// <param name="delProps">Properties to delete.</param> /// <param name="multistatus">Here we report problems with properties.</param> public async Task UpdatePropertiesAsync(IList <PropertyValue> setProps, IList <PropertyName> delProps, MultistatusException multistatus) { throw new DavException("Not implemented.", DavStatus.NOT_IMPLEMENTED); }
/// <summary> /// Deletes the principal. /// </summary> /// <param name="multistatus">We don't use it currently as there are no child objects.</param> public async Task DeleteAsync(MultistatusException multistatus) { throw new DavException("Not implemented.", DavStatus.NOT_IMPLEMENTED); }