/// <summary>
 /// If we already know an HVO for this ID, answer it. Otherwise, assign a new one.
 /// Don't set up the association, because it will be established by assigning the HVO to
 /// a new (or restored) CmObject, and registering that.
 /// Assume we do NOT already have a CmObject for this ID; this method is reserved
 /// for use in the process of creating CmObjects.
 /// </summary>
 internal int GetOrAssignHvoFor(ICmObjectId id)
 {
     lock (SyncRoot)
     {
         ICmObjectOrSurrogate canonicalItem = m_IdentityMap[id];
         if (canonicalItem is CmObjectSurrogate)
         {
             ICmObjectId canonicalId = ((CmObjectSurrogate)canonicalItem).Id;
             if (canonicalId is CmObjectIdWithHvo)
             {
                 return(((CmObjectIdWithHvo)canonicalId).Hvo);
             }
         }
         Debug.Assert(!(canonicalItem is ICmObject));
         if (canonicalItem is CmObjectIdWithHvo)
         {
             return(((CmObjectIdWithHvo)canonicalItem).Hvo);
         }
         return(GetNextRealHvo());
     }
 }
Example #2
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));
        }
Example #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);
		}