Exemplo n.º 1
0
        private void HandleChanged(object sender, EventArgs e)
        {
            CpDeviceReprogrammable device        = sender as CpDeviceReprogrammable;
            CpDeviceUpdate         removedDevice = null;
            CpDeviceUpdate         addedDevice   = null;

            Firmware firmware = CheckForSoftwareUpdate(device);

            lock (iLock)
            {
                foreach (CpDeviceUpdate d in iDeviceUpdateList)
                {
                    if (d.MacAddress == device.MacAddress)
                    {
                        if ((firmware == null || d.Status == CpDeviceReprogrammable.EStatus.eOff) && !d.Updating)
                        {
                            UserLog.WriteLine(DateTime.Now + ": CpDeviceUpdateList: DeviceUpdateable-             MacAddress{" + device.MacAddress + "}");

                            removedDevice = d;
                            iDeviceUpdateList.Remove(removedDevice);
                            break;
                        }
                        else
                        {
                            return;
                        }
                    }
                }

                if (removedDevice == null && firmware != null && device.Status != CpDeviceReprogrammable.EStatus.eOff)
                {
                    UserLog.WriteLine(DateTime.Now + ": CpDeviceUpdateList: DeviceUpdateable+             MacAddress{" + device.MacAddress + "}");

                    addedDevice = new CpDeviceUpdate(device, firmware, iCache, iAdapterAddress, iUpdateListener);
                    iDeviceUpdateList.Add(addedDevice);
                }
            }

            if (removedDevice != null)
            {
                if (iRemoved != null)
                {
                    iRemoved(this, removedDevice);
                }

                removedDevice.Dispose();
            }

            if (addedDevice != null)
            {
                if (iAdded != null)
                {
                    iAdded(this, addedDevice);
                }
            }
        }
Exemplo n.º 2
0
        private void Message(object sender, EventArgs e)
        {
            CpDeviceUpdate device = sender as CpDeviceUpdate;

            JsonObject info = new JsonObject();

            info.Add("MacAddress", new JsonValueString(device.MacAddress));
            info.Add("Message", new JsonValueString(device.Message));
            Send("UpdateableDeviceMessage", info);
        }
Exemplo n.º 3
0
        private void Progress(object sender, EventArgs e)
        {
            CpDeviceUpdate device = sender as CpDeviceUpdate;

            JsonObject info = new JsonObject();

            info.Add("MacAddress", new JsonValueString(device.MacAddress));
            info.Add("Progress", new JsonValueUint(device.Progress));
            Send("UpdateableDeviceProgress", info);
        }
Exemplo n.º 4
0
        private void VersionInfoAvailable(object sender, EventArgs e)
        {
            List <CpDeviceUpdate> removeDeviceList;

            lock (iLock)
            {
                if (iDisposed)
                {
                    return;
                }

                iVersionInfoAvailable = false;

                removeDeviceList = new List <CpDeviceUpdate>(iDeviceUpdateList);
                iDeviceUpdateList.Clear();
            }

            foreach (CpDeviceUpdate d in removeDeviceList)
            {
                if (iRemoved != null)
                {
                    iRemoved(this, d);
                }

                d.Dispose();
            }


            List <CpDeviceUpdate> addDeviceList = new List <CpDeviceUpdate>();

            lock (iLock)
            {
                iVersionInfoAvailable = true;

                foreach (CpDeviceReprogrammable d in iPendingList)
                {
                    Firmware firmware = CheckForSoftwareUpdate(d);
                    if (firmware != null)
                    {
                        CpDeviceUpdate device = new CpDeviceUpdate(d, firmware, iCache, iAdapterAddress, iUpdateListener);
                        iDeviceUpdateList.Add(device);
                        addDeviceList.Add(device);
                    }
                }
            }

            foreach (CpDeviceUpdate d in addDeviceList)
            {
                if (iAdded != null)
                {
                    iAdded(this, d);
                }
            }
        }
Exemplo n.º 5
0
        private void AddDevice(CpDeviceUpdate aDevice, int aIndex)
        {
            JsonObject info = new JsonObject();

            info.Add("Index", new JsonValueInt(aIndex));
            info.Add("MacAddress", new JsonValueString(aDevice.MacAddress));
            info.Add("Description", aDevice.Json);
            info.Add("Progress", new JsonValueUint(aDevice.Progress));
            info.Add("Message", new JsonValueString(aDevice.Message));
            info.Add("NewVersion", new JsonValueString(VersionSupport.SoftwareVersionPretty(aDevice.UpdateSoftwareVersion, true)));
            Send("UpdateableDeviceAdded", info);
        }
