Beispiel #1
0
        private static void LineObjectCollectionToSerializableObjectList <T>(LineContainer lc, ILineObjectCollection <T> locObjects) where T : ILineObject <T>
        {
            string sObjectListName = LineContainer.ContentTypeToObjectListName(typeof(T));

            SyncList <T>           lObjects             = locObjects.ToSyncList();
            SerializableObjectList lSerializableObjects = lc.Objects.EnsureSerializableObjectList(typeof(T), sObjectListName);

            foreach (T objSource in lObjects)
            {
                try
                {
                    ISerializableObject so = objSource.Serialize();

                    lSerializableObjects.Add(so);
                }
                catch (Exception excp)
                {
                    m_logger.Excp(excp, "ToLineContainer() ERROR. Could not add serializable object for {0}", objSource);
                }
            }

            Thread.Sleep(1);
        }
Beispiel #2
0
        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);
        }