public async Task <bool> StartSync() { if (!SyncDbUtils.LockFolderSyncInfo(folderSyncInfo)) { return(false); } try { client = await ClientService.GetClient(); if (client == null) { // ERROR throw new Exception("Error creating webdav client"); } int changedCount = 0; List <SyncInfoDetail> oldList = SyncDbUtils.GetAllSyncInfoDetails(folderSyncInfo); Debug.WriteLine("Sid List before Sync: "); foreach (SyncInfoDetail detail in oldList) { Debug.WriteLine("Detail: " + detail.ToString()); } var sid = SyncDbUtils.GetSyncInfoDetail(resourceInfo, folderSyncInfo); var errorCount = 0; try { if (sid == null) { sid = new SyncInfoDetail(folderSyncInfo) { Path = resourceInfo.Path, FilePath = baseFolder.Path, }; SyncDbUtils.SaveSyncInfoDetail(sid); } else { sidList.Remove(sid); sid.Error = null; } changedCount = await SyncFolder(resourceInfo, baseFolder); foreach (SyncInfoDetail detail in oldList) { if (!sidList.Contains(detail) && detail.FilePath.StartsWith(baseFolder.Path)) { // The items left here must have been deleted both remotely and locally so the sid is obsolete. SyncDbUtils.DeleteSyncInfoDetail(detail, false); changedCount++; } } errorCount = SyncDbUtils.GetErrorConflictCount(folderSyncInfo); } catch (Exception e) { sid.Error = e.Message; errorCount++; } SyncDbUtils.SaveSyncInfoDetail(sid); List <SyncInfoDetail> newSidList = SyncDbUtils.GetAllSyncInfoDetails(folderSyncInfo); Debug.WriteLine("Sid List after Sync: "); foreach (SyncInfoDetail detail in newSidList) { Debug.WriteLine("Detail: " + detail.ToString()); } ToastNotificationService.ShowSyncFinishedNotification(folderSyncInfo.Path, changedCount, errorCount); return(errorCount == 0); } finally { SyncDbUtils.UnlockFolderSyncInfo(folderSyncInfo); } }
public async Task <bool> StartSync() { if (!SyncDbUtils.LockFolderSyncInfo(_folderSyncInfo)) { return(false); } try { _client = await ClientService.GetClient(); if (_client == null) { // ERROR throw new NullReferenceException(_resourceLoader.GetString(ResourceConstants.SyncService_Error_CannotCreateClient)); } var changedCount = 0; var oldList = SyncDbUtils.GetAllSyncInfoDetails(_folderSyncInfo); Debug.WriteLine("Sid List before Sync: "); foreach (var detail in oldList) { Debug.WriteLine("Detail: " + detail); } var sid = SyncDbUtils.GetSyncInfoDetail(_resourceInfo, _folderSyncInfo); var errorCount = 0; try { if (sid == null) { sid = new SyncInfoDetail(_folderSyncInfo) { Path = _resourceInfo.Path, FilePath = _baseFolder.Path, }; SyncDbUtils.SaveSyncInfoDetail(sid); } else { _sidList.Remove(sid); sid.Error = null; } changedCount = await SyncFolder(_resourceInfo, _baseFolder); foreach (var detail in oldList) { if (_sidList.Contains(detail) || !detail.FilePath.StartsWith(_baseFolder.Path)) { continue; } // The items left here must have been deleted both remotely and locally so the sid is obsolete. SyncDbUtils.DeleteSyncInfoDetail(detail, false); changedCount++; } errorCount = SyncDbUtils.GetErrorConflictCount(_folderSyncInfo); } catch (Exception e) { sid.Error = string.Format(_resourceLoader.GetString("UnexpectedException"), e.Message); errorCount++; } SyncDbUtils.SaveSyncInfoDetail(sid); var newSidList = SyncDbUtils.GetAllSyncInfoDetails(_folderSyncInfo); Debug.WriteLine("Sid List after Sync: "); foreach (var detail in newSidList) { Debug.WriteLine("Detail: " + detail); } ToastNotificationService.ShowSyncFinishedNotification(_folderSyncInfo.Path, changedCount, errorCount); return(errorCount == 0); } finally { SyncDbUtils.UnlockFolderSyncInfo(_folderSyncInfo); } }