diff --git a/POEApi.Model/POEModel.cs b/POEApi.Model/POEModel.cs index 010d26f4..c80410cc 100644 --- a/POEApi.Model/POEModel.cs +++ b/POEApi.Model/POEModel.cs @@ -269,14 +269,22 @@ public List GetCharacters(string realm) return GetProperObjectFromTransport>(Transport.GetCharacters(realm)); } - public List GetInventory(string characterName, bool forceRefresh, string accountName, string realm) + public List GetInventory(string characterName, int index, bool forceRefresh, string accountName, string realm) { try { + onStashLoaded(POEEventState.BeforeEvent, index, -1); + if (downOnlyMyCharacters && !Settings.Lists["MyCharacters"].Contains(characterName)) return new List(); - Inventory item = GetProperObjectFromTransport(Transport.GetInventory(characterName, forceRefresh, accountName, realm)); + Inventory item = null; + using (var stream = Transport.GetInventory(characterName, forceRefresh, accountName, realm)) + { + item = GetProperObjectFromTransport(stream); + } + + onStashLoaded(POEEventState.AfterEvent, index, -1); if (item?.Items == null) return new List(); diff --git a/POEApi.Model/Stash.cs b/POEApi.Model/Stash.cs index a6e7c421..8798d63a 100644 --- a/POEApi.Model/Stash.cs +++ b/POEApi.Model/Stash.cs @@ -139,7 +139,7 @@ private void refreshCharacterTab(POEModel currentModel, int tabId, string accoun var charTab = Tabs.First(t => t.i == tabId); var characterName = charTab.Name; - var characterItems = currentModel.GetInventory(characterName, true, accountName, realm); + var characterItems = currentModel.GetInventory(characterName, tabId, true, accountName, realm); var characterStashItems = CharacterStashBuilder.GetCharacterStashItems(characterName, characterItems, tabId + 1); items.AddRange(characterStashItems); diff --git a/Procurement/Controls/Equipped.xaml.cs b/Procurement/Controls/Equipped.xaml.cs index 4f54b1e1..8d5e2729 100644 --- a/Procurement/Controls/Equipped.xaml.cs +++ b/Procurement/Controls/Equipped.xaml.cs @@ -92,7 +92,10 @@ void Equipped_Loaded(object sender, RoutedEventArgs e) private void render() { - equipped = new EquipedItems(ApplicationState.Model.GetInventory(Character, false, ApplicationState.AccountName, ApplicationState.CurrentRealm).Where(i => i.InventoryId != "MainInventory")); + // TODO: Get the correct tabId to use (instead of -1). + equipped = new EquipedItems(ApplicationState.Model.GetInventory(Character, -1, false, + ApplicationState.AccountName, ApplicationState.CurrentRealm).Where( + i => i.InventoryId != "MainInventory")); davinci.Children.Clear(); Dictionary itemsAtPosition = equipped.GetItems(); diff --git a/Procurement/Controls/Inventory.xaml.cs b/Procurement/Controls/Inventory.xaml.cs index d4bf2e81..de36e900 100644 --- a/Procurement/Controls/Inventory.xaml.cs +++ b/Procurement/Controls/Inventory.xaml.cs @@ -40,7 +40,9 @@ void Inventory_Loaded(object sender, RoutedEventArgs e) private void refresh(string accountName) { - this.Invent = ApplicationState.Model.GetInventory(Character, false, accountName, ApplicationState.CurrentRealm).Where(i => i.InventoryId == "MainInventory").ToList(); + // TODO: Get the correct tabId to use (instead of -1). + this.Invent = ApplicationState.Model.GetInventory(Character, -1, false, accountName, + ApplicationState.CurrentRealm).Where(i => i.InventoryId == "MainInventory").ToList(); inventByLocation = Invent.ToDictionary(item => new Tuple(item.X, item.Y)); render(); } diff --git a/Procurement/ViewModel/LoginWindowViewModel.cs b/Procurement/ViewModel/LoginWindowViewModel.cs index 979dbb3c..cdf58082 100644 --- a/Procurement/ViewModel/LoginWindowViewModel.cs +++ b/Procurement/ViewModel/LoginWindowViewModel.cs @@ -299,10 +299,19 @@ private IEnumerable LoadCharacterInventoryItems(Character character, bool if (!offline) _statusController.DisplayMessage((string.Format("Loading {0}'s inventory...", character.Name))); + // TODO: It looks like the character's fake stash tab does not exist at this point. Confirm, and determine + // the best course of action at this point. + var tab = ApplicationState.Stash[character.League].Tabs.FirstOrDefault( + t => t.Name == character.Name && t.IsFakeTab); + int tabId = 0; + if (tab != null) + tabId = tab.i; + List inventory; try { - inventory = ApplicationState.Model.GetInventory(character.Name, false, ApplicationState.AccountName, ApplicationState.CurrentRealm); + inventory = ApplicationState.Model.GetInventory(character.Name, tabId, false, ApplicationState.AccountName, + ApplicationState.CurrentRealm); success = true; } catch (WebException) diff --git a/Tests/POEApi.Model.Tests/PoeModelTests.cs b/Tests/POEApi.Model.Tests/PoeModelTests.cs index acc00cc8..cd65d48c 100644 --- a/Tests/POEApi.Model.Tests/PoeModelTests.cs +++ b/Tests/POEApi.Model.Tests/PoeModelTests.cs @@ -33,7 +33,7 @@ public void GetInventoryTest() { _mockTransport.Setup(m => m.GetInventory("", false, "", Realm.PC)).Returns(stream); - var inventory = _model.GetInventory("", false, "", Realm.PC); + var inventory = _model.GetInventory("", -1, false, "", Realm.PC); Assert.IsNotNull(inventory); } @@ -273,7 +273,7 @@ public void GetPantheonSoulInventoryTest() using (var stream = GenerateStreamFromString(fakeInventoryInfo)) { _mockTransport.Setup(m => m.GetInventory(string.Empty, false, string.Empty, Realm.PC)).Returns(stream); - var inventory = _model.GetInventory(string.Empty, false, string.Empty, Realm.PC); + var inventory = _model.GetInventory(string.Empty, -1, false, string.Empty, Realm.PC); inventory.Should().NotBeNull(); inventory.Should().HaveCount(3); @@ -435,7 +435,7 @@ public void GetInventoryWithQuestItemsTest() { _mockTransport.Setup(m => m.GetInventory("", false, "", Realm.PC)).Returns(stream); - var inventory = _model.GetInventory("", false, "", Realm.PC); + var inventory = _model.GetInventory("", -1, false, "", Realm.PC); Assert.IsNotNull(inventory);