internal ICmObjectId GetCanonicalID(CmObjectId candidate)
 {
     lock (SyncRoot)
     {
         ICmObjectOrSurrogate existing;
         if (!m_IdentityMap.TryGetValue(candidate, out existing))
         {
             m_IdentityMap[candidate] = candidate;
             existing = candidate;
         }
         return(existing.Id);
     }
 }
        /// <summary>
        /// This method should be used when it is desirable to have HVOs associated with
        /// Guids for objects which may not yet have been fluffed up. The ObjectOrId may be
        /// passed to GetHvoFromObjectOrId to get an HVO; anything that actually uses
        /// the HVO will result in the object being fluffed, but that can be delayed (e.g.,
        /// when persisting a pre-sorted list of guids).
        /// It will return null if the guid does not correspond to a real object (that is,
        /// for success the identity map must contain either a CmObject or a surrogate, not
        /// just a CmObjectId.)
        /// </summary>
        internal ICmObjectOrId GetObjectOrIdWithHvoFromGuid(Guid guid)
        {
            ICmObjectOrSurrogate canonicalItem;

            lock (SyncRoot)
            {
                var oldCanonicalId = CmObjectId.FromGuid(guid, this);
                canonicalItem = m_IdentityMap[oldCanonicalId];
            }
            if (canonicalItem is ICmObject)
            {
                return((ICmObject)canonicalItem);
            }
            if (canonicalItem is CmObjectSurrogate)
            {
                return(((CmObjectSurrogate)canonicalItem).ObjectOrIdWithHvo);
            }
            // If it's neither, it doesn't map to a valid object, and we don't want to
            // assign it an HVO.
            return(null);
        }
Exemple #3
0
        /// <summary>
        /// Create a surrogate from some other surrogate (or CmObject).
        /// This is used for porting from one BEP to another,
        /// and it is faster than getting all the stuff from the xml string.
        /// </summary>
        public ICmObjectSurrogate Create(ICmObjectOrSurrogate source)
        {
            var sourceSurrogate = source as ICmObjectSurrogate;

            // No! This is not what is needed in porting,
            // since it makes a new surrogate with the ICmObject from the source BEP.
            //if (sourceSurrogate == null)
            //    return Create(source as ICmObject);
            if (sourceSurrogate == null)
            {
                // Have to make a new surrogate from the extant ICmObject information,
                // since we don't even want to think of just reusing the ICmObject.
                var asCmObject = (ICmObject)source;
                var asInternal = (ICmObjectInternal)asCmObject;
                return(new CmObjectSurrogate(
                           m_cache,
                           CmObjectId.Create(asCmObject.Guid),
                           asCmObject.ClassName,
                           asInternal.ToXmlString()));
            }
            return(new CmObjectSurrogate(m_cache, sourceSurrogate));
        }
Exemple #4
0
 /// <summary>
 /// object ids are equal if their guids are.
 /// </summary>
 public bool Equals(CmObjectId id)
 {
     return(m_guid == id.m_guid);
 }
 ICmObjectId ICmObjectIdFactory.NewId()
 {
     return(CmObjectId.FromGuid(Guid.NewGuid(), this));
 }
 ICmObjectId ICmObjectIdFactory.FromGuid(Guid guid)
 {
     return(CmObjectId.FromGuid(guid, this));
 }
 ICmObjectId ICmObjectIdFactory.FromBase64String(string guid)
 {
     return(CmObjectId.FromGuid(GuidServices.GetGuid(guid), this));
 }