Ejemplo n.º 1
0
        public static Guid GetObjectTypeGuid <T>()
            where T : BaseDto
        {
            RelativityObjectAttribute attribute = typeof(T).GetCustomAttribute <RelativityObjectAttribute>(false);

            return(attribute.ObjectTypeGuid);
        }
Ejemplo n.º 2
0
        public RDO ToRdo()
        {
            RelativityObjectAttribute objectTypeAttribute = this.GetType().GetCustomAttribute <RelativityObjectAttribute>(false);
            RDO rdo = new RDO(objectTypeAttribute.ObjectTypeGuid, ArtifactId);

            if (this.GetParentArtifactIdProperty()?.GetValue(this, null) is int parentId)
            {
                rdo.ParentArtifact = new Artifact(parentId);
            }

            foreach (PropertyInfo property in this.GetType().GetPublicProperties())
            {
                object propertyValue = property.GetValue(this);
                if (propertyValue == null)
                {
                    continue;
                }

                if (TryAddSimplePropertyValue(rdo, property, propertyValue))
                {
                    continue;
                }
            }

            return(rdo);
        }
Ejemplo n.º 3
0
        public static Guid GetRelativityObjectAttributeGuidValue(this Enum enumValue)
        {
            RelativityObjectAttribute attr = enumValue
                                             .GetType()
                                             .GetTypeInfo()
                                             .GetDeclaredField(enumValue.ToString())
                                             .GetCustomAttribute <RelativityObjectAttribute>();

            return(attr.ObjectTypeGuid);
        }
Ejemplo n.º 4
0
        public static RDO GetStubRDO <T>(int artifactId) where T : BaseDto
        {
            RelativityObjectAttribute objectTypeAttribute = typeof(T).GetCustomAttribute <RelativityObjectAttribute>(false);
            RDO stubRdo = new RDO(objectTypeAttribute.ObjectTypeGuid, artifactId);

            var fieldValues = BaseDto.GetFieldsGuids <T>().Select(x => new FieldValue(x, null));

            stubRdo.Fields.AddRange(fieldValues);

            return(stubRdo);
        }
