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

Refactor PackageDependencies property #9803

Merged
merged 10 commits into from
Jun 27, 2019
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
scottmitchell marked this conversation as resolved.
Show resolved Hide resolved
{
/// <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