/// <inheritdoc/> public async Task OpenAsync(IOperationContext operationContext, IResultContext context) { Logger.LogMessage("IFile.OpenAsync()", UserFileSystemPath); // Auto-lock the file. string userFileSystemFilePath = UserFileSystemPath; if (Engine.ChangesProcessingEnabled && FsPath.Exists(userFileSystemFilePath)) { if (Program.Settings.AutoLock && !FsPath.AvoidAutoLock(userFileSystemFilePath) && !await Lock.IsLockedAsync(userFileSystemFilePath) && FsPath.IsWriteLocked(userFileSystemFilePath) && !new PlaceholderFile(userFileSystemFilePath).IsNew()) { try { await new RemoteStorageRawItem(userFileSystemFilePath, Logger).LockAsync(LockMode.Auto); } catch (ClientLockFailedException ex) { // Lock file is blocked by the concurrent thread. This is a normal behaviour. Logger.LogMessage(ex.Message, userFileSystemFilePath); } } } }
/// <inheritdoc/> public async Task DeleteCompletionAsync(IOperationContext operationContext, IResultContext resultContext) { Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(DeleteCompletionAsync)}()", this.UserFileSystemPath); /* * string userFileSystemPath = this.UserFileSystemPath; * string remoteStoragePath = null; * try * { * if (Engine.ChangesProcessingEnabled * && !FsPath.AvoidSync(userFileSystemPath)) * { * await new RemoteStorageRawItem<TItemType>(userFileSystemPath, VirtualDrive, Logger).DeleteAsync(); * Logger.LogMessage("Deleted item in remote storage succesefully", userFileSystemPath); * } * } * catch (Exception ex) * { * Logger.LogError("Delete in remote storage failed", remoteStoragePath, null, ex); * * // Rethrow the exception preserving stack trace of the original exception. * System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw(); * } */ }
/// <inheritdoc/> public async Task DeleteCompletionAsync(IOperationContext operationContext, IResultContext resultContext) { // On Windows, for move with overwrite on folders to function correctly, // the deletion of the folder in the remote storage must be done in DeleteCompletionAsync() // Otherwise the folder will be deleted before files in it can be moved. Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(DeleteCompletionAsync)}()", UserFileSystemPath); FileSystemInfo remoteStorageItem = FsPath.GetFileSystemItem(RemoteStoragePath); if (remoteStorageItem != null) { if (remoteStorageItem is FileInfo) { remoteStorageItem.Delete(); } else { (remoteStorageItem as DirectoryInfo).Delete(true); } Logger.LogMessage("Deleted item in remote storage succesefully", UserFileSystemPath); } Engine.CustomDataManager(UserFileSystemPath, Logger).Delete(); }
/// <inheritdoc/> public async Task OpenAsync(IOperationContext operationContext, IResultContext context) { Logger.LogMessage($"{nameof(IFile)}.{nameof(OpenAsync)}()", UserFileSystemPath); // Auto-lock the file. string userFileSystemFilePath = UserFileSystemPath; if (Engine.ChangesProcessingEnabled && FsPath.Exists(userFileSystemFilePath)) { if (VirtualDrive.Settings.AutoLock && !FsPath.AvoidAutoLock(userFileSystemFilePath) && !await VirtualDrive.LockManager(userFileSystemFilePath, Logger).IsLockedAsync() && FsPath.IsWriteLocked(userFileSystemFilePath) && !new PlaceholderFile(userFileSystemFilePath).IsNew(VirtualDrive)) { RemoteStorageRawItem <IVirtualFile> remoteStorageRawItem = new RemoteStorageRawItem <IVirtualFile>(userFileSystemFilePath, VirtualDrive, Logger); if (await remoteStorageRawItem.IsLockSupportedAsync()) { try { await remoteStorageRawItem.LockAsync(LockMode.Auto); } catch (ClientLockFailedException ex) { // Lock file is blocked by a concurrent thread. This is a normal behaviour. Logger.LogMessage(ex.Message, userFileSystemFilePath); } } } } }
public void UpdateContext(IResultContext <IEnumerable <V> > context) { lock (_syncLock) { _context = context; UpdateTask(); } }
//$> /// <summary> /// Simulates network delays and reports file transfer progress for demo purposes. /// </summary> /// <param name="fileLength">Length of file.</param> /// <param name="context">Context to report progress to.</param> protected void SimulateNetworkDelay(long fileLength, IResultContext resultContext) { if (Program.Settings.NetworkSimulationDelayMs > 0) { int numProgressResults = 5; for (int i = 0; i < numProgressResults; i++) { resultContext.ReportProgress(fileLength, i * fileLength / numProgressResults); Thread.Sleep(Program.Settings.NetworkSimulationDelayMs); } } }
/// <inheritdoc/> public async Task DeleteCompletionAsync(IOperationContext operationContext, IResultContext resultContext) { // On Windows, for move with overwrite on folders to function correctly, // the deletion of the folder in the remote storage must be done in DeleteCompletionAsync() // Otherwise the folder will be deleted before files in it can be moved. Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(DeleteCompletionAsync)}()", UserFileSystemPath); await Program.DavClient.DeleteAsync(new Uri(RemoteStoragePath)); Engine.CustomDataManager(UserFileSystemPath, Logger).Delete(); }
public ResultContextItem(IResultContext <IEnumerable <V> > context, params V[] items) { _context = context; if (null != items && 0 < items.Length) { foreach (var item in items) { _queue.Enqueue(item); } } }
public void Dispose() { if (null != _context) { if (!_context.IsCancelled && !_context.IsCompleted && 0 < _queue.Count) { _context.SetResult(_queue.ToArray()); } _context.Dispose(); _context = null; } }
/// <inheritdoc/> public async Task CloseAsync(IOperationContext operationContext, IResultContext context) { // Here, if the file in the user file system is modified (not in-sync), you will send the file content, // creation time, modification time and attributes to the remote storage. // We also send ETag, to make sure the changes on the server, if any, are not overwritten. Logger.LogMessage("IFile.CloseAsync()", UserFileSystemPath); string userFileSystemFilePath = UserFileSystemPath; // In case the file is moved it does not exist in user file system when CloseAsync() is called. if (Engine.ChangesProcessingEnabled && FsPath.Exists(userFileSystemFilePath) && !FsPath.AvoidSync(userFileSystemFilePath)) { // In case the file is overwritten it is converted to a regular file prior to CloseAsync(). // we need to convert it back into file/folder placeholder. if (!PlaceholderItem.IsPlaceholder(userFileSystemFilePath)) { PlaceholderItem.ConvertToPlaceholder(userFileSystemFilePath, false); Logger.LogMessage("Converted to placeholder", userFileSystemFilePath); } try { if (PlaceholderItem.GetItem(userFileSystemFilePath).IsNew(VirtualDrive)) { // Create new file in the remote storage. await new RemoteStorageRawItem <IVirtualFile>(userFileSystemFilePath, VirtualDrive, Logger).CreateAsync(); } else if (!PlaceholderItem.GetItem(userFileSystemFilePath).IsMoved()) { // Send content to remote storage. Unlock if auto-locked. await new RemoteStorageRawItem <IVirtualFile>(userFileSystemFilePath, VirtualDrive, Logger).UpdateAsync(); } } catch (IOException ex) { // Either the file is already being synced in another thread or client or server file is blocked by concurrent process. // This is a normal behaviour. // The file must be synched by your synchronyzation service at a later time, when the file becomes available. Logger.LogMessage("Failed to upload file. Possibly in use by an application or blocked for synchronization in another thread:", ex.Message); } } }
/// <inheritdoc/> public async Task CloseAsync(IOperationContext operationContext, IResultContext context) { // Here, if the file in user file system is modified (not in-sync), we send file content, // creation time, modification time and attributes to remote storage. // We also create new ETag, associate it with a file in user file system and send it to the server. LogMessage("IFile.CloseAsync()", this.FullPath); string userFileSystemFilePath = this.FullPath; // In case the file is moved it does not exist in user file system when Close() is called. if (!FsPath.Exists(userFileSystemFilePath) || FsPath.AvoidSync(userFileSystemFilePath)) { return; } // In case the file is overwritten it is converted to a regular file prior to Close(). // we need to convert it back into file/folder placeholder. if (!PlaceholderItem.IsPlaceholder(userFileSystemFilePath)) { PlaceholderItem.ConvertToPlaceholder(userFileSystemFilePath, false); LogMessage("Converted to placeholder:", userFileSystemFilePath); } if (!PlaceholderItem.GetItem(userFileSystemFilePath).GetInSync()) { LogMessage("Changed:", userFileSystemFilePath); string remoteStorageFilePath = Mapping.MapPath(userFileSystemFilePath); try { await new RemoteStorageItem(remoteStorageFilePath).UpdateAsync(userFileSystemFilePath); LogMessage("Updated succesefully:", remoteStorageFilePath); } catch (IOException ex) { // Either the file is already being synced in another thread or client or server file is blocked by concurrent process. // This is a normal behaviour. // The file must be synched by your synchronyzation service at a later time, when the file becomes available. LogMessage("Failed to upload file. Possibly in use by an application or blocked for synchronization in another thread:", ex.Message); } } }
public async Task UpdateAsync(Stream stream, IResultContext context) { Logger.LogMessage($"IFile.UpdateAsync", UserFileSystemPath); Logger.LogMessage("Sending to remote storage", UserFileSystemPath); FileInfo remoteStorageItem = new FileInfo(RemoteStoragePath); await using (FileStream remoteStorageStream = remoteStorageItem.Open(FileMode.Open, FileAccess.Write, FileShare.None)) { string userFileSystemPath = Mapping.ReverseMapPath(RemoteStoragePath); // update remote storage file content. if (stream != null) { await stream.CopyToAsync(remoteStorageStream); remoteStorageStream.SetLength(stream.Length); } } Logger.LogMessage("Sent to remote storage succesefully", UserFileSystemPath); }
/// <inheritdoc/> public async Task MoveToCompletionAsync(IMoveCompletionContext moveCompletionContext, IResultContext resultContext) { string userFileSystemNewPath = this.UserFileSystemPath; string userFileSystemOldPath = moveCompletionContext.SourcePath; Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(MoveToCompletionAsync)}()", userFileSystemOldPath, userFileSystemNewPath); if (Engine.ChangesProcessingEnabled) { if (FsPath.Exists(userFileSystemNewPath)) { FileSystemItemTypeEnum itemType = FsPath.GetItemType(userFileSystemNewPath); await new RemoteStorageRawItem <TItemType>(userFileSystemNewPath, VirtualDrive, Logger).MoveToCompletionAsync(); } } }
public async Task OpenAsync(IOperationContext operationContext, IResultContext context) { throw new NotImplementedException(); }
public ResultService(IResultContext context) { _context = context; }
/// <inheritdoc/> public async Task MoveToCompletionAsync(IMoveCompletionContext moveCompletionContext, IResultContext resultContext) { string userFileSystemNewPath = this.UserFileSystemPath; string userFileSystemOldPath = moveCompletionContext.SourcePath; Logger.LogMessage($"{nameof(IFileSystemItem)}.{nameof(MoveToCompletionAsync)}()", userFileSystemOldPath, userFileSystemNewPath); }
/// <inheritdoc/> public async Task DeleteCompletionAsync(IOperationContext operationContext, IResultContext resultContext) { throw new NotImplementedException(); }
/// <inheritdoc/> public async Task MoveToCompletionAsync(IMoveCompletionContext moveCompletionContext, IResultContext resultContext) { throw new NotImplementedException(); }
/// <inheritdoc/> public async Task OpenAsync(IOperationContext operationContext, IResultContext context) { LogMessage("IFile.OpenAsync()", this.FullPath); }
/// <inheritdoc/> public async Task CloseAsync(IOperationContext operationContext, IResultContext context) { Logger.LogMessage($"{nameof(IFile)}.{nameof(CloseAsync)}()", UserFileSystemPath); }
//$> /// <summary> /// Simulates network delays and reports file transfer progress for demo purposes. /// </summary> /// <param name="fileLength">Length of file.</param> /// <param name="context">Context to report progress to.</param> protected void SimulateNetworkDelay(long fileLength, IResultContext resultContext) { throw new NotImplementedException(); }
/// <summary> /// Simulates network delays and reports file transfer progress for demo purposes. /// </summary> /// <param name="fileLength">Length of file.</param> /// <param name="context">Context to report progress to.</param> protected void SimulateNetworkDelay(long fileLength, IResultContext resultContext) { //Thread.Sleep(10000); }
public ResultContextItem(IResultContext <IEnumerable <V> > context) : this(context, null) { }