public void UpdateSourceAssigned(MarshalObjectList mol) { IObjectManager om = Context.ObjectManager; IMarshalingTransformer transformer = new MarshalingTransformer(Context); IClassMap classMap; MarshalProperty mp; object obj; object newValue; foreach (MarshalObject mo in mol.Objects) { if (mo.TempId.Length > 0) { obj = GetInsertedObjectWithTemporaryIdentity(mo.TempId); if (obj != null) { classMap = Context.DomainMap.MustGetClassMap(obj.GetType()); foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.GetIsAssignedBySource()) { mp = mo.GetProperty(propertyMap.Name); if (mp != null) { newValue = transformer.ToPropertyValue(obj, mp.Value, mp, propertyMap); om.SetPropertyValue(obj, propertyMap.Name, newValue); om.SetOriginalPropertyValue(obj, propertyMap.Name, newValue); om.SetNullValueStatus(obj, propertyMap.Name, false); } } } Context.IdentityMap.UpdateIdentity(obj, mo.TempId); } } else { classMap = Context.DomainMap.MustGetClassMap(mo.Type); if (classMap.HasAssignedBySource() ) { obj = GetObjectByMarshalObject(transformer, mo, classMap); foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps()) { if (propertyMap.GetIsAssignedBySource()) { mp = mo.GetProperty(propertyMap.Name); if (mp != null) { newValue = transformer.ToPropertyValue(obj, mp.Value, mp, propertyMap); om.SetPropertyValue(obj, propertyMap.Name, newValue); om.SetOriginalPropertyValue(obj, propertyMap.Name, newValue); om.SetNullValueStatus(obj, propertyMap.Name, false); } } } } } } }
public virtual MarshalUnitOfWork GetUnitOfWork() { MarshalUnitOfWork muow = new MarshalUnitOfWork(); IMarshalingTransformer transformer = new MarshalingTransformer(Context); MarshalObject mo; foreach (object obj in listInsert) { mo = transformer.FromObject(obj, true); muow.InsertObjects.Add(mo); } foreach (object obj in listUpdate) { mo = transformer.FromObject(obj); muow.UpdateObjects.Add(mo); } foreach (object obj in listRemove) { mo = transformer.FromObject(obj); muow.RemoveObjects.Add(mo); } return muow; }
//Refresh issues!! public override IList LoadObjects(IQuery query, IList listToFill) { if (this.url.Length < 1) throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!"); RemotingService rs = new RemotingService(this.Context, url); IMarshalingTransformer transformer = new MarshalingTransformer(Context); MarshalQuery mq = transformer.FromQuery(query); string xmlQuery = (string) Formatter.Serialize(mq); if (useCompression && this.compressor != null) xmlQuery = this.compressor.Compress(xmlQuery); bool doUseCompression = this.useCompression ; if (this.compressor == null) doUseCompression = false; string result = rs.LoadObjects(xmlQuery, this.domainKey, doUseCompression); if (useCompression && this.compressor != null) result = this.compressor.Decompress(result); MarshalObjectList mol = (MarshalObjectList) Formatter.Deserialize(result, typeof(MarshalObjectList)); transformer.ToObjectList(mol, query.RefreshBehavior, listToFill); return listToFill; }
public override void LoadProperty(object obj, string propertyName) { if (this.url.Length < 1) throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!"); RemotingService rs = new RemotingService(this.Context, url); IMarshalingTransformer transformer = new MarshalingTransformer(Context); IObjectManager om = Context.ObjectManager ; IClassMap classMap = Context.DomainMap.MustGetClassMap(obj.GetType()); IPropertyMap propertyMap = classMap.MustGetPropertyMap(propertyName); MarshalReference mr = transformer.FromObjectAsReference(obj); string xmlObject = (string) Formatter.Serialize(mr); if (useCompression && this.compressor != null) xmlObject = this.compressor.Compress(xmlObject); bool doUseCompression = this.useCompression ; if (this.compressor == null) doUseCompression = false; string result = rs.LoadProperty(xmlObject, propertyName, this.domainKey, doUseCompression); if (useCompression && this.compressor != null) result = this.compressor.Decompress(result); if (propertyMap.IsCollection) { if (propertyMap.ReferenceType == ReferenceType.None) { } else { //Refresh issues!!! (the objects in the list being deserialized may exist in the cache!!) MarshalObjectList mol = (MarshalObjectList) Formatter.Deserialize(result, typeof(MarshalObjectList)); IList freshList = transformer.ToObjectList(mol, RefreshBehaviorType.DefaultBehavior, new ArrayList()); //Context.IdentityMap.RegisterLoadedObject(obj); IList orgList = (IList) om.GetPropertyValue(obj, propertyName); LoadReferenceList(freshList, orgList, om, obj, propertyMap); this.Context.InverseManager.NotifyPropertyLoad(obj, propertyMap, orgList); } } else { if (propertyMap.ReferenceType == ReferenceType.None) { MarshalProperty mp = (MarshalProperty) Formatter.Deserialize(result, typeof(MarshalProperty)); transformer.ToProperty(obj, mp, propertyMap, RefreshBehaviorType.DefaultBehavior ); } else { if (result.Length > 0) { MarshalObject mo = (MarshalObject) Formatter.Deserialize(result, typeof(MarshalObject)); string identity = transformer.GetIdentity(mo); IClassMap refClassMap = Context.DomainMap.MustGetClassMap(mo.Type); Type refType = Context.AssemblyManager.MustGetTypeFromClassMap(refClassMap); object refObject = Context.GetObjectById(identity, refType, true); if (om.GetObjectStatus(refObject) == ObjectStatus.NotLoaded) { transformer.ToObject(mo, ref refObject); } // object refObject = Context.TryGetObjectById(identity, refType, true); // if (refObject == null) // { // refObject = Context.GetObjectById(identity, refType, true); // transformer.ToObject(mo, ref refObject); // } om.SetPropertyValue(obj, propertyName, refObject); om.SetOriginalPropertyValue(obj, propertyName, refObject); om.SetNullValueStatus(obj, propertyName, false); this.Context.InverseManager.NotifyPropertyLoad(obj, propertyMap, refObject); } else { om.SetPropertyValue(obj, propertyName, null); om.SetOriginalPropertyValue(obj, propertyName, null); om.SetNullValueStatus(obj, propertyName, true); } } } }
//Should have no refresh issues public override void LoadObject(ref object obj) { if (this.url.Length < 1) throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!"); RemotingService rs = new RemotingService(this.Context, url); IClassMap classMap = Context.DomainMap.MustGetClassMap(obj.GetType()); string id = Context.ObjectManager.GetObjectIdentity(obj); bool doUseCompression = this.useCompression ; if (this.compressor == null) doUseCompression = false; string result = rs.LoadObject(classMap.GetName(), id, this.domainKey, doUseCompression); if (useCompression && this.compressor != null) result = this.compressor.Decompress(result); MarshalObject mo = (MarshalObject) Formatter.Deserialize(result, typeof(MarshalObject)); IMarshalingTransformer transformer = new MarshalingTransformer(Context); Context.IdentityMap.RegisterLoadedObject(obj); transformer.ToObject(mo, ref obj); }