-
Notifications
You must be signed in to change notification settings - Fork 638
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
Defending code #13696
Defending code #13696
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Drawing; | ||
|
@@ -137,9 +137,9 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false) | |
RestartBanner.Visibility = Visibility.Hidden; | ||
ws.ForceComputeWorkspaceReferences = forceCompute; | ||
|
||
var packageDependencies = ws.NodeLibraryDependencies.Where(d => d is PackageDependencyInfo).ToList(); | ||
var localDefinitions = ws.NodeLocalDefinitions.Where(d => d is DependencyInfo).ToList(); | ||
var externalFiles = ws.ExternalFiles.Where(d => d is DependencyInfo).ToList(); | ||
var packageDependencies = ws.NodeLibraryDependencies?.Where(d => d is PackageDependencyInfo).ToList(); | ||
var localDefinitions = ws.NodeLocalDefinitions?.Where(d => d is DependencyInfo).ToList(); | ||
var externalFiles = ws.ExternalFiles?.Where(d => d is DependencyInfo).ToList(); | ||
|
||
foreach (DependencyInfo info in localDefinitions) | ||
{ | ||
|
@@ -187,9 +187,16 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false) | |
foreach (var package in dependencyViewExtension.pmExtension.PackageLoader.LocalPackages.Where(x => | ||
x.LoadState.ScheduledState == PackageLoadState.ScheduledTypes.ScheduledForDeletion || x.LoadState.ScheduledState == PackageLoadState.ScheduledTypes.ScheduledForUnload)) | ||
{ | ||
(packageDependencies.FirstOrDefault(x => x.Name == package.Name) as PackageDependencyInfo).State = | ||
try | ||
{ | ||
(packageDependencies.FirstOrDefault(x => x.Name == package.Name) as PackageDependencyInfo).State = | ||
PackageDependencyState.RequiresRestart; | ||
hasPackageMarkedForUninstall = true; | ||
hasPackageMarkedForUninstall = true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
dependencyViewExtension.OnMessageLogged(LogMessage.Info(string.Format(Properties.Resources.DependencyViewExtensionErrorTemplate, $"failure to set package uninstall state |{ ex.ToString()}"))); | ||
} | ||
} | ||
|
||
RestartBanner.Visibility = hasPackageMarkedForUninstall ? Visibility.Visible: Visibility.Hidden; | ||
|
@@ -200,10 +207,17 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false) | |
{ | ||
foreach (PackageDependencyInfo packageDependencyInfo in packageDependencies) | ||
{ | ||
var targetInfo = pmExtension.PackageLoader.LocalPackages.Where(x => x.Name == packageDependencyInfo.Name).FirstOrDefault(); | ||
if (targetInfo != null) | ||
try | ||
{ | ||
var targetInfo = pmExtension.PackageLoader.LocalPackages.Where(x => x.Name == packageDependencyInfo.Name).FirstOrDefault(); | ||
if (targetInfo != null) | ||
{ | ||
packageDependencyInfo.Path = targetInfo.RootDirectory; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could it cause problems for this to be left null if an exception is caught? should it be to set to empty string or something? I don't actually know if it's null - just something to consider. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
packageDependencyInfo.Path = targetInfo.RootDirectory; | ||
dependencyViewExtension.OnMessageLogged(LogMessage.Info(string.Format(Properties.Resources.DependencyViewExtensionErrorTemplate, ex.ToString()))); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice above that
ws
and its properties are never checked for being null... seems that would be valuable at the start of the function - you can probably use?
for most of it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.