public async Task <(bool success, DeleteResult result)> TryDeleteAsync(IDocument entry, CancellationToken ct) { string name = entry.FullPath(); await Store.Remove(name); await Allocator.Removed(name); RequestLockManager.RemoveStatus(name, RequestStatus.Cached); return(false, null);; }
public async Task <(bool success, IDocument result)> TryMoveToAsync(IDocument entry, ICollection collection, string name, CancellationToken ct) { string from = entry.FullPath(); string to = collection.FullPath() + "/" + name; RequestLockManager.RemoveStatus(from, RequestStatus.Cached); RequestLockManager.AddStatus(to, RequestStatus.Cached); await Store.Move(from, to); await Allocator.Moved(from, to); return(false, null); }
private async Task PredicitiveFillCache(int predicitveFillKey, CancellationToken ct) { IEnumerable <string> predictedFiles = await Predictor.GetLikelyhoodSortedDocuments(); predictedFiles = predictedFiles.ToArray(); IEnumerator <string> predictedFilesEnumerator = predictedFiles.GetEnumerator(); string currentDocKey = null; IDocument currentDoc = null; string currentStreamKey = null; Stream currentStream = null; Func <Task <IDocument> > CurrentDoc = async() => { if (predictedFilesEnumerator.Current != currentDocKey) { SelectionResult selectionResult = await FileSystem.SelectAsync(predictedFilesEnumerator.Current, ct, false); currentDoc = selectionResult.Document; currentDocKey = predictedFilesEnumerator.Current; } return(currentDoc); }; Func <Task <Stream> > CurrentStream = async() => { if (predictedFilesEnumerator.Current != currentStreamKey) { IDocument doc = await CurrentDoc(); currentStream = await doc.OpenReadAsync(ct); currentStreamKey = predictedFilesEnumerator.Current; } return(currentStream); }; //List<string> Cached = new List<string>(); while (predicitveFillKey == activePredicitveFillKey && predictedFilesEnumerator.MoveNext()) { if (RequestLockManager.GetStatus_Chainable(predictedFilesEnumerator.Current).Is(RequestStatus.IgnoreCache)) { continue; } RequestLockManager.AddStatus(predictedFilesEnumerator.Current, RequestStatus.PredicitiveRequest); try { if (!(await Store.TryGet(predictedFilesEnumerator.Current, true)).success) { if (!await Allocator.TryAllocate(predictedFilesEnumerator.Current, CurrentDoc, CurrentStream)) { break; } if (!await Store.TryPut(predictedFilesEnumerator.Current, await CurrentStream())) { break; } } else { await Allocator.TryAllocate(predictedFilesEnumerator.Current, CurrentDoc, CurrentStream); } RequestLockManager.AddStatus(predictedFilesEnumerator.Current, RequestStatus.Cached); } finally{ RequestLockManager.RemoveStatus(predictedFilesEnumerator.Current, RequestStatus.PredicitiveRequest); } } //string log = $"Predicted and Cached:\n {(Cached.Any() ? (Cached.Count == 1 ? Cached.First() : Cached.Aggregate((x, y) => $"{x}\n {y}")) : "None")}"; //Console.WriteLine(log); }