Exemplo n.º 6
0
        //private void Removed(CpDeviceReprogramList aList, CpDeviceReprogrammable aDevice)
        private void Removed(object sender, CpDeviceReprogramListRepeater.CpDeviceReprogrammableEventArgs e)
        {
            CpDeviceReprogrammable aDevice = e.Device;
            CpDeviceUpdate         device  = null;

            lock (iLock)
            {
                if (iDisposed)
                {
                    return;
                }

                foreach (CpDeviceReprogrammable d in iPendingList)
                {
                    if (d.Udn == aDevice.Udn)
                    {
                        iPendingList.Remove(d);

                        aDevice.Changed -= HandleChanged;

                        break;
                    }
                }

                foreach (CpDeviceUpdate d in iDeviceUpdateList)
                {
                    if (d.MacAddress == aDevice.MacAddress)
                    {
                        UserLog.WriteLine(DateTime.Now + ": CpDeviceUpdateList: DeviceUpdateable-             MacAddress{" + aDevice.MacAddress + "}");

                        device = d;

                        iDeviceUpdateList.Remove(d);

                        break;
                    }
                }
            }

            if (device != null)
            {
                if (iRemoved != null)
                {
                    iRemoved(this, device);
                }

                device.Dispose();
            }
        }
Exemplo n.º 7
0
        private void Removed(CpDeviceUpdateList aList, CpDeviceUpdate aDevice)
        {
            lock (iLock)
            {
                Send("UpdateableDeviceRemoved", aDevice.MacAddress);

                aDevice.Changed         -= Changed;
                aDevice.ProgressChanged -= Progress;
                aDevice.MessageChanged  -= Message;
                iDeviceListUpdateable.Remove(aDevice);
            }

            if (NumUpdateableChanged != null)
            {
                NumUpdateableChanged(this, EventArgs.Empty);
            }
        }
Exemplo n.º 8
0
        private void Changed(object sender, EventArgs e)
        {
            lock (iLock)
            {
                CpDeviceUpdate d = sender as CpDeviceUpdate;

                if (d != null)
                {
                    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));
                    info.Add("NewVersion", new JsonValueString(d.UpdateSoftwareVersion));
                    Send("UpdateableDeviceChanged", info);
                }
            }
        }
Exemplo n.º 9
0
        private void Added(CpDeviceUpdateList aList, CpDeviceUpdate aDevice)
        {
            lock (iLock)
            {
                iDeviceListUpdateable.Add(aDevice);
                iDeviceListUpdateable.Sort();
                int index = iDeviceListUpdateable.IndexOf(aDevice);

                AddDevice(aDevice, index);
                aDevice.Changed         += Changed;
                aDevice.ProgressChanged += Progress;
                aDevice.MessageChanged  += Message;
            }

            if (NumUpdateableChanged != null)
            {
                NumUpdateableChanged(this, EventArgs.Empty);
            }
        }
Exemplo n.º 10
0
        //private void Added(CpDeviceReprogramList aList, CpDeviceReprogrammable aDevice)
        private void Added(object sender, CpDeviceReprogramListRepeater.CpDeviceReprogrammableEventArgs e)
        {
            CpDeviceReprogrammable aDevice = e.Device;
            CpDeviceUpdate         device  = null;

            lock (iLock)
            {
                if (iDisposed)
                {
                    return;
                }

                if (iVersionInfoAvailable)
                {
                    Firmware firmware = CheckForSoftwareUpdate(aDevice);
                    if (firmware != null)
                    {
                        UserLog.WriteLine(DateTime.Now + ": CpDeviceUpdateList: DeviceUpdateable+             MacAddress{" + aDevice.MacAddress + "}");

                        device = new CpDeviceUpdate(aDevice, firmware, iCache, iAdapterAddress, iUpdateListener);
                        iDeviceUpdateList.Add(device);
                    }
                }

                iPendingList.Add(aDevice);

                aDevice.Changed += HandleChanged;
            }

            if (device != null)
            {
                if (iAdded != null)
                {
                    iAdded(this, device);
                }
            }
        }