private void Upload() { PlayerItem item = null; do { item = _playerItemDao.GetSingleUnsynchronizedItem(); if (item != null) { var simplified = Map(item); var json = JsonConvert.SerializeObject(simplified); var result = Post($"token={_token}&item={json}", UploadUrl); if (string.IsNullOrEmpty(result)) { Logger.Warn("Error uploading items to remote backup server"); _nextUpload = DateTime.UtcNow.AddMinutes(30); return; } var obj = JsonConvert.DeserializeObject <PlayerItemBackupUploadResponse>(result); if (!obj.Success) { HandleAuthenticationIssues(obj.ErrorCode); Logger.Warn($"Failed synchronizing item with backup, error code {obj.ErrorCode}"); } else { item.OnlineId = obj.OID; _playerItemDao.Update(item); Properties.Settings.Default.LastOnlineBackup = obj.Modified; } } } while (item != null); Properties.Settings.Default.Save(); _nextUpload = DateTime.UtcNow.AddMinutes(3); }
public PlayerItem GetSingleUnsynchronizedItem() { return(ThreadExecuter.Execute( () => repo.GetSingleUnsynchronizedItem() )); }