Exemple #1
0
        internal void DeleteChildObjects <T>(IList <T> parentObjectList, List <int> artifactIds) where T : BaseDto, new()
        {
            Dictionary <PropertyInfo, RelativityObjectChildrenListAttribute> childObjectsInfo = BaseDto.GetRelativityObjectChildrenListInfos <T>();

            if (childObjectsInfo.Count == 0)
            {
                DeleteRDOs(artifactIds);
            }
            else
            {
                foreach (var parentObject in parentObjectList)
                {
                    foreach (var childPropertyInfo in childObjectsInfo)
                    {
                        var propertyInfo      = childPropertyInfo.Key;
                        var theChildAttribute = childPropertyInfo.Value;

                        Type childType = childPropertyInfo.Value.ChildType;

                        var thisChildTypeObj = propertyInfo.GetValue(parentObject, null) as IList;

                        List <int> thisArtifactIDs = new List <int>();

                        foreach (var item in thisChildTypeObj)
                        {
                            thisArtifactIDs.Add((int)item.GetType().GetProperty("ArtifactId").GetValue(item, null));
                        }

                        if (thisArtifactIDs.Count != 0)
                        {
                            MethodInfo method = GetType().GetMethod("DeleteChildObjects", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                            method.Invoke(this, new object[] { thisChildTypeObj, thisArtifactIDs });
                        }
                    }
                }

                DeleteRDOs(artifactIds);
            }
        }
Exemple #2
0
        public void DeleteRelativityObjectRecusively <T>(int objectToDeleteId) where T : BaseDto, new()
        {
            T theObjectToDelete = GetRelativityObject <T>(objectToDeleteId, Base.ObjectFieldsDepthLevel.FullyRecursive);

            Dictionary <PropertyInfo, RelativityObjectChildrenListAttribute> childObjectsInfo = BaseDto.GetRelativityObjectChildrenListInfos <T>();

            if (childObjectsInfo.Count == 0)
            {
                DeleteRDO(theObjectToDelete.ArtifactId);
            }
            else
            {
                foreach (var childPropertyInfo in childObjectsInfo)
                {
                    PropertyInfo propertyInfo = childPropertyInfo.Key;
                    RelativityObjectChildrenListAttribute theChildAttribute = childPropertyInfo.Value;

                    Type childType = childPropertyInfo.Value.ChildType;

                    var thisChildTypeObj = propertyInfo.GetValue(theObjectToDelete, null) as IList;

                    List <int> thisArtifactIDs = new List <int>();

                    foreach (var item in thisChildTypeObj)
                    {
                        thisArtifactIDs.Add((int)item.GetType().GetProperty("ArtifactId").GetValue(item, null));
                    }

                    if (thisArtifactIDs.Count != 0)
                    {
                        MethodInfo method = GetType().GetMethod("DeleteChildObjects", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                        method.Invoke(this, new object[] { thisChildTypeObj, thisArtifactIDs });
                    }
                }

                DeleteRDO(theObjectToDelete.ArtifactId);
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        internal void UpdateChildListObjects <T>(IList <T> objectsToUpdated, int parentArtifactId)
            where T : BaseDto, new()
        {
            Dictionary <PropertyInfo, RelativityObjectChildrenListAttribute> childObjectsInfo = BaseDto.GetRelativityObjectChildrenListInfos <T>();

            if (childObjectsInfo.Count == 0)
            {
                var objectsToBeInserted = objectsToUpdated.Where(o => o.ArtifactId == 0).ToList();

                if (objectsToBeInserted.Count != 0)
                {
                    Type       type   = objectsToBeInserted[0].GetType();
                    MethodInfo method = GetType().GetMethod("InsertChildListObjects", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { type });
                    method.Invoke(this, new object[] { objectsToBeInserted, parentArtifactId });
                }

                bool isFilePropertyPresent = typeof(T).GetProperties().ToList().Where(c => c.DeclaringType.IsAssignableFrom(typeof(RelativityFile))).Count() > 0;
                if (isFilePropertyPresent)
                {
                    List <RDO> rdosToBeUpdated = new List <RDO>();
                    foreach (var objectToBeUpdated in objectsToUpdated.Where(o => o.ArtifactId != 0))
                    {
                        rdosToBeUpdated.Add(objectToBeUpdated.ToRdo());
                    }

                    if (rdosToBeUpdated.Count != 0)
                    {
                        UpdateRdos(rdosToBeUpdated.ToArray());
                    }
                }
                else
                {
                    foreach (var objectToBeUpdated in objectsToUpdated.Where(o => o.ArtifactId != 0))
                    {
                        UpdateRdo(objectToBeUpdated.ToRdo());
                        InsertUpdateFileField(objectToBeUpdated, objectToBeUpdated.ArtifactId);
                    }
                }
            }
            else
            {
                var objectsToBeInserted = objectsToUpdated.Where(o => o.ArtifactId == 0).ToList();

                if (objectsToBeInserted.Count != 0)
                {
                    Type       type   = objectsToBeInserted[0].GetType();
                    MethodInfo method = GetType().GetMethod("InsertChildListObjects", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { type });
                    method.Invoke(this, new object[] { objectsToBeInserted, parentArtifactId });
                }

                foreach (var objectToBeUpdated in objectsToUpdated.Where(o => o.ArtifactId != 0))
                {
                    UpdateRdo(objectToBeUpdated.ToRdo());
                    InsertUpdateFileField(objectToBeUpdated, objectToBeUpdated.ArtifactId);

                    foreach (var childPropertyInfo in childObjectsInfo)
                    {
                        var propertyInfo      = childPropertyInfo.Key;
                        var theChildAttribute = childPropertyInfo.Value;

                        Type childType = childPropertyInfo.Value.ChildType;

                        var childObjectsList = childPropertyInfo.Key.GetValue(objectToBeUpdated, null) as IList;

                        if (childObjectsList != null && childObjectsList.Count != 0)
                        {
                            MethodInfo method = GetType().GetMethod("UpdateChildListObjects", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                            method.Invoke(this, new object[] { childObjectsList, parentArtifactId });
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void UpdateRelativityObject <T>(BaseDto theObjectToUpdate)
            where T : BaseDto, new()
        {
            RDO rdo = theObjectToUpdate.ToRdo();

            UpdateRdo(rdo);
            InsertUpdateFileField(theObjectToUpdate, theObjectToUpdate.ArtifactId);

            Dictionary <PropertyInfo, RelativityObjectChildrenListAttribute> childObjectsInfo = BaseDto.GetRelativityObjectChildrenListInfos <T>();

            if (childObjectsInfo.Count != 0)
            {
                foreach (var childPropertyInfo in childObjectsInfo)
                {
                    var propertyInfo      = childPropertyInfo.Key;
                    var theChildAttribute = childPropertyInfo.Value;

                    Type childType = childPropertyInfo.Value.ChildType;

                    var childObjectsList = childPropertyInfo.Key.GetValue(theObjectToUpdate, null) as IList;

                    if (childObjectsList != null && childObjectsList.Count != 0)
                    {
                        MethodInfo method = GetType().GetMethod("UpdateChildListObjects", BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                        method.Invoke(this, new object[] { childObjectsList, theObjectToUpdate.ArtifactId });
                    }
                }
            }
        }
        public void InsertChildListObjects <T>(IList <T> objectsToInserted, int parentArtifactId)
            where T : BaseDto, new()
        {
            Dictionary <PropertyInfo, RelativityObjectChildrenListAttribute> childObjectsInfo = BaseDto.GetRelativityObjectChildrenListInfos <T>();

            if (childObjectsInfo.Count == 0)
            {
                bool isFilePropertyPresent = typeof(T).GetProperties().ToList().Where(c => c.DeclaringType.IsAssignableFrom(typeof(RelativityFile))).Count() > 0;
                if (isFilePropertyPresent == false)
                {
                    List <RDO> rdosToBeInserted = new List <RDO>();

                    foreach (var objectToBeInserted in objectsToInserted)
                    {
                        PropertyInfo parentArtifactIdProperty = objectToBeInserted.GetParentArtifactIdProperty();
                        PropertyInfo ArtifactIdProperty       = objectToBeInserted.GetType().GetProperty("ArtifactId");

                        if (parentArtifactIdProperty != null)
                        {
                            parentArtifactIdProperty.SetValue(objectToBeInserted, parentArtifactId);
                            ArtifactIdProperty.SetValue(objectToBeInserted, 0);
                        }

                        rdosToBeInserted.Add(objectToBeInserted.ToRdo());
                    }

                    InsertRdos(rdosToBeInserted.ToArray());
                }
                else
                {
                    foreach (var objectToBeInserted in objectsToInserted)
                    {
                        PropertyInfo parentArtifactIdProperty = objectToBeInserted.GetParentArtifactIdProperty();
                        PropertyInfo ArtifactIdProperty       = objectToBeInserted.GetType().GetProperty("ArtifactId");

                        if (parentArtifactIdProperty != null)
                        {
                            parentArtifactIdProperty.SetValue(objectToBeInserted, parentArtifactId);
                            ArtifactIdProperty.SetValue(objectToBeInserted, 0);
                        }

                        int insertedRdoArtifactID = InsertRdo(objectToBeInserted.ToRdo());
                        InsertUpdateFileField(objectToBeInserted, insertedRdoArtifactID);
                    }
                }
            }
            else
            {
                foreach (var objectToBeInserted in objectsToInserted)
                {
                    PropertyInfo parentArtifactIdProperty = objectToBeInserted.GetParentArtifactIdProperty();
                    PropertyInfo ArtifactIdProperty       = objectToBeInserted.GetType().GetProperty("ArtifactId");

                    if (parentArtifactIdProperty != null)
                    {
                        parentArtifactIdProperty.SetValue(objectToBeInserted, parentArtifactId);
                        ArtifactIdProperty.SetValue(objectToBeInserted, 0);
                    }

                    int insertedRdoArtifactID = InsertRdo(objectToBeInserted.ToRdo());
                    InsertUpdateFileField(objectToBeInserted, insertedRdoArtifactID);

                    foreach (var childPropertyInfo in childObjectsInfo)
                    {
                        var propertyInfo      = childPropertyInfo.Key;
                        var theChildAttribute = childPropertyInfo.Value;

                        Type childType = childPropertyInfo.Value.ChildType;

                        var childObjectsList = childPropertyInfo.Key.GetValue(objectToBeInserted, null) as IList;

                        if (childObjectsList != null && childObjectsList.Count != 0)
                        {
                            MethodInfo method = GetType().GetMethod("InsertChildListObjects", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).MakeGenericMethod(new Type[] { childType });

                            method.Invoke(this, new object[] { childObjectsList, insertedRdoArtifactID });
                        }
                    }
                }
            }
        }