示例#1
0
        public void AddSafely(T objSource)
        {
            ILineObjectWithId <T>  objById  = objSource as ILineObjectWithId <T>;
            ILineObjectWithKey <T> objByKey = objSource as ILineObjectWithKey <T>;

            string sKey = null;

            if (objById != null)
            {
                sKey = objById.Id.ToString("G");
            }
            else if (objByKey != null)
            {
                sKey = objByKey.KeyName;
            }
            else
            {
                Debug.Assert(false);
            }

            lock (m_oLocker)
            {
                if (!base.ContainsKey(sKey))
                {
                    base.Add(sKey, objSource);
                }
                //else
                //{
                //    m_logger.WarnFormat("{0} is skipped because it already exists in collection.", objSource);
                //}
            }
        }
示例#2
0
        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);
                }
            }
        }
示例#3
0
        public static string GetKeyName(T objSource)
        {
            ILineObjectWithId <T> objById = objSource as ILineObjectWithId <T>;

            if (objById != null)
            {
                return(objById.Id.ToString("G"));
            }

            ILineObjectWithKey <T> objByKey = objSource as ILineObjectWithKey <T>;

            if (objByKey != null)
            {
                return(objByKey.KeyName);
            }

            Debug.Assert(false);

            return(string.Empty);
        }