static private FromGuid ( System.Guid guid, IdentityMap map ) : ICmObjectId | ||
guid | System.Guid | |
map | IdentityMap | |
Résultat | ICmObjectId |
// IReferenceTypeHandler override public override void Activate(IReferenceActivationContext context) { if (m_serverOnlyMode) { ActivateServer(context); return; } if (m_cache == null) { throw new NullReferenceException("m_cache"); } if (m_identitymap == null) { throw new NullReferenceException("m_identitymap"); } var context2 = (UnmarshallingContext)context; var buffer = (ByteArrayBuffer)context2.Buffer(); // Get Guid and CmObjectId. // Earlier code used a special CmObject.Create() method, I think because it is faster, // and on the assumption that we only activate objects at startup, so none of the // IDs have been seen before. However, with a background thread fluffing things, we // COULD have seen it, even during startup, if we've fluffed some object that references // this one. Also, this code is called in client-server mode when we Refresh an object // to see whether someone else changed it, and then the ID is very likely to exist already. // It MAY be possible to re-introduce the faster ID creation code just during startup // if we're not overlapping fluffing and reading. var reconId = CmObjectId.FromGuid(new Guid(buffer.ReadBytes(16)), m_identitymap); // Get class name. var className = m_unicodeEnc.GetString(buffer.ReadBytes(buffer.ReadInt())); // Get the data. var dataLength = buffer.ReadInt(); // Reconstitute the surrogate. ((CmObjectSurrogate)context.PersistentObject()).InitializeFromDataStore( m_cache, reconId, className, buffer.ReadBytes(dataLength)); }
/// <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); }
/// <summary> /// returns null if there are no more CmObejtcSurroages on the stream. /// </summary> internal CmObjectSurrogate GetNextCmObjectSurrogate(GZipStream stream) { var temp = new byte[16]; if (stream.Read(temp, 0, 16) <= 0) { return(null); } var cmObjectId = CmObjectId.FromGuid(new Guid(temp), m_identityMap); string className = m_unicodeEncoding.GetString(stream.ReadBytes(stream.ReadInt())); byte[] xmldata = stream.ReadBytes(stream.ReadInt()); long id = stream.ReadLong(); var ret = new CmObjectSurrogate(m_cache, cmObjectId, className, xmldata); m_mapId.Add(ret.Id, id); return(ret); }
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)); }