Skip to content

Commit

Permalink
DYN-7255 Add crash guard code to DependencyRegen function and code cl…
Browse files Browse the repository at this point in the history
…ean up (#15432)
  • Loading branch information
QilongTang authored Aug 19, 2024
1 parent 0613864 commit 23b596c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ public partial class WorkspaceDependencyView : UserControl, IDisposable
/// The hyper link where Dynamo user will be forwarded to for submitting comments.
/// </summary>
private readonly string FeedbackLink = "https://forum.dynamobim.com/t/call-for-feedback-on-dynamo-graph-package-dependency-display/37229";
private readonly string customNodeExtension = ".dyf";

internal ViewLoadedParams loadedParams;
private WorkspaceDependencyViewExtension dependencyViewExtension;
private readonly WorkspaceDependencyViewExtension dependencyViewExtension;

private IPackageInstaller packageInstaller;
private readonly IPackageInstaller packageInstaller;

private Boolean hasDependencyIssue = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Windows;
using System.Windows.Controls;
using Dynamo.Core;
using Dynamo.Extensions;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.PackageManager;
Expand All @@ -22,7 +21,7 @@ namespace Dynamo.WorkspaceDependency
public class WorkspaceDependencyViewExtension : ViewExtensionBase, IViewExtension, ILogSource
{
internal MenuItem workspaceReferencesMenuItem;
private readonly String extensionName = Properties.Resources.ExtensionName;
private readonly String extensionName = Resources.ExtensionName;
private readonly string customNodeExtension = ".dyf";

internal WorkspaceDependencyView DependencyView
Expand Down Expand Up @@ -145,7 +144,7 @@ public override void Loaded(ViewLoadedParams viewLoadedParams)
viewLoadedParams.AddExtensionMenuItem(workspaceReferencesMenuItem);
}

/// <summary>
/// <summary>
/// Regenerate dependency table
/// </summary>
/// <param name="ws">workspace model</param>
Expand All @@ -154,7 +153,7 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false)
{
DependencyView.RestartBanner.Visibility = Visibility.Hidden;
ws.ForceComputeWorkspaceReferences = forceCompute;

// Dependency infos for each category
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();
Expand All @@ -178,9 +177,8 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false)
}
catch (Exception ex)
{
OnMessageLogged(LogMessage.Info(string.Format(Properties.Resources.DependencyViewExtensionErrorTemplate, ex.ToString())));
OnMessageLogged(LogMessage.Info(string.Format(Resources.DependencyViewExtensionErrorTemplate, ex.ToString())));
}

HasDependencyIssue = string.IsNullOrEmpty(info.Path);
}

Expand All @@ -198,11 +196,11 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false)
HasDependencyIssue = true;
}

if (packageDependencies.Any())
if (packageDependencies.Count != 0)
{
Boolean hasPackageMarkedForUninstall = false;
// If package is set to uninstall state, update the package info
foreach (var package in pmExtension.PackageLoader.LocalPackages.Where(x =>
foreach (var package in pmExtension.PackageLoader.LocalPackages.Where(x =>
x.LoadState.ScheduledState == PackageLoadState.ScheduledTypes.ScheduledForDeletion || x.LoadState.ScheduledState == PackageLoadState.ScheduledTypes.ScheduledForUnload))
{
try
Expand All @@ -213,11 +211,11 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false)
}
catch (Exception ex)
{
OnMessageLogged(LogMessage.Info(string.Format(Properties.Resources.DependencyViewExtensionErrorTemplate, $"failure to set package uninstall state |{ ex.ToString()}")));
OnMessageLogged(LogMessage.Info(string.Format(Resources.DependencyViewExtensionErrorTemplate, $"failure to set package uninstall state |{ex.ToString()}")));
}
}

DependencyView.RestartBanner.Visibility = hasPackageMarkedForUninstall ? Visibility.Visible: Visibility.Hidden;
DependencyView.RestartBanner.Visibility = hasPackageMarkedForUninstall ? Visibility.Visible : Visibility.Hidden;
}

if (pmExtension != null)
Expand All @@ -234,24 +232,30 @@ internal void DependencyRegen(WorkspaceModel ws, bool forceCompute = false)
}
catch (Exception ex)
{
OnMessageLogged(LogMessage.Info(string.Format(Properties.Resources.DependencyViewExtensionErrorTemplate, ex.ToString())));
OnMessageLogged(LogMessage.Info(string.Format(Resources.DependencyViewExtensionErrorTemplate, ex.ToString())));
}
}
}
try
{
dataRows = packageDependencies?.Select(d => new PackageDependencyRow(d as PackageDependencyInfo));
localDefinitionDataRows = localDefinitions?.Select(d => new DependencyRow(d as DependencyInfo));
externalFilesDataRows = externalFiles?.Select(d => new DependencyRow(d as DependencyInfo));

dataRows = packageDependencies.Select(d => new PackageDependencyRow(d as PackageDependencyInfo));
localDefinitionDataRows = localDefinitions.Select(d => new DependencyRow(d as DependencyInfo));
externalFilesDataRows = externalFiles.Select(d => new DependencyRow(d as DependencyInfo));

DependencyView.Packages.IsExpanded = dataRows.Count() > 0;
DependencyView.LocalDefinitions.IsExpanded = localDefinitionDataRows.Count() > 0;
DependencyView.ExternalFiles.IsExpanded = externalFilesDataRows.Count() > 0;
DependencyView.Packages.IsExpanded = dataRows.Any();
DependencyView.LocalDefinitions.IsExpanded = localDefinitionDataRows.Any();
DependencyView.ExternalFiles.IsExpanded = externalFilesDataRows.Any();

ws.ForceComputeWorkspaceReferences = false;
ws.ForceComputeWorkspaceReferences = false;

DependencyView.PackageDependencyTable.ItemsSource = dataRows;
DependencyView.LocalDefinitionsTable.ItemsSource = localDefinitionDataRows;
DependencyView.ExternalFilesTable.ItemsSource = externalFilesDataRows;
DependencyView.PackageDependencyTable.ItemsSource = dataRows;
DependencyView.LocalDefinitionsTable.ItemsSource = localDefinitionDataRows;
DependencyView.ExternalFilesTable.ItemsSource = externalFilesDataRows;
}
catch(Exception ex)
{
OnMessageLogged(LogMessage.Info(string.Format(Resources.DependencyViewExtensionErrorTemplate, ex.ToString())));
}
}

public override void Closed()
Expand Down

0 comments on commit 23b596c

Please sign in to comment.