-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various improvements to models management (#87)
- Loading branch information
Showing
19 changed files
with
612 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
LM-Kit-Maestro/Services/LLMFileManager.FileSystemEntryRecorder.DirectoryRecord.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
namespace LMKit.Maestro.Services; | ||
|
||
public partial class LLMFileManager | ||
{ | ||
private sealed partial class FileSystemEntryRecorder | ||
{ | ||
public class DirectoryRecord : FileSystemEntryRecord | ||
{ | ||
public List<FileSystemEntryRecord> Entries { get; protected set; } | ||
|
||
public DirectoryRecord(string name, DirectoryRecord? parent) : base(name, parent) | ||
{ | ||
Entries = new List<FileSystemEntryRecord>(); | ||
} | ||
|
||
public bool DeleteEntry(FileSystemEntryRecord entry) | ||
{ | ||
return Entries.Remove(entry); | ||
} | ||
|
||
public void AddEntry(FileSystemEntryRecord entry) | ||
{ | ||
Entries.Add(entry); | ||
} | ||
|
||
public DirectoryRecord? TryGetChildDirectory(string name) | ||
{ | ||
foreach (var child in Entries) | ||
{ | ||
if (child is DirectoryRecord childDirectory && string.CompareOrdinal(child.Name, name) == 0) | ||
{ | ||
return childDirectory; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public FileRecord? TryGetChildFile(string name) | ||
{ | ||
foreach (var child in Entries) | ||
{ | ||
if (child is FileRecord childFile && string.CompareOrdinal(childFile.Name, name) == 0) | ||
{ | ||
return childFile; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public FileSystemEntryRecord? TryGetChildEntry(string name) | ||
{ | ||
foreach (var entry in Entries) | ||
{ | ||
if (string.CompareOrdinal(entry.Name, name) == 0) | ||
{ | ||
return entry; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected override void OnEntryRenamed() | ||
{ | ||
PropagateRenamedParentEntryToChildren(1, Name, this); | ||
} | ||
|
||
private void PropagateRenamedParentEntryToChildren(int ancestorLevel, string newName, DirectoryRecord directoryRecord) | ||
{ | ||
foreach (var child in directoryRecord.Entries) | ||
{ | ||
if (child is FileRecord childFile) | ||
{ | ||
childFile.OnParentDirectoryRenamed(ancestorLevel, newName); | ||
} | ||
else if (child is DirectoryRecord childDirectory) | ||
{ | ||
PropagateRenamedParentEntryToChildren(ancestorLevel + 1, newName, childDirectory); | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
public override string ToString() | ||
{ | ||
return ("(directory)" + Name); | ||
} | ||
#endif | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
LM-Kit-Maestro/Services/LLMFileManager.FileSystemEntryRecorder.FileRecord.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using LMKit.Maestro.Helpers; | ||
|
||
namespace LMKit.Maestro.Services; | ||
|
||
public partial class LLMFileManager | ||
{ | ||
private sealed partial class FileSystemEntryRecorder | ||
{ | ||
public class FileRecord : FileSystemEntryRecord | ||
{ | ||
public Uri FileUri { get; set; } | ||
|
||
public event EventHandler? FilePathChanged; | ||
|
||
public FileRecord(Uri fileUri, string name, DirectoryRecord parent) : base(name, parent) | ||
{ | ||
FileUri = fileUri; | ||
} | ||
|
||
public void OnParentDirectoryRenamed(int ancestorLevel, string newName) | ||
{ | ||
Uri oldUri = FileUri; | ||
FileUri = FileHelpers.GetRenamedFileUri(FileUri, newName, ancestorLevel); | ||
FilePathChanged?.Invoke(this, new FileRecordPathChangedEventArgs(oldUri, FileUri)); | ||
} | ||
|
||
protected override void OnEntryRenamed() | ||
{ | ||
Uri oldUri = FileUri; | ||
FileUri = FileHelpers.GetRenamedFileUri(FileUri, Name); | ||
FilePathChanged?.Invoke(this, new FileRecordPathChangedEventArgs(oldUri, FileUri)); | ||
} | ||
|
||
#if DEBUG | ||
public override string ToString() | ||
{ | ||
return ("(file)" + Name); | ||
} | ||
#endif | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...Maestro/Services/LLMFileManager.FileSystemEntryRecorder.FileRecordPathChangedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace LMKit.Maestro.Services; | ||
|
||
public partial class LLMFileManager | ||
{ | ||
private sealed partial class FileSystemEntryRecorder | ||
{ | ||
public sealed class FileRecordPathChangedEventArgs : EventArgs | ||
{ | ||
public Uri OldPath { get; } | ||
|
||
public Uri NewPath { get; } | ||
|
||
public FileRecordPathChangedEventArgs(Uri oldPath, Uri newPath) | ||
{ | ||
OldPath = oldPath; | ||
NewPath = newPath; | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
LM-Kit-Maestro/Services/LLMFileManager.FileSystemEntryRecorder.FileSystemEntryRecord.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace LMKit.Maestro.Services; | ||
|
||
public partial class LLMFileManager | ||
{ | ||
private sealed partial class FileSystemEntryRecorder | ||
{ | ||
public abstract class FileSystemEntryRecord | ||
{ | ||
public DirectoryRecord? Parent { get; protected set; } | ||
|
||
public string Name { get; private set; } | ||
|
||
public FileSystemEntryRecord(string name, DirectoryRecord? parent) | ||
{ | ||
Name = name; | ||
Parent = parent; | ||
} | ||
|
||
protected abstract void OnEntryRenamed(); | ||
|
||
public void Rename(string name) | ||
{ | ||
Name = name; | ||
OnEntryRenamed(); | ||
} | ||
|
||
public bool Delete() | ||
{ | ||
if (Parent == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return Parent.DeleteEntry(this); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.