Exemplo n.º 1
0
        public void RemoveDevice(IDevice2 device)
        {
            if (device.IsRunning())
            {
                StopListener(device);

                IEnumerator e = _connections.GetEnumerator();
                while (e.MoveNext())
                {
                    Connection c = (Connection)e.Current;
                    if (c.LocalPort == device.Port)
                    {
                        c.Stop();
                    }
                }
            }

            _devices.Remove(device);
        }
Exemplo n.º 2
0
        private void _applianceTable_ColumnChanging(object sender, DataColumnChangeEventArgs e)
        {
            if (e.Column.ColumnName == "DeviceObject")
            {
                return;
            }

            IDevice2 dev = (IDevice2)e.Row["DeviceObject"];

            switch (e.Column.ColumnName)
            {
            case "Port":
                if (dev.Port != (int)e.ProposedValue)
                {
                    if (dev.IsRunning())
                    {
                        if (_server.IsListenerOnPort((int)e.ProposedValue))
                        {
                            e.Row.RejectChanges();
                        }
                        else
                        {
                            dev.Stop();
                            _server.StopListener(dev);

                            dev.Port = (int)e.ProposedValue;

                            dev.Start();
                            _server.StartListener(dev);
                        }
                    }
                    else
                    {
                        dev.Port = (int)e.ProposedValue;
                    }
                }
                break;

            case "Active":
                if ((bool)e.ProposedValue)
                {
                    try
                    {
                        dev.Start();

                        if (dev.IsRunning())
                        {
                            _server.StartListener(dev);
                        }
                        else
                        {
                            e.ProposedValue = false;
                        }
                    }
                    catch (Exception)
                    {
                        dev.Stop();
                        _server.StopListener(dev);
                    }
                }
                else
                {
                    dev.Stop();
                    _server.StopListener(dev);
                }
                break;

            case "Visible":
                ((DebugServerFrame)dev).Visible = (bool)e.ProposedValue;
                break;
            }
        }