Example #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)
                );
            }
        }
Example #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)
                    );
            }
        }
Example #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);
        }
Example #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);
        }
Example #5
0
        private void CreateArduinos(MyGraph <Location> graph, ArduinoGroupWrapper arduinoGroup)
        {
            var groupSegment = new Dictionary <string, List <Segment> >();

            _arduinos = new List <Arduino>();

            foreach (var segment in _segmentManager.Segments)
            {
                var buildBlock   = segment.Switches.First();
                var locationName =
                    graph.SubGraphs.First(subGraph => subGraph.Vertices.Any(vertex => vertex.Name == buildBlock.Name)).Label;

                var agroup =
                    arduinoGroup.ArduinoGroups.FirstOrDefault(
                        group => group.Locations.Any(location => location == locationName));
                if (agroup != null)
                {
                    if (!groupSegment.ContainsKey(agroup.Name))
                    {
                        groupSegment[agroup.Name] = new List <Segment>();
                    }
                    groupSegment[agroup.Name].Add(segment);
                }
                else
                {
                    if (!groupSegment.ContainsKey(locationName))
                    {
                        groupSegment[locationName] = new List <Segment>();
                    }

                    groupSegment[locationName].Add(segment);
                }
            }

            foreach (var groupSegmentItem in groupSegment)
            {
                var arduinos = new List <Arduino>();
                foreach (var segment in groupSegmentItem.Value)
                {
                    var currentArduino = new Arduino(groupSegmentItem.Key);

                    var segment1 = segment;
                    CreateArduinoSwitches(segment1.Switches, ref currentArduino, arduinos);
                    CreateArduinoRelay(segment1.Lights, ref currentArduino, arduinos);
                    arduinos.Add(currentArduino);
                }
                _arduinos.AddRange(ZipArduinos(arduinos));
            }

            MakeArduinoNameUnique();
        }
Example #6
0
        public void GenerateFiles(MyGraph<Location> graph, ArduinoGroupWrapper arduinoGroup, string foldername)
        {
            CreateSegments(graph);

            if (!Directory.Exists(foldername))
            {
                Directory.CreateDirectory(foldername);
            }

            CopyServerFolder(foldername);

            CreateArduinos(graph, arduinoGroup);

            foreach (var arduino in _arduinos)
            {
                CopyArduinoFolder(arduino, foldername);
            }

            var readme = new Readme(_segmentManager, _arduinos);
            var readmeContent = readme.TransformText();
            File.WriteAllText(Path.Combine(foldername, "readme.txt"), readmeContent);
        }
Example #7
0
        public void GenerateFiles(MyGraph <Location> graph, ArduinoGroupWrapper arduinoGroup, string foldername)
        {
            CreateSegments(graph);

            if (!Directory.Exists(foldername))
            {
                Directory.CreateDirectory(foldername);
            }

            CopyServerFolder(foldername);

            CreateArduinos(graph, arduinoGroup);

            foreach (var arduino in _arduinos)
            {
                CopyArduinoFolder(arduino, foldername);
            }

            var readme        = new Readme(_segmentManager, _arduinos);
            var readmeContent = readme.TransformText();

            File.WriteAllText(Path.Combine(foldername, "readme.txt"), readmeContent);
        }
Example #8
0
 public SerializeWrapper(MyGraph <Location> graph, ArduinoGroupWrapper arduinoGroup)
 {
     Graph        = graph;
     ArduinoGroup = arduinoGroup;
 }
Example #9
0
 public SerializeWrapper(MyGraph<Location> graph, ArduinoGroupWrapper arduinoGroup)
 {
     Graph = graph;
     ArduinoGroup = arduinoGroup;
 }
Example #10
0
        private void CreateArduinos(MyGraph<Location> graph, ArduinoGroupWrapper arduinoGroup)
        {
            var groupSegment = new Dictionary<string, List<Segment>>();
            _arduinos = new List<Arduino>();

            foreach (var segment in _segmentManager.Segments)
            {
                var buildBlock = segment.Switches.First();
                var locationName =
                    graph.SubGraphs.First(subGraph => subGraph.Vertices.Any(vertex => vertex.Name == buildBlock.Name)).Label;

                var agroup =
                    arduinoGroup.ArduinoGroups.FirstOrDefault(
                        group => group.Locations.Any(location => location == locationName));
                if (agroup != null)
                {
                    if (!groupSegment.ContainsKey(agroup.Name))
                    {
                        groupSegment[agroup.Name] = new List<Segment>();
                    }
                    groupSegment[agroup.Name].Add(segment);
                }
                else
                {
                    if (!groupSegment.ContainsKey(locationName))
                    {
                        groupSegment[locationName] = new List<Segment>();
                    }

                    groupSegment[locationName].Add(segment);
                }
            }

            foreach (var groupSegmentItem in groupSegment)
            {
                var arduinos = new List<Arduino>();
                foreach (var segment in groupSegmentItem.Value)
                {
                    var currentArduino = new Arduino(groupSegmentItem.Key);

                    var segment1 = segment;
                    CreateArduinoSwitches(segment1.Switches, ref currentArduino, arduinos);
                    CreateArduinoRelay(segment1.Lights, ref currentArduino, arduinos);
                    arduinos.Add(currentArduino);
                }
                _arduinos.AddRange(ZipArduinos(arduinos));
            }

            MakeArduinoNameUnique();
        }