Exemplo n.º 1
0
        private void CreateSegments(MyGraph <Location> graph)
        {
            _segmentManager = new SegmentManager();

            foreach (var edge in graph.Edges.OfType <MyEdge <Location> >())
            {
                var segment = _segmentManager.Segments.FirstOrDefault(sgmt =>
                                                                      sgmt.Switches.Any(switchItem => switchItem.Name == edge.Source.Name) ||
                                                                      sgmt.Lights.Any(lightItem => lightItem.Name == edge.Destination.Name));
                if (segment != null)
                {
                    if (segment.Switches.All(switchItem => switchItem.Name != edge.Source.Name))
                    {
                        segment.AddSwitch(edge.Source.Name, _identity.NextAddress());
                    }

                    if (segment.Lights.All(lightItem => lightItem.Name != edge.Destination.Name))
                    {
                        segment.AddLight(edge.Destination.Name, _identity.NextAddress());
                    }
                }
                else
                {
                    segment = new Segment(_identity.NextSegmentName(), _identity.NextSequentialId());
                    _segmentManager.AddSegmentItem(segment);
                    segment.AddSwitch(edge.Source.Name, _identity.NextAddress());
                    segment.AddLight(edge.Destination.Name, _identity.NextAddress());
                }
            }
        }
Exemplo n.º 2
0
 public Readme(SegmentManager segmentManager, IEnumerable <Arduino> arduinos)
 {
     Segments = segmentManager.Segments;
     Arduinos = arduinos;
 }