From c93222598bcb0ececf32a4361ad1d8d032c9221c Mon Sep 17 00:00:00 2001 From: Christoph Hofmann Date: Sun, 17 Dec 2023 20:55:15 +0100 Subject: [PATCH] Added OH4 support (#214) * Added OH4 support * Adjusted log configuration and moved to structured logging * Fixed refresh when changing the sitemap * Fixed SonarCloud integration and issues Signed-off-by: Christoph Hofmann --- .github/workflows/ci.yml | 35 +- .sonarlint/OpenHAB.Windows.slconfig | 15 - .../CSharp/SonarLint.xml | 89 ----- .../openhab_openhab-windowscsharp.ruleset | 370 ------------------ src/openHAB.Core/Model/OpenHABItem.cs | 2 +- src/openHAB.Core/Model/OpenHabVersion.cs | 5 + src/openHAB.Core/Openhab.Core.csproj | 40 +- src/openHAB.Core/SDK/OpenHABClient.cs | 4 +- src/openHAB.Core/Services/IconCaching.cs | 4 +- .../Notification/OpenHABEventParser.cs | 2 +- .../Controls/ColorWidget.xaml.cs | 2 +- .../Controls/ConnectionDialog.xaml | 2 +- .../Controls/ImageLabel.xaml.cs | 6 +- .../Controls/SetpointWidget.xaml.cs | 2 +- .../Converters/IconToPathConverter.cs | 4 +- .../Converters/OpenHabUrlStateToGlyph.cs | 3 +- src/openHAB.Windows/DIService.cs | 20 +- .../ViewModel/LogsViewModel.cs | 2 +- .../ViewModel/MainViewModel.cs | 9 +- src/openHAB.Windows/openHAB.Windows.csproj | 38 +- 20 files changed, 77 insertions(+), 577 deletions(-) delete mode 100644 .sonarlint/OpenHAB.Windows.slconfig delete mode 100644 .sonarlint/openhab_openhab-windows/CSharp/SonarLint.xml delete mode 100644 .sonarlint/openhab_openhab-windowscsharp.ruleset diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2316b11c..2737e577 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,44 +27,41 @@ jobs: - name: setup-msbuild uses: microsoft/setup-msbuild@v1 - - name: Set up JDK 11 - uses: actions/setup-java@v1 + - name: Set up JDK 17 + uses: actions/setup-java@v3 with: - java-version: 1.11 + java-version: 17 + distribution: 'zulu' - name: Cache SonarCloud packages - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ~\sonar\cache - key: ${{runner.os}}-sonar - restore-keys: ${{runner.os}}-sonar + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar - name: Cache SonarCloud scanner id: cache-sonar-scanner - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: .\.sonar\scanner - key: ${{runner.os}}-sonar-scanner-msbuild - restore-keys: ${{runner.os}}-sonar-scanner-msbuild + key: ${{ runner.os }}-sonar-scanner + restore-keys: ${{ runner.os }}-sonar-scanner - name: Install SonarCloud scanner if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' - shell: pwsh + shell: powershell run: | - $directory = New-Item -Path .\.sonar\scanner -ItemType Directory - # dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner - - $file = Join-Path $directory.FullName "sonar-scanner.zip" - Invoke-WebRequest -Uri "https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.2.1.31210/sonar-scanner-msbuild-5.2.1.31210-net46.zip" -OutFile $file - Expand-Archive -LiteralPath $file -DestinationPath "$($directory.FullName)" + New-Item -Path .\.sonar\scanner -ItemType Directory + dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner - name: Begin SonarQube analyze env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - SONAR_TOKEN: ${{secrets.SONAR_TOKE }} + SONAR_TOKEN: ${{secrets.SONAR_TOKEN}} shell: pwsh run: | - .\.sonar\scanner\SonarScanner.MSBuild.exe begin /k:"openhab_openhab-windows" /o:"openhab" /d:sonar.login="${{secrets.SONAR_TOKEN}}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.projectBaseDir="${{github.workspace}}/repo/src/" /d:sonar.verbose="true" + .\.sonar\scanner\dotnet-sonarscanner begin /k:"openhab_openhab-windows" /o:"openhab" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" - name: Build App id: create_app_package @@ -82,4 +79,4 @@ jobs: SONAR_TOKEN: ${{secrets.SONAR_TOKEN}} shell: pwsh run: | - .\.sonar\scanner\SonarScanner.MSBuild.exe end /d:sonar.login="${{secrets.SONAR_TOKEN}}" \ No newline at end of file + .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file diff --git a/.sonarlint/OpenHAB.Windows.slconfig b/.sonarlint/OpenHAB.Windows.slconfig deleted file mode 100644 index 704efb31..00000000 --- a/.sonarlint/OpenHAB.Windows.slconfig +++ /dev/null @@ -1,15 +0,0 @@ -{ - "ServerUri": "https://sonarcloud.io/", - "Organization": { - "Key": "openhab", - "Name": "openHAB" - }, - "ProjectKey": "openhab_openhab-windows", - "ProjectName": "openhab-windows", - "Profiles": { - "CSharp": { - "ProfileKey": "AXflIL33YGfeNt47qUY1", - "ProfileTimestamp": "2021-11-22T10:44:23Z" - } - } -} \ No newline at end of file diff --git a/.sonarlint/openhab_openhab-windows/CSharp/SonarLint.xml b/.sonarlint/openhab_openhab-windows/CSharp/SonarLint.xml deleted file mode 100644 index 90bc98df..00000000 --- a/.sonarlint/openhab_openhab-windows/CSharp/SonarLint.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - sonar.cs.analyzeGeneratedCode - false - - - sonar.cs.file.suffixes - .cs - - - sonar.cs.ignoreHeaderComments - true - - - sonar.cs.roslyn.ignoreIssues - false - - - - - S107 - - - max - 7 - - - - - S110 - - - max - 5 - - - - - S1479 - - - maximum - 30 - - - - - S2342 - - - flagsAttributeFormat - ^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?s$ - - - format - ^([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?$ - - - - - S2436 - - - max - 2 - - - maxMethod - 3 - - - - - S3776 - - - propertyThreshold - 3 - - - threshold - 15 - - - - - \ No newline at end of file diff --git a/.sonarlint/openhab_openhab-windowscsharp.ruleset b/.sonarlint/openhab_openhab-windowscsharp.ruleset deleted file mode 100644 index 79df8173..00000000 --- a/.sonarlint/openhab_openhab-windowscsharp.ruleset +++ /dev/null @@ -1,370 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/openHAB.Core/Model/OpenHABItem.cs b/src/openHAB.Core/Model/OpenHABItem.cs index cbf47601..f1582444 100644 --- a/src/openHAB.Core/Model/OpenHABItem.cs +++ b/src/openHAB.Core/Model/OpenHABItem.cs @@ -187,7 +187,7 @@ public void UpdateValue(object value) /// State as double value. public double GetStateAsDoubleValue() { - string newstate = Regex.Replace(_state, "[^0-9,.]", string.Empty); + string newstate = Regex.Replace(_state, "[^0-9,.]", string.Empty, RegexOptions.None, TimeSpan.FromMilliseconds(100)); double value = 0; double.TryParse(newstate, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out value); diff --git a/src/openHAB.Core/Model/OpenHabVersion.cs b/src/openHAB.Core/Model/OpenHabVersion.cs index 0944e3e2..b43c5e48 100644 --- a/src/openHAB.Core/Model/OpenHabVersion.cs +++ b/src/openHAB.Core/Model/OpenHabVersion.cs @@ -20,6 +20,11 @@ public enum OpenHABVersion /// Three = 3, + /// + /// OpenHAB V4 + /// + Four = 4, + /// /// Used when no connection is available /// diff --git a/src/openHAB.Core/Openhab.Core.csproj b/src/openHAB.Core/Openhab.Core.csproj index 688edd88..24f15a1a 100644 --- a/src/openHAB.Core/Openhab.Core.csproj +++ b/src/openHAB.Core/Openhab.Core.csproj @@ -1,4 +1,4 @@ - + @@ -11,8 +11,8 @@ OpenHAB.Core en-US UAP - 10.0.19041.0 - 10.0.17763.0 + 10.0.22621.0 + 10.0.20348.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -28,7 +28,6 @@ x86 false prompt - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset bin\x86\Debug\OpenHAB.Core.XML @@ -41,7 +40,6 @@ x86 false prompt - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset ARM @@ -53,7 +51,6 @@ ARM false prompt - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset ARM @@ -65,7 +62,6 @@ ARM false prompt - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset x64 @@ -77,7 +73,6 @@ x64 false prompt - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset x64 @@ -89,7 +84,6 @@ x64 false prompt - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset @@ -170,36 +164,36 @@ - 7.1.2 + 8.2.2 - 6.0.0 + 8.0.0 runtime; build; native; contentfiles; analyzers; buildtransitive all - 6.0.0 + 8.0.0 - 6.2.13 + 6.2.14 - 10.1901.28001 + 10.2307.3001 - 7.1.2 + 7.1.3 - 7.1.2 + 7.1.3 2.6.0-prerelease.210129001 - 13.0.1 + 13.0.3 - 1.7.4 + 5.3.7 1.1.118 @@ -227,16 +221,6 @@ - - - openhab_openhab-windowscsharp.ruleset - - - - - SonarLint.xml - - 14.0 diff --git a/src/openHAB.Core/SDK/OpenHABClient.cs b/src/openHAB.Core/SDK/OpenHABClient.cs index 74612028..e367572f 100644 --- a/src/openHAB.Core/SDK/OpenHABClient.cs +++ b/src/openHAB.Core/SDK/OpenHABClient.cs @@ -113,7 +113,7 @@ public async Task> GetOpenHABServerInfo(OpenHABCo return new HttpResponseResult(serverInfo, result.StatusCode); } - string runtimeversion = Regex.Replace(apiInfo?.RuntimeInfo.Version, "[^.0-9]", string.Empty); + string runtimeversion = Regex.Replace(apiInfo?.RuntimeInfo.Version, "[^.0-9]", string.Empty, RegexOptions.None, TimeSpan.FromMilliseconds(100)); if (!Version.TryParse(runtimeversion, out Version serverVersion)) { string message = "Not able to parse runtime verion from openHAB server"; @@ -171,7 +171,7 @@ public async Task> LoadItemsFromSitemap(OpenHABSitema string resultString = await result.Content.ReadAsStringAsync().ConfigureAwait(false); ICollection items = null; - if (version == OpenHABVersion.Two || version == OpenHABVersion.Three) + if (version == OpenHABVersion.Two || version == OpenHABVersion.Three || version == OpenHABVersion.Four) { var jsonObject = JObject.Parse(resultString); items = JsonConvert.DeserializeObject>(jsonObject["homepage"]["widgets"].ToString()); diff --git a/src/openHAB.Core/Services/IconCaching.cs b/src/openHAB.Core/Services/IconCaching.cs index f4ef0898..5b321e7f 100644 --- a/src/openHAB.Core/Services/IconCaching.cs +++ b/src/openHAB.Core/Services/IconCaching.cs @@ -29,8 +29,8 @@ public async Task ResolveIconPath(string iconUrl, string iconFormat) { try { - Match iconName = Regex.Match(iconUrl, "icon/[0-9a-zA-Z]*"); - Match iconState = Regex.Match(iconUrl, "state=[0-9a-zA-Z=]*"); + Match iconName = Regex.Match(iconUrl, "icon/[0-9a-zA-Z]*", RegexOptions.None, TimeSpan.FromMilliseconds(100)); + Match iconState = Regex.Match(iconUrl, "state=[0-9a-zA-Z=]*", RegexOptions.None, TimeSpan.FromMilliseconds(100)); if (!iconName.Success) { diff --git a/src/openHAB.Core/Services/Notification/OpenHABEventParser.cs b/src/openHAB.Core/Services/Notification/OpenHABEventParser.cs index 8e9286c3..30a0627f 100644 --- a/src/openHAB.Core/Services/Notification/OpenHABEventParser.cs +++ b/src/openHAB.Core/Services/Notification/OpenHABEventParser.cs @@ -24,7 +24,7 @@ public OpenHABEvent Parse(string message) { var data = JsonConvert.DeserializeObject(message.Remove(0, 6)); - if (data.Type == "ThingUpdatedEvent" || data.Type == "ThingStatusInfoChangedEvent") + if (data.Type == "ThingUpdatedEvent" || data.Type == "ThingStatusInfoChangedEvent" || data.Type == "ALIVE") { _logger.LogWarning($"Event type is not supported '{data.Type}'."); return null; diff --git a/src/openHAB.Windows/Controls/ColorWidget.xaml.cs b/src/openHAB.Windows/Controls/ColorWidget.xaml.cs index 0c5caae0..f9b91a25 100644 --- a/src/openHAB.Windows/Controls/ColorWidget.xaml.cs +++ b/src/openHAB.Windows/Controls/ColorWidget.xaml.cs @@ -53,7 +53,7 @@ internal override void SetState() string rgbString = Widget.Item?.State; string[] rgbSegements = Widget.Item?.State.Split(','); - Regex rgbRegEx = new Regex(@"^(([1-9][\.\d]*)(,)){2}([1-9][\.\d]*)"); + Regex rgbRegEx = new Regex(@"^(([1-9][\.\d]*)(,)){2}([1-9][\.\d]*)", RegexOptions.None, TimeSpan.FromMilliseconds(100)); if (rgbString == null || rgbString.Length == 0 || !rgbRegEx.IsMatch(rgbString) || rgbSegements == null) { diff --git a/src/openHAB.Windows/Controls/ConnectionDialog.xaml b/src/openHAB.Windows/Controls/ConnectionDialog.xaml index afd26323..4788dfc6 100644 --- a/src/openHAB.Windows/Controls/ConnectionDialog.xaml +++ b/src/openHAB.Windows/Controls/ConnectionDialog.xaml @@ -89,7 +89,7 @@ VerticalAlignment="Top" FontSize="32" FontFamily="{StaticResource SymbolThemeFontFamily}" - Glyph="{Binding State, Converter={StaticResource OpenHabUrlStateToGlyph}, Mode=TwoWay}" /> + Glyph="{Binding Status, Converter={StaticResource OpenHabUrlStateToGlyph}, Mode=TwoWay}" /> diff --git a/src/openHAB.Windows/Controls/ImageLabel.xaml.cs b/src/openHAB.Windows/Controls/ImageLabel.xaml.cs index b3c47e70..fd3b3973 100644 --- a/src/openHAB.Windows/Controls/ImageLabel.xaml.cs +++ b/src/openHAB.Windows/Controls/ImageLabel.xaml.cs @@ -41,13 +41,13 @@ private static async void IconChangedCallback(DependencyObject dependencyObject, // fix IconPathState by removing empty space and special characters string iconPath = control.IconPath; - Match format = Regex.Match(iconPath, @"format=svg"); - Match state = Regex.Match(iconPath, @"state=(.+?)&"); + Match format = Regex.Match(iconPath, @"format=svg", RegexOptions.None, TimeSpan.FromMilliseconds(100)); + Match state = Regex.Match(iconPath, @"state=(.+?)&", RegexOptions.None, TimeSpan.FromMilliseconds(100)); if (state != null) { if (!string.IsNullOrEmpty(state.Value)) { - string newstate = Regex.Replace(state.Groups[1].Value, "[^0-9a-zA-Z.&]", string.Empty); + string newstate = Regex.Replace(state.Groups[1].Value, "[^0-9a-zA-Z.&]", string.Empty, RegexOptions.None, TimeSpan.FromMilliseconds(100)); iconPath = control.IconPath.Replace(state.Groups[1].Value, newstate, StringComparison.InvariantCulture); } } diff --git a/src/openHAB.Windows/Controls/SetpointWidget.xaml.cs b/src/openHAB.Windows/Controls/SetpointWidget.xaml.cs index b04688e1..291d8933 100644 --- a/src/openHAB.Windows/Controls/SetpointWidget.xaml.cs +++ b/src/openHAB.Windows/Controls/SetpointWidget.xaml.cs @@ -101,7 +101,7 @@ private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs string newValue = (string)e.AddedItems.FirstOrDefault(); if (Widget.Item.Unit != null) { - newValue = newValue.Replace(Widget.Item.Unit, string.Empty, StringComparison.InvariantCultureIgnoreCase); + newValue = newValue?.Replace(Widget.Item.Unit, string.Empty, StringComparison.InvariantCultureIgnoreCase); } if (newValue != null) diff --git a/src/openHAB.Windows/Converters/IconToPathConverter.cs b/src/openHAB.Windows/Converters/IconToPathConverter.cs index 0fcc2aa7..2f7c5c02 100644 --- a/src/openHAB.Windows/Converters/IconToPathConverter.cs +++ b/src/openHAB.Windows/Converters/IconToPathConverter.cs @@ -33,13 +33,13 @@ public object Convert(object value, Type targetType, object parameter, string la var state = widget.Item?.State ?? "ON"; string iconFormat = _settings.UseSVGIcons ? "svg" : "png"; - var regMatch = Regex.Match(state, @"\d+"); + var regMatch = Regex.Match(state, @"\d+", RegexOptions.None, TimeSpan.FromMilliseconds(100)); if (regMatch.Success) { state = regMatch.Value; } - return openHABVersion == OpenHABVersion.Two || openHABVersion == OpenHABVersion.Three ? + return openHABVersion == OpenHABVersion.Two || openHABVersion == OpenHABVersion.Three || openHABVersion == OpenHABVersion.Four ? $"{serverUrl}icon/{widget.Icon}?state={state}&format={iconFormat}" : $"{serverUrl}images/{widget.Icon}.png"; } diff --git a/src/openHAB.Windows/Converters/OpenHabUrlStateToGlyph.cs b/src/openHAB.Windows/Converters/OpenHabUrlStateToGlyph.cs index 9809fbbc..291fbec6 100644 --- a/src/openHAB.Windows/Converters/OpenHabUrlStateToGlyph.cs +++ b/src/openHAB.Windows/Converters/OpenHabUrlStateToGlyph.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using OpenHAB.Core.Model; +using OpenHAB.Windows.ViewModel; using Windows.UI.Xaml.Data; namespace OpenHAB.Windows.Converters @@ -27,7 +28,7 @@ public class OpenHabUrlStateToGlyph : IValueConverter /// Returns a glyph for an url state. public object Convert(object value, Type targetType, object parameter, string language) { - ConnectionState state = (ConnectionState)value; + ConnectionState state = ((ConnectionStatusViewModel)value).State; _stateToGlyphMapping.TryGetValue(state, out string glyph); return glyph; diff --git a/src/openHAB.Windows/DIService.cs b/src/openHAB.Windows/DIService.cs index a335097a..9c5530f4 100644 --- a/src/openHAB.Windows/DIService.cs +++ b/src/openHAB.Windows/DIService.cs @@ -41,7 +41,7 @@ private void RegisterServices() { // configure Logging with NLog loggingBuilder.ClearProviders(); - loggingBuilder.SetMinimumLevel(LogLevel.Trace); + loggingBuilder.SetMinimumLevel(LogLevel.Information); loggingBuilder.AddNLog(GetLoggingConfiguration()); }); @@ -73,21 +73,21 @@ private void RegisterViewModels() private LoggingConfiguration GetLoggingConfiguration() { - CsvLayout layout = new CsvLayout() + JsonLayout layout = new JsonLayout() { - Delimiter = CsvColumnDelimiterMode.Semicolon, + IncludeEventProperties = true, }; - layout.Columns.Add(new CsvColumn("time", @"${date:format=HH\:mm\:ss}")); - layout.Columns.Add(new CsvColumn("level", "${level:upperCase=true}")); - layout.Columns.Add(new CsvColumn("callsite", "${callsite:includeSourcePath=false}")); - layout.Columns.Add(new CsvColumn("message", "${message}")); - layout.Columns.Add(new CsvColumn("exception", "${exception:format=ToString}")); - layout.Columns.Add(new CsvColumn("stacktrace", "${onexception:inner=${stacktrace:topFrames=10}}")); + layout.Attributes.Add(new JsonAttribute("time", @"${date:format=HH\:mm\:ss}")); + layout.Attributes.Add(new JsonAttribute("level", "${level:upperCase=true}")); + layout.Attributes.Add(new JsonAttribute("callsite", "${callsite:includeSourcePath=false}")); + layout.Attributes.Add(new JsonAttribute("message", "${message}")); + layout.Attributes.Add(new JsonAttribute("exception", "${exception:format=ToString}")); + layout.Attributes.Add(new JsonAttribute("stacktrace", "${onexception:inner=${stacktrace:topFrames=10}}")); FileTarget fileTarget = new FileTarget("file") { - FileName = "${var:LogPath}/logs/${shortdate}.log", + FileName = "${var:LogPath}/logs/${shortdate}.json", Layout = layout, MaxArchiveFiles = 3, ArchiveEvery = FileArchivePeriod.Day, diff --git a/src/openHAB.Windows/ViewModel/LogsViewModel.cs b/src/openHAB.Windows/ViewModel/LogsViewModel.cs index 62fb4749..326ce625 100644 --- a/src/openHAB.Windows/ViewModel/LogsViewModel.cs +++ b/src/openHAB.Windows/ViewModel/LogsViewModel.cs @@ -20,7 +20,7 @@ public class LogsViewModel : ViewModelBase, IDisposable private string _logFileContent; private FileSystemWatcher _logFileWatcher; private ILogger _logger; - private string _logFilename = $"{DateTime.Now:yyyy-MM-dd}.log"; + private string _logFilename = $"{DateTime.Now:yyyy-MM-dd}.json"; private ICommand _openLogFileCommand; private CoreDispatcher _dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher; diff --git a/src/openHAB.Windows/ViewModel/MainViewModel.cs b/src/openHAB.Windows/ViewModel/MainViewModel.cs index 64d09488..6e8b60e2 100644 --- a/src/openHAB.Windows/ViewModel/MainViewModel.cs +++ b/src/openHAB.Windows/ViewModel/MainViewModel.cs @@ -27,7 +27,6 @@ public class MainViewModel : ViewModelBase private readonly StoreServicesFeedbackLauncher _feedbackLauncher; private readonly IOpenHAB _openHabsdk; private readonly ISettingsService _settingsService; - private CancellationTokenSource _cancellationTokenSource; private ObservableCollection _currentWidgets; private ActionCommand _feedbackCommand; private bool _isDataLoading; @@ -56,7 +55,6 @@ public MainViewModel(IOpenHAB openHabsdk, ISettingsService settingsService, ILog _openHabsdk = openHabsdk; _settingsService = settingsService; _feedbackLauncher = StoreServicesFeedbackLauncher.GetDefault(); - _cancellationTokenSource = new CancellationTokenSource(); StrongReferenceMessenger.Default.Register(this, async (recipient, msg) => await TriggerCommand(recipient, msg).ConfigureAwait(false)); StrongReferenceMessenger.Default.Register(this, (recipient, msg) => OnWidgetClickedAction(recipient, msg.Widget)); @@ -130,6 +128,7 @@ public SitemapViewModel SelectedSitemap SetWidgetsOnScreen(SelectedSitemap.Widgets); } + SelectedWidget = null; SelectedMenuItem = value; } } @@ -253,7 +252,10 @@ private async void OnWidgetClickedAction(object recipient, OpenHABWidget widget) /// A representing the asynchronous operation. public async Task LoadSitemapsAndItemData() { - await LoadData(_cancellationTokenSource.Token).ConfigureAwait(false); + using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource()) + { + await LoadData(cancellationTokenSource.Token).ConfigureAwait(false); + } } private async Task ReloadSitemap() @@ -466,6 +468,7 @@ public void WidgetGoBack() } Subtitle = widget == null ? SelectedSitemap?.Label : widget.Label; + SelectedWidget = widget; SetWidgetsOnScreen(widget != null ? widget.LinkedPage.Widgets : SelectedSitemap.Widgets); } diff --git a/src/openHAB.Windows/openHAB.Windows.csproj b/src/openHAB.Windows/openHAB.Windows.csproj index 988bbed5..89b7f11b 100644 --- a/src/openHAB.Windows/openHAB.Windows.csproj +++ b/src/openHAB.Windows/openHAB.Windows.csproj @@ -1,4 +1,4 @@ - + @@ -11,8 +11,8 @@ OpenHAB.Windows en-US UAP - 10.0.19041.0 - 10.0.17763.0 + 10.0.22621.0 + 10.0.20348.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -39,7 +39,6 @@ false prompt true - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset bin\x86\Debug\OpenHAB.Windows.XML false false @@ -55,7 +54,6 @@ prompt true true - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset true @@ -67,7 +65,6 @@ false prompt true - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset false @@ -81,7 +78,6 @@ prompt true true - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset true @@ -93,7 +89,6 @@ false prompt true - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset false @@ -107,7 +102,6 @@ prompt true true - ..\..\.sonarlint\openhab_openhab-windowscsharp.ruleset @@ -124,9 +118,6 @@ Strings\en-us\Errors.resw - - openhab_openhab-windowscsharp.ruleset - @@ -238,9 +229,6 @@ - - SonarLint.xml - @@ -397,10 +385,6 @@ - - False - ..\..\..\..\..\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\XamlCompiler\Microsoft.UI.Xaml.Markup.winmd - False ..\..\libaries\MJPEGDecoderWinRTLib.dll @@ -419,30 +403,30 @@ Visual C++ 2015 Runtime for Universal Windows Platform Apps - + Windows Desktop Extensions for the UWP - 7.1.2 + 8.2.2 - 6.0.0 + 8.0.0 runtime; build; native; contentfiles; analyzers; buildtransitive all - 6.0.0 + 8.0.0 - 6.2.13 + 6.2.14 - 10.1901.28001 + 10.2307.3001 - 7.1.2 + 7.1.3 2.6.0-prerelease.210129001 @@ -451,7 +435,7 @@ 2.0.1 - 1.7.4 + 5.3.7 1.1.118