public async Task <Boolean> SynchronizeTrip(Trip _trip) { Boolean _status = true; ResponseContainer _folderDesc = null; ProgressUpdate(Res.GetString("SynchroTrip") + " " + _trip.Summary.FolderTopName, 0); String _request = API_METADATA + "/sandbox/" + _trip.Summary.FolderTopName + "?access_token=" + Token + "&hash=" + _trip.Hash; HttpResponseMessage _response = await SendRequest(_request); if (_response != null) { if (_response.StatusCode == HttpStatusCode.OK) { _folderDesc = await Serialization.DeserializeHttpToJson <ResponseContainer>(_response.Content) as ResponseContainer; } else if (_response.StatusCode == HttpStatusCode.NotFound) { _folderDesc = await CreateFolder(_trip.Summary.FolderTopName); } else if (_response.StatusCode == HttpStatusCode.NotModified) { return(true); } } if (_folderDesc.contents != null) { //check if all dropbox folders are synchronized with local folders foreach (ResponseElement _element in _folderDesc.contents) { if (_element.is_dir) { Boolean _found = false; foreach (Album _album in _trip.Albums) { if ("/" + _trip.DisplayName + "/" + _album.PathAlbum == _element.path) { _status &= await synchronizeAlbum(_album, _trip.DisplayName, _trip.Summary); _found = true; } if (!_status) { return(false); } } if (!_found) { _status &= await Delete(_element.path); } } else { //not a folder, delete file _status &= await Delete(_element.path); } } } //check if all local folders are synchronized with dropbox folders foreach (Album _album in _trip.Albums) { Boolean _found = false; if (_folderDesc.contents != null) { foreach (ResponseElement _element in _folderDesc.contents) { if (_album.DisplayName == _element.path) { //already synchronized _found = true; } } } if (!_found) { _status &= await synchronizeAlbum(_album, _trip.DisplayName, _trip.Summary); } if (!_status || CancelInProgress()) { return(false); } } //get hash code of synchronized folder _request = API_METADATA + "/sandbox/" + _trip.Summary.FolderTopName + "?access_token=" + Token; _response = await SendRequest(_request); if ((_response != null) && (_response.StatusCode == HttpStatusCode.OK)) { _folderDesc = await Serialization.DeserializeHttpToJson <ResponseContainer>(_response.Content) as ResponseContainer; _trip.Hash = _folderDesc.hash; return(true); } //should never reach this code return(false); }
public async override Task <SynchroManager.Status> Synchronize(SynchroHandle _syncHandle) { _handle = _syncHandle; SynchroManager.Status _syncStatus = SynchroManager.Status.ErrorOrNotConnected; if (!Connection.InternetAccess()) { return(_syncStatus); } ProgressUpdate(Res.GetString("SynchroStart"), 0); //list top-folder, login if not logged (reentrant) ResponseContainer _folderDesc = await MetadataTopFolder(SyncMngr, true); if ((_folderDesc != null) && (_folderDesc.contents != null)) { Boolean _status = true; List <String> _listTripNames = new List <string>(); foreach (ResponseElement _element in _folderDesc.contents) { if (_element.is_dir) { _listTripNames.Add(_element.path); } } // check if trip folder name match, rename if necessary foreach (String _tripName in _listTripNames) { // no error check since the folder may not exist if ((_syncHandle.TripSummary.SyncDropbox.PreviousName != null) && (_syncHandle.TripSummary.SyncDropbox.PreviousName != "")) { if (_syncHandle.TripSummary.SyncDropbox.PreviousName == _tripName) { await RenameFolder(_tripName, _syncHandle.TripSummary.FolderTopName); } } // check cancellation if (CancelInProgress()) { return(SynchroManager.Status.NoRequest); } } Trip _trip = await Trip.LoadFromSummary(_syncHandle.TripSummary); UploadList = new List <UploadOperation>(); _status &= await SynchronizeTrip(_trip); // check error status if (CancelInProgress()) { return(SynchroManager.Status.NoRequest); } else if (!_status) { return(SynchroManager.Status.ErrorOrNotConnected); } _status &= await UploadAll(UploadList); // check error status if (CancelInProgress()) { _syncStatus = SynchroManager.Status.NoRequest; } else if (!_status) { _syncStatus = SynchroManager.Status.ErrorOrNotConnected; } else { _syncStatus = SynchroManager.Status.Synchronized; } return(_syncStatus); } else { ProgressFinished(""); return(SynchroManager.Status.ErrorOrNotConnected); } }