public static InspectionPlanCharacteristicDto GetOrCreateCharacteristic(DataServiceRestClient client, string partName, string characteristicName, Dictionary <string, ushort> mapping, Dictionary <string, object> values) { var characteristics = client.GetCharacteristics(PathHelper.String2PartPathInformation(partName), 1).Result; var attributes = values.Select(pair => new AttributeDto(mapping[pair.Key], pair.Value)).ToArray(); var existingCharacteristic = characteristics.FirstOrDefault(p => string.Equals(p.Path.Name, characteristicName)); if (existingCharacteristic == null) { existingCharacteristic = new InspectionPlanCharacteristicDto { Path = PathHelper.RoundtripString2PathInformation("PC:/" + partName + " / " + characteristicName + "/"), Uuid = Guid.NewGuid(), Attributes = attributes }; client.CreateCharacteristics(new[] { existingCharacteristic }).Wait(); } else { existingCharacteristic.Attributes = attributes; //maybe update the existing characteristic, so the attributes are up-to-date client.UpdateCharacteristics(new[] { existingCharacteristic }).Wait(); } return(existingCharacteristic); }