-
-
- var fullFileName = fileInfo.FullName;
- using (var gate = NetworkGate.Acquire(fullFileName, NetworkOperation.Uploading))
- {
- //Abort if the file is already being uploaded or downloaded
- if (gate.Failed)
- return;
-
- var cloudFile = action.CloudFile;
- var account = cloudFile.Account ?? accountInfo.UserName;
-
- var client = new CloudFilesClient(accountInfo);
- //Even if GetObjectInfo times out, we can proceed with the upload
- var info = client.GetObjectInfo(account, cloudFile.Container, cloudFile.Name);
- var cloudHash = info.Hash.ToLower();
-
- var hash = action.LocalHash.Value;
- var topHash = action.TopHash.Value;
-
- //If the file hashes match, abort the upload
- if (hash == cloudHash || topHash == cloudHash)
- {
- //but store any metadata changes
- StatusKeeper.StoreInfo(fullFileName, info);
- Log.InfoFormat("Skip upload of {0}, hashes match", fullFileName);
- return;
- }
-
- if (info.AllowedTo == "read")
- return;
-
- //Mark the file as modified while we upload it
- StatusKeeper.SetFileOverlayStatus(fullFileName, FileOverlayStatus.Modified);
- //And then upload it
-
- //Upload even small files using the Hashmap. The server may already containt
- //the relevant folder
-
- //First, calculate the tree hash
- var treeHash = await Signature.CalculateTreeHashAsync(fileInfo.FullName, accountInfo.BlockSize,
- accountInfo.BlockHash);
-
- await UploadWithHashMap(accountInfo, cloudFile, fileInfo, cloudFile.Name, treeHash);
-
- //If everything succeeds, change the file and overlay status to normal
- StatusKeeper.SetFileState(fullFileName, FileStatus.Unchanged, FileOverlayStatus.Normal);
- }
- //Notify the Shell to update the overlays
- NativeMethods.RaiseChangeNotification(fullFileName);
- StatusNotification.NotifyChangedFile(fullFileName);
- }
- catch (AggregateException ex)
- {
- var exc = ex.InnerException as WebException;
- if (exc == null)
- throw ex.InnerException;
- if (HandleUploadWebException(action, exc))
- return;
- throw;
- }
- catch (WebException ex)
- {
- if (HandleUploadWebException(action, ex))
- return;
- throw;