private FileTransfer FetchOrInsertInProgressFileTransfer(string folderId, string path, ItemChangedItemType itemType, ItemChangedActionType actionType) { var key = new FolderPathKey(folderId, path); bool created = false; FileTransfer fileTransfer; lock (this.transfersLock) { if (!this.inProgressTransfers.TryGetValue(key, out fileTransfer) && this.folderManager.TryFetchById(folderId, out var folder)) { created = true; fileTransfer = new FileTransfer(folder, path, itemType, actionType); logger.Debug("Created file transfer: {0}", fileTransfer); this.inProgressTransfers.Add(key, fileTransfer); } } if (created) { this.OnTransferStarted(fileTransfer); } return(fileTransfer); }
private void CompleteFileTransfer(FileTransfer fileTransfer, string error) { // This is always called from within a lock, but you can't be too sure... lock (this.transfersLock) { var key = new FolderPathKey(fileTransfer.FolderId, fileTransfer.Path); fileTransfer.SetComplete(error); this.inProgressTransfers.Remove(key); logger.Debug("File Transfer set to complete: {0}", fileTransfer); this.completedTransfers.Enqueue(fileTransfer); if (this.completedTransfers.Count > maxCompletedTransfers) { this.completedTransfers.Dequeue(); } List <FileTransfer> recentlySynchronizedList; if (!this.recentlySynchronized.TryGetValue(fileTransfer.FolderId, out recentlySynchronizedList)) { recentlySynchronizedList = new List <FileTransfer>(); this.recentlySynchronized[fileTransfer.FolderId] = recentlySynchronizedList; } recentlySynchronizedList.Add(fileTransfer); } }
private void CompleteFileTransfer(FileTransfer fileTransfer, string error) { // This is always called from within a lock, but you can't be too sure... lock (this.transfersLock) { var key = new FolderPathKey(fileTransfer.FolderId, fileTransfer.Path); bool isNewError = false; if (error == null) { this.currentlyFailingTransfers.Remove(key); } else { FailingTransfer failingTransfer; if (!this.currentlyFailingTransfers.TryGetValue(key, out failingTransfer) || failingTransfer.Error != error) { // Remove will only do something in the case that the failure existed, but the error changed this.currentlyFailingTransfers.Remove(key); this.currentlyFailingTransfers.Add(key, new FailingTransfer(fileTransfer.FolderId, fileTransfer.Path, error)); isNewError = true; } } fileTransfer.SetComplete(error, isNewError); this.inProgressTransfers.Remove(key); logger.Debug("File Transfer set to complete: {0}", fileTransfer); this.completedTransfers.Enqueue(fileTransfer); if (this.completedTransfers.Count > maxCompletedTransfers) { this.completedTransfers.Dequeue(); } List <FileTransfer> recentlySynchronizedList; if (!this.recentlySynchronized.TryGetValue(fileTransfer.FolderId, out recentlySynchronizedList)) { recentlySynchronizedList = new List <FileTransfer>(); this.recentlySynchronized[fileTransfer.FolderId] = recentlySynchronizedList; } recentlySynchronizedList.Add(fileTransfer); } }
private void ItemDownloadProgressChanged(object sender, ItemDownloadProgressChangedEventArgs e) { logger.Debug("Item progress changed. Folder: {0}, Item: {1}", e.Folder, e.Item); // If we didn't see the started event, tough. We don't have enough information to re-create it... var key = new FolderPathKey(e.Folder, e.Item); FileTransfer fileTransfer; lock (this.transfersLock) { if (!this.inProgressTransfers.TryGetValue(key, out fileTransfer)) { return; // Nothing we can do... } fileTransfer.SetDownloadProgress(e.BytesDone, e.BytesTotal); logger.Debug("File transfer progress changed: {0}", fileTransfer); } this.OnTransferStateChanged(fileTransfer); }