diff --git a/NodeNetwork/NodeNetwork.csproj b/NodeNetwork/NodeNetwork.csproj index 2e2e12f..f440a8f 100644 --- a/NodeNetwork/NodeNetwork.csproj +++ b/NodeNetwork/NodeNetwork.csproj @@ -25,11 +25,11 @@ - + - + diff --git a/NodeNetworkToolkit/Group/NodeGrouper.cs b/NodeNetworkToolkit/Group/NodeGrouper.cs index 7ba62ef..c1668d8 100644 --- a/NodeNetworkToolkit/Group/NodeGrouper.cs +++ b/NodeNetworkToolkit/Group/NodeGrouper.cs @@ -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. /// - public Func GroupNodeFactory { get; set; } + public Func GroupNodeFactory { get; set; } = subnet => new NodeViewModel(); /// /// Constructs a viewmodel for the subnetwork that will contain the group member nodes. /// - public Func SubNetworkFactory { get; set; } + public Func SubNetworkFactory { get; set; } = () => new NetworkViewModel(); /// /// Constructs the node in the subnet that provides access to (mostly) inputs to the group /// - public Func EntranceNodeFactory { get; set; } + public Func EntranceNodeFactory { get; set; } = () => new NodeViewModel(); /// /// Constructs the node in the subnet that provides access to (mostly) outputs of the group /// - public Func ExitNodeFactory { get; set; } + public Func ExitNodeFactory { get; set; } = () => new NodeViewModel(); /// /// Constructs a NodeGroupIOBinding from a group, entrance and exit node. /// public Func IOBindingFactory { get; set; } + private bool CheckPropertiesValid() => + GroupNodeFactory != null && SubNetworkFactory != null && EntranceNodeFactory != null && ExitNodeFactory != null && IOBindingFactory != null; + /// /// 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. @@ -51,6 +54,19 @@ public class NodeGrouper /// Returns the NodeGroupIOBinding that was constructed for this group using the IOBindingFactory. public NodeGroupIOBinding MergeIntoGroup(NetworkViewModel network, IEnumerable 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 set ? set : new HashSet(nodesToGroup); @@ -167,6 +183,15 @@ public NodeGroupIOBinding MergeIntoGroup(NetworkViewModel network, IEnumerableThe NodeGroupIOBinding of the group to dissolve. 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;