public static SeeMetaData AddDirectoryLocally(this SeeMetaData md, String name) { var ret = new SeeMetaData() { Path = md.Path + "/" + name, Is_Dir = true, Contents = null, Parent = md }; delay[ret] = new List<SeeMetaData>(); ret.ExpandContents = () => Task.Run(async () => { await Task.Delay(5000); ret.Contents = delay[ret]; }); (md.Contents ?? delay[md]).Add(ret); return ret; }
DBNodeVM GetNode(SeeMetaData md, bool dontref = false) { DBNodeVM_L thisnode = new DBNodeVM_L(); thisnode.name = md.Name; thisnode.fileSize = md.Size; thisnode.children = view.CreatePreferredCollection<DBNodeVM>(); thisnode.SeeMetaData = md; thisnode.itemtype = md.Is_Dir ? DBNodeType.Dir : DBNodeType.File; thisnode.stateOfChildren = md.Is_Dir && md.ExpandContents != null ? DBChildState.Queryable : DBChildState.Loaded; if(!dontref) md.Ref(thisnode); return thisnode; }
DBNodeVM ConvertNode(SeeMetaData md, bool dontrefroot = false) { var thisnode = GetNode(md, dontrefroot); if (md.Contents != null) { foreach (var mdc in md.Contents) { var c = ConvertNode(mdc, false); c.parent = thisnode; thisnode.children.Add(c); } } return thisnode; }
DBNodeVM GenModels(SeeMetaData root) { return ConvertNode(root); }
public Task<bool> CreateFolder(String folder, SeeMetaData inside, IProgress<ProgClass> progress) { return FakeTask(() => { var nf = inside.AddDirectoryLocally(folder); ModelChanged(new ModelChangedEventArgs() { changed = nf, changetype = ModelChangedEventType.Added }); }, "Creating folder " + folder + " in " + inside.Name, "Created folder " + folder + " in " + inside.Name, "Error creating folder: ", progress, 500); }
public Task<bool> Delete(SeeMetaData file, IProgress<ProgClass> progress) { // error now. if (file.Is_Dir) { progress.Report(new ProgClass() { val = 0, msg = "Error: Deleting directories not supported." }); return Task.FromResult<bool>(false); } String m1 = "Deleting " + file.Name, m2 = "Deleted " + file.Name, m3 = "Error deleting: "; return FakeTask(() => { var pf = file.Parent; pf.Contents.Remove(file); ModelChanged(new ModelChangedEventArgs() { changed = file, changetype = ModelChangedEventType.Removed }); }, m1, m2, m3, progress, 300); }
public static SeeMetaData AddFileLocally(this SeeMetaData md, String name, long size) { var ret = new SeeMetaData() { Path = md.Path + "/" + name, Size = size, Parent = md }; (md.Contents ?? delay[md]).Add(ret); return ret; }
public Task<bool> Upload(String file, SeeMetaData to, IProgress<ProgClass> progress) { return FakeTask(() => { FileInfo fi = new FileInfo(file); var nf = to.AddFileLocally(fi.Name, fi.Length); ModelChanged(new ModelChangedEventArgs() { changed = nf, changetype = ModelChangedEventType.Added }); }, "Uploading " + file + " to " + to.Name, "Finished uploading " + file + " to " + to.Name, "Error uploading: ", progress, 4000); }
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> Download(SeeMetaData file, String to, IProgress<ProgClass> progress) { return FakeTask(() => { var dlf = Path.Combine(to, file.Name); File.WriteAllText(dlf, "lol no fie!l"); }, "Downloading " + file.Name + " to " + to, "Finished downloading " + file.Name + " to " + to, "Error downloading: ", progress, 5000); }
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; }); }
SeeMetaData JsonToModel(JObject md, SeeMetaData parent) { SeeMetaData ret = new SeeMetaData(); ret.Is_Dir = md["is_dir"].Value<bool>(); ret.Path = md["path"].Value<String>(); ret.Size = ParseSize(md["size"].Value<String>()); ret.Parent = parent; if (md["contents"] != null) { ret.Contents = new List<SeeMetaData>(); foreach (JObject j in md["contents"]) ret.Contents.Add(JsonToModel(j, ret)); } return ret; }
void ContentExpanders(SeeMetaData root) { bool folded = false; var rc = root.Contents; for (int i = 0; i < rc.Count; i++) if (rc[i].Is_Dir) { if (rc[i].Contents == null) // needy scan! { folded = true; var capture = rc[i]; capture.ExpandContents = () => { return Task.Run(() => { // this is a dir, we needa add it childrens var nroot = JsonToModel(JObject.Parse(wc.GetString(DB_METADATA(capture.Path))), capture.Parent); capture.Contents = nroot.Contents; // copycopy ContentExpanders(capture); }); }; } } }