public HandleVector <int> .Handle Allocate(ConduitType conduit_type, int conduit_idx, HandleVector <int> .Handle conduit_structure_temperature_handle, ref ConduitFlow.ConduitContents contents) { StructureTemperaturePayload payload = GameComps.StructureTemperatures.GetPayload(conduit_structure_temperature_handle); Element element = payload.primaryElement.Element; BuildingDef def = payload.building.Def; float conduit_heat_capacity = def.MassForTemperatureModification * element.specificHeatCapacity; float conduit_thermal_conductivity = element.thermalConductivity * def.ThermalConductivity; int num = ConduitTemperatureManager_Add(contents.temperature, contents.mass, (int)contents.element, payload.simHandleCopy, conduit_heat_capacity, conduit_thermal_conductivity, def.ThermalConductivity < 1f); HandleVector <int> .Handle result = default(HandleVector <int> .Handle); result.index = num; int handleIndex = Sim.GetHandleIndex(num); if (handleIndex + 1 > temperatures.Length) { Array.Resize(ref temperatures, (handleIndex + 1) * 2); Array.Resize(ref conduitInfo, (handleIndex + 1) * 2); } temperatures[handleIndex] = contents.temperature; conduitInfo[handleIndex] = new ConduitInfo { type = conduit_type, idx = conduit_idx }; return(result); }
private void UpdateSegmentEndIndex(ConduitInfo oldConduitInfo, ConduitInfo newConduitInfo) { if (oldConduitInfo != null) { // Remove all old references foreach (var segment in oldConduitInfo.Segments) { _conduitSegmentEndsByPointOfInterestId[segment.FromRouteNodeId].Remove(segment); _conduitSegmentEndsByPointOfInterestId[segment.ToRouteNodeId].Remove(segment); } } // Add new references foreach (var segment in newConduitInfo.Segments) { if (!_conduitSegmentEndsByPointOfInterestId.ContainsKey(segment.FromRouteNodeId)) { _conduitSegmentEndsByPointOfInterestId[segment.FromRouteNodeId] = new List <ISegment>(); } _conduitSegmentEndsByPointOfInterestId[segment.FromRouteNodeId].Add(segment); if (!_conduitSegmentEndsByPointOfInterestId.ContainsKey(segment.ToRouteNodeId)) { _conduitSegmentEndsByPointOfInterestId[segment.ToRouteNodeId] = new List <ISegment>(); } _conduitSegmentEndsByPointOfInterestId[segment.ToRouteNodeId].Add(segment); } }
public unsafe void Sim200ms(float dt) { IntPtr value = ConduitTemperatureManager_Update(dt, (IntPtr)(void *)Game.Instance.simData.buildingTemperatures); ConduitTemperatureUpdateData *ptr = (ConduitTemperatureUpdateData *)(void *)value; int numEntries = ptr->numEntries; if (numEntries > 0) { Marshal.Copy((IntPtr)(void *)ptr->temperatures, temperatures, 0, numEntries); } for (int i = 0; i < ptr->numFrozenHandles; i++) { int h = ptr->frozenHandles[i]; int handleIndex = Sim.GetHandleIndex(h); ConduitInfo conduitInfo = this.conduitInfo[handleIndex]; ConduitFlow flowManager = Conduit.GetFlowManager(conduitInfo.type); flowManager.FreezeConduitContents(conduitInfo.idx); } for (int j = 0; j < ptr->numMeltedHandles; j++) { int h2 = ptr->meltedHandles[j]; int handleIndex2 = Sim.GetHandleIndex(h2); ConduitInfo conduitInfo2 = this.conduitInfo[handleIndex2]; ConduitFlow flowManager2 = Conduit.GetFlowManager(conduitInfo2.type); flowManager2.MeltConduitContents(conduitInfo2.idx); } }
internal int AddInnerConduit(ConduitColorEnum color, int outerDiameter, int innerDiameter, IRouteNetworkState routeNetworkQueryService, IConduitNetworkQueryService conduitNetworkQueryService) { var multiConduitInfo = conduitNetworkQueryService.GetMultiConduitInfo(Id); int seqNo = 1; if (multiConduitInfo.Children != null && multiConduitInfo.Children.Count > 0) { var lastInnerConduitSeqNo = multiConduitInfo.Children.OfType <ConduitInfo>().Max(c => c.SequenceNumber); seqNo = lastInnerConduitSeqNo + 1; } var innerConduitInfo = new ConduitInfo() { Id = Guid.NewGuid(), Name = "Subrør " + seqNo, Color = color, Kind = ConduitKindEnum.InnerConduit, InnerDiameter = innerDiameter, OuterDiameter = outerDiameter, Shape = ConduitShapeKindEnum.Round, ColorMarking = ConduitColorEnum.None }; var innerConduitAddedEvent = new MultiConduitInnerConduitAdded() { MultiConduitId = Id, MultiConduitIndex = seqNo, ConduitInfo = innerConduitInfo }; RaiseEvent(innerConduitAddedEvent); return(seqNo); }
private void UpdateRouteSegmentPassByIndex(ConduitInfo oldConduitInfo, ConduitInfo newConduitInfo) { var conduitWalkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(newConduitInfo.GetRootConduit().WalkOfInterestId); if (oldConduitInfo != null) { // Remove old references foreach (var segment in oldConduitInfo.Segments.OfType <ConduitSegmentInfo>()) { var passThroughRouteSegments = GetPassThroughRouteSegments(segment, conduitWalkOfInterest); foreach (var passThroughRouteSegment in passThroughRouteSegments) { _conduitSegmentPassByRouteSegmenttId[passThroughRouteSegment].Remove(segment); } } } // Add new references foreach (var segment in newConduitInfo.Segments.OfType <ConduitSegmentInfo>()) { var passThroughRouteSegments = GetPassThroughRouteSegments(segment, conduitWalkOfInterest); foreach (var passThroughRouteSegment in passThroughRouteSegments) { if (!_conduitSegmentPassByRouteSegmenttId.ContainsKey(passThroughRouteSegment)) { _conduitSegmentPassByRouteSegmenttId[passThroughRouteSegment] = new List <ISegment>(); } _conduitSegmentPassByRouteSegmenttId[passThroughRouteSegment].Add(segment); } } }
public bool CheckIfConduitIsCut(Guid conduitId, Guid pointOfInterestId) { ConduitInfo conduitToCheck = null; if (_singleConduitInfos.ContainsKey(conduitId)) { conduitToCheck = _singleConduitInfos[conduitId]; } else if (_multiConduitInfos.ContainsKey(conduitId)) { conduitToCheck = _multiConduitInfos[conduitId]; } else { throw new KeyNotFoundException("Cannot find any conduit with id: " + conduitId); } // Check if conduit is cut if (conduitToCheck.Segments.Exists(s => s.FromRouteNodeId == pointOfInterestId || s.ToRouteNodeId == pointOfInterestId)) { return(true); } else { return(false); } }
/// <summary> /// Helper function to find related segment /// </summary> /// <param name="conduitId"></param> /// <param name="pointOfInterestId"></param> /// <returns></returns> private List <RelatedSingleConduitSegmentInfo> FindRelatedSegmentInfo(ConduitInfo conduit, Guid pointOfInterestId, ConduitEndKindEnum?conduitEndKind = null) { List <RelatedSingleConduitSegmentInfo> result = new List <RelatedSingleConduitSegmentInfo>(); var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(conduit.GetRootConduit().WalkOfInterestId); foreach (var existingSegment in conduit.Segments.OfType <ConduitSegmentInfo>()) { var segmentWalk = walkOfInterest.SubWalk2(existingSegment.FromRouteNodeId, existingSegment.ToRouteNodeId); if (segmentWalk.StartNodeId == pointOfInterestId) { if (conduitEndKind == null || conduitEndKind.Value == ConduitEndKindEnum.Outgoing) { result.Add( new RelatedSingleConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.Outgoing } ); } } if (segmentWalk.EndNodeId == pointOfInterestId) { if (conduitEndKind == null || conduitEndKind.Value == ConduitEndKindEnum.Incomming) { result.Add( new RelatedSingleConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.Incomming } ); } } if (result.Count == 0 && segmentWalk.AllNodeIds.Contains(pointOfInterestId)) { if (conduitEndKind == null || conduitEndKind.Value == ConduitEndKindEnum.Incomming) { result.Add( new RelatedSingleConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.PassThrough } ); } } } return(result); }
public void Free(HandleVector <int> .Handle handle) { if (handle.IsValid()) { int handleIndex = Sim.GetHandleIndex(handle.index); temperatures[handleIndex] = -1f; conduitInfo[handleIndex] = new ConduitInfo { type = ConduitType.None, idx = -1 }; ConduitTemperatureManager_Remove(handle.index); } }
private void ConnectTerminals(ConduitClosureInfo conduitClosure, ConduitInfo singleConduit, Guid pointOfInterestId, Guid junctionId, ConduitEndKindEnum endKind) { var relatedSegments = FindRelatedSegmentInfo(singleConduit, pointOfInterestId, endKind); if (relatedSegments.Count == 1) { var segment = relatedSegments[0].Segment; // Check if terminal with such segment exists if (conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == segment.Id)))) { var side = conduitClosure.Sides.Find(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == segment.Id))); var port = side.Ports.Find(p => p.Terminals.Exists(t => t.LineSegmentId == segment.Id)); var terminal = port.Terminals.Find(t => t.LineSegmentId == segment.Id); ConduitSegmentInfo connectedSegment = null; // Get the segment on the other side of the junction if (segment.FromNodeId == junctionId && segment.FromNode.NeighborElements.OfType <ConduitSegmentInfo>().Any(n => n != segment)) { connectedSegment = segment.FromNode.NeighborElements.OfType <ConduitSegmentInfo>().First(n => n != segment); } else if (segment.ToNodeId == junctionId && segment.ToNode.NeighborElements.OfType <ConduitSegmentInfo>().Any(n => n != segment)) { connectedSegment = segment.ToNode.NeighborElements.OfType <ConduitSegmentInfo>().First(n => n != segment); } // Check if terminal with related segment exisits if (connectedSegment != null && conduitClosure.Sides.Exists(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == connectedSegment.Id)))) { var connectedSide = conduitClosure.Sides.Find(s => s.Ports.Exists(p => p.Terminals.Exists(t => t.LineSegmentId == connectedSegment.Id))); var connectedPort = connectedSide.Ports.Find(p => p.Terminals.Exists(t => t.LineSegmentId == connectedSegment.Id)); var connectedTerminal = connectedPort.Terminals.Find(t => t.LineSegmentId == connectedSegment.Id); // Okay, we're safe to connect the two terminals together terminal.ConnectionKind = ConduitClosureInternalConnectionKindEnum.Connected; terminal.ConnectedToSide = connectedSide.Position; terminal.ConnectedToPort = connectedPort.Position; terminal.ConnectedToTerminal = connectedTerminal.Position; connectedTerminal.ConnectionKind = ConduitClosureInternalConnectionKindEnum.Connected; connectedTerminal.ConnectedToSide = side.Position; connectedTerminal.ConnectedToPort = port.Position; connectedTerminal.ConnectedToTerminal = terminal.Position; } } } }
public static SingleConduitPlaced CreateSingleConduitPlacedEvent(Guid conduitId, Guid walkOfInteresId, string demoDataSpec) { string[] specSplit = demoDataSpec.Split('-'); var conduitType = specSplit[0]; int outerConduitDiameter = 12; int innerConduitDiameter = 8; var conduitShape = ConduitShapeKindEnum.Round; // Default orange color var conduitColor = ConduitColorEnum.Orange; // Marking color var markingColor = ConduitColorEnum.None; var assetInfo = new AssetInfo(); assetInfo.Manufacturer = new ManufacturerInfo() { Name = "GM Plast" }; assetInfo.Model = new ProductModelInfo() { Name = "Ø12" }; var conduitInfo = new ConduitInfo() { Id = conduitId, Name = "R" + Numbers.GetNextConduitNumber(), Shape = conduitShape, Color = conduitColor, ColorMarking = markingColor, OuterDiameter = outerConduitDiameter, InnerDiameter = innerConduitDiameter }; return(new SingleConduitPlaced() { WalkOfInterestId = walkOfInteresId, SingleConduitId = conduitId, ConduitInfo = conduitInfo, AssetInfo = assetInfo }); }
/// <summary> /// Helper function to find related segment /// </summary> /// <param name="multiConduitId"></param> /// <param name="pointOfInterestId"></param> /// <returns></returns> private RelatedMultiConduitSegmentInfo FindRelatedSegmentInfo(ConduitInfo conduit, Guid pointOfInterestId) { var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(conduit.GetRootConduit().WalkOfInterestId); foreach (var existingSegment in conduit.Segments.OfType <ConduitSegmentInfo>()) { var segmentWalk = walkOfInterest.SubWalk2(existingSegment.FromRouteNodeId, existingSegment.ToRouteNodeId); if (segmentWalk.StartNodeId == pointOfInterestId) { return(new RelatedMultiConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.Outgoing }); } else if (segmentWalk.EndNodeId == pointOfInterestId) { return(new RelatedMultiConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.Incomming }); } else if (segmentWalk.AllNodeIds.Contains(pointOfInterestId)) { return(new RelatedMultiConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.PassThrough }); } } return(null); }
public static List <MultiConduitInnerConduitAdded> CreateInnerConduitAddedEvents(MultiConduitPlaced multiConduitPlacedEvent, string demoDataSpec) { List <MultiConduitInnerConduitAdded> result = new List <MultiConduitInnerConduitAdded>(); string[] specSplit = demoDataSpec.Split('-'); var conduitType = specSplit[0]; int nInnerConduits = Convert.ToInt32(conduitType.Replace("G", "").Replace("E", "").Replace("R", "").Replace("F", "")); for (int i = 0; i < nInnerConduits; i++) { int parentIndex = i + 1; var conduitInfo = new ConduitInfo() { Id = Guid.NewGuid(), Name = "Subrør " + parentIndex, Color = (ConduitColorEnum)parentIndex, InnerDiameter = 8, OuterDiameter = 12, Shape = ConduitShapeKindEnum.Round, ColorMarking = ConduitColorEnum.None }; var innerConduitAddedEvent = new MultiConduitInnerConduitAdded() { MultiConduitId = multiConduitPlacedEvent.ConduitInfo.Id, MultiConduitIndex = parentIndex, ConduitInfo = conduitInfo }; result.Add(innerConduitAddedEvent); } return(result); }
public static void CutConduit(ConduitInfo conduitInfo, WalkOfInterestInfo walkOfInterest, RouteNodeInfo nodeWhereToCut) { ConduitSegmentInfo newSegment = null; List <ISegment> newSegmentList = new List <ISegment>(); int newSequenceNumber = 1; var fromNodeId = conduitInfo.Segments[0].FromRouteNodeId; foreach (var existingSegment in conduitInfo.Segments) { List <Guid> segmentWalk = walkOfInterest.SubWalk(existingSegment.FromRouteNodeId, existingSegment.ToRouteNodeId); newSegmentList.Add(existingSegment); existingSegment.SequenceNumber = newSequenceNumber; existingSegment.FromRouteNodeId = fromNodeId; // If the segment is cut by point of interest, divide it if (segmentWalk.Contains(nodeWhereToCut.Id)) { // Create the segment newSequenceNumber++; if (conduitInfo.Kind != ConduitKindEnum.MultiConduit) { newSegment = new SingleConduitSegmentInfo(); } else { newSegment = new MultiConduitSegmentInfo(); } newSegment.Id = Guid.NewGuid(); newSegment.ConduitId = ((ConduitSegmentInfo)existingSegment).ConduitId; newSegment.SequenceNumber = newSequenceNumber; newSegment.FromRouteNodeId = nodeWhereToCut.Id; newSegment.ToRouteNodeId = existingSegment.ToRouteNodeId; // we need copy to side info newSegment.ToNodeId = existingSegment.ToNodeId; // we need copy to side info newSegment.ToNode = existingSegment.ToNode; // we need copy to side info // Update the existing segment existingSegment.ToRouteNodeId = nodeWhereToCut.Id; existingSegment.ToNodeId = Guid.Empty; // cannot possible have to junction anymore if it had so (transfered to new segment) existingSegment.ToNode = null; // cannot possible have to junction anymore if it had so (transfered to new segment) // Set from node on next segment to from node on inserted segment fromNodeId = newSegment.ToRouteNodeId; newSegmentList.Add(newSegment); } else { // set from node to this one to node fromNodeId = existingSegment.ToRouteNodeId; } newSequenceNumber++; } conduitInfo.Segments = newSegmentList; // Needed to wake up Marten conduitInfo.Name = conduitInfo.Name; }
private void ResolveReferences(ConduitInfo condutiInfo) { var woi = routeNetworkQueryService.GetWalkOfInterestInfo(condutiInfo.GetRootConduit().WalkOfInterestId); // Resolve from node if (condutiInfo.FromRouteNode == null) { condutiInfo.FromRouteNode = routeNetworkQueryService.GetRouteNodeInfo(woi.StartNodeId); } // Resolve to node if (condutiInfo.ToRouteNode == null) { condutiInfo.ToRouteNode = routeNetworkQueryService.GetRouteNodeInfo(woi.EndNodeId); } // Resolve references inside segment foreach (var segment in condutiInfo.Segments.OfType <ConduitSegmentInfo>()) { // Resolve conduit reference segment.Conduit = condutiInfo; // Resolve conduit segment parent/child relationship if (segment.Conduit.Kind == ConduitKindEnum.InnerConduit) { // Create parents list if null if (segment.Parents == null) { segment.Parents = new List <ISegment>(); } var innerConduitSegmentWalkOfInterest = woi.SubWalk2(segment.FromRouteNodeId, segment.ToRouteNodeId); var multiConduit = segment.Conduit.Parent; // Go through each segment of the multi conduit to find if someone intersects with the inner conduit segment foreach (var multiConduitSegment in multiConduit.Segments) { // Create childre list if null if (multiConduitSegment.Children == null) { multiConduitSegment.Children = new List <ISegment>(); } var multiConduitSegmentWalkOfInterest = woi.SubWalk2(multiConduitSegment.FromRouteNodeId, multiConduitSegment.ToRouteNodeId); // Create hash set for quick lookup HashSet <Guid> multiConduitSegmentWalkOfInterestSegmetns = new HashSet <Guid>(); foreach (var segmentId in multiConduitSegmentWalkOfInterest.AllSegmentIds) { multiConduitSegmentWalkOfInterestSegmetns.Add(segmentId); } // check if overlap from segments of the inner conduit to the the multi conduit segment foreach (var innerConduitSegmentId in innerConduitSegmentWalkOfInterest.AllSegmentIds) { if (multiConduitSegmentWalkOfInterestSegmetns.Contains(innerConduitSegmentId)) { if (!multiConduitSegment.Children.Contains(segment)) { multiConduitSegment.Children.Add(segment); } if (!segment.Parents.Contains(multiConduitSegment)) { segment.Parents.Add(multiConduitSegment); } } } } } // From Junction if (segment.FromNodeId != Guid.Empty) { if (!_singleConduitJuncionInfos.ContainsKey(segment.FromNodeId)) { var newJunction = new SingleConduitSegmentJunctionInfo() { Id = segment.FromNodeId }; newJunction.AddToConduitSegment(segment); _singleConduitJuncionInfos.Add(newJunction.Id, newJunction); segment.FromNode = newJunction; } else { var existingJunction = _singleConduitJuncionInfos[segment.FromNodeId]; //existingJunction.ToConduitSegments = segment; existingJunction.AddToConduitSegment(segment); segment.FromNode = existingJunction; } } // To Junction if (segment.ToNodeId != Guid.Empty) { if (!_singleConduitJuncionInfos.ContainsKey(segment.ToNodeId)) { var newJunction = new SingleConduitSegmentJunctionInfo() { Id = segment.ToNodeId }; newJunction.AddFromConduitSegment(segment); _singleConduitJuncionInfos.Add(newJunction.Id, newJunction); segment.ToNode = newJunction; } else { var existingJunction = _singleConduitJuncionInfos[segment.ToNodeId]; existingJunction.AddFromConduitSegment(segment); segment.ToNode = existingJunction; } } } }
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); } } }
// Apply conduit placement event private void Apply(SingleConduitPlaced @event) { Id = @event.ConduitInfo.Id; _outerConduitInfo = @event.ConduitInfo; _assetInfo = @event.AssetInfo; }
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); } }
/// <summary> /// Create MultiConduitPlaced event with detailed conduit information /// </summary> public static MultiConduitPlaced CreateMultiConduitPlacedEvent(Guid conduitId, Guid walkOfInteresId, string demoDataSpec) { string[] specSplit = demoDataSpec.Split('-'); var conduitType = specSplit[0]; var conduitNumber = specSplit[1]; string conduitMarkingColor = null; if (specSplit.Length > 2) { conduitMarkingColor = specSplit[2]; } int outerConduitDiameter = 0; int innerConduitDiameter = 0; // Default round shape var conduitShape = ConduitShapeKindEnum.Round; // Default orange color var conduitColor = ConduitColorEnum.Orange; // If flatliner if (conduitType.EndsWith("F")) { conduitShape = ConduitShapeKindEnum.Flat; conduitColor = ConduitColorEnum.Clear; } // Marking color var markingColor = ConduitColorEnum.None; if (conduitMarkingColor != null) { markingColor = ColorCodeConverter.GetConduitColorFromCode(conduitMarkingColor); } var assetInfo = new AssetInfo(); // Handle common GM Plast conduit types if (conduitType.StartsWith("G")) { assetInfo.Manufacturer = new ManufacturerInfo() { Name = "GM Plast" }; if (conduitType == "G12F") { assetInfo.Model = new ProductModelInfo() { Name = "Flatliner 12x12/8" }; } else if (conduitType == "G10F") { assetInfo.Model = new ProductModelInfo() { Name = "Flatliner 10x12/8" }; } else if (conduitType == "G6F") { assetInfo.Model = new ProductModelInfo() { Name = "Flatliner 6x12/8" }; } else { throw new ArgumentException("Don't know how to handle GM Plast conduit type: " + conduitType); } } // Handle common Emetelle conduit types else if (conduitType.StartsWith("E")) { assetInfo.Manufacturer = new ManufacturerInfo() { Name = "Emetelle" }; if (conduitType == "E10R") { assetInfo.Model = new ProductModelInfo() { Name = "Ø50 10x12/8" }; outerConduitDiameter = 50; } else if (conduitType == "E7R") { assetInfo.Model = new ProductModelInfo() { Name = "Ø40 7x12/8" }; outerConduitDiameter = 40; } else if (conduitType == "E5R") { assetInfo.Model = new ProductModelInfo() { Name = "Ø35 5x12/8" }; outerConduitDiameter = 35; } else { throw new ArgumentException("Don't know how to handle Emetelle conduit type: " + conduitType); } } // Handle flex conduit else if (conduitType.StartsWith("FLEX")) { assetInfo.Manufacturer = new ManufacturerInfo() { Name = "GM Plast" }; assetInfo.Model = new ProductModelInfo() { Name = "Ø40 Flex" }; outerConduitDiameter = 40; conduitColor = ConduitColorEnum.Red; } else { throw new Exception("Don't know how to handle conduit spec: " + conduitType); } var conduitInfo = new ConduitInfo() { Id = conduitId, Name = "R" + Numbers.GetNextConduitNumber(), Shape = conduitShape, Color = conduitColor, ColorMarking = markingColor, OuterDiameter = outerConduitDiameter, InnerDiameter = innerConduitDiameter }; return(new MultiConduitPlaced() { WalkOfInterestId = walkOfInteresId, MultiConduitId = conduitId, ConduitInfo = conduitInfo, AssetInfo = assetInfo }); }
public void Update(ConduitInfo oldConduitInfo, ConduitInfo newConduitInfo) { UpdateSegmentEndIndex(oldConduitInfo, newConduitInfo); UpdateSegmentPassByIndex(oldConduitInfo, newConduitInfo); UpdateRouteSegmentPassByIndex(oldConduitInfo, newConduitInfo); }