예제 #1
0
        internal void AttachConduitEndToClosure(Guid conduitId, ConduitClosureInfoSide side, int portPosition, int terminalPosition, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService, IConduitClosureRepository conduitClosureRepository)
        {
            // Check if conduit is passing by closure
            var conduit        = conduitNetworkQueryService.GetConduitInfo(conduitId);
            var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(conduit.WalkOfInterestId);

            if (!walkOfInterest.AllNodeIds.Contains(_pointOfInterestId))
            {
                throw new ArgumentException("Conduit: " + conduitId + " is not related to the point of interest: " + _pointOfInterestId + " where conduit closure: " + Id + " is placed at all.");
            }

            if (!(walkOfInterest.StartNodeId == _pointOfInterestId || walkOfInterest.EndNodeId == _pointOfInterestId))
            {
                throw new ArgumentException("Conduit: " + conduitId + " is not ending in point of interest: " + _pointOfInterestId + " - but not pasing through it. Please use AttachPassByConduitToClosure instead. The AttachConduitEndToClosure can only be used on conduits that are ending in the point of interest (route node) where the conduit closure is placed.");
            }

            var conduitClosureInfo = conduitClosureRepository.GetConduitClosureInfo(Id);


            // Check if conduit is already attached to closure
            if (conduitClosureInfo.Sides.Exists(s => s.Ports.Exists(p => p.MultiConduitId == conduitId)))
            {
                throw new ArgumentException("The conduit: " + conduitId + " is already attached to the closure: " + this.Id);
            }

            if (conduitClosureInfo.Sides.Exists(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineId == conduitId))))
            {
                throw new ArgumentException("The conduit: " + conduitId + " is already attached to the closure: " + this.Id);
            }



            // If ports already exists on the side and outgoing port argument not set, find next available port
            if (portPosition == 0 && conduitClosureInfo.Sides.Find(s => s.Position == side).Ports.Count != 0)
            {
                portPosition = conduitClosureInfo.Sides.Find(s => s.Position == side).Ports.OrderByDescending(p => p.Position).First().Position + 1;
            }
            else
            {
                portPosition = 1; // No ports yet, so we put it on port 1
            }
            // Check if port is the next in sequence.
            if (conduitClosureInfo.Sides.Find(s => s.Position == side).Ports.Count != 0)
            {
                if (conduitClosureInfo.Sides.Find(s => s.Position == side).Ports.OrderByDescending(p => p.Position).First().Position != (portPosition - 1))
                {
                    throw new ArgumentException("Incomming port: " + portPosition + "on side: " + side + " is not the next number in sequence. Last port number used on side: " + side + " is: " + conduitClosureInfo.Sides.Find(s => s.Position == side).Ports.OrderByDescending(p => p.Position).First().Position);
                }
            }
            else
            {
                if (portPosition != 1)
                {
                    throw new ArgumentException("Incomming port: " + portPosition + "on side: " + side + " is not the next number in sequence. No ports currently added to side: " + side + ". Therefor port number = 1 was expected.");
                }
            }

            // If a single conduit, and terminal not specified, find next avaiable terminal position
            if (terminalPosition == 0 && conduitClosureInfo.Sides.Exists(s => s.Position == side && s.Ports.Exists(p => p.Position == portPosition && p.Terminals.Count != 0)))
            {
                terminalPosition = conduitClosureInfo.
                                   Sides.Find(s => s.Position == side).
                                   Ports.Find(p => p.Position == portPosition).
                                   Terminals.OrderByDescending(p => p.Position).First().Position + 1;
            }
            else
            {
                terminalPosition = 1; // No terminals yet, so we put it on terminal 1
            }
            ///////////////////////////////////////////////////////////////
            /// Finish checking. Now created the domain events
            var conduitEndAttached = new ConduitClosureConduitEndAttached()
            {
                ConduitClosureId = this.Id,
                ConduitId        = conduitId,
                Side             = side,
                PortPosition     = portPosition,
                TerminalPosition = terminalPosition
            };

            RaiseEvent(conduitEndAttached);
        }
예제 #2
0
 private void Apply(ConduitClosureConduitEndAttached @event)
 {
 }
        private void OnConduitClosureConduitEndAttached(ConduitClosureInfo conduitClosure, ConduitClosureConduitEndAttached @event)
        {
            // Get conduit
            var conduit = conduitNetworkQueryService.GetConduitInfo(@event.ConduitId);

            if (conduit is MultiConduitInfo)
            {
                AttachMultiConduitEndToPort(conduitClosure, @event.ConduitId, @event.Side, @event.PortPosition);
                //AttachInnerConduitsToTerminals(conduitClosure, @event, @event.IncommingSide);
                conduitClosureRepository.UpdateConduitClosureInfo(conduitClosure);
            }
            else if (conduit is SingleConduitInfo)
            {
                AttachSingleConduitToPortTerminal(conduitClosure, @event.ConduitId, @event.Side, @event.PortPosition, @event.TerminalPosition);
                conduitClosureRepository.UpdateConduitClosureInfo(conduitClosure);
            }
        }