Ejemplo n.º 1
0
        protected void InsertUpdateFileField(RelativityFile relativityFile, int parentId)
        {
            if (relativityFile?.FileValue == null)
            {
                return;
            }

            if (relativityFile.FileValue.Path != null)
            {
                rsapiProvider.UploadFile(relativityFile, parentId, relativityFile.FileValue.Path);
            }
            else if (!string.IsNullOrEmpty(relativityFile.FileMetadata.FileName))
            {
                string fileName = Path.GetTempPath() + relativityFile.FileMetadata.FileName;
                File.WriteAllBytes(fileName, relativityFile.FileValue.Data);

                try
                {
                    rsapiProvider.UploadFile(relativityFile, parentId, fileName);
                }
                finally
                {
                    invokeWithRetryService.InvokeVoidMethodWithRetry(() => File.Delete(fileName));
                }
            }
        }
Ejemplo n.º 2
0
        protected RelativityFile GetFile(int fileFieldArtifactId, int ourFileContainerInstanceArtifactId)
        {
            using (IRSAPIClient proxyToWorkspace = CreateProxy())
            {
                try
                {
                    var fileRequest = new FileRequest(proxyToWorkspace.APIOptions);
                    fileRequest.Target.FieldId          = fileFieldArtifactId;
                    fileRequest.Target.ObjectArtifactId = ourFileContainerInstanceArtifactId;

                    RelativityFile returnValue;
                    var            fileData = invokeWithRetryService.InvokeWithRetry(() => proxyToWorkspace.Download(fileRequest));

                    using (MemoryStream ms = (MemoryStream)fileData.Value)
                    {
                        FileValue    fileValue    = new FileValue(null, ms.ToArray());
                        FileMetadata fileMetadata = fileData.Key.Metadata;

                        returnValue = new RelativityFile(fileFieldArtifactId, fileValue, fileMetadata);
                    }

                    return(returnValue);
                }
                catch (Exception ex)
                {
                    throw new ProxyOperationFailedException("Failed in method: " + System.Reflection.MethodInfo.GetCurrentMethod(), ex);
                }
            }
        }
Ejemplo n.º 3
0
 protected void InsertUpdateFileFields(BaseDto objectToInsert, int parentId)
 {
     foreach (var propertyInfo in objectToInsert.GetType().GetProperties().Where(c => c.GetCustomAttribute <RelativityObjectFieldAttribute>()?.FieldType == RdoFieldType.File))
     {
         RelativityFile relativityFile = propertyInfo.GetValue(objectToInsert) as RelativityFile;
         InsertUpdateFileField(relativityFile, parentId);
     }
 }
