public virtual XElement Write(IGraphSceneDisplayMesh <IVisual, IVisualEdge> mesh) { var result = new XElement(NodeNames.Mesh); var backHandler = mesh.BackHandler <IThing, ILink>(); var thingGraphs = new XElement(NodeNames.Files, backHandler.BackGraphs .Select(g => ThingMeshHelper.GetIori(g)) .Where(i => i != null) .Select(i => new XElement(NodeNames.File, Write(NodeNames.Name, i.ToString())))); result.Add(thingGraphs); var displaySerializer = new GraphSceneDisplayXmlSerializer(); var displays = new XElement(NodeNames.Displays); foreach (var disp in mesh.Displays.Where(d => d.Data != null)) { var iori = ThingMeshHelper.GetIori(backHandler.BackGraphOf(disp.Data.Graph)); if (disp.DataId == 0) { disp.DataId = Isaac.Long; } displays.Add(displaySerializer.Write(new GraphSceneDisplayMemento(disp) { Iori = iori })); } result.Add(displays); return(result); }
public virtual void Resume(IConceptUsecase usecase) { if (XmlUsecase == null || usecase.FavoriteManager == null) { return; } ComposeContentViewers(); Mesh.ClearDisplays(); var backHandler = Mesh.BackHandler <IThing, ILink>(); var backGraphs = backHandler.BackGraphs.ToArray(); var ser = new UsecaseXmlSerializer(); ser.Read(XmlUsecase, usecase); var graphChanged = backGraphs.Distinct().Any(); // close others foreach (var g in backHandler.BackGraphs //.Where(g=>backGraphs.Contains(g) .Select(g => new { iori = ThingMeshHelper.GetIori(g), graph = g }) .Where(g => g.iori == null || !ser.FileNames.Contains(g.iori.ToString())) .Select(j => j.graph) .ToArray()) { backHandler.UnregisterBackGraph(g); usecase.GraphSceneUiManager.SetContent(ThingMeshHelper.GetContent(g)); usecase.GraphSceneUiManager.Close(); } if (graphChanged) { usecase.FavoriteManager.Clear(); usecase.SceneManager.Clear(); usecase.VisualsDisplayHistory.Clear(); foreach (var d in Mesh.Displays) { if (d.Info.Id != usecase.FavoriteManager.HomeId) { usecase.VisualsDisplayHistory.Store(d, usecase.SceneManager); } } } var thingGraph = backHandler.BackGraphs.FirstOrDefault() as IThingGraph; if (thingGraph != null) { usecase.GraphSceneUiManager.SetContent(ThingMeshHelper.GetContent(thingGraph)); } var focused = usecase.SplitView.Display1.Data.Focused; usecase.SplitView.Display1.Data.FocusChanged?.Invoke(usecase.SplitView.Display1.Data, focused); usecase.SplitView.Display1.OnSceneFocusChanged(); }
public virtual void Read(XElement node, IConceptUsecase usecase) { var ms = new MeshXmlSerializer(); ms.Read(node, Mesh); FileNames = ms.FileNames; var backHandler = Mesh.BackHandler <IThing, ILink> (); var filesOpen = backHandler .BackGraphs .Select(g => new { Iori = ThingMeshHelper.GetIori(g), Graph = g }) .Where(i => i.Iori != null) .ToDictionary(k => k.Iori.ToString(), e => e.Graph); foreach (var file in ms.FileNames) { var io = Registry.Pooled <ThingGraphIoPool> ().Find(Path.GetExtension(file), Limaki.Contents.IO.IoMode.Read) as ThingGraphIo; if (!filesOpen.ContainsKey(file)) { try { var content = io.Open(Iori.FromFileName(file)); var g = backHandler.WrapGraph(content.Data); backHandler.RegisterBackGraph(g); } catch (Exception e) { } } } var displays = ReadElement(ReadElement(node, NodeNames.SplitView), NodeNames.Displays); foreach (var display in ReadElements(displays, GraphSceneDisplayXmlSerializer.NodeNames.Display)) { var name = Read <string> (display, NodeNames.Name); var id = Read <long> (display, SceneInfoXmlSerializer.NodeNames.Id); var d = Mesh.Displays.Where(disp => disp.DataId == id).FirstOrDefault(); if (d == null) { var dm = ms.Displays.Where(disp => disp.Info.Id == id).FirstOrDefault(); if (name == NodeNames.SplitViewDisplay1 && dm != null) { dm.Restore(usecase.SplitView.Display1); AfterRestore?.Invoke(d, name); } if (name == NodeNames.SplitViewDisplay2 && dm != null) { dm.Restore(usecase.SplitView.Display2); AfterRestore?.Invoke(d, name); } } } var homeId = Read <long> (ReadElement(node, NodeNames.Favorites), NodeNames.HomeId); usecase.FavoriteManager.HomeId = homeId; }