Skip to content

SC-442 Fix IsEnd assignment for line segments - #918

Open
StephenCWills wants to merge 3 commits into
masterfrom
SC-442
Open

SC-442 Fix IsEnd assignment for line segments#918
StephenCWills wants to merge 3 commits into
masterfrom
SC-442

Conversation

@StephenCWills

Copy link
Copy Markdown
Member

The logic in LineSegmentWizardController.PostData() was a bit of a mess so I tried to break it into a distinct set of tasks that could each be done independently and therefore verified for correctness. As a result, there is a rather large diff, but most of the logic is the same. Mainly, I tried to reduce nested loops, nested Linq queries, and loops handling multiple tasks into Join()/GroupJoin()/GroupBy() calls to improve performance and cut down on the complexity of the code. Some of the Linq queries are still a little tricky to comprehend, though.

Functionally, the only thing that changed is at the very end of the method, where it walks through buses to set the IsEnd flag. The logic there ensures that we change true to false or vice-versa as needed to achieve the expected state based on which segments are connected to each tap. This will completely overwrite any manual adjustments if the wizard is used to update the configuration, but it will ensure that the IsEnd flags are always selected based on the most logical interpretation by just looking at the topology of the line.

As for OpenXDAAssetController, it simply wasn't copying the IsEnd flag from the client into the database model. That's why the database wouldn't update when the user clicked the Save Changes button.

@StephenCWills
StephenCWills requested a review from elwills August 6, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the line-segment wizard save flow to simplify and speed up topology updates, and fixes persistence of the IsEnd flag so client changes correctly reach the database.

Changes:

  • Refactors LineSegmentWizardController.PostData() into clearer, more set-based operations (joins/grouping) for deletes/updates/inserts and connection rebuilds.
  • Recomputes LineSegment.IsEnd based on bus topology at the end of the save operation (to enforce consistent end-flagging).
  • Fixes OpenXDAAssetController to copy IsEnd from the incoming JSON payload into the DB model.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Source/Applications/SystemCenter/Controllers/OpenXDA/Assets/OpenXDAAssetController.cs Copies IsEnd from client JSON into LineSegment model during JToken → model mapping.
Source/Applications/SystemCenter/Controllers/ExternalDB/LineSegmentWizardController.cs Refactors save logic and rebuilds segment connections/locations; recomputes and persists IsEnd from topology.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +281 to 283
List<Segment> allSegments = [.. record.Sections
.SelectMany(s => s.Segments)];

Comment on lines +311 to +313
segmentTbl.UpdateRecord(oldSegment);
oldSegment.ConnectedSegments.ForEach(cxn => segmentCxnTbl.DeleteRecord(cxn));
oldSegment.AssetLocations.ForEach(loc => assetLocationTbl.DeleteRecord(loc));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants