Beispiel #1
0
        public List <T> GetDTOs <T>(int[] artifactIDs, ObjectFieldsDepthLevel depthLevel)
            where T : BaseDto, new()
        {
            List <RDO> objectsRdos = GetRdos(artifactIDs);

            switch (depthLevel)
            {
            case ObjectFieldsDepthLevel.FirstLevelOnly:
                return(objectsRdos.Select <RDO, T>(rdo => rdo.ToHydratedDto <T>()).ToList());

            case ObjectFieldsDepthLevel.FullyRecursive:
                var allDtos = new List <T>();

                foreach (var rdo in objectsRdos)
                {
                    var dto = rdo.ToHydratedDto <T>();

                    PopulateChildrenRecursively <T>(dto, rdo, depthLevel);

                    allDtos.Add(dto);
                }

                return(allDtos);

            default:
                return(objectsRdos.Select <RDO, T>(rdo => rdo.ToHydratedDto <T>()).ToList());
            }
        }
Beispiel #2
0
        public List <T> GetAllDTOs <T>(Condition queryCondition = null, ObjectFieldsDepthLevel depthLevel = ObjectFieldsDepthLevel.FirstLevelOnly)
            where T : BaseDto, new()
        {
            List <T> returnList = null;

            List <RDO> objectsRdos = GetRdos <T>(queryCondition);

            switch (depthLevel)
            {
            case ObjectFieldsDepthLevel.FirstLevelOnly:
                returnList = objectsRdos.Select <RDO, T>(rdo => rdo.ToHydratedDto <T>()).ToList();
                break;

            case ObjectFieldsDepthLevel.FullyRecursive:
                var allDtos = new List <T>();

                foreach (var rdo in objectsRdos)
                {
                    var dto = rdo.ToHydratedDto <T>();

                    PopulateChildrenRecursively <T>(dto, rdo, depthLevel);

                    allDtos.Add(dto);
                }

                returnList = allDtos;
                break;

            default:
                return(objectsRdos.Select <RDO, T>(rdo => rdo.ToHydratedDto <T>()).ToList());
            }

            return(returnList);
        }
Beispiel #3
0
        public T Get <T>(int artifactID, ObjectFieldsDepthLevel depthLevel)
            where T : BaseDto, new()
        {
            RDO objectRdo = GetRdo(artifactID);

            return(GetHydratedDTO <T>(objectRdo, depthLevel));
        }
Beispiel #4
0
        private T GetHydratedDTO <T>(RDO objectRdo, ObjectFieldsDepthLevel depthLevel)
            where T : BaseDto, new()
        {
            T dto = objectRdo.ToHydratedDto <T>();

            PopulateChoices(dto, objectRdo);
            switch (depthLevel)
            {
            case ObjectFieldsDepthLevel.OnlyParentObject:
                break;

            case ObjectFieldsDepthLevel.FirstLevelOnly:
                PopulateChildrenRecursively <T>(dto, objectRdo, ObjectFieldsDepthLevel.OnlyParentObject);
                break;

            case ObjectFieldsDepthLevel.FullyRecursive:
                PopulateChildrenRecursively <T>(dto, objectRdo, ObjectFieldsDepthLevel.FullyRecursive);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(depthLevel));
            }

            return(dto);
        }
Beispiel #5
0
        public List <T> Get <T>(int[] artifactIDs, ObjectFieldsDepthLevel depthLevel)
            where T : BaseDto, new()
        {
            List <RDO> objectsRdos = GetRdos(artifactIDs);

            return(objectsRdos.Select(rdo => GetHydratedDTO <T>(rdo, depthLevel)).ToList());
        }
Beispiel #6
0
        public IEnumerable <T> Query <T>(Condition queryCondition = null, ObjectFieldsDepthLevel depthLevel = ObjectFieldsDepthLevel.FirstLevelOnly)
            where T : BaseDto, new()
        {
            IEnumerable <RDO> objectsRdos = GetRdos <T>(queryCondition);

            return(objectsRdos.Select(rdo => GetHydratedDTO <T>(rdo, depthLevel)));
        }
