diff options
| -rw-r--r-- | WindowedReader.cs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/WindowedReader.cs b/WindowedReader.cs new file mode 100644 index 0000000..99c6e01 --- /dev/null +++ b/WindowedReader.cs @@ -0,0 +1,50 @@ +using System.Reflection; + +namespace HyperBooru; + +public class WindowedReader<T> where T : class { + public int WindowSize { get; init; } = 200; + + private LinkedList<T> window = new(); + private IQueryable<T> DataSource { get; set; } + + private object loadLock = new(); + private Task loadTask = Task.CompletedTask; + private LoadOperation currentOperation = LoadOperation.None; + + public WindowedReader(IQueryable<T> dataSource) => + DataSource = dataSource; + + private void DoLoad(LoadOperation operation) { + T? bookmark = null; + IQueryable<T> query = DataSource; + + PropertyInfo orderProperty; + + switch(operation) { + case LoadOperation.InitialLoad: + window = new(DataSource.Take(WindowSize)); + break; + case LoadOperation.LoadPrevious: + bookmark = window.FirstOrDefault(); + break; + case LoadOperation.LoadNext: + bookmark = window.LastOrDefault(); + break; + default: + return; + } + + if(bookmark is null) { + DoLoad(LoadOperation.InitialLoad); + return; + } + } +} + +public enum LoadOperation { + None = 0, + InitialLoad, + LoadPrevious, + LoadNext +} |
