private static void MergeCollections <T>(SyncList <T> lSource, DictionaryOfLineObjectCollection dlocTarget) where T : ILineObject <T> { Debug.Assert(lSource != null); ILineObjectCollection <T> locTarget = dlocTarget.GetLineObjectCollection <T>(); foreach (T objSource in lSource) { ILineObjectWithId <T> objById = objSource as ILineObjectWithId <T>; ILineObjectWithKey <T> objByKey = objSource as ILineObjectWithKey <T>; try { if (objById != null) { if (objById.Id != 0) { locTarget.MergeLineObject(objSource); } } else if (objByKey != null) { locTarget.MergeLineObject(objSource); } else { Debug.Assert(false); } } catch (Exception excp) { m_logger.Excp(excp, "Could not merge object {0}", objSource); } } }
public static int MergeLineObjects <T>(LineContainer lc, ILineObjectCollection <T> loc, MergeLineObjectsCallBack <T> objectsCallBack, ref long lOperationMask) where T : ILineObject <T> { Debug.Assert(objectsCallBack.GetLineObject != null); Debug.Assert(objectsCallBack.CreateLineObject != null); int iSucceededCount = 0; if (loc != null) { string sObjectListName = LineContainer.ContentTypeToObjectListName(typeof(T)); SerializableObjectList lObjects = lc.Objects.SafelyGetValue(sObjectListName); if (lObjects != null) { foreach (ISerializableObject so in lObjects) { //so.MethodTag = dgo; try { T tObj = objectsCallBack.GetLineObject(so); if (so.IsToRemove()) { if (tObj != null) { tObj = loc.MergeLineObject(tObj, so); if (objectsCallBack.RemoveLineObject != null) { objectsCallBack.RemoveLineObject(tObj); //m_logger.InfoFormat("Removed from Line {0}", tObj); lOperationMask |= (long)eOperationMask.RemovedFromCollection; } } } else { if (tObj == null) { // Object is NEW - DOES NOT exist yet in line tObj = objectsCallBack.CreateLineObject(); tObj.Deserialize(so); tObj = loc.MergeLineObject(tObj); lOperationMask |= (long)eOperationMask.AddedToCollection; //m_logger.DebugFormat("Added to Line {0}", tObj); } else { // Object Already Exists tObj = loc.MergeLineObject(tObj, so); if (tObj.ChangedProps != null && tObj.ChangedProps.Count > 0) { lOperationMask |= (long)eOperationMask.ObjectEdited; } } if (objectsCallBack.OnLineObjectMerged != null) { objectsCallBack.OnLineObjectMerged(tObj); } } iSucceededCount++; } catch (Exception excp) { m_logger.Error(excp.Message, excp); ExcpHelper.ThrowUp(excp, "MergeLineObjects<{0}>() ERROR for {1}", typeof(T).Name, so); } } } } return(iSucceededCount); }