public void AddEdge(DeviceControl device1, DeviceControl device2)
        {
            //makes sure the edge is valid and does not already exist
            if (Edge[device1].ContainsKey(device2) || device1.DataFlow == device2.DataFlow)
            {
                return;
            }

            //create a "repeater" for the edge
            DeviceControl capture;
            DeviceControl render;

            if (device1.DataFlow == DataFlow.Capture)
            {
                capture = device1;
                render  = device2;
            }
            else
            {
                capture = device2;
                render  = device1;
            }

            RepeaterInfo repeater = new RepeaterInfo(capture, render, this);

            AddEdge(device1, device2, repeater);
        }
        private void AddEdge(DeviceControl device1, DeviceControl device2, RepeaterInfo info)
        {
            Edge[device1].Add(device2, info);
            Edge[device2].Add(device1, info);

            MainWindow.GraphMap.Children.Add(info.Link);
        }
        public RepeaterMenu(RepeaterInfo info, BipartiteDeviceGraph graph)
        {
            InitializeComponent();

            List <Channel> channelList = Enum.GetValues(typeof(Channel)).Cast <Channel>().ToList();

            for (int i = 0; i < channelList.Count; i++)
            {
                Channel c = channelList[i];

                TextBlock text = new TextBlock();
                text.Text = c.ToString();
                Grid.SetRow(text, 0);
                Grid.SetColumn(text, i);

                CheckBox checkBox = new CheckBox();
                checkBox.Tag = c;
                Grid.SetRow(checkBox, 1);
                Grid.SetColumn(checkBox, i);
                Binding bindChannel = new Binding("ChannelMask");
                bindChannel.Converter          = new ChannelConverter(info);
                bindChannel.ConverterParameter = (int)c;
                bindChannel.Source             = info;
                checkBox.SetBinding(CheckBox.IsCheckedProperty, bindChannel);

                channels.Children.Add(text);
                channels.Children.Add(checkBox);
            }

            Info        = info;
            DataContext = Info;
            this.graph  = graph;
        }
        public static BipartiteDeviceGraph LoadGraph(string filename)
        {
            BipartiteDeviceGraph graph = new BipartiteDeviceGraph();

            StreamReader reader = new StreamReader(filename);

            Dictionary <string, MMDevice> deviceFromID = new Dictionary <string, MMDevice>();

            //create ID dictionary to get the correct MMDevice
            foreach (MMDevice device in new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.All, DeviceState.All))
            {
                deviceFromID[device.ID] = device;
            }

            if (!int.TryParse(reader.ReadLine(), out int N))
            {
                return(new BipartiteDeviceGraph());
            }

            DeviceControl[] devices = new DeviceControl[N];

            //get array of verteces
            for (int i = 0; i < N; i++)
            {
                try
                {
                    MMDevice device = deviceFromID[reader.ReadLine()];
                    double[] pos    = reader.ReadLine().Split().Select(x => double.Parse(x)).ToArray();

                    DeviceControl control = new DeviceControl(device, graph);
                    control.Left = pos[0];
                    control.Top  = pos[1];
                    MainWindow.GraphMap.Children.Add(control);
                    graph.AddVertex(control);
                    devices[i] = control;
                }
                catch
                {
                    devices[i] = null;
                }
            }

            if (!int.TryParse(reader.ReadLine(), out int M))
            {
                return(new BipartiteDeviceGraph());
            }

            //add edges to graph
            for (int i = 0; i < M; i++)
            {
                int[]         adj  = reader.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                List <string> data = new List <string>();
                for (int j = 0; j < 8; j++)
                {
                    data.Add(reader.ReadLine());
                }

                DeviceControl capture = devices[adj[0]];
                DeviceControl render  = devices[adj[1]];

                if (capture == null || render == null)
                {
                    continue;
                }

                RepeaterInfo repeater = new RepeaterInfo(capture, render, graph);
                repeater.SetData(data);

                graph.AddEdge(capture, render, repeater);
            }

            reader.Close();

            return(graph);
        }