Ejemplo n.º 5
0
        public RDO ToRdo()
        {
            RelativityObjectAttribute objectTypeAttribute = this.GetType().GetCustomAttribute <RelativityObjectAttribute>(false);
            RDO rdo = new RDO(objectTypeAttribute.ObjectTypeGuid, ArtifactId);

            var parentProperty = this.GetParentArtifactIdProperty();

            if (parentProperty != null)
            {
                var parentId = parentProperty.GetValue(this, null);
                if (parentId != null)
                {
                    rdo.ParentArtifact = new kCura.Relativity.Client.DTOs.Artifact((int)parentId);
                }
            }

            foreach (PropertyInfo property in this.GetType().GetPublicProperties())
            {
                object theFieldValue = null;

                RelativityObjectFieldAttribute fieldAttribute = property.GetCustomAttribute <RelativityObjectFieldAttribute>();

                if (fieldAttribute != null)
                {
                    object propertyValue = property.GetValue(this);
                    if (propertyValue != null && fieldAttribute.FieldType != (int)RdoFieldType.File)
                    {
                        switch (fieldAttribute.FieldType)
                        {
                        case (int)RdoFieldType.Currency:
                        case (int)RdoFieldType.Date:
                        case (int)RdoFieldType.Decimal:
                        case (int)RdoFieldType.Empty:
                        case (int)RdoFieldType.LongText:
                        case (int)RdoFieldType.WholeNumber:
                        case (int)RdoFieldType.YesNo:
                        case (int)RdoFieldType.User:
                            theFieldValue = propertyValue;
                            break;

                        case (int)RdoFieldType.FixedLengthText:
                            int stringLenght;
                            stringLenght = property.GetCustomAttribute <RelativityObjectFieldAttribute>().Length != null?
                                           property.GetCustomAttribute <RelativityObjectFieldAttribute>().Length.Value:
                                           3000;

                            string theString = propertyValue as string;
                            if (string.IsNullOrEmpty(theString) == false && theString.Length > stringLenght)
                            {
                                theString  = theString.Substring(0, (stringLenght - 3));
                                theString += "...";
                            }

                            theFieldValue = theString;
                            break;

                        case (int)RdoFieldType.MultipleChoice:
                            // We have IList<Enum> values here
                            var multiChoiceFieldValueList = new MultiChoiceFieldValueList();

                            IEnumerable enumEnumerable = propertyValue as IEnumerable;
                            Type        entryType      = enumEnumerable.AsQueryable().ElementType;

                            var enumValues = Enum.GetValues(entryType);
                            foreach (var enumValueObject in enumEnumerable)
                            {
                                var memberInfo = entryType.GetMember(enumValueObject.ToString());
                                var relativityObjectAttribute = memberInfo[0].GetCustomAttribute <RelativityObjectAttribute>();
                                multiChoiceFieldValueList.Add(new kCura.Relativity.Client.DTOs.Choice(relativityObjectAttribute.ObjectTypeGuid));
                            }

                            theFieldValue = multiChoiceFieldValueList;
                            break;

                        case (int)RdoFieldType.MultipleObject:
                            var listOfObjects = new FieldValueList <kCura.Relativity.Client.DTOs.Artifact>();

                            foreach (int artifactId in (IList <int>)propertyValue)
                            {
                                listOfObjects.Add(new kCura.Relativity.Client.DTOs.Artifact(artifactId));
                            }

                            theFieldValue = listOfObjects;
                            break;

                        case (int)RdoFieldType.SingleChoice:

                            bool isEnumDefined = Enum.IsDefined(propertyValue.GetType(), propertyValue);

                            if (isEnumDefined == true)
                            {
                                var choiceGuid = propertyValue.GetType().GetMember(propertyValue.ToString())[0].GetCustomAttribute <RelativityObjectAttribute>().ObjectTypeGuid;
                                theFieldValue = new kCura.Relativity.Client.DTOs.Choice(choiceGuid);
                            }
                            break;

                        case (int)RdoFieldType.SingleObject:
                            if ((int)propertyValue > 0)
                            {
                                theFieldValue = new kCura.Relativity.Client.DTOs.Artifact((int)propertyValue);
                            }
                            break;

                        case SharedConstants.FieldTypeCustomListInt:
                            theFieldValue = ((IList <int>)propertyValue).ToSeparatedString(SharedConstants.ListIntSeparatorChar);
                            break;

                        case SharedConstants.FieldTypeByteArray:
                            theFieldValue = Convert.ToBase64String((byte[])propertyValue);
                            break;
                        }

                        rdo.Fields.Add(new FieldValue(fieldAttribute.FieldGuid, theFieldValue));
                    }
                }
            }

            foreach (PropertyInfo property in this.GetType().GetPublicProperties())
            {
                object theFieldValue = null;
                RelativitySingleObjectAttribute   singleObjectAttribute   = property.GetCustomAttribute <RelativitySingleObjectAttribute>();
                RelativityMultipleObjectAttribute multipleObjectAttribute = property.GetCustomAttribute <RelativityMultipleObjectAttribute>();

                if (singleObjectAttribute != null)
                {
                    int fieldsWithSameGuid = rdo.Fields.Where(c => c.Guids.Contains(singleObjectAttribute.FieldGuid)).Count();

                    if (fieldsWithSameGuid == 0)
                    {
                        object propertyValue = property.GetValue(this);
                        if (propertyValue != null)
                        {
                            int artifactId = (int)propertyValue.GetType().GetProperty("ArtifactId").GetValue(propertyValue, null);
                            if (artifactId != 0)
                            {
                                theFieldValue = new kCura.Relativity.Client.DTOs.Artifact(artifactId);
                                rdo.Fields.Add(new FieldValue(singleObjectAttribute.FieldGuid, theFieldValue));
                            }
                            else
                            {
                                theFieldValue = null;
                                rdo.Fields.Add(new FieldValue(singleObjectAttribute.FieldGuid, theFieldValue));
                            }
                        }
                    }
                }

                if (multipleObjectAttribute != null)
                {
                    int fieldsWithSameGuid = rdo.Fields.Where(c => c.Guids.Contains(multipleObjectAttribute.FieldGuid)).Count();

                    if (fieldsWithSameGuid == 0)
                    {
                        object propertyValue = property.GetValue(this);
                        if (propertyValue != null)
                        {
                            var listOfObjects = new FieldValueList <kCura.Relativity.Client.DTOs.Artifact>();

                            foreach (var objectValue in propertyValue as IList)
                            {
                                int artifactId = (int)objectValue.GetType().GetProperty("ArtifactId").GetValue(objectValue, null);

                                listOfObjects.Add(new kCura.Relativity.Client.DTOs.Artifact(artifactId));
                            }

                            theFieldValue = listOfObjects;
                            rdo.Fields.Add(new FieldValue(multipleObjectAttribute.FieldGuid, theFieldValue));
                        }
                    }
                }
            }

            return(rdo);
        }