Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sysManager.LookupTreeItem is not working with the latest 4026 beta #115

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions TwinpackVsixShared/Dialogs/CatalogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -957,13 +957,10 @@ public bool IsLicenseDialogRequired(ITcPlcLibraryManager libManager, Models.Pack
(!string.IsNullOrEmpty(packageVersion.LicenseBinary) || (!string.IsNullOrEmpty(packageVersion.LicenseTmcBinary) && (ForceShowLicense || !shownLicenses.Contains(licenseId))));
}

public HashSet<string> ShowLicensesIfNeeded(IEnumerable<PackageVersionGetResponse> packageVersions, HashSet<string> knownLicenseIds, bool showLicenseDialog, HashSet<string> shownLicenseIds = null)
public HashSet<string> ShowLicensesIfNeeded(ITcPlcLibraryManager libManager, IEnumerable<PackageVersionGetResponse> packageVersions, HashSet<string> knownLicenseIds, bool showLicenseDialog, HashSet<string> shownLicenseIds = null)
{
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

var plc = _plc.Object as dynamic;
var sysManager = plc.SystemManager as ITcSysManager2;
var libManager = sysManager.LookupTreeItem(plc.PathName + "^References") as ITcPlcLibraryManager;
shownLicenseIds = shownLicenseIds ?? (ForceShowLicense ? new HashSet<string>() : new HashSet<string>(knownLicenseIds));

// todo: flatten dependencies and versions and iterate over this
Expand All @@ -984,7 +981,7 @@ public HashSet<string> ShowLicensesIfNeeded(IEnumerable<PackageVersionGetRespons

if(packageVersion.Dependencies != null)
{
shownLicenseIds = ShowLicensesIfNeeded(packageVersion.Dependencies, knownLicenseIds, showLicenseDialog, shownLicenseIds);
shownLicenseIds = ShowLicensesIfNeeded(libManager, packageVersion.Dependencies, knownLicenseIds, showLicenseDialog, shownLicenseIds);
}
}

Expand All @@ -999,13 +996,18 @@ public async Task AddOrUpdatePackageAsync(IEnumerable<PackageVersionGetResponse>
throw new Exception("Invalid package(s) should be added or updated!");

var cachePath = $@"{Path.GetDirectoryName(_context.Solution.FullName)}\.Zeugwerk\libraries";

var plc = _plc.Object as dynamic;
var sysManager = plc.SystemManager as ITcSysManager2;
var libManager = sysManager.LookupTreeItem(plc.PathName + "^References") as ITcPlcLibraryManager;
var libManagerItem = plc.LookupChild("References");
var libManager = libManagerItem as ITcPlcLibraryManager;

//var sysManager = plc.SystemManager as ITcSysManager16;
// var libManager = sysManager.LookupTreeItem(plc.PathName + "^References") as ITcPlcLibraryManager;

var knownLicenseIds = TwinpackUtils.KnownLicenseIds();

// license handling
ShowLicensesIfNeeded(packageVersions, knownLicenseIds, showLicenseDialog);
ShowLicensesIfNeeded(libManager, packageVersions, knownLicenseIds, showLicenseDialog);
TwinpackUtils.CopyLicenseTmcIfNeeded(packageVersions, knownLicenseIds);

// download packages and close Library Manager and all windows that are related to the library. These windows cause race conditions
Expand Down