How to uniquely Identify an ISegmentPair in the ActiveDocument that has multiple Files?

Here is the scenario:  

I am a user on the Editor View.  The ActiveDocument consists of 2 or more files that I have opened so that I see all of the segment pairs from each file.  How can I quickly say I want to get the third ISegmentPair from the second file?  The reason I am asking is the code I am working with needs to reference the previous segment of the ActiveDocument.ActiveSegmentPair at some point.

One approach a previous developer took was to Build a Dictionary<int, ISegmentPair> by mapping the ISegmentPair.Properties.Id.Id value to the ISegmentPair object.  He then was grabbing the segment pair by id and working with the resulting ISegmentPair object.  The problem with this approach, though, is that if I have 2 or more files open, the first file will have ISegmentPair whose Properties.Id.Id is 1 to n, and the second file will have ISegmentPair objects with Properties.Id.Id from 1 to m.  So it appears the ISegmentPair.Properties.Id.Id is not actually a way to uniquely identify a segment pair in the ActiveDocument.

The second approach I took was to construct a LinkedList<ISegmentPair> object from the ActiveDocument.SegmentPairs.  I then grabbed the active segment pair from the ActiveDocument.  The problem is, it appears they haven't overwritten the Equals method so the following code returns null.

LinkedList<ISegmentPair> allSegmentPairs = new LinkedList<ISegmentPair>(ActiveDocument.SegmentPairs);

LinkedListNode<ISegmentPair> current = allSegmentPairsLinkedList.Find(ActiveDocument.ActiveSegmentPair) returns null.

So I can't reference the Previous segment pair by saying current.Previous.

So again, my question is, how do you uniquely identify an ISegmentPair in the ActiveDocument?

Any thoughts would be appreciated.

Parents
  • After further looking at this, I found I can do something like the following.  The main thing is to create a nested dictionary where the outer dictionary is the ProjectFile.Id

    public class Helper
    {
    public static Dictionary<Guid, Dictionary<int, ISegmentPair>> AllSegmentPairs = null;

    public static void GetAllSegmentPairs(EditorController editorController)
    {


    if (Helper.AllSegmentPairs == null)
    {
    Helper.AllSegmentPairs = new Dictionary<Guid, Dictionary<int, ISegmentPair>>();

    Document document = editorController.ActiveDocument;
    List<ISegmentPair> allSegmentPairs = document.SegmentPairs.ToList();
    int allSegmentPairsLength = allSegmentPairs.Count;
    int firstSegmentOfFilePosition = 0;
    int lastSegmentId = int.MinValue;
    foreach (ProjectFile file in document.Files)
    {
    var fileSegmentPairs = new Dictionary<int, ISegmentPair>();
    for (int i = firstSegmentOfFilePosition; i < allSegmentPairsLength; i++)
    {
    ISegmentPair segmentPair = allSegmentPairsIdea;
    int segmentId = int.Parse(segmentPair.Properties.Id.Id);
    // This is how I know I have started a new file
    if (lastSegmentId > segmentId)
    {
    break;
    }

    lastSegmentId = segmentId;
    fileSegmentPairs.Add(segmentId, segmentPair);
    firstSegmentOfFilePosition++;
    }

    Helper.AllSegmentPairs.Add(file.Id, fileSegmentPairs);
    lastSegmentId = int.MinValue;
    }
    }
    }
    }

    Then when I go to reference a segment pair in the active file, I can do something like this:

    ProjectFile activeFile = _editorController.ActiveDocument.ActiveFile;

    // We need to get the segment pairs for this file
    Dictionary<int, ISegmentPair> fileSegmentPairs = Helper.AllSegmentPairs[activeFile.Id];

Reply
  • After further looking at this, I found I can do something like the following.  The main thing is to create a nested dictionary where the outer dictionary is the ProjectFile.Id

    public class Helper
    {
    public static Dictionary<Guid, Dictionary<int, ISegmentPair>> AllSegmentPairs = null;

    public static void GetAllSegmentPairs(EditorController editorController)
    {


    if (Helper.AllSegmentPairs == null)
    {
    Helper.AllSegmentPairs = new Dictionary<Guid, Dictionary<int, ISegmentPair>>();

    Document document = editorController.ActiveDocument;
    List<ISegmentPair> allSegmentPairs = document.SegmentPairs.ToList();
    int allSegmentPairsLength = allSegmentPairs.Count;
    int firstSegmentOfFilePosition = 0;
    int lastSegmentId = int.MinValue;
    foreach (ProjectFile file in document.Files)
    {
    var fileSegmentPairs = new Dictionary<int, ISegmentPair>();
    for (int i = firstSegmentOfFilePosition; i < allSegmentPairsLength; i++)
    {
    ISegmentPair segmentPair = allSegmentPairsIdea;
    int segmentId = int.Parse(segmentPair.Properties.Id.Id);
    // This is how I know I have started a new file
    if (lastSegmentId > segmentId)
    {
    break;
    }

    lastSegmentId = segmentId;
    fileSegmentPairs.Add(segmentId, segmentPair);
    firstSegmentOfFilePosition++;
    }

    Helper.AllSegmentPairs.Add(file.Id, fileSegmentPairs);
    lastSegmentId = int.MinValue;
    }
    }
    }
    }

    Then when I go to reference a segment pair in the active file, I can do something like this:

    ProjectFile activeFile = _editorController.ActiveDocument.ActiveFile;

    // We need to get the segment pairs for this file
    Dictionary<int, ISegmentPair> fileSegmentPairs = Helper.AllSegmentPairs[activeFile.Id];

Children
No Data