/// <summary> /// Сохранение значений в бакнет-сеть /// </summary> public bool SaveValuesToNetwork(Dictionary <string, string> values) { values = values.Where(d => _backnetAddressRegex.IsMatch(d.Key)).ToDictionary(dk => dk.Key, dk => dk.Value); // много значений if (values.Count > 1) { var result = true; var devWithObjValues = new List <DeviceWithObjValues>(); foreach (var val in values) { var obj = val.Key.Split('.'); var isContains = false; foreach (var dev in devWithObjValues.Where(dev => dev.DeviceId == obj[0])) { var newValues = new Dictionary <BacnetPropertyId, object> { { BacnetPropertyId.PresentValue, val.Value } }; dev.ObjValues.Add(obj[1], newValues); isContains = true; } if (isContains) { continue; } var propWithValues = new Dictionary <BacnetPropertyId, object> { { BacnetPropertyId.PresentValue, val.Value } }; var devWithValues = new DeviceWithObjValues { DeviceId = obj[0], ObjValues = new Dictionary <string, Dictionary <BacnetPropertyId, object> > { { obj[1], propWithValues } } }; devWithObjValues.Add(devWithValues); } foreach (var deviceWithObjValues in devWithObjValues) { result &= WriteSeveralValues(deviceWithObjValues.DeviceId, deviceWithObjValues.ObjValues); Thread.Sleep(100); } return(result); } // одно значение if (values.Count == 1) { var pair = values.ElementAt(0); var addr = pair.Key.Split('.'); return(WriteValue(addr[0], addr[1], pair.Value)); } return(true); }
/// <summary> /// Сохранение значений в бакнет-сеть /// </summary> public bool SaveValuesToNetwork(Dictionary<string, string> values) { values = values.Where(d => _backnetAddressRegex.IsMatch(d.Key)).ToDictionary(dk => dk.Key, dk => dk.Value); // много значений if (values.Count > 1) { var result = true; var devWithObjValues = new List<DeviceWithObjValues>(); foreach (var val in values) { var obj = val.Key.Split('.'); var isContains = false; foreach (var dev in devWithObjValues.Where(dev => dev.DeviceId == obj[0])) { var newValues = new Dictionary<BacnetPropertyId, object> { { BacnetPropertyId.PresentValue, val.Value } }; dev.ObjValues.Add(obj[1], newValues); isContains = true; } if (isContains) continue; var propWithValues = new Dictionary<BacnetPropertyId, object> { { BacnetPropertyId.PresentValue, val.Value } }; var devWithValues = new DeviceWithObjValues { DeviceId = obj[0], ObjValues = new Dictionary<string, Dictionary<BacnetPropertyId, object>> { { obj[1], propWithValues } } }; devWithObjValues.Add(devWithValues); } foreach (var deviceWithObjValues in devWithObjValues) { result &= WriteSeveralValues(deviceWithObjValues.DeviceId, deviceWithObjValues.ObjValues); Thread.Sleep(100); } return result; } // одно значение if (values.Count == 1) { var pair = values.ElementAt(0); var addr = pair.Key.Split('.'); return WriteValue(addr[0], addr[1], pair.Value); } return true; }