Skip to content

Commit

Permalink
Update dependencies, provide defaults and input validation in NodeGro…
Browse files Browse the repository at this point in the history
…uper.
  • Loading branch information
Wouterdek committed Sep 21, 2020
1 parent 5bfb345 commit 91b83bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions NodeNetwork/NodeNetwork.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.9" />
<PackageReference Include="log4net" Version="2.0.10" />
<PackageReference Include="ReactiveUI" Version="11.5.35" />
<PackageReference Include="ReactiveUI.Events.WPF" Version="11.5.35" />
<PackageReference Include="ReactiveUI.WPF" Version="11.5.35" />
<PackageReference Include="Splat.Drawing" Version="9.5.35" />
<PackageReference Include="Splat.Drawing" Version="9.5.37" />
<PackageReference Include="System.Buffers" Version="4.5.1" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" />
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
Expand Down
33 changes: 29 additions & 4 deletions NodeNetworkToolkit/Group/NodeGrouper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,31 @@ public class NodeGrouper
/// Constructs a new node that represents a group of nodes.
/// The parameter is the subnetwork (constructed with SubNetworkFactory) that contains the group member nodes.
/// </summary>
public Func<NetworkViewModel, NodeViewModel> GroupNodeFactory { get; set; }
public Func<NetworkViewModel, NodeViewModel> GroupNodeFactory { get; set; } = subnet => new NodeViewModel();

/// <summary>
/// Constructs a viewmodel for the subnetwork that will contain the group member nodes.
/// </summary>
public Func<NetworkViewModel> SubNetworkFactory { get; set; }
public Func<NetworkViewModel> SubNetworkFactory { get; set; } = () => new NetworkViewModel();

/// <summary>
/// Constructs the node in the subnet that provides access to (mostly) inputs to the group
/// </summary>
public Func<NodeViewModel> EntranceNodeFactory { get; set; }
public Func<NodeViewModel> EntranceNodeFactory { get; set; } = () => new NodeViewModel();

/// <summary>
/// Constructs the node in the subnet that provides access to (mostly) outputs of the group
/// </summary>
public Func<NodeViewModel> ExitNodeFactory { get; set; }
public Func<NodeViewModel> ExitNodeFactory { get; set; } = () => new NodeViewModel();

/// <summary>
/// Constructs a NodeGroupIOBinding from a group, entrance and exit node.
/// </summary>
public Func<NodeViewModel, NodeViewModel, NodeViewModel, NodeGroupIOBinding> IOBindingFactory { get; set; }

private bool CheckPropertiesValid() =>
GroupNodeFactory != null && SubNetworkFactory != null && EntranceNodeFactory != null && ExitNodeFactory != null && IOBindingFactory != null;

/// <summary>
/// Move the specified set of nodes to a new subnetwork, create a new group node that contains this subnet,
/// restore inter- and intra-network connections.
Expand All @@ -51,6 +54,19 @@ public class NodeGrouper
/// <returns>Returns the NodeGroupIOBinding that was constructed for this group using the IOBindingFactory.</returns>
public NodeGroupIOBinding MergeIntoGroup(NetworkViewModel network, IEnumerable<NodeViewModel> nodesToGroup)
{
if (!CheckPropertiesValid())
{
throw new InvalidOperationException("All properties must be set before usage");
}
else if (network == null)
{
throw new ArgumentNullException(nameof(network));
}
else if (nodesToGroup == null)
{
throw new ArgumentNullException(nameof(nodesToGroup));
}

var groupNodesSet = nodesToGroup is HashSet<NodeViewModel> set
? set
: new HashSet<NodeViewModel>(nodesToGroup);
Expand Down Expand Up @@ -167,6 +183,15 @@ public NodeGroupIOBinding MergeIntoGroup(NetworkViewModel network, IEnumerable<N
/// <param name="nodeGroupInfo">The NodeGroupIOBinding of the group to dissolve.</param>
public void Ungroup(NodeGroupIOBinding nodeGroupInfo)
{
if (!CheckPropertiesValid())
{
throw new InvalidOperationException("All properties must be set before usage");
}
else if (nodeGroupInfo == null)
{
throw new ArgumentNullException(nameof(nodeGroupInfo));
}

var supernet = nodeGroupInfo.SuperNetwork;
var subnet = nodeGroupInfo.SubNetwork;

Expand Down

0 comments on commit 91b83bf

Please sign in to comment.