public override async Task <Result> UpdateConfig(Origin origin, ObjectValue[] updateOrDeleteObjects, MemberValue[] updateOrDeleteMembers, AddArrayElement[] addArrayElements) { try { var changedObjects = new HashSet <ObjectRef>(); foreach (ObjectValue ov in updateOrDeleteObjects) { if (!mapObjests.ContainsKey(ov.Object)) { throw new Exception("Failed to update object " + ov.Object + " because no object found with this id."); } IModelObject obj = mapObjests[ov.Object]; if (ov.Value.IsEmpty) { var objInfo = mapObjectInfos[ov.Object]; MemberRefIdx?parent = objInfo.Parent; if (!parent.HasValue) { throw new Exception("Failed to delete object " + ov.Object + " because there is no parent object."); } var objParent = mapObjests[parent.Value.Object]; objParent.RemoveChildObject(parent.Value.Name, obj); changedObjects.Add(parent.Value.Object); } else { ov.Value.PopulateObject(obj); changedObjects.Add(ov.Object); } } foreach (MemberValue m in updateOrDeleteMembers) { if (!mapObjests.ContainsKey(m.Member.Object)) { throw new Exception("Failed to update member " + m.Member.Name + " because no object found with id: " + m.Member.Object); } IModelObject obj = mapObjests[m.Member.Object]; obj.SetMemberValue(m.Member.Name, m.Value); changedObjects.Add(m.Member.Object); } foreach (AddArrayElement element in addArrayElements) { if (!mapObjests.ContainsKey(element.ArrayMember.Object)) { throw new Exception("Failed to add item to member " + element.ArrayMember.Name + " because no object found with id: " + element.ArrayMember.Object); } IModelObject obj = mapObjests[element.ArrayMember.Object]; obj.AddChildObject(element.ArrayMember.Name, element.ValueToAdd); changedObjects.Add(element.ArrayMember.Object); } await OnConfigModelChanged(init : false); modelAsString = SerializeModelToString(model); WriteConfigFile(modelFileName, modelAsString); if (notifier != null) { notifier.Notify_ConfigChanged(changedObjects.ToArray()); } return(Result.OK); } catch (Exception exp) { model = DeserializeModelFromString(modelAsString); // restore model which might have been partially modified before the exception ModifyModelAfterInit(); await OnConfigModelChanged(init : false); return(Result.Failure("UpdateConfig failed: " + exp.Message)); } }