/// <summary>
        /// Restore either <see cref="IWorkplanStep.Inputs"/> or <see cref="IWorkplanStep.Outputs"/>.
        /// </summary>
        private static IConnector[] RestoreReferences(StepEntity stepEntity, ConnectorRole role, IDictionary <long, IConnector> connectors)
        {
            var referenceEntities = stepEntity.Connectors.Where(c => c.Role == role).ToList();

            var references = new IConnector[referenceEntities.Count];

            for (int index = 0; index < referenceEntities.Count; index++)
            {
                var referenceEntity = referenceEntities.First(f => f.Index == index);
                if (referenceEntity.ConnectorId.HasValue)
                {
                    references[index] = connectors[referenceEntity.ConnectorId.Value];
                }
            }

            return(references);
        }
        /// <summary>
        /// Update either inputs or outputs in the database
        /// </summary>
        private static void UpdateConnectors(IConnectorReferenceRepository referenceRepo, StepEntity stepEntity, IWorkplanStep step, ConnectorRole role, IDictionary <long, ConnectorEntity> connectors)
        {
            // Update inputs first
            var connectorArray = role == ConnectorRole.Input ? step.Inputs : step.Outputs;

            for (int index = 0; index < connectorArray.Length; index++)
            {
                var connector          = connectorArray[index];
                var connectorReference = stepEntity.Connectors.FirstOrDefault(c => c.Role == role && c.Index == index);
                if (connectorReference == null && connector != null)
                {
                    // Reference not yet stored in database
                    connectorReference           = referenceRepo.Create(index, role);
                    connectorReference.Step      = stepEntity;
                    connectorReference.Connector = connectors[connector.Id];
                }
                else if (connectorReference != null && connector != null)
                {
                    // Reference possible modified
                    connectorReference.Connector = connectors[connector.Id];
                }
                else if (connectorReference != null)
                {
                    // Reference removed
                    connectorReference.Connector = null;
                }
                else
                {
                    // Connector null and no entity exists
                    connectorReference      = referenceRepo.Create(index, role);
                    connectorReference.Step = stepEntity;
                }
            }
        }