From 1865ad904d16c957b461d4f539cd762dfaf29dae Mon Sep 17 00:00:00 2001 From: Panagiotis Kanavos Date: Mon, 30 Apr 2012 10:31:18 +0300 Subject: [PATCH] Added selective sync check after resuming sync --- trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs | 6 +-- trunk/Pithos.Core/Agents/Downloader.cs | 40 ++++++++++++-------- trunk/Pithos.Core/Agents/SelectiveUris.cs | 13 ++++--- trunk/Pithos.Core/Agents/Uploader.cs | 34 +++++++++++------ 4 files changed, 58 insertions(+), 35 deletions(-) diff --git a/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs b/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs index 6190ee4..1065eb9 100644 --- a/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs +++ b/trunk/Pithos.Client.WPF/Properties/AssemblyInfo.cs @@ -92,6 +92,6 @@ using System.Windows; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.7.20425.0")] -[assembly: AssemblyFileVersionAttribute("0.7.20425.0")] +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.7.20430.0")] +[assembly: AssemblyFileVersionAttribute("0.7.20430.0")] diff --git a/trunk/Pithos.Core/Agents/Downloader.cs b/trunk/Pithos.Core/Agents/Downloader.cs index 4075774..ef2c5a9 100644 --- a/trunk/Pithos.Core/Agents/Downloader.cs +++ b/trunk/Pithos.Core/Agents/Downloader.cs @@ -52,10 +52,10 @@ namespace Pithos.Core.Agents Contract.EndContractBlock(); using (ThreadContext.Stacks["Operation"].Push("DownloadCloudFile")) { - // var cancellationToken=_cts.Token;// .ThrowIfCancellationRequested(); - - cancellationToken.ThrowIfCancellationRequested(); - await UnpauseEvent.WaitAsync(); + // var cancellationToken=_cts.Token;// .ThrowIfCancellationRequested(); + + if (await WaitOrAbort(cloudFile, cancellationToken)) + return; var localPath = FileInfoExtensions.GetProperFilePathCapitalization(filePath); @@ -152,10 +152,10 @@ namespace Pithos.Core.Agents throw new ArgumentNullException("serverHash"); if (cloudFile.IsDirectory) throw new ArgumentException("cloudFile is a directory, not a file", "cloudFile"); - Contract.EndContractBlock(); - - cancellationToken.ThrowIfCancellationRequested(); - await UnpauseEvent.WaitAsync(); + Contract.EndContractBlock(); + + if (await WaitOrAbort(cloudFile, cancellationToken)) + return; var fileAgent = GetFileAgent(accountInfo); var localPath = FileInfoExtensions.GetProperFilePathCapitalization(filePath); @@ -175,9 +175,9 @@ namespace Pithos.Core.Agents var localHashes = treeHash.HashDictionary; ReportDownloadProgress(Path.GetFileName(localPath), 0, upHashes.Length, cloudFile.Bytes); for (int i = 0; i < upHashes.Length; i++) - { - cancellationToken.ThrowIfCancellationRequested(); - await UnpauseEvent.WaitAsync(); + { + if (await WaitOrAbort(cloudFile, cancellationToken)) + return; //For every non-matching hash var upHash = upHashes[i]; @@ -236,10 +236,10 @@ namespace Pithos.Core.Agents throw new ArgumentException("The localPath must be rooted", "filePath"); if (cloudFile.IsDirectory) throw new ArgumentException("cloudFile is a directory, not a file", "cloudFile"); - Contract.EndContractBlock(); - - cancellationToken.ThrowIfCancellationRequested(); - await UnpauseEvent.WaitAsync(); + Contract.EndContractBlock(); + + if (await WaitOrAbort(cloudFile, cancellationToken)) + return; var localPath = FileInfoExtensions.GetProperFilePathCapitalization(filePath); StatusNotification.SetPithosStatus(PithosStatus.LocalSyncing, String.Format("Downloading {0}", Path.GetFileName(localPath))); @@ -325,6 +325,16 @@ namespace Pithos.Core.Agents private static FileAgent GetFileAgent(AccountInfo accountInfo) { return AgentLocator.Get(accountInfo.AccountPath); + } + + private async Task WaitOrAbort(ObjectInfo cloudFile, CancellationToken token) + { + token.ThrowIfCancellationRequested(); + await UnpauseEvent.WaitAsync(); + var shouldAbort = !Selectives.IsSelected(cloudFile); + if (shouldAbort) + Log.InfoFormat("Aborting [{0}]", cloudFile.Uri); + return shouldAbort; } [Import] diff --git a/trunk/Pithos.Core/Agents/SelectiveUris.cs b/trunk/Pithos.Core/Agents/SelectiveUris.cs index 63cbbd6..884d7d8 100644 --- a/trunk/Pithos.Core/Agents/SelectiveUris.cs +++ b/trunk/Pithos.Core/Agents/SelectiveUris.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel.Composition; using System.IO; @@ -13,14 +14,14 @@ namespace Pithos.Core.Agents public class Selectives { - public Dictionary> SelectiveUris { get; private set; } + public ConcurrentDictionary> SelectiveUris { get; private set; } - private Dictionary> SelectivePaths { get; set; } + private ConcurrentDictionary> SelectivePaths { get; set; } public Selectives() - { - SelectiveUris = new Dictionary>(); - SelectivePaths = new Dictionary>(); + { + SelectiveUris = new ConcurrentDictionary>(); + SelectivePaths = new ConcurrentDictionary>(); } public void SetSelectedUris(AccountInfo account,List uris) diff --git a/trunk/Pithos.Core/Agents/Uploader.cs b/trunk/Pithos.Core/Agents/Uploader.cs index c962797..07e1072 100644 --- a/trunk/Pithos.Core/Agents/Uploader.cs +++ b/trunk/Pithos.Core/Agents/Uploader.cs @@ -260,9 +260,9 @@ namespace Pithos.Core.Agents using (StatusNotification.GetNotifier("Uploading {0}", "Finished Uploading {0}", fileInfo.Name)) { - token.ThrowIfCancellationRequested(); - await UnpauseEvent.WaitAsync(); - + if (await WaitOrAbort(cloudFile, token)) + return; + var fullFileName = fileInfo.GetProperCapitalization(); var account = cloudFile.Account ?? accountInfo.UserName; @@ -276,16 +276,18 @@ namespace Pithos.Core.Agents ReportUploadProgress(fileInfo.Name, block++, missingHashes.Count, fileInfo.Length); //If the server returns no missing hashes, we are done while (missingHashes.Count > 0) - { + { + + if (await WaitOrAbort(cloudFile, token)) + return; - token.ThrowIfCancellationRequested(); - await UnpauseEvent.WaitAsync(); var buffer = new byte[accountInfo.BlockSize]; foreach (var missingHash in missingHashes) - { - token.ThrowIfCancellationRequested(); - await UnpauseEvent.WaitAsync(); + { + if (await WaitOrAbort(cloudFile, token)) + return; + //Find the proper block var blockIndex = treeHash.HashDictionary[missingHash]; @@ -313,8 +315,18 @@ namespace Pithos.Core.Agents ReportUploadProgress(fileInfo.Name, missingHashes.Count, missingHashes.Count, fileInfo.Length); } - } - + } + + private async Task WaitOrAbort(ObjectInfo cloudFile, CancellationToken token) + { + token.ThrowIfCancellationRequested(); + await UnpauseEvent.WaitAsync(); + var shouldAbort = !Selectives.IsSelected(cloudFile); + if (shouldAbort) + Log.InfoFormat("Aborting [{0}]",cloudFile.Uri); + return shouldAbort; + } + private void ReportUploadProgress(string fileName, int block, int totalBlocks, long fileSize) { StatusNotification.Notify(totalBlocks == 0 -- 1.7.10.4