Beispiel #7
0
        private object GetChildObjectRecursively(BaseDto baseDto, RDO objectRdo, ObjectFieldsDepthLevel depthLevel, PropertyInfo property)
        {
            var relativityObjectFieldAttibutes = property.GetCustomAttribute <RelativityObjectFieldAttribute>();

            if (relativityObjectFieldAttibutes != null)
            {
                var fieldType = relativityObjectFieldAttibutes.FieldType;
                var fieldGuid = relativityObjectFieldAttibutes.FieldGuid;

                //multiple object
                if (fieldType == RdoFieldType.MultipleObject)
                {
                    Type objectType = property.PropertyType.GetEnumerableInnerType();

                    int[] childArtifactIds = objectRdo[fieldGuid]
                                             .GetValueAsMultipleObject <kCura.Relativity.Client.DTOs.Artifact>()
                                             .Select(artifact => artifact.ArtifactID)
                                             .ToArray();

                    var allObjects = this.InvokeGenericMethod(objectType, nameof(Get), childArtifactIds, depthLevel) as IEnumerable;

                    return(MakeGenericList(allObjects, objectType));
                }

                //single object
                if (fieldType == RdoFieldType.SingleObject)
                {
                    var childArtifact = objectRdo[fieldGuid].ValueAsSingleObject;
                    if (childArtifact == null)
                    {
                        return(null);
                    }

                    var objectType      = property.PropertyType;
                    var childArtifactId = childArtifact.ArtifactID;
                    return(childArtifactId == 0
                                                ? Activator.CreateInstance(objectType)
                                                : this.InvokeGenericMethod(objectType, nameof(Get), childArtifactId, depthLevel));
                }
            }

            //child object
            if (property.GetCustomAttribute <RelativityObjectChildrenListAttribute>() != null)
            {
                var childType = property.PropertyType.GetEnumerableInnerType();

                var allChildObjects = this.InvokeGenericMethod(childType, nameof(GetAllChildDTOs), baseDto.ArtifactId, depthLevel) as IEnumerable;

                return(MakeGenericList(allChildObjects, childType));
            }

            //file
            if (property.GetValue(baseDto, null) is RelativityFile relativityFile)
            {
                return(GetFile(relativityFile.ArtifactTypeId, baseDto.ArtifactId));
            }

            return(null);
        }
Beispiel #8
0
        internal IEnumerable <T> GetAllChildDTOs <T>(int parentArtifactID, ObjectFieldsDepthLevel depthLevel)
            where T : BaseDto, new()
        {
            var parentFieldGuid = typeof(T)
                                  .GetPropertyAttributeTuples <RelativityObjectFieldParentArtifactIdAttribute>()
                                  .First().Item2.FieldGuid;

            Condition queryCondition = new WholeNumberCondition(parentFieldGuid, NumericConditionEnum.EqualTo, parentArtifactID);

            return(Query <T>(queryCondition, depthLevel));
        }
Beispiel #9
0
        public T GetRelativityObject <T>(int artifactId, ObjectFieldsDepthLevel depthLevel)
            where T : BaseDto, new()
        {
            RDO objectRdo = GetRdo(artifactId);

            T theObject = objectRdo.ToHydratedDto <T>();

            if (depthLevel != ObjectFieldsDepthLevel.OnlyParentObject)
            {
                PopulateChildrenRecursively <T>(theObject, objectRdo, depthLevel);
            }

            return(theObject);
        }
Beispiel #10
0
        internal T GetDTO <T>(int artifactID, ObjectFieldsDepthLevel depthLevel)
            where T : BaseDto, new()
        {
            RDO objectRdo = GetRdo(artifactID);

            switch (depthLevel)
            {
            case ObjectFieldsDepthLevel.FirstLevelOnly:
                return(objectRdo.ToHydratedDto <T>());

            case ObjectFieldsDepthLevel.FullyRecursive:
                T dto = objectRdo.ToHydratedDto <T>();
                PopulateChildrenRecursively <T>(dto, objectRdo, depthLevel);
                return(dto);

            default:
                return(objectRdo.ToHydratedDto <T>());
            }
        }
