Skip to content

Commit

Permalink
Refactor PackageDependencies property (#9803)
Browse files Browse the repository at this point in the history
* Refactor PackageDependencies property

* Add test to verify multiple packages not listed as dependencies for one node

* Keep original package dependency by default and add API to void original package dependency

* Add comment

* Move helper methods out of properties region

* Fix IsLoaded logic

* Update test .dyn to avoid serialization test failures

* Exclude new dyn from serialization tests

* Use preexisting method to exclude test dyn from serialization tests
  • Loading branch information
scottmitchell authored Jun 27, 2019
1 parent 405cac2 commit ffed170
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 153 deletions.
111 changes: 104 additions & 7 deletions src/DynamoCore/Graph/Workspaces/PackageDependencyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
namespace Dynamo.Graph.Workspaces
{
/// <summary>
/// Class containing info about a Dynamo package.
/// Used for serialization.
/// Class containing info about a package
/// </summary>
internal class PackageDependencyInfo
internal class PackageInfo
{
/// <summary>
/// Name of the package
Expand All @@ -19,6 +18,86 @@ internal class PackageDependencyInfo
/// </summary>
internal Version Version { get; set; }

/// <summary>
/// Create a package info object from the package name and version
/// </summary>
/// <param name="name"></param>
/// <param name="version"></param>
internal PackageInfo(string name, Version version)
{
Name = name;
Version = version;
}

/// <summary>
/// Checks whether two PackageInfos are equal
/// They are equal if their Name and Versions are equal
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
if (!(obj is PackageInfo))
{
return false;
}

var other = obj as PackageInfo;
if (other.Name == this.Name && other.Version == this.Version)
{
return true;
}
return false;
}

/// <summary>
/// Gets the hashcode for this PackageInfo
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return Name.GetHashCode() ^ Version.GetHashCode();
}

/// <summary>
/// Get the string representing this PackageInfo
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Name + ", Version=" + Version.ToString();
}
}

/// <summary>
/// Class containing info about a workspace package dependency
/// </summary>
internal class PackageDependencyInfo
{
/// <summary>
/// PackageInfo for this package
/// </summary>
internal PackageInfo PackageInfo { get; set; }

/// <summary>
/// Name of the package
/// </summary>
internal string Name => PackageInfo.Name;

/// <summary>
/// Version of the package
/// </summary>
internal Version Version => PackageInfo.Version;

/// <summary>
/// Indicates whether this package is loaded in the current session
/// </summary>
internal bool IsLoaded { get; set; }

/// <summary>
/// Guids of nodes in the workspace that are dependent on this package
/// </summary>
Expand All @@ -29,14 +108,23 @@ internal HashSet<Guid> Nodes
private HashSet<Guid> nodes;

/// <summary>
/// Create a package info object from the package name and version
/// Create a package dependency from the package name and version
/// </summary>
/// <param name="name"></param>
/// <param name="version"></param>
internal PackageDependencyInfo(string name, Version version)
{
Name = name;
Version = version;
PackageInfo = new PackageInfo(name, version);
nodes = new HashSet<Guid>();
}

/// <summary>
/// Create a package dependency from its package info
/// </summary>
/// <param name="packageInfo"></param>
internal PackageDependencyInfo(PackageInfo packageInfo)
{
PackageInfo = packageInfo;
nodes = new HashSet<Guid>();
}

Expand Down Expand Up @@ -71,7 +159,7 @@ internal void RemoveDependent(Guid guid)
}

/// <summary>
/// Checks whether two PackageDependencyInfos are equal
/// Checks whether two PackageDependencyInfo instances are equal
/// They are equal if their Name and Versions are equal
/// </summary>
/// <param name="obj"></param>
Expand Down Expand Up @@ -103,5 +191,14 @@ public override int GetHashCode()
{
return Name.GetHashCode() ^ Version.GetHashCode();
}

/// <summary>
/// Get the string representing this PackageDependencyInfo
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Name + ", Version=" + Version.ToString();
}
}
}
8 changes: 4 additions & 4 deletions src/DynamoCore/Graph/Workspaces/SerializationConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,17 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
}

/// <summary>
/// PackageDependencyInfoConverter is used to serialize and deserialize graph package dependencies
/// PackageDependencyConverter is used to serialize and deserialize graph package dependencies
/// </summary>
public class PackageDependencyInfoConverter : JsonConverter
public class PackageDependencyConverter : JsonConverter
{
private Logging.ILogger logger;

/// <summary>
/// Constructs a PackageDependencyInfoConverter.
/// Constructs a PackageDependencyConverter.
/// </summary>
/// <param name="logger"></param>
public PackageDependencyInfoConverter(Logging.ILogger logger)
public PackageDependencyConverter(Logging.ILogger logger)
{
this.logger = logger;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Graph/Workspaces/SerializationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal static string ToJson(this WorkspaceModel workspace, EngineController en
new WorkspaceWriteConverter(engine),
new DummyNodeWriteConverter(),
new TypedParameterConverter(),
new PackageDependencyInfoConverter(logger),
new PackageDependencyConverter(logger),
},
ReferenceResolverProvider = () => { return new IdReferenceResolver(); }
};
Expand Down
Loading

0 comments on commit ffed170

Please sign in to comment.