Ejemplo n.º 1
0
        private ActiveDevice[] GetActiveDeviceArray()
        {
            var deviceArray = new ActiveDevice[this.activeDevices.Count];

            for (int i = 0; i < this.activeDevices.Count; i++)
            {
                deviceArray[i] = this.activeDevices[i];
            }
            return(deviceArray);
        }
Ejemplo n.º 2
0
 public StatusHelper(ActiveDevice device)
 {
     this.activeDevice = device;
     this.activeDevice.OperationInProgress = true;
 }
Ejemplo n.º 3
0
        public async Task UpdateActiveDevicesAsync(IList <DeviceInformation> allDevices)
        {
            int nextDeviceIndex = 0;

            foreach (var deviceInformation in allDevices)
            {
                if (deviceInformation.IsChecked)
                {
                    int currentDeviceIndex = this.TryGetActiveDeviceIndex(deviceInformation.Address);

                    if (currentDeviceIndex >= 0)
                    {
                        // We already have this active device so just put it in the next position

                        // Only move it if it's in the wrong position
                        if (currentDeviceIndex != nextDeviceIndex)
                        {
                            var activeDevice = this.activeDevices[currentDeviceIndex];
                            this.activeDevices.RemoveAt(currentDeviceIndex);
                            this.activeDevices.Insert(nextDeviceIndex, activeDevice);
                        }
                    }
                    else
                    {
                        // We don't have an active device for this item so create and add
                        var activeDevice = new ActiveDevice(deviceInformation);
                        activeDevice.GetRunningProcessesOnHeartbeat = true; // maybe just do this with the selected device
                        activeDevice.Log += this.LogDeviceMessage;
                        this.activeDevices.Insert(nextDeviceIndex, activeDevice);
                    }

                    ++nextDeviceIndex;
                }
            }

            // remove any Active Devices the user doesn't want
            while (this.activeDevices.Count > nextDeviceIndex)
            {
                var activeDevice = this.activeDevices[nextDeviceIndex];
                await activeDevice.Close();

                this.activeDevices.RemoveAt(nextDeviceIndex);
            }

            // Get the heartbeat going if we need to
            if (this.activeDevices.Count > 0 && !this.heartbeatActive)
            {
                this.LogMessage(false, "Starting heartbeat");
                // we have active devices but no heartbeat so start it
                this.heartbeatActive = true;
                Device.StartTimer(TimeSpan.FromSeconds(5.0), () =>
                {
                    //this.LogMessage(false, "Heartbeat");

                    if (!this.inHeartbeat)
                    {
                        this.inHeartbeat = true;
                        this.HeartbeatTimerTick();
                        this.inHeartbeat = false;
                    }

                    return(this.heartbeatActive);
                });
            }
            else if (this.activeDevices.Count == 0 && this.heartbeatActive)
            {
                this.LogMessage(false, "Stopping heartbeat");

                // We have no active devices but there is a heartbeat. So stop it
                this.heartbeatActive = false;
            }
        }