Ejemplo n.º 4
0
        protected void InsertUpdateFileField(RelativityFile relativityFile, int parentId)
        {
            if (relativityFile != null)
            {
                if (relativityFile.FileValue != null)
                {
                    if (relativityFile.FileValue.Path != null)
                    {
                        using (IRSAPIClient proxyToWorkspace = CreateProxy())
                        {
                            var uploadRequest = new UploadRequest(proxyToWorkspace.APIOptions);
                            uploadRequest.Metadata.FileName       = relativityFile.FileValue.Path;
                            uploadRequest.Metadata.FileSize       = new FileInfo(uploadRequest.Metadata.FileName).Length;
                            uploadRequest.Overwrite               = true;
                            uploadRequest.Target.FieldId          = relativityFile.ArtifactTypeId;
                            uploadRequest.Target.ObjectArtifactId = parentId;

                            try
                            {
                                invokeWithRetryService.InvokeVoidMethodWithRetry(() => proxyToWorkspace.Upload(uploadRequest));
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                    else if (string.IsNullOrEmpty(relativityFile.FileMetadata.FileName) == false)
                    {
                        string tempPath = Path.GetTempPath();
                        string fileName = tempPath + relativityFile.FileMetadata.FileName;

                        using (IRSAPIClient proxyToWorkspace = CreateProxy())
                        {
                            System.IO.File.WriteAllBytes(fileName, relativityFile.FileValue.Data);

                            var uploadRequest = new UploadRequest(proxyToWorkspace.APIOptions);
                            uploadRequest.Metadata.FileName       = fileName;
                            uploadRequest.Metadata.FileSize       = new FileInfo(uploadRequest.Metadata.FileName).Length;
                            uploadRequest.Overwrite               = true;
                            uploadRequest.Target.FieldId          = relativityFile.ArtifactTypeId;
                            uploadRequest.Target.ObjectArtifactId = parentId;

                            try
                            {
                                invokeWithRetryService.InvokeVoidMethodWithRetry(() => proxyToWorkspace.Upload(uploadRequest));

                                invokeWithRetryService.InvokeVoidMethodWithRetry(() => System.IO.File.Delete(fileName));
                            }
                            catch (Exception)
                            {
                                invokeWithRetryService.InvokeVoidMethodWithRetry(() => System.IO.File.Delete(fileName));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public void UploadFile(RelativityFile relativityFile, int parentId, string fileName)
 {
     using (IRSAPIClient proxyToWorkspace = CreateProxy())
     {
         var uploadRequest = new UploadRequest(proxyToWorkspace.APIOptions)
         {
             Metadata =
             {
                 FileName = fileName,
                 FileSize = new FileInfo(fileName).Length
             },
             Overwrite = true,
             Target    =
             {
                 FieldId          = relativityFile.ArtifactTypeId,
                 ObjectArtifactId = parentId
             }
         };
         InvokeProxyWithRetry(proxyToWorkspace, proxy => proxy.Upload(uploadRequest));
     }
 }
Ejemplo n.º 6
0
        // TODO: Scope a US to replace the usage of kCura.Relativity.Client.FieldType with our own enum for only our usages
        public static T ToHydratedDto <T>(this RDO rdo)
            where T : BaseDto, new()
        {
            T returnDto = new T();

            returnDto.ArtifactId = rdo.ArtifactID;

            foreach (PropertyInfo property in typeof(T).GetPublicProperties())
            {
                RelativityObjectFieldAttribute fieldAttribute = property.GetCustomAttribute <RelativityObjectFieldAttribute>();
                object newValueObject = null;
                if (fieldAttribute != null)
                {
                    FieldValue theFieldValue = rdo[fieldAttribute.FieldGuid];

                    switch ((int)fieldAttribute.FieldType)
                    {
                    case (int)RdoFieldType.Currency:
                        newValueObject = theFieldValue.ValueAsCurrency;
                        break;

                    case (int)RdoFieldType.Date:
                        newValueObject = theFieldValue.ValueAsDate;
                        break;

                    case (int)RdoFieldType.Decimal:
                        newValueObject = theFieldValue.ValueAsDecimal;
                        break;

                    case (int)RdoFieldType.Empty:
                        newValueObject = null;
                        break;

                    case (int)RdoFieldType.File:
                        if (theFieldValue.Value != null)
                        {
                            RelativityFile fileData = new RelativityFile(theFieldValue.ArtifactID);
                            newValueObject = fileData;
                        }
                        break;

                    case (int)RdoFieldType.FixedLengthText:
                        newValueObject = theFieldValue.ValueAsFixedLengthText;
                        break;

                    case (int)RdoFieldType.LongText:
                        newValueObject = theFieldValue.ValueAsLongText;
                        break;

                    case (int)RdoFieldType.MultipleChoice:
                        // Means we have IList<some_enum> here, in fieldAttribute.ObjectDTOType
                        var valueAsMultipleChoice = theFieldValue.ValueAsMultipleChoice;
                        if (valueAsMultipleChoice != null)
                        {
                            var listOfEnumValuesDoNotUse = typeof(List <>).MakeGenericType(fieldAttribute.ObjectFieldDTOType);
                            var listOfEnumValuesInstance = (IList)Activator.CreateInstance(listOfEnumValuesDoNotUse);
                            foreach (var choice in valueAsMultipleChoice)
                            {
                                string       choiceNameTrimmed = choice.Name.Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", "");
                                System.Array enumValues        = System.Enum.GetValues(fieldAttribute.ObjectFieldDTOType);
                                for (int i = 0; i < enumValues.Length; i++)
                                {
                                    object theValueObject = enumValues.GetValue(i);
                                    if (theValueObject.ToString().Equals(choiceNameTrimmed, StringComparison.OrdinalIgnoreCase) == true)
                                    {
                                        listOfEnumValuesInstance.Add(theValueObject);
                                    }
                                }
                            }

                            // Now we have a List<object> and we need it to be List<fieldAttribute.ObjectFieldDTOType>
                            newValueObject = listOfEnumValuesInstance;
                        }
                        break;

                    case (int)RdoFieldType.MultipleObject:
                        newValueObject = theFieldValue.GetValueAsMultipleObject <kCura.Relativity.Client.DTOs.Artifact>()
                                         .Select <kCura.Relativity.Client.DTOs.Artifact, int>(artifact => artifact.ArtifactID).ToList();
                        break;

                    case (int)RdoFieldType.SingleChoice:
                        kCura.Relativity.Client.DTOs.Choice theChoice = theFieldValue.ValueAsSingleChoice;
                        if (theChoice != null)
                        {
                            string       choiceNameTrimmed = theChoice.Name.Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", "");
                            System.Array enumValues        = System.Enum.GetValues(fieldAttribute.ObjectFieldDTOType);
                            for (int i = 0; i < enumValues.Length; i++)
                            {
                                object theValueObject = enumValues.GetValue(i);
                                if (theValueObject.ToString().Equals(choiceNameTrimmed, StringComparison.OrdinalIgnoreCase) == true)
                                {
                                    newValueObject = theValueObject;
                                    break;
                                }
                            }
                        }
                        break;

                    case (int)RdoFieldType.SingleObject:
                        if (theFieldValue != null && theFieldValue.ValueAsSingleObject != null && theFieldValue.ValueAsSingleObject.ArtifactID > 0)
                        {
                            newValueObject = theFieldValue.ValueAsSingleObject.ArtifactID;
                        }
                        break;

                    case (int)RdoFieldType.User:
                        if (theFieldValue.Value != null)
                        {
                            if (property.PropertyType == typeof(User))
                            {
                                newValueObject = theFieldValue.Value as User;
                            }
                        }
                        break;

                    case (int)RdoFieldType.WholeNumber:
                        newValueObject = theFieldValue.ValueAsWholeNumber;
                        break;

                    case (int)RdoFieldType.YesNo:
                        newValueObject = theFieldValue.ValueAsYesNo;
                        break;

                    case SharedConstants.FieldTypeCustomListInt:
                        newValueObject = theFieldValue.ValueAsLongText.ToListInt(SharedConstants.ListIntSeparatorChar);
                        break;

                    case SharedConstants.FieldTypeByteArray:
                        if (theFieldValue.ValueAsLongText != null)
                        {
                            newValueObject = Convert.FromBase64String(theFieldValue.ValueAsLongText);
                        }
                        break;
                    }

                    property.SetValue(returnDto, newValueObject);
                }
            }

            return(returnDto);
        }
Ejemplo n.º 7
0
        protected void InsertUpdateFileField(BaseDto objectToInsert, int parentId)
        {
            foreach (var propertyInfo in objectToInsert.GetType().GetProperties().Where(c => c.GetCustomAttribute <RelativityObjectFieldAttribute>() != null))
            {
                RelativityObjectFieldAttribute attributeValue = propertyInfo.GetCustomAttribute <RelativityObjectFieldAttribute>();
                if (attributeValue.FieldType == (int)RdoFieldType.File)
                {
                    RelativityFile relativityFile = propertyInfo.GetValue(objectToInsert) as RelativityFile;
                    if (relativityFile != null)
                    {
                        if (relativityFile.FileValue != null)
                        {
                            if (relativityFile.FileValue.Path != null)
                            {
                                using (IRSAPIClient proxyToWorkspace = CreateProxy())
                                {
                                    var uploadRequest = new UploadRequest(proxyToWorkspace.APIOptions);
                                    uploadRequest.Metadata.FileName       = relativityFile.FileValue.Path;
                                    uploadRequest.Metadata.FileSize       = new FileInfo(uploadRequest.Metadata.FileName).Length;
                                    uploadRequest.Overwrite               = true;
                                    uploadRequest.Target.FieldId          = relativityFile.ArtifactTypeId;
                                    uploadRequest.Target.ObjectArtifactId = parentId;

                                    try
                                    {
                                        invokeWithRetryService.InvokeVoidMethodWithRetry(() => proxyToWorkspace.Upload(uploadRequest));
                                    }
                                    catch (Exception ex)
                                    {
                                        throw ex;
                                    }
                                }
                            }
                            else if (string.IsNullOrEmpty(relativityFile.FileMetadata.FileName) == false)
                            {
                                string tempPath = Path.GetTempPath();
                                string fileName = tempPath + relativityFile.FileMetadata.FileName;

                                using (IRSAPIClient proxyToWorkspace = CreateProxy())
                                {
                                    System.IO.File.WriteAllBytes(fileName, relativityFile.FileValue.Data);

                                    var uploadRequest = new UploadRequest(proxyToWorkspace.APIOptions);
                                    uploadRequest.Metadata.FileName       = fileName;
                                    uploadRequest.Metadata.FileSize       = new FileInfo(uploadRequest.Metadata.FileName).Length;
                                    uploadRequest.Overwrite               = true;
                                    uploadRequest.Target.FieldId          = relativityFile.ArtifactTypeId;
                                    uploadRequest.Target.ObjectArtifactId = parentId;

                                    try
                                    {
                                        invokeWithRetryService.InvokeVoidMethodWithRetry(() => proxyToWorkspace.Upload(uploadRequest));

                                        invokeWithRetryService.InvokeVoidMethodWithRetry(() => System.IO.File.Delete(fileName));
                                    }
                                    catch (Exception)
                                    {
                                        invokeWithRetryService.InvokeVoidMethodWithRetry(() => System.IO.File.Delete(fileName));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static T ToHydratedDto <T>(this RDO rdo)
            where T : BaseDto, new()
        {
            T returnDto = new T();

            returnDto.ArtifactId = rdo.ArtifactID;
            returnDto.GetParentArtifactIdProperty()?.SetValue(returnDto, rdo.ParentArtifact?.ArtifactID);

            foreach ((PropertyInfo property, RelativityObjectFieldAttribute fieldAttribute)
                     in typeof(T).GetPropertyAttributeTuples <RelativityObjectFieldAttribute>())
            {
                object     newValueObject = null;
                FieldValue theFieldValue  = rdo[fieldAttribute.FieldGuid];

                switch (fieldAttribute.FieldType)
                {
                case RdoFieldType.SingleObject:
                case RdoFieldType.MultipleObject:
                    break;

                case RdoFieldType.Currency:
                    newValueObject = theFieldValue.ValueAsCurrency;
                    break;

                case RdoFieldType.Date:
                    newValueObject = theFieldValue.ValueAsDate;
                    break;

                case RdoFieldType.Decimal:
                    newValueObject = theFieldValue.ValueAsDecimal;
                    break;

                case RdoFieldType.Empty:
                    newValueObject = null;
                    break;

                case RdoFieldType.File:
                    if (theFieldValue.Value != null)                             // value is file name string
                    {
                        newValueObject = new RelativityFile(theFieldValue.ArtifactID);
                    }
                    break;

                case RdoFieldType.FixedLengthText:
                    newValueObject = theFieldValue.ValueAsFixedLengthText;
                    break;

                case RdoFieldType.LongText:
                    newValueObject = theFieldValue.ValueAsLongText;
                    break;

                case RdoFieldType.User:
                    if (theFieldValue.Value is User user && property.PropertyType == typeof(User))
                    {
                        newValueObject = user;
                    }
                    break;

                case RdoFieldType.WholeNumber:
                    newValueObject = theFieldValue.ValueAsWholeNumber;
                    break;

                case RdoFieldType.YesNo:
                    newValueObject = theFieldValue.ValueAsYesNo;
                    break;
                }

                property.SetValue(returnDto, newValueObject);
            }

            return(returnDto);
        }