// Update our route node info object private void OnRouteSegmentAdded(RouteSegmentInfo routeSegment, RouteSegmentPlanned @event) { routeSegment.FromRouteNodeId = @event.FromNodeId; routeSegment.ToRouteNodeId = @event.ToNodeId; routeSegment.SegmentKind = @event.SegmentKind; routeSegment.Geometry = @event.InitialGeometry; routeNetworkQueryService.AddRouteSegmentInfo(routeSegment); }
internal RouteSegment(Guid routeSegmentId, Guid fromNodeId, Guid toNodeId, RouteSegmentKindEnum segmentKind, RouteNetwork.Events.Model.Geometry geometry) : this() { // Check that we got some valid geometry if (geometry == null) { throw new ArgumentException("Cannot create route segment with id: " + routeSegmentId + " because Geometry is null, which is not allowed."); } if (geometry.GeoJsonType == null) { throw new ArgumentException("Cannot create route segment with id: " + routeSegmentId + " because Geometry.GeoJsonType is null, which is not allowed."); } if (geometry.GeoJsonType.ToLower() != "linestring") { throw new ArgumentException("Cannot create route segment with id: " + routeSegmentId + " because Geometry.GeoJsonType is: " + geometry.GeoJsonType + ", which is not allowed in route segments. Expected LineString."); } if (geometry.GeoJsonCoordinates == null) { throw new ArgumentException("Cannot create route segment with id: " + routeSegmentId + " because Geometry.GeoJsonCoordinates is null, which is not allowed."); } // Try parse geojson var line = ConvertFromLineGeoJson(geometry.GeoJsonCoordinates); // Create domain event var routeNodeAdded = new RouteSegmentPlanned() { Id = routeSegmentId, FromNodeId = fromNodeId, ToNodeId = toNodeId, SegmentKind = segmentKind, InitialGeometry = geometry }; RaiseEvent(routeNodeAdded); }
// Apply route segment added event private void Apply(RouteSegmentPlanned @event) { Id = @event.Id; }
/// <summary> /// Add a new route segment to the network /// </summary> /// <param name="routeSegmentId"></param> /// <param name="fromNodeId"></param> /// <param name="toNodeId"></param> /// <param name="segmentKind"></param> /// <param name="geometry"></param> public void AddRouteSegment(Guid routeSegmentId, Guid fromNodeId, Guid toNodeId, RouteSegmentKindEnum segmentKind, RouteNetwork.Events.Model.Geometry geometry) { // Id check if (routeSegmentId == null || routeSegmentId == Guid.Empty) { throw new ArgumentException("Id cannot be null or empty"); } // Check that segment not already exists if (routeNetworkState.CheckIfRouteSegmentIdExists(routeSegmentId)) { throw new ArgumentException("A route segment with id: " + routeSegmentId + " already exists"); } // Check if from node exists if (!routeNetworkState.CheckIfRouteNodeIdExists(fromNodeId)) { throw new ArgumentException("The FromNodeId parameter is invalid. Cannot find any node in the network with id: " + fromNodeId); } // Check if to node exists if (!routeNetworkState.CheckIfRouteNodeIdExists(toNodeId)) { throw new ArgumentException("The ToNodeId parameter is invalid. Cannot find any node in the network with id: " + toNodeId); } // Check that we got some valid geometry if (geometry == null) { throw new ArgumentException("Cannot create route segment with id: " + routeSegmentId + " because Geometry is null, which is not allowed."); } if (geometry.GeoJsonType == null) { throw new ArgumentException("Cannot create route segment with id: " + routeSegmentId + " because Geometry.GeoJsonType is null, which is not allowed."); } if (geometry.GeoJsonType.ToLower() != "linestring") { throw new ArgumentException("Cannot create route segment with id: " + routeSegmentId + " because Geometry.GeoJsonType is: " + geometry.GeoJsonType + ", which is not allowed in route segments. Expected LineString."); } if (geometry.GeoJsonCoordinates == null) { throw new ArgumentException("Cannot create route segment with id: " + routeSegmentId + " because Geometry.GeoJsonCoordinates is null, which is not allowed."); } // Try parse geojson var line = GeometryConversionHelper.ConvertFromLineGeoJson(geometry.GeoJsonCoordinates); // Create domain event var routeSegmentPlanned = new RouteSegmentPlanned() { Id = routeSegmentId, FromNodeId = fromNodeId, ToNodeId = toNodeId, SegmentKind = segmentKind, InitialGeometry = geometry }; RaiseEvent(routeSegmentPlanned, false); }