Exemple #1
0
        public void Deserialize(string fileName, out MyGraph <Location> graph, out ArduinoGroupWrapper arduinoGroup)
        {
            var binder       = new TypeNameSerializationBinder();
            var graphString  = File.ReadAllText(fileName);
            var deserialized = JsonConvert.DeserializeObject <SerializeWrapper>(graphString, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto,
                Binder           = binder
            });

            graph        = deserialized.Graph;
            arduinoGroup = deserialized.ArduinoGroup;

            foreach (var edge in graph.Edges.OfType <MyEdge <Location> >().ToList())
            {
                var from = edge.Source;
                var to   = edge.Destination;

                var vertices = graph.SubGraphs.SelectMany(subgraph => subgraph.Vertices).ToList();
                vertices.AddRange(graph.Vertices);

                graph.RemoveEdge(edge);
                graph.AddEdge(
                    new MyEdge <Location>(vertices.First(vertex => vertex.Name == from.Name),
                                          vertices.First(vertex => vertex.Name == to.Name), edge.DestinationArrow)
                    );
            }
        }
Exemple #2
0
        public void Deserialize(string fileName, out MyGraph<Location> graph, out ArduinoGroupWrapper arduinoGroup)
        {
            var binder = new TypeNameSerializationBinder();
            var graphString = File.ReadAllText(fileName);
            var deserialized = JsonConvert.DeserializeObject<SerializeWrapper>(graphString, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto,
                Binder = binder
            });

            graph = deserialized.Graph;
            arduinoGroup = deserialized.ArduinoGroup;

            foreach (var edge in graph.Edges.OfType<MyEdge<Location>>().ToList())
            {
                var from = edge.Source;
                var to = edge.Destination;

                var vertices = graph.SubGraphs.SelectMany(subgraph => subgraph.Vertices).ToList();
                vertices.AddRange(graph.Vertices);

                graph.RemoveEdge(edge);
                graph.AddEdge(
                    new MyEdge<Location>(vertices.First(vertex => vertex.Name == from.Name),
                    vertices.First(vertex => vertex.Name == to.Name),edge.DestinationArrow)
                );
            }
        }
Exemple #3
0
        public void Persist(MyGraph <Location> graph, ArduinoGroupWrapper arduinoGroup, string fileName)
        {
            var binder           = new TypeNameSerializationBinder();
            var serilaizeWrapper = new SerializeWrapper(graph, arduinoGroup);

            var serializedJson = JsonConvert.SerializeObject(serilaizeWrapper, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto,
                Binder           = binder
            });

            File.WriteAllText(fileName, serializedJson);
        }
Exemple #4
0
        public void Persist(MyGraph<Location> graph, ArduinoGroupWrapper arduinoGroup, string fileName)
        {
            var binder = new TypeNameSerializationBinder();
            var serilaizeWrapper = new SerializeWrapper(graph, arduinoGroup);

            var serializedJson = JsonConvert.SerializeObject(serilaizeWrapper, Formatting.Indented, new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.Auto,
                    Binder = binder
                });

            File.WriteAllText(fileName, serializedJson);
        }