Skip to content

Commit

Permalink
refactor: removed unused properties from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
iadonkey committed Sep 14, 2024
1 parent 98ef1e8 commit 0096e3f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 60 deletions.
56 changes: 11 additions & 45 deletions TwinpackCli/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,53 +67,19 @@ public override int Execute(CommandContext context, Settings settings)

Initialize(settings.Headed);

var usedPackages = _twinpack.RetrieveUsedPackagesAsync().GetAwaiter().GetResult();
List<PackageItem> packages;
if (settings.Packages != null || settings.Frameworks != null)
{
packages = usedPackages.Where(
x => (settings.ProjectName == null || settings.ProjectName == x.ProjectName) &&
(settings.ProjectName == null || settings.ProjectName == x.ProjectName) &&
(settings.Packages == null || settings.Packages.Any(y => y == x.Update?.Name)) &&
(settings.Frameworks == null || settings.Frameworks.Any(y => y == x.Update?.Framework)))
.Select(x => new PackageItem(x) { Package = new Protocol.Api.PackageGetResponse(x.Update), PackageVersion = x.Update }).ToList();

foreach (var package in packages)
{
var i = settings.Packages != null && package.Package.Name != null ? Array.IndexOf(settings.Packages, package.Package.Name) : -1;
if (i >= 0)
{
package.Config.Version = settings.Versions?.ElementAtOrDefault(i) ?? package.PackageVersion.Version;
package.Config.Branch = settings.Branches?.ElementAtOrDefault(i) ?? package.PackageVersion.Branch;
package.Config.Configuration = settings.Configurations?.ElementAtOrDefault(i) ?? package.PackageVersion.Configuration;
package.Config.Target = settings.Targets?.ElementAtOrDefault(i) ?? package.PackageVersion.Target;
}

i = settings.Frameworks != null && package.PackageVersion.Framework != null ? Array.IndexOf(settings.Frameworks, package.PackageVersion.Framework) : -1;
if (i >= 0)
{
package.Config.Version = settings.Versions?.ElementAtOrDefault(i) ?? package.PackageVersion.Version;
package.Config.Branch = settings.Branches?.ElementAtOrDefault(i) ?? package.PackageVersion.Branch;
package.Config.Configuration = settings.Configurations?.ElementAtOrDefault(i) ?? package.PackageVersion.Configuration;
package.Config.Target = settings.Targets?.ElementAtOrDefault(i) ?? package.PackageVersion.Target;
}
}

// force new retrievable of metadata
foreach (var package in packages)
{
package.Package = null;
package.PackageVersion = null;
}
}
else
{
packages = usedPackages.Select(x => new PackageItem(x) { Package = new Protocol.Api.PackageGetResponse(x.Update), PackageVersion = x.Update }).ToList();
}

// update all packages
_twinpack.UpdatePackagesAsync(
packages,
new TwinpackService.UpdatePackageFilters
{
ProjectName = settings.ProjectName,
PlcName = settings.ProjectName,
Packages = settings.Packages,
Frameworks = settings.Frameworks,
Versions = settings.Versions,
Branches = settings.Branches,
Configurations = settings.Configurations,
Targets = settings.Targets,
},
new TwinpackService.UpdatePackageOptions
{
IncludeProvidedPackages = settings.IncludeProvidedPackages,
Expand Down
12 changes: 1 addition & 11 deletions TwinpackCore/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public ConfigPlcPackage(PackageItem pv)
{
Name = pv.PackageVersion?.Name ?? pv.Package?.Name ?? pv.Config?.Name ?? pv.Catalog?.Name;
DistributorName = pv.PackageVersion?.DistributorName ?? pv.Package?.DistributorName ?? pv.Config?.DistributorName ?? pv.Catalog?.DistributorName;
Framework = pv.PackageVersion?.Framework ?? pv.Package?.Framework ?? pv.Config?.Framework;

Version = pv.PackageVersion?.Version;
Branch = pv.PackageVersion?.Branch;
Expand All @@ -78,7 +77,6 @@ public ConfigPlcPackage(PackageVersionGetResponse pv)
Namespace = pv.Name;
Parameters = null;
Options = null;
Framework = pv.Framework;
}

public ConfigPlcPackage(ConfigPlcPackage pv)
Expand All @@ -92,12 +90,10 @@ public ConfigPlcPackage(ConfigPlcPackage pv)
Namespace = pv.Name;
Parameters = pv.Parameters;
Options = pv.Options;
Framework = pv.Framework;
}

public ConfigPlcPackage()
{
Repository = "";
Name = "";
Branch = "main";
Target = "TC3.1";
Expand All @@ -107,12 +103,10 @@ public ConfigPlcPackage()
Namespace = null;
Parameters = null;
Options = null;
Framework = null;
}
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("repository")]
public string Repository { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

Expand Down Expand Up @@ -151,10 +145,6 @@ public ConfigPlcPackage()
[JsonPropertyName("options")]
public AddPlcLibraryOptions Options { get; set; }

[DefaultValue(null)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("framework")]
public string Framework { get; set; }
}

// This class is used for deserializing a json config file
Expand Down
1 change: 0 additions & 1 deletion TwinpackCore/Configuration/ConfigPlcFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ AddPlcLibraryOptions ParseOptions(XElement element, bool isLibraryReference)
packages.Add(new ConfigPlcPackage
{
DistributorName = packageVersion.DistributorName,
Repository = packageVersion.Repository,
Branch = packageVersion.Branch,
Configuration = packageVersion.Configuration,
Name = packageVersion.Name,
Expand Down
1 change: 1 addition & 0 deletions TwinpackCore/Core/TwinpackService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Twinpack.Configuration;
using System.Windows.Navigation;
using Microsoft.VisualStudio.PlatformUI;
using NuGet.Configuration;

namespace Twinpack.Core
{
Expand Down
1 change: 0 additions & 1 deletion TwinpackCore/Protocol/Native/TwinpackServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,6 @@ public async Task PushAsync(IEnumerable<ConfigPlcProject> plcs, string configura
Binary = binary,
Dependencies = plc.Packages?.Select(x => new PackageVersionDependency
{
Repository = x.Repository,
DistributorName = x.DistributorName,
Name = x.Name,
Version = x.Version,
Expand Down
1 change: 1 addition & 0 deletions TwinpackTests/SystemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace TwinpackTests
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
Expand Down
2 changes: 0 additions & 2 deletions TwinpackVsixShared/Dialogs/PackageVersionWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
LatestVersion = _packageVersionLatest?.Version;
Dependencies = _plcConfig?.Packages?.Select(x => new Protocol.Api.PackageVersionGetResponse
{
Repository = x.Repository,
DistributorName = x.DistributorName,
Name = x.Name,
Branch = x.Branch,
Expand Down Expand Up @@ -919,7 +918,6 @@ private async void Publish_Click(object sender, RoutedEventArgs e)
Binary = Convert.ToBase64String(File.ReadAllBytes($@"{cachePath}\{target}\{_plcConfig.Name}_{_plcConfig.Version}.{suffix}")),
Dependencies = _plcConfig.Packages?.Select(x => new Protocol.Api.PackageVersionDependency
{
Repository = x.Repository,
DistributorName = x.DistributorName,
Name = x.Name,
Version = x.Version,
Expand Down

0 comments on commit 0096e3f

Please sign in to comment.