Skip to content

Commit

Permalink
feat: improved migration support in case that config.json are broken …
Browse files Browse the repository at this point in the history
…before the migration
  • Loading branch information
iadonkey committed Dec 21, 2023
1 parent 5ffec26 commit be2c3a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion TwinpackShared/Models/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public bool IsUpdateable
{
try
{
return InstalledVersion != null && Update?.Version != null && new Version(InstalledVersion) < new Version(Update?.Version);
return (Installed?.Version == null && Update?.Version != null) || (Update?.Version != null && new Version(Installed?.Version) < new Version(Update?.Version));
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion TwinpackVsixShared/Dialogs/CatalogWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
</Grid>

<Grid Margin="0 3 0 0" Grid.Column="0" Grid.Row="2"
IsEnabled="{Binding IsCatalogEnabled}"
IsEnabled="{Binding IsRestoreAllEnabled}"
Visibility="{Binding IsRestoreAllVisible, Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
Expand Down
25 changes: 18 additions & 7 deletions TwinpackVsixShared/Dialogs/CatalogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ public bool IsRestoreAllVisible
}
}

public bool IsRestoreAllEnabled
{
get { return _isRestoreAllEnabled; }
}

public bool IsInitializing
{
get { return _isInitializing; }
Expand All @@ -340,7 +345,9 @@ public bool IsCatalogEnabled
set
{
_isCatalogEnabled = value;
_isRestoreAllEnabled = _installedPackages.Any(x => x.PackageId == null) == false;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsCatalogEnabled)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsRestoreAllEnabled)));
}
}

Expand Down Expand Up @@ -505,6 +512,7 @@ private async void Dialog_Loaded(object sender, RoutedEventArgs e)
{
IsInitializing = false;
IsCatalogLoading = false;
IsCatalogEnabled = true;
IsPackageVersionPanelEnabled = _plcConfig != null;
IsUpdateAvailable = _twinpackServer.IsClientUpdateAvailable == true;
btnLogin.Text = _twinpackServer.LoggedIn ? "Logout" : "Login";
Expand All @@ -525,17 +533,14 @@ public async Task LoadPlcConfigAsync(CancellationToken cancellationToken)
if (config != null)
{
_plcConfig = ConfigPlcProjectFactory.MapPlcConfigToPlcProj(config, _plc);
IsCreateConfigVisible = false;
IsMigrateConfigVisible = false;
IsMigrateConfigVisible = _plcConfig?.Packages?.Any() == false && _plcConfig.Frameworks?.Zeugwerk?.References?.Any() == true;
}
else
{
IsCreateConfigVisible = true;
IsMigrateConfigVisible = false;
_plcConfig = await ConfigPlcProjectFactory.CreateAsync(_context.Solution, _plc, _twinpackServer, cancellationToken);
}

IsCreateConfigVisible = config == null;
IsMigrateConfigVisible = config != null && _plcConfig?.Packages?.Any() == false && _plcConfig.Frameworks?.Zeugwerk?.References?.Any() == true;
IsConfigured = _plcConfig != null;
}
catch (Exception ex)
Expand Down Expand Up @@ -589,6 +594,7 @@ public async void EditPackageButton_Click(object sender, RoutedEventArgs e)
}
finally
{
IsCatalogEnabled = true;
IsPackageVersionPanelEnabled = _plcConfig != null;
}
}
Expand Down Expand Up @@ -1270,14 +1276,17 @@ private async Task LoadInstalledPackagesAsync(CancellationToken cancellationToke
item.Configuration, item.Branch, item.Target,
cancellationToken: cancellationToken);

// force the actual references version even if the version was not found
// force the packageVersion references version even if the version was not found
if (packageVersion.PackageVersionId != null)
{
catalogItem = new CatalogItem(packageVersion);
catalogItem.Installed = packageVersion;
catalogItem.Update = packageVersionLatest;
}

// a package might be updateable but not available on Twinpack
if (packageVersionLatest.PackageVersionId != null)
catalogItem.Update = packageVersionLatest;

var packageId = catalogItem.PackageId ?? packageVersionLatest.PackageId;
if (packageId == null || !_installedPackages.Any(x => x.PackageId == packageId))
{
Expand Down Expand Up @@ -1526,6 +1535,7 @@ public async void ReloadButton_Click(object sender, RoutedEventArgs e)
{
IsPackageVersionPanelEnabled = _plcConfig != null;
IsCatalogLoading = false;
IsCatalogEnabled = true;
IsInitializing = false;
}
}
Expand Down Expand Up @@ -1591,6 +1601,7 @@ public async void CreateConfig_Click(object sender, RoutedEventArgs e)
}
finally
{
IsCatalogEnabled = true;
IsPackageVersionPanelEnabled = _plcConfig != null;
}
}
Expand Down

0 comments on commit be2c3a0

Please sign in to comment.