public UnloadedAppliance(ApplianceStub applStub) : base(applStub) { if (_connection != null) { _connection.Stop(); _connection = null; } }
/// <summary> /// This method resets the connection with the server, /// disconnecting all devices and re-downloading the /// server information. /// </summary> /// <param name="openAll">specifies whether all appliances on the server should be opened</param> public void Reset(bool openAll) { // disconnect current connection _connection.MessageReceivedEvent -= new Connection.MessageReceivedHandler(this.messageReceived); _connection.ConnectionRegainedEvent -= new Connection.ConnectionRegainedHandler(this.connectionRegained); _connection.Stop(); // disconnect any currently connected appliances IEnumerator e = _appliances.Values.GetEnumerator(); while (e.MoveNext()) { ApplianceStub astub = (ApplianceStub)e.Current; if (astub is Appliance) { Globals.GetFrame((Appliance)astub).RemoveAppliance((Appliance)astub); ((Appliance)astub)._connection.Stop(); } } // clear all appliances from the list _appliances.Clear(); // clear menu if (_menu != null) { _menu.MenuItems.Clear(); } // should we open all when we reconnect? _openAllNext = openAll; // reconnect to server connectToServer(_connection.GetConnectionAddr()); // set menuitem for server // (temporary until server information msg arrives) MenuItem mi = new MenuItem(); if (_connection.IsConnected()) { mi.Text = "No Appliances!"; } else { mi.Text = "Not Connected"; } mi.Enabled = false; _menu.MenuItems.Add(mi); }
public ApplianceStub(ApplianceStub stub) { _server = stub._server; _port = stub._port; _serverName = stub._serverName; _uniqueName = stub._uniqueName; _mark = stub._mark; _connection = stub._connection; _serverMenuItem = stub._serverMenuItem; _serverMenuListener = stub._serverMenuListener; _serverMenuListener.SetAppliance(this); }
public void SetAppliance(ApplianceStub appl) { _appliance = appl; }
public ServerMenuListener(ApplianceStub appl) { _appliance = appl; }
protected void initUIMenu(ServerInformation msg) { _name = msg.GetServerName(); if (_menu == null) { initMenu(); } _menu.MenuItems.Clear(); clearMarks(); int count = 0; _menu.Text = _name; IEnumerator e = msg.GetDevices(); while (e.MoveNext()) { ServerInformation.DeviceInfo device = (ServerInformation.DeviceInfo)e.Current; ApplianceStub astub = (ApplianceStub)_appliances[device.GetDeviceUniqueString()]; if (astub == null) { astub = new UnloadedAppliance(this, device.GetDevicePort(), device.GetDeviceName(), device.GetDeviceUniqueString()); _appliances[astub.GetUniqueName()] = astub; if (_openAllNext) { ((UnloadedAppliance)astub).LoadAppliance(); } } astub.SetMark(true); count++; MenuItem mi = new MenuItem(); mi.Text = device.GetDeviceName(); _menu.MenuItems.Add(mi); astub.SetServerMenuItem(mi); mi.Click += new System.EventHandler(astub.GetServerMenuListener().MenuClicked); } _openAllNext = false; if (count < _appliances.Count) { MenuItem mi = null; if (count > 0) { mi = new MenuItem(); mi.Text = "-"; _menu.MenuItems.Add(mi); } e = _appliances.Values.GetEnumerator(); while (e.MoveNext()) { ApplianceStub astub = (ApplianceStub)e.Current; if (!astub.IsMarked()) { mi = new MenuItem(); mi.Text = astub.GetServerName(); mi.Enabled = false; _menu.MenuItems.Add(mi); } } } if (_appliances.Count == 0 && _menu.MenuItems.Count == 0) { MenuItem mi = new MenuItem(); mi.Text = "No Appliances!"; mi.Enabled = false; _menu.MenuItems.Add(mi); } }