public Entity Deserialize(Stream input, Encoding encoding) { bool forceHypermedia; using (var reader = CreateReader(input, encoding, out forceHypermedia)) { GraphWriter graphWriter = null; using (var writer = new DelayedWriter()) { writer.Intercept += (o, e) => { if (e.Node.Type.HasFlag(NodeType.Property)) { var isPayload = "form".EqualsIgnoreCase(e.Node.Value as string) || "record".EqualsIgnoreCase(e.Node.Value as string) || "records".EqualsIgnoreCase(e.Node.Value as string); graphWriter = isPayload ? new GraphWriter(typeof(Payload)) : new GraphWriter(typeof(Entity)); writer.SetWriter(graphWriter); } }; reader.CopyTo(writer); } var graph = graphWriter?.Graphs.Cast <object>().FirstOrDefault(); var entity = graph as Entity ?? throw new NotImplementedException(); //var entity = graph is Payload payload ? payload.ToEntity() : (Entity)graph; return(entity); } }
public void WriteDebugGraph(ChangeSetHistory history, Graph graph, string targetHash, string findMe) { var dbgGraph = graph.Clone(); dbgGraph.MinimizeTo(targetHash); var highlightedNodes = new Dictionary <GraphNode, string>(); foreach (var node in dbgGraph.AllNodes) { var changeSet = history.ChangeSets.Single(cs => cs.Id == node.CommitHash); var actionsDone = changeSet.Items.Where(item => item.ServerPath.Contains(findMe)) .Select(FormatItem).ToList(); if (actionsDone.Any()) { highlightedNodes.Add(node, string.Join("\n", actionsDone)); } } var shortHash = targetHash.Substring(0, 5); var file = Path.Combine(_directory, $"conflict_graph_{shortHash}_{findMe}.dot"); var graphWriter = new GraphWriter(); graphWriter.SaveGraphSimplified(file, dbgGraph, highlightedNodes); }
public void SuccessName() { var gw = new GraphWriter <int, int>(graph, PropValue); Assert.AreEqual(PropValue, gw.GetGraphProperty(NameStr)); Assert.AreEqual(0, gw.GetVertexProperty(0, LabelStr)); Assert.AreEqual(10, gw.GetEdgeProperty(0, 3, LabelStr)); }
public void Success() { var gw = new GraphWriter <int, int>(graph); Assert.AreEqual(string.Empty, gw.GetGraphProperty(NameStr)); Assert.AreEqual(0, gw.GetVertexProperty(0, LabelStr)); Assert.AreEqual(10, gw.GetEdgeProperty(0, 3, LabelStr)); }
/// <inheritdoc/> public T Deserialize <T>(string text) { CurrentGraph = GraphWriter.ReadGraph(text); //// The root object will always have ID of "0". var o = ReadGraph(CurrentGraph.Nodes.Get(0.ToString())); return((T)o); }
private T Read <T>(Reader reader) where T : class, new() { using (var writer = new GraphWriter <T>()) { reader.CopyTo(writer); return(writer.Graphs.FirstOrDefault()); } }
public void OutputInFile(object sender, EventArgs e) { try { GraphWriter.Write(PathToFile, Graph); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
public static void ShowGraph(GraphWriter graph, string title = "Graph") { string fileName = title + DateTime.Now.ToString("_MM_dd_yy_HH_mm_ss_ff"); string dotFileName = fileName + ".gv"; string svgFileName = fileName + ".svg"; graph.Write(dotFileName); try { Process.Start("dot", "-Tsvg -o" + "\"" + svgFileName + "\" \"" + dotFileName + "\"").WaitForExit(); } catch (Exception e) { Console.WriteLine("Problem with converting DOT to SVG"); Console.WriteLine($"Exception message: \"{e.Message}\"\n"); Console.WriteLine("If \"dot\" program is not installed, install Graphviz\nand add a path to \"dot\" to the PATH\n"); Console.WriteLine($"DOT file is saved to \"{Path.GetFullPath(dotFileName)}\"\n"); return; } try { var p = new Process(); p.StartInfo = new ProcessStartInfo(svgFileName); p.StartInfo.UseShellExecute = true; p.Start(); } catch { Console.WriteLine("Can't open SVG file using shell\n"); Console.WriteLine($"DOT file is saved to \"{Path.GetFullPath(dotFileName)}\"\n"); Console.WriteLine($"SVG file is saved to \"{Path.GetFullPath(svgFileName)}\"\n"); } }
public void Setup() { writer = new GraphWriter <int, int>(graph); }
public void Setup() { writer = new GraphWriter <int, int>(graph); writer.SetGraphProperty(NameStr, NameStr); }
/// <inheritdoc/> public string Serialize <T>(T value) { BuildGraph(value); return(GraphWriter.WriteGraph(CurrentGraph)); }