Click or drag to resize

IFileSystemItemDeleteAsync Method

IT Hit User File System
Called when a file or a folder is deleted from user file system.

Namespace:  ITHit.FileSystem
Assembly:  ITHit.FileSystem (in ITHit.FileSystem.dll) Version: 1.4.4298.0
Syntax
Task DeleteAsync(
	IOperationContext operationContext,
	IConfirmationResultContext resultContext
)

Parameters

operationContext
Type: ITHit.FileSystemIOperationContext
Provides information about the environment.
resultContext
Type: ITHit.FileSystemIConfirmationResultContext
Used to confirm the operation, report progress and status to the platform.

Return Value

Type: Task
.
Remarks

This method is called by the Engine when a file or a folder is being deleted. In your method implementation you will either delete the file or folder in your remote storage and confirm the operation or will just confirm the operation, while the acual deletion of the file/folder in the remote storage will be performed during your synchronization process.

Inside this method you will accept or reject the operation. To confirm the operation call the ReturnConfirmationResult method of the IConfirmationResultContext interface, passed via resultContext parameter. See IConfirmationResultContext interface description for details about confirming or rejecting the operation.

When a placeholder file with content on local disk is being deleted it is also being moved to a recycle bin after calling this method. After calling this method, the Engine calls MoveToAsync(String, IOperationContext, IConfirmationResultContext) method with a recycle bin path. When a placeholder file without content on local disk is being deleted, only this method is called, without moving the file into a recycle bin.

Examples

The code below is part of 'VirtualFileSystem' C# sample provided with the SDK.

C#
public async Task DeleteAsync(IOperationContext operationContext, IConfirmationResultContext resultContext)
{
    Logger.LogMessage("IFileSystemItem.DeleteAsync()", this.UserFileSystemPath);

    string userFileSystemPath = this.UserFileSystemPath;
    string remoteStoragePath = null;
    try
    {
        remoteStoragePath = Mapping.MapPath(userFileSystemPath);

        if (Engine.ChangesProcessingEnabled
            && !FsPath.AvoidSync(userFileSystemPath))
        {
            await new RemoteStorageItem(userFileSystemPath).DeleteAsync();
            Logger.LogMessage("Deleted succesefully", remoteStoragePath);
        }
    }
    catch (Exception ex)
    {
        // remove try-catch when error processing inside CloudProvider is fixed.
        Logger.LogError("Delete failed", remoteStoragePath, null, ex);
    }
    finally
    {
        resultContext.ReturnConfirmationResult();
    }
}
C#
public async Task DeleteAsync(IOperationContext operationContext, IConfirmationResultContext resultContext)
{
    Logger.LogMessage("IFileSystemItem.DeleteAsync()", this.UserFileSystemPath);

    string userFileSystemPath = this.UserFileSystemPath;
    string remoteStoragePath = null;
    try
    {
        if (Engine.ChangesProcessingEnabled
            && !FsPath.AvoidSync(userFileSystemPath))
        {
            await new RemoteStorageRawItem(userFileSystemPath, Logger).DeleteAsync();
            Logger.LogMessage("Deleted item in remote storage succesefully", userFileSystemPath);
        }
    }
    catch (Exception ex)
    {
        Logger.LogError("Delete failed", remoteStoragePath, null, ex);
    }
    finally
    {
        resultContext.ReturnConfirmationResult();
    }
}
See Also