diff --git a/NewWorldCompanion.Services/Data/CraftingRecipes.json b/NewWorldCompanion.Services/Data/CraftingRecipes.json index da53382..ee19107 100644 --- a/NewWorldCompanion.Services/Data/CraftingRecipes.json +++ b/NewWorldCompanion.Services/Data/CraftingRecipes.json @@ -57110,7 +57110,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -57607,7 +57607,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -58104,7 +58104,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -58601,7 +58601,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -59098,7 +59098,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -59453,7 +59453,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -59950,7 +59950,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -73298,7 +73298,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -73795,7 +73795,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -74292,7 +74292,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -74789,7 +74789,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -75144,7 +75144,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -87427,7 +87427,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -87924,7 +87924,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -88421,7 +88421,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -88918,7 +88918,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -89415,7 +89415,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -89912,7 +89912,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -90409,7 +90409,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -90906,7 +90906,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -91403,7 +91403,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -91900,7 +91900,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -92397,7 +92397,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -92894,7 +92894,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -93391,7 +93391,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -93888,7 +93888,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -94385,7 +94385,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -163965,7 +163965,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -164462,7 +164462,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -164959,7 +164959,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", @@ -165456,7 +165456,7 @@ "OutputQty": 1, "ItemID": "", "SkipGrantItems": null, - "BaseGearScore": 550, + "BaseGearScore": 502, "BaseTier": 5, "ProceduralTierID1": "", "ProceduralTierID2": "", diff --git a/NewWorldCompanion.Services/HttpClientHandler.cs b/NewWorldCompanion.Services/HttpClientHandler.cs index 02881f7..bb7b011 100644 --- a/NewWorldCompanion.Services/HttpClientHandler.cs +++ b/NewWorldCompanion.Services/HttpClientHandler.cs @@ -1,10 +1,12 @@ -using NewWorldCompanion.Interfaces; +using Microsoft.Extensions.Logging; +using NewWorldCompanion.Interfaces; using Prism.Events; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Headers; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -13,6 +15,7 @@ namespace NewWorldCompanion.Services public class HttpClientHandler : IHttpClientHandler { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; // HttpClient is intended to be instantiated once per application, rather than per-use. static readonly HttpClient _client = new HttpClient(); @@ -21,11 +24,14 @@ public class HttpClientHandler : IHttpClientHandler #region Constructor - public HttpClientHandler(IEventAggregator eventAggregator) + public HttpClientHandler(IEventAggregator eventAggregator, ILogger logger) { // Init IEventAggregator _eventAggregator = eventAggregator; + // Init logger + _logger = logger; + // Config client //_client.DefaultRequestHeaders.Clear(); //_client.DefaultRequestHeaders.Add("Cache-Control", "no-cache"); @@ -60,8 +66,10 @@ public async Task GetRequest(string uri) { return await _client.GetStringAsync(uri); } - catch (Exception) + catch (Exception ex) { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + return string.Empty; } } diff --git a/NewWorldCompanion.Services/NewWorldCompanion.Services.csproj b/NewWorldCompanion.Services/NewWorldCompanion.Services.csproj index 8bee59f..a9ab710 100644 --- a/NewWorldCompanion.Services/NewWorldCompanion.Services.csproj +++ b/NewWorldCompanion.Services/NewWorldCompanion.Services.csproj @@ -22,6 +22,7 @@ + diff --git a/NewWorldCompanion.Services/OcrHandler.cs b/NewWorldCompanion.Services/OcrHandler.cs index 8acc922..dbd28da 100644 --- a/NewWorldCompanion.Services/OcrHandler.cs +++ b/NewWorldCompanion.Services/OcrHandler.cs @@ -1,4 +1,5 @@ -using NewWorldCompanion.Entities; +using Microsoft.Extensions.Logging; +using NewWorldCompanion.Entities; using NewWorldCompanion.Events; using NewWorldCompanion.Interfaces; using Prism.Events; @@ -7,6 +8,7 @@ using System.Drawing; using System.IO; using System.Linq; +using System.Reflection; using System.Text.Json; using TesserNet; @@ -15,6 +17,7 @@ namespace NewWorldCompanion.Services public class OcrHandler : IOcrHandler { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; private readonly INewWorldDataStore _newWorldDataStore; private readonly IScreenProcessHandler _screenProcessHandler; @@ -31,13 +34,16 @@ public class OcrHandler : IOcrHandler #region Constructor - public OcrHandler(IEventAggregator eventAggregator, INewWorldDataStore newWorldDataStore, IScreenProcessHandler screenProcessHandler) + public OcrHandler(IEventAggregator eventAggregator, ILogger logger, INewWorldDataStore newWorldDataStore, IScreenProcessHandler screenProcessHandler) { // Init IEventAggregator _eventAggregator = eventAggregator; _eventAggregator.GetEvent().Subscribe(HandleOcrImageReadyEvent); _eventAggregator.GetEvent().Subscribe(HandleOcrImageCountReadyEvent); + // Init logger + _logger = logger; + // Init services _newWorldDataStore = newWorldDataStore; _screenProcessHandler = screenProcessHandler; @@ -83,7 +89,10 @@ private void HandleOcrImageReadyEvent() _eventAggregator.GetEvent().Publish(); _eventAggregator.GetEvent().Publish(); } - catch (Exception) { } + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } } } @@ -109,7 +118,10 @@ private void HandleOcrImageCountReadyEvent() _eventAggregator.GetEvent().Publish(); } - catch (Exception) { } + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } } } @@ -132,7 +144,10 @@ private void UpdateOcrMappings() _ocrMappings = JsonSerializer.Deserialize>(stream) ?? new List(); } } - catch (Exception){} + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } #endregion diff --git a/NewWorldCompanion.Services/PriceManager.cs b/NewWorldCompanion.Services/PriceManager.cs index bc054fd..1cd68f8 100644 --- a/NewWorldCompanion.Services/PriceManager.cs +++ b/NewWorldCompanion.Services/PriceManager.cs @@ -1,4 +1,5 @@ -using NewWorldCompanion.Entities; +using Microsoft.Extensions.Logging; +using NewWorldCompanion.Entities; using NewWorldCompanion.Events; using NewWorldCompanion.Helpers; using NewWorldCompanion.Interfaces; @@ -7,6 +8,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Text.Json; using System.Threading.Tasks; @@ -15,6 +17,7 @@ namespace NewWorldCompanion.Services public class PriceManager : IPriceManager { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; private readonly ISettingsManager _settingsManager; private readonly IHttpClientHandler _httpClientHandler; private readonly INewWorldDataStore _newWorldDataStore; @@ -30,11 +33,14 @@ public class PriceManager : IPriceManager #region Constructor - public PriceManager(IEventAggregator eventAggregator, ISettingsManager settingsManager, IHttpClientHandler httpClientHandler, INewWorldDataStore newWorldDataStore) + public PriceManager(IEventAggregator eventAggregator, ILogger logger, ISettingsManager settingsManager, IHttpClientHandler httpClientHandler, INewWorldDataStore newWorldDataStore) { // Init IEventAggregator _eventAggregator = eventAggregator; + // Init logger + _logger = logger; + // Init services _settingsManager = settingsManager; _httpClientHandler = httpClientHandler; @@ -88,9 +94,9 @@ private async void UpdateServerList() } } } - catch (Exception) + catch (Exception ex) { - + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); } _eventAggregator.GetEvent().Publish(); @@ -159,7 +165,10 @@ public void UpdatePriceData(string itemName) }; } } - catch (Exception) { }; + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } // Always remove from queue, even with exceptions. diff --git a/NewWorldCompanion.Services/ScreenCaptureHandler.cs b/NewWorldCompanion.Services/ScreenCaptureHandler.cs index 84a5f5e..91758ee 100644 --- a/NewWorldCompanion.Services/ScreenCaptureHandler.cs +++ b/NewWorldCompanion.Services/ScreenCaptureHandler.cs @@ -1,10 +1,12 @@ -using NewWorldCompanion.Events; +using Microsoft.Extensions.Logging; +using NewWorldCompanion.Events; using NewWorldCompanion.Helpers; using NewWorldCompanion.Interfaces; using Prism.Events; using System; using System.Diagnostics; using System.Drawing; +using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Media.Imaging; @@ -15,6 +17,7 @@ namespace NewWorldCompanion.Services public class ScreenCaptureHandler : IScreenCaptureHandler { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; private DispatcherTimer _captureTimer = new(); private DispatcherTimer _coordinatesTimer = new(); @@ -31,11 +34,14 @@ public class ScreenCaptureHandler : IScreenCaptureHandler #region Constructor - public ScreenCaptureHandler(IEventAggregator eventAggregator) + public ScreenCaptureHandler(IEventAggregator eventAggregator, ILogger logger) { // Init IEventAggregator _eventAggregator = eventAggregator; + // Init logger + _logger = logger; + // Capture timer _captureTimer = new DispatcherTimer { @@ -128,11 +134,15 @@ private void ScreenCapture() } else { - _captureTimer.Interval = TimeSpan.FromMilliseconds(Delay * 10); + _logger.LogWarning($"{MethodBase.GetCurrentMethod()?.Name}: Invalid windowHandle. NewWorld processes found: {processes.Length}. Retry in 10 seconds."); + + _captureTimer.Interval = TimeSpan.FromMilliseconds(Delay * 100); } } - catch (Exception) + catch (Exception ex) { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + _captureTimer.Interval = TimeSpan.FromMilliseconds(Delay * 10); } _captureTimer.Start(); diff --git a/NewWorldCompanion.Services/ScreenProcessHandler.cs b/NewWorldCompanion.Services/ScreenProcessHandler.cs index 8d07f61..eec1521 100644 --- a/NewWorldCompanion.Services/ScreenProcessHandler.cs +++ b/NewWorldCompanion.Services/ScreenProcessHandler.cs @@ -2,6 +2,7 @@ using Emgu.CV.CvEnum; using Emgu.CV.Structure; using Emgu.CV.Util; +using Microsoft.Extensions.Logging; using NewWorldCompanion.Constants; using NewWorldCompanion.Events; using NewWorldCompanion.Interfaces; @@ -11,6 +12,7 @@ using System.Drawing; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -19,6 +21,8 @@ namespace NewWorldCompanion.Services public class ScreenProcessHandler : IScreenProcessHandler { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; + private readonly ISettingsManager _settingsManager; private readonly IScreenCaptureHandler _screenCaptureHandler; @@ -42,12 +46,15 @@ public class ScreenProcessHandler : IScreenProcessHandler #region Constructor - public ScreenProcessHandler(IEventAggregator eventAggregator, ISettingsManager settingsManager, IScreenCaptureHandler screenCaptureHandler) + public ScreenProcessHandler(IEventAggregator eventAggregator, ILogger logger, ISettingsManager settingsManager, IScreenCaptureHandler screenCaptureHandler) { // Init IEventAggregator _eventAggregator = eventAggregator; _eventAggregator.GetEvent().Subscribe(HandleScreenCaptureReadyEvent); + // Init logger + _logger = logger; + // Init services _settingsManager = settingsManager; _screenCaptureHandler = screenCaptureHandler; @@ -218,8 +225,10 @@ private void ProcessImage(Mat img) _eventAggregator.GetEvent().Publish(); ProcessImageOCR(crop); } - catch (Exception) + catch (Exception ex) { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + _eventAggregator.GetEvent().Publish(); } } @@ -264,7 +273,10 @@ private void ProcessImageOCR(Mat img) imgFilter.Save(@"ocrimages\itemname.png"); _eventAggregator.GetEvent().Publish(); } - catch (Exception) { } + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } private void ProcessImageCountOCR(Mat img) @@ -286,7 +298,10 @@ private void ProcessImageCountOCR(Mat img) imgFilter.Save(@"ocrimages\itemcount.png"); _eventAggregator.GetEvent().Publish(); } - catch (Exception) { } + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } public void ProcessImageCountOCRDebug(int minR, int minG, int minB, int maxR, int maxG, int maxB) @@ -314,7 +329,10 @@ public void ProcessImageCountOCRDebug(int minR, int minG, int minB, int maxR, in imgFilter.Save(@"ocrimages\itemcount.png"); _eventAggregator.GetEvent().Publish(); } - catch (Exception) { } + catch(Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } } diff --git a/NewWorldCompanion/App.xaml.cs b/NewWorldCompanion/App.xaml.cs index 78daf7d..dcbb5e6 100644 --- a/NewWorldCompanion/App.xaml.cs +++ b/NewWorldCompanion/App.xaml.cs @@ -1,16 +1,14 @@ using MahApps.Metro.Controls.Dialogs; +using Microsoft.Extensions.DependencyInjection; using NewWorldCompanion.Interfaces; using NewWorldCompanion.Services; using NewWorldCompanion.Views; +using NLog.Extensions.Logging; using Prism.Ioc; using Prism.Unity; -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; using System.Windows; +using Unity; +using Unity.Microsoft.DependencyInjection; namespace NewWorldCompanion { @@ -39,6 +37,19 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry) containerRegistry.RegisterSingleton(); } + protected override IContainerExtension CreateContainerExtension() + { + var serviceCollection = new ServiceCollection(); + serviceCollection.AddLogging(loggingBuilder => + loggingBuilder.AddNLog(configFileRelativePath: "Config/NLog.config")); + + var container = new UnityContainer(); + container.BuildServiceProvider(serviceCollection); + + return new UnityContainerExtension(container); + } + + protected override Window CreateShell() { var w = Container.Resolve(); diff --git a/NewWorldCompanion/Config/NLog.config b/NewWorldCompanion/Config/NLog.config new file mode 100644 index 0000000..329ec01 --- /dev/null +++ b/NewWorldCompanion/Config/NLog.config @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NewWorldCompanion/NewWorldCompanion.csproj b/NewWorldCompanion/NewWorldCompanion.csproj index dda9910..8e05cb8 100644 --- a/NewWorldCompanion/NewWorldCompanion.csproj +++ b/NewWorldCompanion/NewWorldCompanion.csproj @@ -35,11 +35,13 @@ + + @@ -58,6 +60,9 @@ + + Always + Always diff --git a/NewWorldCompanion/ViewModels/MainWindowViewModel.cs b/NewWorldCompanion/ViewModels/MainWindowViewModel.cs index 8dd108e..d014bec 100644 --- a/NewWorldCompanion/ViewModels/MainWindowViewModel.cs +++ b/NewWorldCompanion/ViewModels/MainWindowViewModel.cs @@ -1,4 +1,5 @@ -using NewWorldCompanion.Events; +using Microsoft.Extensions.Logging; +using NewWorldCompanion.Events; using NewWorldCompanion.Interfaces; using Prism.Events; using Prism.Mvvm; @@ -12,6 +13,7 @@ namespace NewWorldCompanion.ViewModels public class MainWindowViewModel : BindableBase { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; private readonly ISettingsManager _settingsManager; private readonly IOverlayHandler _overlayHandler; private readonly IVersionManager _versionManager; @@ -22,12 +24,15 @@ public class MainWindowViewModel : BindableBase #region Constructor - public MainWindowViewModel(IEventAggregator eventAggregator, ISettingsManager settingsManager, IOverlayHandler overlayHandler, IVersionManager versionManager) + public MainWindowViewModel(IEventAggregator eventAggregator, ILogger logger, ISettingsManager settingsManager, IOverlayHandler overlayHandler, IVersionManager versionManager) { // Init IEventAggregator _eventAggregator = eventAggregator; _eventAggregator.GetEvent().Subscribe(HandleVersionInfoUpdatedEvent); + // Init logger + _logger = logger; + // Init services _settingsManager = settingsManager; _overlayHandler = overlayHandler; @@ -61,6 +66,8 @@ private void HandleVersionInfoUpdatedEvent() WindowTitle = $"New World Companion v{Assembly.GetExecutingAssembly().GetName().Version}"; } RaisePropertyChanged(nameof(WindowTitle)); + + _logger.LogInformation(WindowTitle); } #endregion diff --git a/NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs b/NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs index 15164a9..646f15b 100644 --- a/NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs +++ b/NewWorldCompanion/ViewModels/Tabs/CraftingViewModel.cs @@ -1,4 +1,5 @@ -using NewWorldCompanion.Constants; +using Microsoft.Extensions.Logging; +using NewWorldCompanion.Constants; using NewWorldCompanion.Entities; using NewWorldCompanion.Events; using NewWorldCompanion.Interfaces; @@ -23,6 +24,7 @@ namespace NewWorldCompanion.ViewModels.Tabs public class CraftingViewModel : BindableBase { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; private readonly ICraftingRecipeManager _craftingRecipeManager; private readonly IScreenCaptureHandler _screenCaptureHandler; private readonly IOcrHandler _ocrHandler; @@ -64,7 +66,7 @@ public class CraftingViewModel : BindableBase #region Constructor - public CraftingViewModel(IEventAggregator eventAggregator, ICraftingRecipeManager craftingRecipeManager, IScreenCaptureHandler screenCaptureHandler, IOcrHandler ocrHandler, + public CraftingViewModel(IEventAggregator eventAggregator, ILogger logger, ICraftingRecipeManager craftingRecipeManager, IScreenCaptureHandler screenCaptureHandler, IOcrHandler ocrHandler, IPriceManager priceManager) { // Init IEventAggregator @@ -72,6 +74,9 @@ public CraftingViewModel(IEventAggregator eventAggregator, ICraftingRecipeManage _eventAggregator.GetEvent().Subscribe(HandleOcrTextReadyEvent); _eventAggregator.GetEvent().Subscribe(HandlePriceCacheUpdatedEvent); + // Init logger + _logger = logger; + // Init services _craftingRecipeManager = craftingRecipeManager; _screenCaptureHandler = screenCaptureHandler; @@ -367,7 +372,10 @@ private void CopyRecipeNameExecute(object obj) System.Windows.Clipboard.SetText(recipeName.Trim()); } - catch (Exception) { } + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } private void CreateCraftingRecipesFilteredView() diff --git a/NewWorldCompanion/ViewModels/Tabs/Debug/DebugScreenCountOCRViewModel.cs b/NewWorldCompanion/ViewModels/Tabs/Debug/DebugScreenCountOCRViewModel.cs index 96163bc..612a601 100644 --- a/NewWorldCompanion/ViewModels/Tabs/Debug/DebugScreenCountOCRViewModel.cs +++ b/NewWorldCompanion/ViewModels/Tabs/Debug/DebugScreenCountOCRViewModel.cs @@ -1,4 +1,5 @@ -using NewWorldCompanion.Events; +using Microsoft.Extensions.Logging; +using NewWorldCompanion.Events; using NewWorldCompanion.Interfaces; using Prism.Commands; using Prism.Events; @@ -6,6 +7,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -16,6 +18,7 @@ namespace NewWorldCompanion.ViewModels.Tabs.Debug public class DebugScreenCountOCRViewModel : BindableBase { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; private readonly IScreenProcessHandler _screenProcessHandler; private readonly IOcrHandler _ocrHandler; @@ -35,13 +38,16 @@ public class DebugScreenCountOCRViewModel : BindableBase #region Constructor - public DebugScreenCountOCRViewModel(IEventAggregator eventAggregator, IScreenProcessHandler screenProcessHandler, IOcrHandler ocrHandler) + public DebugScreenCountOCRViewModel(IEventAggregator eventAggregator, ILogger logger, IScreenProcessHandler screenProcessHandler, IOcrHandler ocrHandler) { // Init IEventAggregator _eventAggregator = eventAggregator; _eventAggregator.GetEvent().Subscribe(HandleOcrImageCountReadyEvent); _eventAggregator.GetEvent().Subscribe(HandleOcrTextCountReadyEvent); + // Init logger + _logger = logger; + // Init services _screenProcessHandler = screenProcessHandler; _ocrHandler = ocrHandler; @@ -196,7 +202,10 @@ private void CopyItemCountExecute() { System.Windows.Clipboard.SetText(ItemCount); } - catch (Exception) { } + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } #endregion diff --git a/NewWorldCompanion/ViewModels/Tabs/Debug/DebugScreenOCRViewModel.cs b/NewWorldCompanion/ViewModels/Tabs/Debug/DebugScreenOCRViewModel.cs index 901610f..f6e9ad6 100644 --- a/NewWorldCompanion/ViewModels/Tabs/Debug/DebugScreenOCRViewModel.cs +++ b/NewWorldCompanion/ViewModels/Tabs/Debug/DebugScreenOCRViewModel.cs @@ -1,10 +1,12 @@ -using NewWorldCompanion.Constants; +using Microsoft.Extensions.Logging; +using NewWorldCompanion.Constants; using NewWorldCompanion.Events; using NewWorldCompanion.Interfaces; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using System; +using System.Reflection; using System.Windows; using System.Windows.Media.Imaging; @@ -13,6 +15,7 @@ namespace NewWorldCompanion.ViewModels.Tabs.Debug public class DebugScreenOCRViewModel : BindableBase { private readonly IEventAggregator _eventAggregator; + private readonly ILogger _logger; private readonly ISettingsManager _settingsManager; private readonly IScreenProcessHandler _screenProcessHandler; private readonly IOcrHandler _ocrHandler; @@ -27,7 +30,7 @@ public class DebugScreenOCRViewModel : BindableBase #region Constructor - public DebugScreenOCRViewModel(IEventAggregator eventAggregator, ISettingsManager settingsManager, IScreenProcessHandler screenProcessHandler, IOcrHandler ocrHandler) + public DebugScreenOCRViewModel(IEventAggregator eventAggregator, ILogger logger, ISettingsManager settingsManager, IScreenProcessHandler screenProcessHandler, IOcrHandler ocrHandler) { // Init IEventAggregator _eventAggregator = eventAggregator; @@ -36,6 +39,9 @@ public DebugScreenOCRViewModel(IEventAggregator eventAggregator, ISettingsManage _eventAggregator.GetEvent().Subscribe(HandleOcrTextReadyEvent); _eventAggregator.GetEvent().Subscribe(HandleOcrTextCountReadyEvent); + // Init logger + _logger = logger; + // Init services _settingsManager = settingsManager; _screenProcessHandler = screenProcessHandler; @@ -226,7 +232,10 @@ private void CopyItemNameExecute() { System.Windows.Clipboard.SetText(ItemName); } - catch (Exception) { } + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } private void CopyItemCountExecute() @@ -235,7 +244,10 @@ private void CopyItemCountExecute() { System.Windows.Clipboard.SetText(ItemCount); } - catch (Exception) { } + catch (Exception ex) + { + _logger.LogError(ex, MethodBase.GetCurrentMethod()?.Name); + } } #endregion diff --git a/NewWorldCompanion/common.props b/NewWorldCompanion/common.props index a4cab80..2f78aa2 100644 --- a/NewWorldCompanion/common.props +++ b/NewWorldCompanion/common.props @@ -1,7 +1,8 @@ - 1.0.4.4 - 1.0.4.4 + 1.0.5.0 + 1.0.5.0 Copyright © 2022 + net6.0-windows \ No newline at end of file