public static async Task InitDrive( CancellationToken ct = default(CancellationToken), DriveProgressHandler inprogress = null, DriveProgressHandler done = null) { try { inprogress?.Invoke("Loading Cache..."); using (await DriveLock.LockAsync()) { DriveTree.Clear(); RecordData cache = null; await Task.Run(() => { cache = LoadFromBinaryFile(cachefile); }, ct); inprogress?.Invoke("Restore tree..."); await Task.Run(() => { ConstructDriveTree(cache); }, ct); } await GetChanges(checkpoint : checkpoint, ct : ct, inprogress : inprogress, done : done); done?.Invoke("Changes Loaded."); } catch { // Load Root await GetChanges(ct : ct, inprogress : inprogress, done : done); } }
public static async Task <FileMetadata_Info[]> GetChanges( string checkpoint = null, CancellationToken ct = default(CancellationToken), DriveProgressHandler inprogress = null, DriveProgressHandler done = null) { List <FileMetadata_Info> ret = new List <FileMetadata_Info>(); inprogress?.Invoke("Loading Changes..."); using (await DriveLock.LockAsync()) { if (checkpoint == null) { DriveTree.Clear(); } historydata.Clear(); while (!ct.IsCancellationRequested) { Changes_Info[] history = null; int retry = 6; while (--retry > 0) { try { history = await Drive.changes(checkpoint : checkpoint, ct : ct); break; } catch (Exception ex) { Config.Log.LogOut("[GetChanges] " + ex.Message); } } if (history == null) { break; } foreach (var h in history) { if (!(h.end ?? false)) { if (h.nodes.Count() > 0) { ConstructDriveTree(h.nodes); ret.AddRange(h.nodes); historydata.AddRange(h.nodes); } DriveData.checkpoint = h.checkpoint; checkpoint = h.checkpoint; } } if ((history.FirstOrDefault()?.nodes.Count() ?? 0) == 0 && (history.LastOrDefault()?.end ?? false)) { break; } } done?.Invoke("Changes Loaded."); return(ret.ToArray()); } }