public DeviceInfo(EDeviceType type) { m_device_id = new DeviceID(-1, string.Empty); this.type = type; ipAddress = "0.0.0.0"; username = password = string.Empty; deleted = false; collectors = CollectorInfo.FromCollectorTypes(type.GetCollectors()); driveNames = new Dictionary <string, string>(); monitoredDrives = new MonitoredDriveManager(); groupID = -1; }
public void Merge(SystemConfiguration config) { HashSet <string> doomed = new HashSet <string>(configuration.Keys, StringComparer.OrdinalIgnoreCase); foreach (KeyValuePair <string, ConfigurationData> configpair in config.configuration) { doomed.Remove(configpair.Key); configuration[configpair.Key] = configpair.Value; } doomed.ToList().ForEach(c => configuration[c].deleted = true); doomed.Clear(); doomed.Concat(devices.ConvertAll <string>(d => d.name)); // Never remove the System device, or the device that is a Server. DeviceInfo system = devices.FirstOrDefault(d => d.type == EDeviceType.System); doomed.Remove("System"); DeviceInfo server = devices.FirstOrDefault(d => d.type == EDeviceType.Server); if (server != null) { doomed.Remove(server.name); } foreach (DeviceInfo new_device in config.devices) { // Don't allow the System to be imported if (new_device.type == EDeviceType.System) { continue; } doomed.Remove(new_device.name); DeviceInfo old_device = devices.FirstOrDefault(d => string.Compare(d.name, new_device.name, true) == 0); DeviceInfo insert_device = new DeviceInfo(new_device.type) { DID = new DeviceID(-1, new_device.name) }; if (old_device != null) { devices.Remove(old_device); insert_device.DID = new DeviceID(old_device.DID.ID, new_device.name); } switch (new_device.type) { case EDeviceType.Server: case EDeviceType.System: insert_device.ipAddress = "0.0.0.0"; break; case EDeviceType.Workstation: insert_device.ipAddress = new_device.ipAddress; insert_device.username = new_device.username; insert_device.password = new_device.password; break; case EDeviceType.Camera: case EDeviceType.RPM: case EDeviceType.Generic: case EDeviceType.Unknown: default: insert_device.ipAddress = new_device.ipAddress; insert_device.username = insert_device.password = string.Empty; break; } foreach (CollectorInfo insert_ci in insert_device.collectors) { CollectorInfo new_ci = new_device.collectors.FirstOrDefault(nc => nc.collectorType == insert_ci.collectorType); if (new_ci != null) { insert_ci.Merge(new_ci); } } devices.Add(insert_device); } foreach (string name in doomed) { DeviceInfo doomed_device = devices.FirstOrDefault(d => d.name == name); if (doomed_device != null) { doomed_device.deleted = true; } } mostRecentData = config.mostRecentData; }
public void Merge(CollectorInfo other) { frequencyInMinutes = other.frequencyInMinutes; isEnabled = other.isEnabled; }