private void Changed(object sender, EventArgs e) { lock (iLock) { CpDeviceAdvanced d = sender as CpDeviceAdvanced; if (d != null) { int oldIndex = iDeviceListAdvanced.IndexOf(d); iDeviceListAdvanced.Sort(); int newIndex = iDeviceListAdvanced.IndexOf(d); if (oldIndex == newIndex) { JsonObject info = new JsonObject(); info.Add("MacAddress", new JsonValueString(d.MacAddress)); info.Add("Description", d.Json); info.Add("Progress", new JsonValueUint(d.Progress)); info.Add("Message", new JsonValueString(d.Message)); Send("AdvancedDeviceChanged", info); } else { RemoveDevice(d); AddDevice(d, newIndex); } } } }
private void Removed(object sender, CpDeviceReprogramListRepeater.CpDeviceReprogrammableEventArgs e) { UserLog.WriteLine(DateTime.Now + ": CpDeviceAdvancedList: Device- Udn{" + e.Device.Udn + "}"); CpDeviceAdvanced device = null; lock (iLock) { if (iDisposed) { return; } foreach (CpDeviceAdvanced d in iDeviceListAdvanced) { if (d.MacAddress == e.Device.MacAddress) { device = d; iDeviceListAdvanced.Remove(d); e.Device.Changed -= HandleChanged; break; } } } if (iRemoved != null) { iRemoved(this, device); device.Dispose(); } }
private void Message(object sender, EventArgs e) { CpDeviceAdvanced device = sender as CpDeviceAdvanced; JsonObject info = new JsonObject(); info.Add("MacAddress", new JsonValueString(device.MacAddress)); info.Add("Message", new JsonValueString(device.Message)); Send("AdvancedDeviceMessage", info); }
private void Progress(object sender, EventArgs e) { CpDeviceAdvanced device = sender as CpDeviceAdvanced; JsonObject info = new JsonObject(); info.Add("MacAddress", new JsonValueString(device.MacAddress)); info.Add("Progress", new JsonValueUint(device.Progress)); Send("AdvancedDeviceProgress", info); }
private void HandleChanged(object sender, EventArgs e) { CpDeviceReprogrammable device = sender as CpDeviceReprogrammable; CpDeviceAdvanced removedDevice = null; CpDeviceAdvanced addedDevice = null; lock (iLock) { foreach (CpDeviceAdvanced d in iDeviceListAdvanced) { if (d.MacAddress == device.MacAddress) { if (d.Status == CpDeviceReprogrammable.EStatus.eOff && !d.Updating) { UserLog.WriteLine(DateTime.Now + ": CpDeviceAdvancedList: DeviceAdvanced- MacAddress{" + device.MacAddress + "}"); removedDevice = d; iDeviceListAdvanced.Remove(removedDevice); break; } else { return; } } } if (removedDevice == null && device.Status != CpDeviceReprogrammable.EStatus.eOff) { UserLog.WriteLine(DateTime.Now + ": CpDeviceAdvancedList: DeviceAdvanced+ MacAddress{" + device.MacAddress + "}"); addedDevice = new CpDeviceAdvanced(device, iVersionReader.GetDeviceVariant(device.PcbNumberList), iAdapterAddress, iUpdateListener); iDeviceListAdvanced.Add(addedDevice); } } if (removedDevice != null) { if (iRemoved != null) { iRemoved(this, removedDevice); } removedDevice.Dispose(); } if (addedDevice != null) { if (iAdded != null) { iAdded(this, addedDevice); } } }
private void Removed(CpDeviceAdvancedList aList, CpDeviceAdvanced aDevice) { lock (iLock) { RemoveDevice(aDevice); aDevice.Changed -= Changed; aDevice.ProgressChanged -= Progress; aDevice.MessageChanged -= Message; iDeviceListAdvanced.Remove(aDevice); } }
private void AddDevice(CpDeviceAdvanced aDevice, int aIndex) { Console.WriteLine(aDevice.MacAddress); JsonObject info = new JsonObject(); info.Add("Index", new JsonValueInt(aIndex)); info.Add("MacAddress", new JsonValueString(aDevice.MacAddress)); info.Add("ProductId", new JsonValueString(aDevice.ProductId)); info.Add("Description", aDevice.Json); info.Add("Progress", new JsonValueUint(aDevice.Progress)); info.Add("Message", new JsonValueString(aDevice.Message)); Send("AdvancedDeviceAdded", info); }
private void Added(CpDeviceAdvancedList aList, CpDeviceAdvanced aDevice) { lock (iLock) { iDeviceListAdvanced.Add(aDevice); iDeviceListAdvanced.Sort(); int index = iDeviceListAdvanced.IndexOf(aDevice); AddDevice(aDevice, index); aDevice.Changed += Changed; aDevice.ProgressChanged += Progress; aDevice.MessageChanged += Message; } }
private void Added(object sender, CpDeviceReprogramListRepeater.CpDeviceReprogrammableEventArgs e) { UserLog.WriteLine(DateTime.Now + ": CpDeviceAdvancedList: Device+ Udn{" + e.Device.Udn + "}"); CpDeviceAdvanced device = new CpDeviceAdvanced(e.Device, iVersionReader.GetDeviceVariant(e.Device.PcbNumberList), iAdapterAddress, iUpdateListener); lock (iLock) { if (iDisposed) { return; } iDeviceListAdvanced.Add(device); e.Device.Changed += HandleChanged; } if (iAdded != null) { iAdded(this, device); } }
private void RemoveDevice(CpDeviceAdvanced aDevice) { Send("AdvancedDeviceRemoved", aDevice.MacAddress); }