public void TestRemoveHalfStack() { const long oid = 456499611; long id; { var item = new PlayerItem { BaseRecord = "for-testing-item-halfstack-removal", Mod = string.Empty, MinimumLevel = 200, LevelRequirement = 200, StackCount = 30, OnlineId = oid }; dao.Save(item); item.Id.Should().Be.GreaterThan(0); id = item.Id; } // Reduce to 15 { var reloaded = dao.GetByOnlineId(oid); reloaded.Id.Should().Be.EqualTo(id); reloaded.StackCount = 15; dao.Update(new List <PlayerItem> { reloaded }, true); } // Ensure the online ID has been cleared { var reloaded = dao.GetByOnlineId(oid); reloaded.Should().Be.Null(); } // Ensure the item still exists { var reloaded = dao.GetById(id); reloaded.Should().Not.Be.Null(); reloaded.Count.Should().Be.EqualTo(15); } // Ensure the old OID is marked for removal var deletionEntry = dao.GetItemsMarkedForOnlineDeletion().FirstOrDefault(m => m.OID == oid); deletionEntry.Should().Not.Be.Null(); }
private TransferStatus TransferItems(string transferFile, List <PlayerItem> items, int maxItemsToTransfer) { // Remove all items deposited (may or may not be less than the requested amount, if no inventory space is available) string error; int numItemsReceived = (int)items.Sum(item => Math.Max(1, item.StackCount)); int numItemsRequested = Math.Min(maxItemsToTransfer, numItemsReceived); _itemStatService.ApplyStatsToPlayerItems(items); // For item class? 'IsStackable' maybe? _stashManager.Deposit(transferFile, items, maxItemsToTransfer, out error); _dao.Update(items, true); int NumItemsTransferred = numItemsRequested - (numItemsRequested - (int)items.Sum(item => Math.Max(1, item.StackCount))); if (!string.IsNullOrEmpty(error)) { Logger.Warn(error); _browser.ShowMessage(error, "Error"); } return(new TransferStatus { NumItemsTransferred = NumItemsTransferred, NumItemsRequested = numItemsRequested }); }
private TransferStatus TransferItems(string transferFile, List <PlayerItem> items) { var numReceived = items.Sum(item => Math.Max(1, item.StackCount)); // Remove all items deposited (may or may not be less than the requested amount, if no inventory space is available) string error; int numItemsReceived = (int)items.Sum(item => Math.Max(1, item.StackCount)); _itemStatService.ApplyStatsToPlayerItems(items); // For item class? 'IsStackable' maybe? try { _transferStashService.Deposit(transferFile, items, out error); _dao.Update(items, true); var numItemsAfterTransfer = items.Sum(item => item.StackCount); long numItemsTransferred = numReceived - numItemsAfterTransfer; if (!string.IsNullOrEmpty(error)) { Logger.Warn(error); _browser.ShowMessage(error, UserFeedbackLevel.Danger); } return(new TransferStatus { NumItemsTransferred = (int)numItemsTransferred, }); } catch (TransferStashService.DepositException) { _browser.ShowMessage(RuntimeSettings.Language.GetTag("iatag_feedback_unable_to_deposit"), UserFeedbackLevel.Danger); return(new TransferStatus { NumItemsTransferred = 0, }); } }
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 void Update(IList <PlayerItem> items, bool clearOnlineId) { ThreadExecuter.Execute( () => repo.Update(items, clearOnlineId) ); }