Example #1
0
        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);
            }
        }
Example #2
0
        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);
        }
Example #3
0
            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));
            }
Example #4
0
            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));
            }
Example #5
0
        /// <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);
        }
Example #6
0
 private T Read <T>(Reader reader)
     where T : class, new()
 {
     using (var writer = new GraphWriter <T>())
     {
         reader.CopyTo(writer);
         return(writer.Graphs.FirstOrDefault());
     }
 }
Example #7
0
 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;
     }
 }
Example #8
0
        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");
            }
        }
Example #9
0
 public void Setup()
 {
     writer = new GraphWriter <int, int>(graph);
 }
Example #10
0
 public void Setup()
 {
     writer = new GraphWriter <int, int>(graph);
     writer.SetGraphProperty(NameStr, NameStr);
 }
Example #11
0
 /// <inheritdoc/>
 public string Serialize <T>(T value)
 {
     BuildGraph(value);
     return(GraphWriter.WriteGraph(CurrentGraph));
 }