Beispiel #11
0
        internal void PopulateChildrenRecursively <T>(BaseDto baseDto, RDO objectRdo, ObjectFieldsDepthLevel depthLevel)
        {
            foreach (var objectPropertyInfo in BaseDto.GetRelativityMultipleObjectPropertyInfos <T>())
            {
                var propertyInfo = objectPropertyInfo.Key;
                var theMultipleObjectAttribute = objectPropertyInfo.Value;

                Type childType = objectPropertyInfo.Value.ChildType;

                int[] childArtifactIds = objectRdo[objectPropertyInfo.Value.FieldGuid].GetValueAsMultipleObject <kCura.Relativity.Client.DTOs.Artifact>()
                                         .Select <kCura.Relativity.Client.DTOs.Artifact, int>(artifact => artifact.ArtifactID).ToArray();

                MethodInfo method = GetType().GetMethod("GetDTOs", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                var allObjects = method.Invoke(this, new object[] { childArtifactIds, depthLevel }) as IEnumerable;

                var   listType   = typeof(List <>).MakeGenericType(theMultipleObjectAttribute.ChildType);
                IList returnList = (IList)Activator.CreateInstance(listType);

                foreach (var item in allObjects)
                {
                    returnList.Add(item);
                }

                propertyInfo.SetValue(baseDto, returnList);
            }

            foreach (var ObjectPropertyInfo in BaseDto.GetRelativitySingleObjectPropertyInfos <T>())
            {
                var propertyInfo = ObjectPropertyInfo.Key;

                Type objectType   = ObjectPropertyInfo.Value.ChildType;
                var  singleObject = Activator.CreateInstance(objectType);

                int childArtifactId = objectRdo[ObjectPropertyInfo.Value.FieldGuid].ValueAsSingleObject.ArtifactID;

                MethodInfo method = GetType().GetMethod("GetDTO", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { objectType });

                if (childArtifactId != 0)
                {
                    singleObject = method.Invoke(this, new object[] { childArtifactId, depthLevel });
                }

                propertyInfo.SetValue(baseDto, singleObject);
            }

            foreach (var childPropertyInfo in BaseDto.GetRelativityObjectChildrenListInfos <T>())
            {
                var propertyInfo      = childPropertyInfo.Key;
                var theChildAttribute = childPropertyInfo.Value;

                Type       childType = childPropertyInfo.Value.ChildType;
                MethodInfo method    = GetType().GetMethod("GetAllChildDTOs", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                Guid parentFieldGuid = childType.GetRelativityObjectGuidForParentField();

                var allChildObjects = method.Invoke(this, new object[] { parentFieldGuid, baseDto.ArtifactId, depthLevel }) as IEnumerable;

                var   listType   = typeof(List <>).MakeGenericType(theChildAttribute.ChildType);
                IList returnList = (IList)Activator.CreateInstance(listType);

                foreach (var item in allChildObjects)
                {
                    returnList.Add(item);
                }

                propertyInfo.SetValue(baseDto, returnList);
            }

            foreach (var filePropertyInfo in baseDto.GetType().GetPublicProperties().Where(prop => prop.PropertyType == typeof(RelativityFile)))
            {
                var filePropertyValue = filePropertyInfo.GetValue(baseDto, null) as RelativityFile;

                if (filePropertyValue != null)
                {
                    filePropertyValue = GetFile(filePropertyValue.ArtifactTypeId, baseDto.ArtifactId);
                }

                filePropertyInfo.SetValue(baseDto, filePropertyValue);
            }
        }
Beispiel #12
0
        public List <T> GetAllChildDTOs <T>(Guid parentFieldGuid, int parentArtifactID, ObjectFieldsDepthLevel depthLevel)
            where T : BaseDto, new()
        {
            Condition  queryCondition = new WholeNumberCondition(parentFieldGuid, NumericConditionEnum.EqualTo, parentArtifactID);
            List <RDO> objectsRdos    = GetRdos <T>(queryCondition);

            switch (depthLevel)
            {
            case ObjectFieldsDepthLevel.FirstLevelOnly:
                return(objectsRdos.Select <RDO, T>(rdo => rdo.ToHydratedDto <T>()).ToList());

            case ObjectFieldsDepthLevel.FullyRecursive:
                var allChildDtos = new List <T>();
                foreach (var childRdo in objectsRdos)
                {
                    var childDto = childRdo.ToHydratedDto <T>();

                    PopulateChildrenRecursively <T>(childDto, childRdo, depthLevel);

                    allChildDtos.Add(childDto);
                }
                return(allChildDtos);

            default:
                return(objectsRdos.Select <RDO, T>(rdo => rdo.ToHydratedDto <T>()).ToList());
            }
        }
Beispiel #13
0
 internal void PopulateChildrenRecursively <T>(BaseDto baseDto, RDO objectRdo, ObjectFieldsDepthLevel depthLevel)
 {
     foreach (var objectPropertyInfo in baseDto.GetType().GetPublicProperties())
     {
         var childValue = GetChildObjectRecursively(baseDto, objectRdo, depthLevel, objectPropertyInfo);
         if (childValue != null)
         {
             objectPropertyInfo.SetValue(baseDto, childValue);
         }
     }
 }