Example #1
0
        public IItemEnumerable <IRelationship> GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes,
                                                                RelationshipDirection?relationshipDirection, IObjectType type, IOperationContext context)
        {
            if (objectId == null || objectId.Id == null)
            {
                throw new ArgumentException("Invalid object id!");
            }

            string id     = objectId.Id;
            string typeId = (type == null ? null : type.Id);
            IRelationshipService service = Binding.GetRelationshipService();
            IOperationContext    ctxt    = new OperationContext(context);

            PageFetcher <IRelationship> .FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount)
            {
                // fetch the relationships
                IObjectList relList = service.GetObjectRelationships(RepositoryId, id, includeSubRelationshipTypes, relationshipDirection,
                                                                     typeId, ctxt.FilterString, ctxt.IncludeAllowableActions, maxNumItems, skipCount, null);

                // convert relationship objects
                IList <IRelationship> page = new List <IRelationship>();
                if (relList.Objects != null)
                {
                    foreach (IObjectData rod in relList.Objects)
                    {
                        IRelationship relationship = GetObject(CreateObjectId(rod.Id), ctxt) as IRelationship;
                        if (relationship == null)
                        {
                            throw new CmisRuntimeException("Repository returned an object that is not a relationship!");
                        }

                        page.Add(relationship);
                    }
                }

                return(new PageFetcher <IRelationship> .Page <IRelationship>(page, relList.NumItems, relList.HasMoreItems));
            };

            return(new CollectionEnumerable <IRelationship>(new PageFetcher <IRelationship>(DefaultContext.MaxItemsPerPage, fetchPageDelegate)));
        }