private RouteSegment CreateRouteSegment(dynamic routeSegment) { var mappedRouteSegment = new RouteSegment { Mrid = new Guid(routeSegment.mrid.ToString()), Coord = (JObject)routeSegment.coord is null ? null : Convert.FromBase64String(routeSegment.coord.wkb.ToString()), Username = routeSegment.user_name.ToString(), WorkTaskMrid = routeSegment.work_task_mrid.ToString() == string.Empty ? System.Guid.Empty : new Guid(routeSegment.work_task_mrid.ToString()), ApplicationName = routeSegment.application_name.ToString(), MarkAsDeleted = (bool)routeSegment.marked_to_be_deleted, ApplicationInfo = routeSegment.application_info.ToString(), DeleteMe = (bool)routeSegment.delete_me, LifeCycleInfo = new LifecycleInfo( _infoMapper.MapDeploymentState((string)routeSegment.lifecycle_deployment_state), (DateTime?)routeSegment.lifecycle_installation_date, (DateTime?)routeSegment.lifecycle_removal_date ), MappingInfo = new MappingInfo( _infoMapper.MapMappingMethod((string)routeSegment.mapping_method), (string)routeSegment.mapping_vertical_accuracy, (string)routeSegment.mapping_horizontal_accuracy, (DateTime?)routeSegment.mapping_survey_date, (string)routeSegment.mapping_source_info ), NamingInfo = new NamingInfo( (string)routeSegment.naming_name, (string)routeSegment.naming_description ), SafetyInfo = new SafetyInfo( (string)routeSegment.safety_classification, (string)routeSegment.safety_remark ), RouteSegmentInfo = new RouteSegmentInfo( _infoMapper.MapRouteSegmentKind((string)routeSegment.routesegment_kind), (string)routeSegment.routesegment_width, (string)routeSegment.routesegment_height ) }; // Make fully empty objects into nulls. mappedRouteSegment.LifeCycleInfo = AreAnyPropertiesNotNull <LifecycleInfo>(mappedRouteSegment.LifeCycleInfo) ? mappedRouteSegment.LifeCycleInfo : null; mappedRouteSegment.MappingInfo = AreAnyPropertiesNotNull <MappingInfo>(mappedRouteSegment.MappingInfo) ? mappedRouteSegment.MappingInfo : null; mappedRouteSegment.NamingInfo = AreAnyPropertiesNotNull <NamingInfo>(mappedRouteSegment.NamingInfo) ? mappedRouteSegment.NamingInfo : null; mappedRouteSegment.RouteSegmentInfo = AreAnyPropertiesNotNull <RouteSegmentInfo>(mappedRouteSegment.RouteSegmentInfo) ? mappedRouteSegment.RouteSegmentInfo : null; mappedRouteSegment.SafetyInfo = AreAnyPropertiesNotNull <SafetyInfo>(mappedRouteSegment.SafetyInfo) ? mappedRouteSegment.SafetyInfo : null; return(mappedRouteSegment); }
private static NamingInfo CalculateName(IEventStore eventStore, NamingInfo namingInfo, SpanEquipmentSpecification spec) { if (spec.Category != null && spec.Category.ToLower().Contains("conduit")) { var nextConduitSeqStr = eventStore.Sequences.GetNextVal("conduit").ToString(); var conduitName = "R" + nextConduitSeqStr.PadLeft(6, '0'); namingInfo = new NamingInfo(conduitName, null); } else if (spec.Category != null && spec.Category.ToLower().Contains("cable")) { var nextCableSeqStr = eventStore.Sequences.GetNextVal("cable").ToString(); var conduitName = "K" + nextCableSeqStr.PadLeft(6, '0'); namingInfo = new NamingInfo(conduitName, null); } return(namingInfo); }
private void PlaceConduit(string externalId, Guid specificationId, List <Guid> segmentIds, List <Guid> additionalStructureSpecIds, string markingColor) { Guid correlationId = Guid.NewGuid(); RouteNetworkElementIdList walkIds = new RouteNetworkElementIdList(); walkIds.AddRange(segmentIds); // Register walk of interest var walkOfInterestId = Guid.NewGuid(); var registerWalkOfInterestCommand = new RegisterWalkOfInterest(correlationId, new UserContext("conversion", _bentleyMultiConduitConversion), walkOfInterestId, walkIds); var registerWalkOfInterestCommandResult = _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(registerWalkOfInterestCommand).Result; if (registerWalkOfInterestCommandResult.IsFailed) { _logger.LogInformation("Failed to add conduit: " + externalId + " Error: " + registerWalkOfInterestCommandResult.Errors.First().Message); return; } // conduit name var nextConduitSeqStr = _eventStore.Sequences.GetNextVal("conduit").ToString(); var conduitName = "R" + nextConduitSeqStr.PadLeft(6, '0'); var namingInfo = new NamingInfo(conduitName, null); // Place conduit var placeSpanEquipmentCommand = new PlaceSpanEquipmentInRouteNetwork(correlationId, new UserContext("conversion", _bentleyMultiConduitConversion), Guid.NewGuid(), specificationId, registerWalkOfInterestCommandResult.Value) { MarkingInfo = markingColor != null ? new MarkingInfo() { MarkingColor = markingColor } : null, NamingInfo = namingInfo }; var placeSpanEquipmentResult = _commandDispatcher.HandleAsync <PlaceSpanEquipmentInRouteNetwork, Result>(placeSpanEquipmentCommand).Result; if (placeSpanEquipmentResult.IsFailed) { _logger.LogInformation("Failed to add conduit: " + externalId + " Error: " + placeSpanEquipmentResult.Errors.First().Message); return; } // Place additional structures if (additionalStructureSpecIds.Count > 0) { var addStructure = new PlaceAdditionalStructuresInSpanEquipment(correlationId, new UserContext("conversion", _bentleyMultiConduitConversion), spanEquipmentId: placeSpanEquipmentCommand.SpanEquipmentId, structureSpecificationIds: additionalStructureSpecIds.ToArray() ); var addStructureResult = _commandDispatcher.HandleAsync <PlaceAdditionalStructuresInSpanEquipment, Result>(addStructure).Result; if (addStructureResult.IsFailed) { _logger.LogInformation("Failed to add additional structures to: " + externalId + " Error: " + placeSpanEquipmentResult.Errors.First().Message); return; } } }
public Result PlaceCableSpanEquipment(NpgsqlCommand logCmd, Guid spanEquipmentId, string externalId, Guid specificationId, List <Guid> routeSegmentIds, List <CableConduitRel> conduitRels) { Guid correlationId = Guid.NewGuid(); RouteNetworkElementIdList walkIds = new RouteNetworkElementIdList(); walkIds.AddRange(routeSegmentIds); // Cable name var nextConduitSeqStr = _eventStore.Sequences.GetNextVal("cable").ToString(); var conduitName = "K" + nextConduitSeqStr.PadLeft(6, '0'); var namingInfo = new NamingInfo(conduitName, null); // HACK use NE id var neIdSplit = externalId.Split(':'); namingInfo = new NamingInfo("K" + neIdSplit.Last(), null); System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); System.Diagnostics.Debug.WriteLine($"*** Place cable: {externalId} ***"); System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); // Get validated walk of interest var walk = new RouteNetworkElementIdList(); walk.AddRange(routeSegmentIds); var validateInterestCommand = new ValidateWalkOfInterest(correlationId, new UserContext("conversion", _workTaskId), walk); var validateInterestResult = _commandDispatcher.HandleAsync <ValidateWalkOfInterest, Result <ValidatedRouteNetworkWalk> >(validateInterestCommand).Result; if (validateInterestResult.IsFailed) { return(Result.Fail(validateInterestResult.Errors.First())); } // trace all conduits var conduitsTraceResult = TraceAllConduits(conduitRels); foreach (var conduitTrace in conduitsTraceResult) { System.Diagnostics.Debug.WriteLine($"NE conduit path found starting in {conduitTrace.ConduitName} node {conduitTrace.OriginalTrace.FromRouteNodeName} ({conduitTrace.OriginalTrace.FromRouteNodeId}) <-> {conduitTrace.OriginalTrace.ToRouteNodeName} ({conduitTrace.OriginalTrace.ToRouteNodeId}) span segment id: {conduitTrace.SpanSegmentId}"); } var routingHops = BuildRouteHops(validateInterestResult.Value, conduitsTraceResult, externalId); System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); foreach (var hop in routingHops) { System.Diagnostics.Debug.WriteLine($"Routing hop: start route node id: {hop.StartRouteNode} span equipment id: {hop.StartSpanSegmentId}"); } // Place cable var placeSpanEquipmentCommand = new PlaceSpanEquipmentInUtilityNetwork(correlationId, new UserContext("conversion", _workTaskId), spanEquipmentId, specificationId, routingHops.ToArray()) { NamingInfo = namingInfo, }; var placeSpanEquipmentResult = _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentCommand).Result; if (placeSpanEquipmentResult.IsFailed) { var errorMsg = "Failed to route cable: " + externalId + " through conduit network: " + placeSpanEquipmentResult.Errors.First().Message; System.Diagnostics.Debug.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------"); System.Diagnostics.Debug.WriteLine(errorMsg); _logger.LogInformation(errorMsg); // Try place cable directly in route network var placeSpanEquipmentDirectlyInRouteNetworkCmd = new PlaceSpanEquipmentInUtilityNetwork(correlationId, new UserContext("conversion", _workTaskId), spanEquipmentId, specificationId, new RoutingHop[] { new RoutingHop(validateInterestResult.Value.RouteNetworkElementRefs.ToArray()) } ) { NamingInfo = namingInfo, }; var placeSpanEquipmentDirectlyInRouteNetworkResult = _commandDispatcher.HandleAsync <PlaceSpanEquipmentInUtilityNetwork, Result>(placeSpanEquipmentDirectlyInRouteNetworkCmd).Result; if (placeSpanEquipmentDirectlyInRouteNetworkResult.IsFailed) { errorMsg = "GENERAL FAILURE PLACING DIRECTLY IN ROUTE NETWORK: " + placeSpanEquipmentResult.Errors.First().Message + " " + errorMsg; } LogStatus((NpgsqlCommand)logCmd, _tableName, errorMsg, externalId); return(placeSpanEquipmentResult); } return(Result.Ok()); }
private Result PlaceConduitSpanEquipment(NpgsqlCommand logCmd, Guid spanEquipmentId, string externalId, Guid specificationId, List <Guid> segmentIds, List <Guid> additionalStructureSpecIds, string markingColor, Guid?accessAddressId, Guid?unitAddressId, string?addressRemark) { Guid correlationId = Guid.NewGuid(); RouteNetworkElementIdList walkIds = new RouteNetworkElementIdList(); walkIds.AddRange(segmentIds); // Register walk of interest var walkOfInterestId = Guid.NewGuid(); var registerWalkOfInterestCommand = new RegisterWalkOfInterest(correlationId, new UserContext("conversion", _neMultiConduitConversion), walkOfInterestId, walkIds); var registerWalkOfInterestCommandResult = _commandDispatcher.HandleAsync <RegisterWalkOfInterest, Result <RouteNetworkInterest> >(registerWalkOfInterestCommand).Result; if (registerWalkOfInterestCommandResult.IsFailed) { _logger.LogInformation("Failed to add conduit: " + externalId + " Error: " + registerWalkOfInterestCommandResult.Errors.First().Message); LogStatus((NpgsqlCommand)logCmd, _tableName, registerWalkOfInterestCommandResult.Errors.First().Message, externalId); return(registerWalkOfInterestCommandResult); } // conduit name var nextConduitSeqStr = _eventStore.Sequences.GetNextVal("conduit").ToString(); var conduitName = "R" + nextConduitSeqStr.PadLeft(6, '0'); var namingInfo = new NamingInfo(conduitName, null); AddressInfo?addressInfo = null; if (accessAddressId != null || unitAddressId != null && addressRemark != null) { addressInfo = new AddressInfo() { AccessAddressId = accessAddressId, UnitAddressId = unitAddressId, Remark = addressRemark }; } // Place conduit var placeSpanEquipmentCommand = new PlaceSpanEquipmentInRouteNetwork(correlationId, new UserContext("conversion", _neMultiConduitConversion), spanEquipmentId, specificationId, registerWalkOfInterestCommandResult.Value) { MarkingInfo = markingColor != null ? new MarkingInfo() { MarkingColor = markingColor } : null, NamingInfo = namingInfo, AddressInfo = addressInfo }; var placeSpanEquipmentResult = _commandDispatcher.HandleAsync <PlaceSpanEquipmentInRouteNetwork, Result>(placeSpanEquipmentCommand).Result; if (placeSpanEquipmentResult.IsFailed) { _logger.LogInformation("Failed to add conduit: " + externalId + " Error: " + placeSpanEquipmentResult.Errors.First().Message); LogStatus((NpgsqlCommand)logCmd, _tableName, placeSpanEquipmentResult.Errors.First().Message, externalId); return(placeSpanEquipmentResult); } // Place additional structures if (additionalStructureSpecIds.Count > 0) { var addStructure = new PlaceAdditionalStructuresInSpanEquipment(correlationId, new UserContext("conversion", _neMultiConduitConversion), spanEquipmentId: placeSpanEquipmentCommand.SpanEquipmentId, structureSpecificationIds: additionalStructureSpecIds.ToArray() ); var addStructureResult = _commandDispatcher.HandleAsync <PlaceAdditionalStructuresInSpanEquipment, Result>(addStructure).Result; if (addStructureResult.IsFailed) { _logger.LogInformation("Failed to add additional structures to: " + externalId + " Error: " + placeSpanEquipmentResult.Errors.First().Message); LogStatus((NpgsqlCommand)logCmd, _tableName, addStructureResult.Errors.First().Message, externalId); return(addStructureResult); } } return(Result.Ok()); }