Exemple #1
0
        protected List <RDO> GetRdos <T>(Condition queryCondition = null)
            where T : BaseDto
        {
            Query <RDO> query = new Query <RDO>()
            {
                ArtifactTypeGuid = BaseDto.GetObjectTypeGuid <T>(),
                Condition        = queryCondition
            };

            query.Fields = FieldValue.AllFields;

            QueryResultSet <RDO> results;

            using (IRSAPIClient proxyToWorkspace = CreateProxy())
            {
                try
                {
                    results = invokeWithRetryService.InvokeWithRetry(() => proxyToWorkspace.Repositories.RDO.Query(query));
                }
                catch (Exception ex)
                {
                    throw new ProxyOperationFailedException("Failed in method: " + System.Reflection.MethodInfo.GetCurrentMethod(), ex);
                }
            }

            if (results.Success == false)
            {
                throw new ArgumentException(results.Message);
            }

            return(results.Results.Select <Result <RDO>, RDO>(result => result.Artifact as RDO).ToList());
        }
Exemple #2
0
        public void UpdateField <T>(int rdoID, Guid fieldGuid, object value)
            where T : BaseDto
        {
            PropertyInfo fieldProperty = typeof(T).GetProperties()
                                         .SingleOrDefault(p => p.GetCustomAttribute <RelativityObjectFieldAttribute>()?.FieldGuid == fieldGuid);

            if (fieldProperty == null)
            {
                throw new InvalidOperationException($"Field not on type {typeof(T)}");
            }


            object rdoValue;

            if (!TryGetRelativityFieldValue <T>(fieldProperty, value, out rdoValue))
            {
                return;
            }

            if (rdoValue is RelativityFile rdoValueFile)
            {
                InsertUpdateFileField(rdoValueFile, rdoID);
                return;
            }

            RDO theRdo = new RDO(rdoID);

            theRdo.ArtifactTypeGuids.Add(BaseDto.GetObjectTypeGuid <T>());
            theRdo.Fields.Add(new FieldValue(fieldGuid, rdoValue));
            UpdateRdo(theRdo);
        }
Exemple #3
0
        protected IEnumerable <RDO> GetRdos <T>(Condition queryCondition = null)
            where T : BaseDto
        {
            Query <RDO> query = new Query <RDO>()
            {
                ArtifactTypeGuid = BaseDto.GetObjectTypeGuid <T>(),
                Condition        = queryCondition,
                Fields           = BaseDto.GetFieldsGuids <T>().Select(x => new FieldValue(x)).ToList()
            };

            return(rsapiProvider.Query(query).SelectMany(x => x.GetResultData()));
        }
Exemple #4
0
        public void UpdateField <T>(int rdoID, Guid fieldGuid, object value)
            where T : BaseDto, new()
        {
            RDO theRdo = new RDO(rdoID);

            theRdo.ArtifactTypeGuids.Add(BaseDto.GetObjectTypeGuid <T>());

            Type fieldType = typeof(T).GetProperties().Where(p => p.GetFieldGuidValueFromAttribute() == fieldGuid).FirstOrDefault().PropertyType;

            if (fieldType.IsGenericType)
            {
                if (fieldType.GetGenericTypeDefinition() == typeof(IList <>))
                {
                    if ((value as IList).HeuristicallyDetermineType().IsEnum)
                    {
                        MultiChoiceFieldValueList choices = new MultiChoiceFieldValueList();
                        List <Guid> choiceValues          = new List <Guid>();
                        foreach (var enumValue in (value as IList))
                        {
                            choices.Add(new kCura.Relativity.Client.DTOs.Choice(((Enum)enumValue).GetRelativityObjectAttributeGuidValue()));
                        }

                        theRdo.Fields.Add(new FieldValue(fieldGuid, choices));
                    }

                    if (value.GetType().GetGenericArguments() != null && value.GetType().GetGenericArguments().Length != 0)
                    {
                        if (value.GetType().GetGenericArguments()[0].IsSubclassOf(typeof(BaseDto)))
                        {
                            var listOfObjects = new FieldValueList <kCura.Relativity.Client.DTOs.Artifact>();

                            foreach (var objectValue in value as IList)
                            {
                                listOfObjects.Add(new kCura.Relativity.Client.DTOs.Artifact((int)objectValue.GetType().GetProperty("ArtifactId").GetValue(objectValue, null)));
                            }

                            theRdo.Fields.Add(new FieldValue(fieldGuid, listOfObjects));
                        }

                        if (value.GetType().GetGenericArguments()[0].IsEquivalentTo(typeof(int)))
                        {
                            var listOfObjects = new FieldValueList <kCura.Relativity.Client.DTOs.Artifact>();

                            foreach (var objectValue in value as IList)
                            {
                                listOfObjects.Add(new kCura.Relativity.Client.DTOs.Artifact((int)objectValue));
                            }

                            theRdo.Fields.Add(new FieldValue(fieldGuid, listOfObjects));
                        }
                    }
                }
                else if (value == null)
                {
                    theRdo.Fields.Add(new FieldValue(fieldGuid, value));
                }
                else if (value.GetType() == typeof(string) ||
                         value.GetType() == typeof(int) ||
                         value.GetType() == typeof(bool) ||
                         value.GetType() == typeof(decimal) ||
                         value.GetType() == typeof(DateTime))
                {
                    theRdo.Fields.Add(new FieldValue(fieldGuid, value));
                }

                UpdateRdo(theRdo);
            }
            else
            {
                RelativityObjectFieldAttribute fieldAttributeValue = typeof(T).GetProperties().Where(p => p.GetFieldGuidValueFromAttribute() == fieldGuid).FirstOrDefault().GetCustomAttribute <RelativityObjectFieldAttribute>();

                if (fieldAttributeValue != null)
                {
                    if (fieldAttributeValue.FieldType == (int)RdoFieldType.File)
                    {
                        if (value.GetType().BaseType != null)
                        {
                            if (value.GetType().BaseType.IsAssignableFrom(typeof(RelativityFile)))
                            {
                                InsertUpdateFileField(value as RelativityFile, rdoID);
                            }
                        }
                    }

                    if (fieldAttributeValue.FieldType == (int)RdoFieldType.User)
                    {
                        if (value.GetType() == typeof(User))
                        {
                            theRdo.Fields.Add(new FieldValue(fieldGuid, value));
                            UpdateRdo(theRdo);
                        }
                    }

                    if (value.GetType().IsEnum)
                    {
                        var choice = new kCura.Relativity.Client.DTOs.Choice(((Enum)value).GetRelativityObjectAttributeGuidValue());

                        theRdo.Fields.Add(new FieldValue(fieldGuid, choice));
                        UpdateRdo(theRdo);
                    }

                    if (value.GetType() == typeof(string) ||
                        value.GetType() == typeof(int) ||
                        value.GetType() == typeof(bool) ||
                        value.GetType() == typeof(decimal) ||
                        value.GetType() == typeof(DateTime))
                    {
                        theRdo.Fields.Add(new FieldValue(fieldGuid, value));
                        UpdateRdo(theRdo);
                    }
                }
            }
        }