private void LoadLocalDevices() { var deviceConfigs = DeviceConfiguration.ReadAll(FileLocations.Devices); if (deviceConfigs != null) { foreach (var deviceConfig in deviceConfigs) { if (deviceConfig.Description != null) { AddDevice(new DeviceDescription(deviceConfig)); } } } SendDevicesLoadedMessage(); }
private void CheckLocalDevices() { // Retrieves a list of devices by reading the local 'Devices' folder (if not logged in) var configs = DeviceConfiguration.ReadAll(FileLocations.Devices).ToList(); if (configs != null) { if (configs.Count > 0) { foreach (DeviceConfiguration config in configs) { if (config != null) { lock (_lock) { int index = -1; index = devices.FindIndex(x => x != null && x.Configuration.UniqueId == config.UniqueId); if (index >= 0) // Server is already part of list { var server = devices[index]; // Check if Configuration has changed if (server.Configuration.UpdateId != config.UpdateId || !server.IsRunning) { // If changed at all then stop the current server server.Stop(); // If changed and still enabled then restart server if (config.Enabled) { server.Configuration = config; server.Start(); UpdateLoginInformation(server); } else // Remove from List { devices.RemoveAt(index); logger.Info("Device Removed :: " + server.Configuration.Description.Description + " [" + server.Configuration.Description.DeviceId + "]"); } } } else // Create & Add Device Server { if (config.Enabled) { AddDevice(config); } } } } } lock (_lock) { // Find devices that were removed foreach (var device in devices.ToList()) { if (!configs.Exists(x => x != null && x.UniqueId == device.Configuration.UniqueId)) { var d = devices.Find(x => x != null && x.Configuration.UniqueId == device.Configuration.UniqueId); if (d != null) { d.Stop(); devices.Remove(d); } } } } } else { RemoveAllDevices(); } } else { RemoveAllDevices(); } }