/// <summary> /// Creates a folder in the remote storage. /// </summary> /// <param name="folderInfo">Information about the new folder.</param> /// <returns>New ETag returned from the remote storage.</returns> public async Task <string> CreateFolderAsync(IFolderBasicInfo folderInfo) { Uri newFolderUri = new Uri(new Uri(RemoteStorageUri), folderInfo.Name); await Program.DavClient.CreateFolderAsync(newFolderUri); return(null); // This implementation does not support ETags on folders. }
/// <summary> /// Creates or updates folder in the remote storage. /// </summary> /// <param name="remoteStoragePath">Path of the folder to be created or updated in the remote storage.</param> /// <param name="newInfo">New information about the folder, such as modification date, attributes, custom data, etc.</param> /// <param name="mode">Specifies if a new folder should be created or existing folder should be updated.</param> /// <returns>New ETag returned from the remote storage.</returns> protected async Task <string> CreateOrUpdateFolderAsync(string remoteStoragePath, IFolderBasicInfo newInfo, FileMode mode) { // Get ETag and lock-token here and send it to the remote storage with the new item content/info if needed. if (mode == FileMode.Open) { // Get ETag. string eTag = await ETag.GetETagAsync(UserFileSystemPath); // Get lock-token. string lockToken = Lock?.LockToken; } DirectoryInfo remoteStorageItem = new DirectoryInfo(remoteStoragePath); try { Program.RemoteStorageMonitorInstance.Enabled = false; // Disable RemoteStorageMonitor to avoid circular calls. remoteStorageItem.Create(); string userFileSystemPath = Mapping.ReverseMapPath(remoteStoragePath); if (mode == FileMode.Open) { // Verify that the item in the remote storage is not modified since it was downloaded to the user file system. // In your real-life application you will send the ETag to the server as part of the update request. FileSystemItemBasicInfo itemInfo = Mapping.GetUserFileSysteItemBasicInfo(remoteStorageItem); if (!(await ETag.ETagEqualsAsync(userFileSystemPath, itemInfo))) { throw new ConflictException(Modified.Server, "Item is modified in the remote storage, ETags not equal."); } } // Update ETag/LastWriteTime in user file system, so the synchronyzation or remote storage monitor would not start the new update. // This is only required to avoid circular updates because of the simplicity of this sample. // In your real-life application you will receive a new ETag from server in the update response. string eTag = newInfo.LastWriteTime.ToBinary().ToString(); await ETag.SetETagAsync(userFileSystemPath, eTag); remoteStorageItem.Attributes = newInfo.Attributes; remoteStorageItem.CreationTimeUtc = newInfo.CreationTime; remoteStorageItem.LastWriteTimeUtc = newInfo.LastWriteTime; remoteStorageItem.LastAccessTimeUtc = newInfo.LastAccessTime; remoteStorageItem.LastWriteTimeUtc = newInfo.LastWriteTime; return(eTag); } finally { Program.RemoteStorageMonitorInstance.Enabled = true; } }
/// <summary> /// Updates folder in the remote storage. /// </summary> /// <param name="folderInfo">New folder information.</param> /// <returns>New ETag returned from the remote storage.</returns> public async Task <string> UpdateAsync(IFolderBasicInfo folderInfo) { return(await CreateOrUpdateFolderAsync(RemoteStoragePath, folderInfo, FileMode.Open)); }
/// <summary> /// Creates a folder in the remote storage. /// </summary> /// <param name="folderInfo">Information about the new folder.</param> /// <returns>New ETag returned from the remote storage.</returns> public async Task <string> CreateFolderAsync(IFolderBasicInfo folderInfo) { string itemPath = Path.Combine(RemoteStoragePath, folderInfo.Name); return(await CreateOrUpdateFolderAsync(itemPath, folderInfo, FileMode.CreateNew)); }
/// <summary> /// Updates folder in the remote storage. /// </summary> /// <param name="folderInfo">New folder information.</param> /// <param name="lockInfo">Information about the lock. Caller passes null if the item is not locked.</param> /// <returns>New ETag returned from the remote storage.</returns> public async Task <string> UpdateAsync(IFolderBasicInfo folderInfo, ServerLockInfo lockInfo = null) { return(null); }