private bool ResolveProductConflict(ObjectChangeConflict conflict) { Product current = (Product)conflict.Object; if (conflict.IsDeleted) { // we don't attempt to resolve delete conflicts - // we send those back to the client return(false); } switch (current.ResolveMethod) { case "ThrowValidationEx": throw new ValidationException("testing"); case "ThrowDomainServiceEx": throw new DomainException("testing"); case "MergeIntoCurrent": conflict.Resolve(RefreshMode.KeepChanges); break; case "KeepCurrent": conflict.Resolve(RefreshMode.KeepCurrentValues); break; case "RefreshCurrent": conflict.Resolve(RefreshMode.OverwriteCurrentValues); break; case "ReturnTrueNoResolve": return(true); case "ReturnFalse": return(false); case "ReturnFalseWithResolve": conflict.Resolve(RefreshMode.OverwriteCurrentValues); return(false); case "": conflict.Resolve(RefreshMode.KeepCurrentValues); break; default: { throw new NotImplementedException(string.Format("ResolveMethod {0} is not defined", current.ResolveMethod)); } } return(conflict.IsResolved); }
/// <summary> /// Updates each entry in the ChangeSet with its corresponding conflict info. /// </summary> /// <param name="operationConflictMap">Map of conflicts to their corresponding operations entries.</param> private void SetChangeSetConflicts(Dictionary <ObjectChangeConflict, ChangeSetEntry> operationConflictMap) { foreach (var conflictEntry in operationConflictMap) { ObjectChangeConflict occ = conflictEntry.Key; ChangeSetEntry operationInConflict = conflictEntry.Value; PropertyDescriptorCollection properties = null; // only create a StoreEntity if the object in conflict is not deleted in the store if (!occ.IsDeleted) { // Calling GetOriginalEntityState will create a copy of the original // object for us ITable table = this.DataContext.GetTable(occ.Object.GetType()); operationInConflict.StoreEntity = table.GetOriginalEntityState(occ.Object); properties = TypeDescriptor.GetProperties(operationInConflict.StoreEntity); string[] propertyNamesInConflict = new string[occ.MemberConflicts.Count]; for (int i = 0; i < occ.MemberConflicts.Count; i++) { MemberChangeConflict mcc = occ.MemberConflicts[i]; string propertyName = mcc.Member.Name; // Store the members that are in conflict. propertyNamesInConflict[i] = propertyName; Debug.Assert(properties[propertyName] != null, "Expected to find property."); // if the entity is not deleted in the store, also let the client know what the store state is. properties[propertyName].SetValue(operationInConflict.StoreEntity, mcc.DatabaseValue); } operationInConflict.ConflictMembers = propertyNamesInConflict; } else { operationInConflict.IsDeleteConflict = true; } } }