public MultiConduit(Guid conduitId, Guid walkOfInterestId, Guid conduitSpecificationId, string name, ConduitColorEnum markingColor, string markingText, IConduitNetworkQueryService conduitNetworkQueryService, IConduitSpecificationRepository conduitSpecificationRepository, string demoDataSpec = null) : this() { // Conduit Id check if (conduitId == null || conduitId == Guid.Empty) { throw new ArgumentException("Id cannot be null or empty"); } // Walk of interest id check if (walkOfInterestId == null || walkOfInterestId == Guid.Empty) { throw new ArgumentException("WalkOfInterestId cannot be null or empty"); } // Check that not already exists if (conduitNetworkQueryService.CheckIfMultiConduitIdExists(conduitId)) { throw new ArgumentException("A multi conduit id: " + conduitId + " already exists"); } // Create the multi conduit itself if (demoDataSpec != null && demoDataSpec != "") { var multiConduitPlaced = ConduitEventBuilder.CreateMultiConduitPlacedEvent(conduitId, walkOfInterestId, demoDataSpec); RaiseEvent(multiConduitPlaced); // Create all the inner conduits (if the multi conduit has such - the demo data builder will know) if (!demoDataSpec.StartsWith("FLEX")) { var innerConduitAddedEvents = ConduitEventBuilder.CreateInnerConduitAddedEvents(multiConduitPlaced, demoDataSpec); foreach (var innerConduitAddedEvent in innerConduitAddedEvents) { RaiseEvent(innerConduitAddedEvent); } } } else { var conduitSpec = conduitSpecificationRepository.GetConduitSpecification(conduitSpecificationId); var assetInfo = new AssetInfo(); assetInfo.Model = conduitSpec.ProductModels[0]; assetInfo.Manufacturer = conduitSpec.ProductModels[0].Manufacturer; var conduitInfo = new ConduitInfo() { Id = conduitId, Name = name, Shape = conduitSpec.Shape, Color = conduitSpec.Color, ColorMarking = markingColor, TextMarking = markingText, OuterDiameter = conduitSpec.OuterDiameter, InnerDiameter = conduitSpec.InnerDiameter }; var multiConduitEvent = new MultiConduitPlaced() { WalkOfInterestId = walkOfInterestId, MultiConduitId = conduitId, ConduitInfo = conduitInfo, AssetInfo = assetInfo }; RaiseEvent(multiConduitEvent); // Create all the inner conduit foreach (var innerConduitSpec in conduitSpec.ChildSpecifications) { var innerConduitInfo = new ConduitInfo() { Id = Guid.NewGuid(), Name = "Subrør " + innerConduitSpec.SequenceNumber, Color = innerConduitSpec.Color, InnerDiameter = innerConduitSpec.InnerDiameter, OuterDiameter = innerConduitSpec.OuterDiameter, Shape = innerConduitSpec.Shape, ColorMarking = ConduitColorEnum.None }; var innerConduitAddedEvent = new MultiConduitInnerConduitAdded() { MultiConduitId = conduitId, MultiConduitIndex = innerConduitSpec.SequenceNumber, ConduitInfo = innerConduitInfo }; RaiseEvent(innerConduitAddedEvent); } } }
public SingleConduit(Guid conduitId, Guid walkOfInterestId, Guid conduitSpecificationId, string name, ConduitColorEnum markingColor, string markingText, IConduitNetworkQueryService conduitNetworkQueryService, IConduitSpecificationRepository conduitSpecificationRepository, string demoDataSpec = null) : this() { ////////////////////////////////////////////////////////////////////////////////////// // NOTICE: // This constructor is currently a hack that just uses the demo data builder. // Must be refactored to use a conduit catalog system. // Conduit Id check if (conduitId == null || conduitId == Guid.Empty) { throw new ArgumentException("Id cannot be null or empty"); } // Walk of interest id check if (walkOfInterestId == null || walkOfInterestId == Guid.Empty) { throw new ArgumentException("WalkOfInterestId cannot be null or empty"); } // Check that not already exists if (conduitNetworkQueryService.CheckIfSingleConduitIdExists(conduitId)) { throw new ArgumentException("A singe conduit id: " + conduitId + " already exists"); } // Create the conduit if (demoDataSpec != null && demoDataSpec != "") { var singleConduitPlaced = ConduitEventBuilder.CreateSingleConduitPlacedEvent(conduitId, walkOfInterestId, demoDataSpec); RaiseEvent(singleConduitPlaced); } else { var conduitSpec = conduitSpecificationRepository.GetConduitSpecification(conduitSpecificationId); var assetInfo = new AssetInfo(); if (conduitSpec.ProductModels != null && conduitSpec.ProductModels.Count > 0) { assetInfo.Model = conduitSpec.ProductModels[0]; if (conduitSpec.ProductModels[0].Manufacturer != null) { assetInfo.Manufacturer = conduitSpec.ProductModels[0].Manufacturer; } } var conduitInfo = new ConduitInfo() { Id = conduitId, Name = name, Shape = conduitSpec.Shape, Color = conduitSpec.Color, ColorMarking = markingColor, OuterDiameter = conduitSpec.OuterDiameter, InnerDiameter = conduitSpec.InnerDiameter }; var singleConduitPlaccedEvent = new SingleConduitPlaced() { WalkOfInterestId = walkOfInterestId, SingleConduitId = conduitId, ConduitInfo = conduitInfo, AssetInfo = assetInfo }; RaiseEvent(singleConduitPlaccedEvent); } }
public ConduitServiceCommandHandler(IMediator commandBus, IConduitClosureRepository conduitClosureRepository, IConduitNetworkQueryService conduitNetworkQueryService, IRouteNetworkState routeNetwork, IConduitNetworkQueryService conduitNetwork, IConduitSpecificationRepository conduitSpecificationRepository) { Description = "API for sending commands to the conduit service"; Field <ConduitClosureCommandHandler>("conduitClosure", resolve: context => new { }); Field <MultiConduitCommandHandler>("multiConduit", resolve: context => new { }); Field <SingleConduitCommandHandler>("singleConduit", resolve: context => new { }); Field <ConduitInfoType>( "placeConduit", description: "Place a multi or single conduit in the route network", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitSpecificationId" }, new QueryArgument <NonNullGraphType <ListGraphType <IdGraphType> > > { Name = "walkOfInterest", Description = "Route network walk specified as a list of route element ids (route-node-id, route-segment-id, route-node-id...)" }, new QueryArgument <IdGraphType> { Name = "conduitId", Description = "If not specified, a new guid will automatically be created" }, new QueryArgument <StringGraphType> { Name = "name" }, new QueryArgument <ConduitColorEnumType> { Name = "markingColor" }, new QueryArgument <StringGraphType> { Name = "markingText" } ), resolve: context => { try { var conduitSpec = conduitSpecificationRepository.GetConduitSpecification(context.GetArgument <Guid>("conduitSpecificationId")); // Check that conduit not already exists // First create walk of interest var walkOfInterestCmd = new RegisterWalkOfInterestCommand() { WalkOfInterestId = Guid.NewGuid(), RouteElementIds = context.GetArgument <List <Guid> >("walkOfInterest") }; commandBus.Send(walkOfInterestCmd).Wait(); var conduitId = context.GetArgument <Guid>("conduitId"); // Multi conduit if (conduitSpec.Kind == ConduitKindEnum.MultiConduit) { var placeConduitCommand = new PlaceMultiConduitCommand() { MultiConduitId = Guid.NewGuid(), ConduitSpecificationId = context.GetArgument <Guid>("conduitSpecificationId"), WalkOfInterestId = walkOfInterestCmd.WalkOfInterestId, Name = context.GetArgument <string>("name"), MarkingColor = context.GetArgument <ConduitColorEnum>("markingColor"), MarkingText = context.GetArgument <string>("markingText") }; if (conduitId != Guid.Empty) { placeConduitCommand.MultiConduitId = conduitId; } commandBus.Send(placeConduitCommand).Wait(); return(conduitNetworkQueryService.GetMultiConduitInfo(placeConduitCommand.MultiConduitId)); } // Single conduit else { var placeConduitCommand = new PlaceSingleConduitCommand() { SingleConduitId = Guid.NewGuid(), ConduitSpecificationId = context.GetArgument <Guid>("conduitSpecificationId"), WalkOfInterestId = walkOfInterestCmd.WalkOfInterestId, Name = context.GetArgument <string>("name"), MarkingColor = context.GetArgument <ConduitColorEnum>("markingColor"), MarkingText = context.GetArgument <string>("markingText") }; if (conduitId != Guid.Empty) { placeConduitCommand.SingleConduitId = conduitId; } commandBus.Send(placeConduitCommand).Wait(); return(conduitNetworkQueryService.GetSingleConduitInfo(placeConduitCommand.SingleConduitId)); } } catch (Exception ex) { context.Errors.Add(new ExecutionError(ex.Message, ex)); } return(null); }); Field <StringGraphType>( "placeFiberCableWithinConduit", description: "Place a fiber cable inside a conduit", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "cableSegmentId", Description = "Id of the cable segment to be placed inside a conduit" }, new QueryArgument <NonNullGraphType <IdGraphType> > { Name = "conduitSegmentId1", Description = "Id of the conduit segment where the cable should be placed" }, new QueryArgument <IdGraphType> { Name = "conduitSegmentId2", Description = "Used when placing cables into a conduit that is cut and not connected in a well. The you must specify both the incomming and outgoing conduit segment in the well, because otherwise the cable has an unknown route." } ), resolve: context => { return(null); }); }