async Task FakeProcess(IProgress<ProgClass> progress, ProgClass pc, int delay) { int rep = 1000 / 60; // 60fps int ud = delay / rep; for (int i = 0; i < ud; i++) { pc.val = i / (float)ud; progress.Report(pc); await Task.Delay(rep); } pc.val = 1f; }
Task<bool> FakeTask(Action worky, String init, String win, String fail, IProgress<ProgClass> prog, int delay) { ProgClass pc = new ProgClass(); pc.val = 0; pc.msg = init; prog.Report(pc); return Task.Run<bool>(async () => { bool suc = false; try { worky(); await FakeProcess(prog, pc, delay); pc.msg = win; suc = true; } catch (IOException e) { pc.msg = fail + e.ToString(); } prog.Report(pc); return suc; }); }
public Task<bool> Delete(SeeMetaData file, IProgress<ProgClass> progress) { ProgClass pc = new ProgClass() { msg = "Deleting " +file.Name, val = 0f }; progress.Report(pc); return Task.Run<bool>(() => { wc.GetString(DB_DELETE(file.Path)); file.Parent.Contents.Remove(file); ModelChanged(new ModelChangedEventArgs() { changed = file, changetype = ModelChangedEventType.Removed }); pc.val = 1f; progress.Report(pc); return true; }); }
public Task<bool> CreateFolder(string folder, SeeMetaData inside, IProgress<ProgClass> progress) { String fp = inside.Path + "/" + folder; ProgClass pc = new ProgClass() { msg = "Creating " + fp, val = 0f }; progress.Report(pc); return Task.Run<bool>(() => { String newmetadata = wc.GetString(DB_CREATEFOLDER(fp)); var nmd = JsonToModel(JObject.Parse(newmetadata), inside); nmd.Contents = new List<SeeMetaData>(); // is empty... inside.Contents.Add(nmd); ModelChanged(new ModelChangedEventArgs() { changed = nmd, changetype = ModelChangedEventType.Added }); pc.val = 1f; progress.Report(pc); return true; }); }
public Task<bool> Upload(string file, SeeMetaData to, IProgress<ProgClass> progress) { ProgClass pc = new ProgClass() { msg = "Uploading " + file, val = 0f }; progress.Report(pc); return Task.Run<bool>(() => { var fi = new FileInfo(file); long tot = fi.Length; String name = fi.Name, resp = "Unknown Error"; if (wc.PutData(DB_UPLOAD(to.Path.TrimStart('/') + name), file, f => { pc.val = f / (float)tot; progress.Report(pc); }, out resp)) { var nmd = JsonToModel(JObject.Parse(resp), to); to.Contents.Add(nmd); ModelChanged(new ModelChangedEventArgs() { changed = nmd, changetype = ModelChangedEventType.Added }); return true; } else { pc.msg = resp; progress.Report(pc); return false; } }); }
// commandies public Task<bool> Download(SeeMetaData file, string to, IProgress<ProgClass> progress) { ProgClass pc = new ProgClass() { msg = "Downloading " + file.Path, val = 0f }; progress.Report(pc); return Task.Run<bool>(() => { wc.GetData(DB_DOWNLOAD(file.Path), Path.Combine(to, file.Name), f => { pc.val = f/(float)file.Size; progress.Report(pc); }); return true; }); }