internal LayerConnections(ConnectionType type, Layer connectedLayer)
        {
            Debug.Assert(connectedLayer != null);

            ConnectedLayer = connectedLayer;
            Type = type;
        }
Beispiel #2
0
        internal IndexedLayer(Layer layer, int index)
        {
            Debug.Assert(layer != null);
            Debug.Assert(index >= 0);

            Layer = layer;
            Index = index;
        }
        public void Add(Layer item, FlowDirection direction)
        {
            Args.Requires(() => item, () => item != null);
            Args.Requires(() => direction, () => direction == FlowDirection.OneWay || direction == FlowDirection.OneWayToSource || direction == FlowDirection.TwoWay);

            if (!otherLayers.Any(l => l.Item2 == item))
            {
                WithOtherSideUpdateSuppressed(item, () =>
                {
                    if (Type == ConnectionType.Output)
                    {
                        item.InputConnections.Add(ConnectedLayer, direction);
                    }
                    else
                    {
                        item.OutputConnections.Add(ConnectedLayer, direction);
                    }
                });
                otherLayers.Add(Tuple.Create(direction, item));
            }
        }
        public bool Remove(Layer item)
        {
            Args.Requires(() => item, () => item != null);

            var toRemove = otherLayers.FirstOrDefault(i => i.Item2 == item);
            if (toRemove != null && otherLayers.Remove(toRemove))
            {
                WithOtherSideUpdateSuppressed(item, () =>
                {
                    if (Type == ConnectionType.Output)
                    {
                        item.InputConnections.Remove(ConnectedLayer);
                    }
                    else
                    {
                        item.OutputConnections.Remove(ConnectedLayer);
                    }
                });
                return true;
            }
            return false;
        }
 public void AddOneWayToSource(Layer item)
 {
     Add(item, FlowDirection.OneWayToSource);
 }
 public void AddTwoWay(Layer item)
 {
     Add(item, FlowDirection.TwoWay);
 }
 public void AddOneWay(Layer item)
 {
     Add(item, FlowDirection.OneWay);
 }
 private void WithOtherSideUpdateSuppressed(Layer item, Action method)
 {
     if (!suppressOtherSideUpdate)
     {
         ((LayerConnections)item.InputConnections).suppressOtherSideUpdate = true;
         ((LayerConnections)item.OutputConnections).suppressOtherSideUpdate = true;
         try
         {
             method();
         }
         finally
         {
             ((LayerConnections)item.InputConnections).suppressOtherSideUpdate = false;
             ((LayerConnections)item.OutputConnections).suppressOtherSideUpdate = false;
         }
     }
 }