Example #1
0
        private PatchedPath CreatePatchedPath(string path)
        {
            PatchedPath patchedPath = new PatchedPath(path);

            patchedPath.PropertyChanged += PatchedPath_PropertyChanged;
            return(patchedPath);
        }
Example #2
0
        private void UpdatePatchedPaths(SortedSet <string> allPaths)
        {
            // master/update because we build the ObservableCollection in order also
            // and we want to strictly minimize the changes in the observable collection
            int masterCount = PatchedPaths.Count;
            int masterIndex = 0;

            foreach (string update in allPaths)
            {
                if (masterIndex == masterCount)
                {
                    // ran our of master records, all updates go in
                    PatchedPaths.Insert(masterIndex, CreatePatchedPath(update));
                    masterIndex++;
                    masterCount++;
                    continue;
                }

                // scan up to the current update
                while (masterIndex < masterCount)
                {
                    PatchedPath master     = PatchedPaths[masterIndex];
                    int         comparison = string.Compare(master.Path, update, StringComparison.Ordinal);
                    if (comparison < 0)
                    {
                        // master item is no longer present
                        PatchedPaths.RemoveAt(masterIndex);
                        masterCount--;
                        DisposePatchedPath(master);
                        continue;
                    }

                    if (comparison == 0)
                    {
                        // found existing item, advance update and master
                        masterIndex++;
                        break;
                    }

                    // insert update item before master and keep considering the same master record
                    // (which is now one further to the right)
                    PatchedPaths.Insert(masterIndex, CreatePatchedPath(update));
                    masterIndex++;
                    masterCount++;
                    break;
                }
            }
        }
Example #3
0
 private void DisposePatchedPath(PatchedPath patchedPath)
 {
     patchedPath.PropertyChanged -= PatchedPath_PropertyChanged;
 }