/// <summary> /// Fetches a list of CollectionEntry objects of the Relation /// <paramref name="relId"/> which are owned by the object with the /// ID <paramref name="parentObjID"/> in the role <paramref name="serializableRole"/>. /// </summary> /// <param name="version">Current version of generated Zetbox.Objects assembly</param> /// <param name="relId">the requested Relation</param> /// <param name="serializableRole">the parent role (1 == A, 2 == B)</param> /// <param name="parentObjID">the ID of the parent object</param> /// <returns>the requested collection entries</returns> public byte[] FetchRelation(Guid version, Guid relId, int serializableRole, int parentObjID) { using (Logging.Facade.DebugTraceMethodCallFormat("FetchRelation", "relId = [{0}], role = [{1}], parentObjID = [{2}]", relId, serializableRole, parentObjID)) { try { DebugLogIdentity(); using (IZetboxContext ctx = _ctxFactory()) { var endRole = (RelationEndRole)serializableRole; // TODO: Use FrozenContext Relation rel = ctx.FindPersistenceObject <Relation>(relId); var ifTypeA = _iftFactory(rel.A.Type.GetDataType()); var ifTypeB = _iftFactory(rel.B.Type.GetDataType()); var ifType = endRole == RelationEndRole.A ? ifTypeA : ifTypeB; int resultCount = 0; var ticks = _perfCounter.IncrementFetchRelation(ifType); try { var lst = _sohFactory .GetServerCollectionHandler( ctx, ifTypeA, ifTypeB, endRole) .GetCollectionEntries(version, ctx, relId, endRole, parentObjID); resultCount = lst.Count(); return(SendObjects(lst.Cast <IStreamable>(), true).ToArray()); } finally { _perfCounter.DecrementFetchRelation(ifType, resultCount, ticks); } } } catch (Exception ex) { Helper.ThrowFaultException(ex); // Never called, Handle errors throws an Exception return(null); } } }
public IEnumerable <T> FetchRelation <T>(IZetboxContext ctx, Guid relationId, RelationEndRole role, IDataObject parent, out List <IStreamable> auxObjects) where T : class, IRelationEntry { var ifType = ctx.GetInterfaceType(parent); var ticks = _perfCounter.IncrementFetchRelation(ifType); int resultCount = 0; try { // TODO: could be implemented in generated properties if (parent.ObjectState == DataObjectState.New) { auxObjects = new List <IStreamable>(); return(new List <T>()); } IEnumerable <T> result = null; List <IStreamable> tmpAuxObjects = null; byte[] bytes = null; MakeRequest(() => { bytes = _service.FetchRelation(ZetboxGeneratedVersionAttribute.Current, relationId, (int)role, parent.ID); }); using (MemoryStream s = new MemoryStream(bytes)) using (var sr = _readerFactory(new BinaryReader(s))) { result = ReceiveObjects(ctx, sr, out tmpAuxObjects).Cast <T>(); } resultCount = result.Count(); auxObjects = tmpAuxObjects; return(result); } finally { _perfCounter.DecrementFetchRelation(ifType, resultCount, ticks); } }