public async Task <Template> Unlink(TemplateLink link) //CLONE { var entity = await _store.LoadWithParent(link.TemplateId); if (entity.IsLinked) { TemplateUtility tu = new TemplateUtility(entity.Parent.Detail); tu.Name = entity.Name; tu.LocalizeDiskPaths(entity.Workspace.Id, entity.Id); entity.Detail = tu.ToString(); entity.Parent = null; await _store.Update(entity); } return(Mapper.Map <Template>( await _store.Load(link.TemplateId) )); }
public async Task Export(string[] ids, string src, string dest) { var list = new List <Data.Workspace>(); foreach (string id in ids) { var topo = await _workspaceStore.LoadWithParents(id); if (topo != null) { list.Add(topo); } } if (list.Count < 1) { return; } string docSrc = Path.Combine(src, "_docs"); string docDest = Path.Combine(dest, "_docs"); if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } if (!Directory.Exists(docDest)) { Directory.CreateDirectory(docDest); } foreach (var topo in list) { string folder = Path.Combine(dest, topo.Id); Directory.CreateDirectory(folder); File.WriteAllText( Path.Combine(folder, "import.this"), "please import this workspace" ); //export data topo.Workers.Clear(); topo.Gamespaces.Clear(); // topo.Id = 0; topo.ShareCode = ""; foreach (var template in topo.Templates) { // template.Id = 0; template.WorkspaceId = null; template.Workspace = null; } File.WriteAllText( Path.Combine(folder, "topo.json"), JsonSerializer.Serialize(topo, jsonSerializerSettings) ); //export doc try { CopyFile( Path.Combine(docSrc, topo.Id) + ".md", Path.Combine(docDest, topo.Id) + ".md" ); CopyFolder( Path.Combine(docSrc, topo.Id), Path.Combine(docDest, topo.Id) ); } catch {} //export disk-list var disks = new List <string>(); foreach (var template in topo.Templates) { var tu = new TemplateUtility(template.Detail ?? template.Parent.Detail); var t = tu.AsTemplate(); foreach (var disk in t.Disks) { disks.Add(disk.Path); } if (t.Iso.NotEmpty()) { disks.Add(t.Iso); } } if (disks.Count > 0) { File.WriteAllLines( Path.Combine(folder, "topo.disks"), disks.Distinct() ); } } }