/// <summary>
        /// Copies the files to target path.
        /// </summary>
        /// <param name="documentDetail">The document detail.</param>
        /// <param name="result">if set to <c>true</c> [result].</param>
        /// <param name="imageErrorBuilder">The image error builder.</param>
        /// <param name="pageCount">The page count.</param>
        /// <param name="imgFileNames">The img file names.</param>
        private static void CopyFilesToTargetPath(ExportDocumentDetail documentDetail, ref bool result, StringBuilder imageErrorBuilder, ref int pageCount, List <string> imgFileNames)
        {
            foreach (var file in documentDetail.ImageFiles)
            {
                try
                {
                    var updatedTargeFiletPath = string.Empty;
                    var fileName   = imgFileNames[pageCount] + Path.GetExtension(file.SourceFilePath);
                    var targetPath = Path.Combine(file.DestinationFolder, fileName);

                    var startIncrementIndex = 2;
                    //Check file exists or not, if we have an overlapping file the second record with the same name would get a (2) after the file name.
                    //Example: if sample.txt already exists then it will copy the second, third,... with name as sample (2).txt, sample (3).txt, ...
                    var isFileExists = IsFileExists(targetPath, out updatedTargeFiletPath, ref startIncrementIndex);
                    if (!isFileExists)
                    {
                        File.Copy(file.SourceFilePath, updatedTargeFiletPath);
                    }
                    file.DestinationFolder = updatedTargeFiletPath;
                }
                catch (Exception)
                {
                    result = false;
                    imageErrorBuilder.Append(Constants.ExportImageCopyErrorMessage);
                    imageErrorBuilder.Append(file.SourceFilePath);
                    imageErrorBuilder.Append(Constants.ExportBreakMessage);
                }
                pageCount++;
            }
        }
         /// <summary>
         /// Set Image source files
         /// </summary>
        public void SetImageSourceFiles(ExportDocumentDetail documentDetail, ExportOption exportOption)
        {
            if (!exportOption.IsImage && !exportOption.IsProduction) return;

            var imageCollectionId = exportOption.IsImage
                ? exportOption.ImageSetCollectionId
                : exportOption.ProductionSetCollectionId;

            var documentFiles = DocumentBO.GetImagesForExportLoadFile(documentDetail.DocumentId,
                exportOption.IsImage,
                exportOption.IsProduction,
                imageCollectionId, Convert.ToInt32(_exportLoadJobDetailBeo.MatterId));

            if ((documentDetail.ImageFiles!=null && documentDetail.ImageFiles.Any()) && documentFiles.Any())
            {
                var sourceFiles = documentFiles.OrderBy(p => p.Path).ToList();
                var pathIndex = 0;
                foreach (var image in documentDetail.ImageFiles)
                {
                    if (pathIndex > sourceFiles.Count) break;
                    image.SourceFilePath =  sourceFiles[pathIndex].Path;
                    image.DestinationFolder = string.Format("{0}{1}", documentDetail.ExportBasePath, image.DestinationFolder);
                    pathIndex++;
                }
            }
            else
            {
                var lstImgFiles = new List<ExportFileInformation>();
                if (documentFiles != null)
                {
                    lstImgFiles.AddRange(ConvertToExportFileInformation(documentFiles));
                }
                documentDetail.ImageFiles = lstImgFiles;
            }
        }
        /// <summary>
        /// Gets the name of the file.
        /// </summary>
        /// <param name="documentDetail">The document detail.</param>
        /// <param name="result">if set to <c>true</c> [result].</param>
        /// <param name="textErrorBuilder">The text error builder.</param>
        /// <param name="file">The file.</param>
        /// <param name="targetPath">The target path.</param>
        private static void GetFileName(ExportDocumentDetail documentDetail, ref bool result, StringBuilder textErrorBuilder, ExportFileInformation file, ref string targetPath)
        {
            var txtFileName = documentDetail.TextFileName;

            if (string.IsNullOrEmpty(txtFileName))
            {
                textErrorBuilder.Append(TextFileError);
                result = false;
            }
            else
            {
                txtFileName = Regex.Replace(txtFileName, Constants.FileSpecialCharactersRegex, string.Empty); //Remove the illegal character in the filename
                targetPath  = Path.Combine(file.DestinationFolder, txtFileName + TxtExtension);
            }
            var updatedTargeFiletPath = string.Empty;
            var startIncrementIndex   = 2;
            //Check file exists or not, if we have an overlapping file the second record with the same name would get a (2) after the file name.
            //Example: if sample.txt already exists then it will copy the second, third,... with name as sample (2).txt, sample (3).txt, ...
            var isFileExists = IsFileExists(targetPath, out updatedTargeFiletPath, ref startIncrementIndex);

            if (!isFileExists)
            {
                targetPath = updatedTargeFiletPath;
            }
        }
예제 #4
0
        /// <summary>
        /// Set volume folder for source file.
        /// </summary>
        private ExportDocumentDetail SetDestinationFolderByFileType(ExportDocumentDetail documentDetail)
        {
            GetVolumeName(documentDetail);

            CreateFolders(documentDetail);
            return(documentDetail);
        }
        /// <summary>
        /// Copy Image Files
        /// </summary>
        /// <param name="documentDetail">documentDetail</param>
        /// <param name="errorMessage">errorMessage</param>
        /// <returns></returns>
        private bool CopyImageFiles(ExportDocumentDetail documentDetail, out string errorMessage)
        {
            #region assertion
            documentDetail.ShouldNotBe(null);
            #endregion

            var result            = true;
            var imageErrorBuilder = new StringBuilder();
            try
            {
                var pageCount = 0;

                if (documentDetail.ImageFiles != null && documentDetail.ImageFiles.Count > 0)
                {
                    var imageFieldId = DocumentBO.GetFieldIdByNameForExportJob(_dataset, _fieldImageFileName, false);
                    var fieldValue   = DocumentBO.GetFieldValueForExportJob(Convert.ToInt64(_exportLoadJobDetailBeo.MatterId), _dataset.CollectionId, documentDetail.DocumentId, imageFieldId);

                    var imageFileName = (!string.IsNullOrEmpty(fieldValue)) ?fieldValue: string.Empty;

                    imageFileName = Regex.Replace(imageFileName, Constants.FileSpecialCharactersRegex, string.Empty); //Remove the illegal character in the filename
                    if (string.IsNullOrEmpty(imageFileName))
                    {
                        imageErrorBuilder.Append(Constants.ExportImageNoValueCopyErrorMessage);
                        errorMessage = imageErrorBuilder.ToString();
                        return(false);
                    }
                    Int64 noOfImageFiles = documentDetail.ImageFiles.Count;
                    var   imgFileNames   = new List <string>();
                    if (_lstBatesAndDpnFieldTypes.Contains(_imageNameFieldType) && imageFileName.Contains(','))//if  field value contains , then it means field is bates field
                    {
                        imgFileNames = GetFileNamesForCommaSeperatedFields(imageFileName, noOfImageFiles, imgFileNames);
                    }
                    else
                    {
                        bool status = GetFileNamesWithStatus(ref imgFileNames, noOfImageFiles, imageFileName, out errorMessage);
                        if (!status)
                        {
                            return(false);
                        }
                    }
                    CopyFilesToTargetPath(documentDetail, ref result, imageErrorBuilder, ref pageCount, imgFileNames);
                }
                else
                {
                    imageErrorBuilder.Append(Constants.ExportImageNoValueCopyErrorMessage);
                    errorMessage = imageErrorBuilder.ToString();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ex.AddUsrMsg("Export File Copy Worker: Unable to copy image files for job run id: {0}", PipelineId).Trace().Swallow();
                result = false;
            }
            errorMessage = imageErrorBuilder.ToString();
            return(result);
        }
        /// <summary>
        /// Construct Helper File (.OPT) row based on Helper file format for Image File
        /// </summary>
        private string ConstructImageHelperFileRow(ExportDocumentDetail docDetail, out bool isERROR)
        {
            isERROR = false;
            StringBuilder sbImageHelperFileData = new StringBuilder();
            int           fileCount             = 0;

            try
            {
                foreach (ExportFileInformation imageDocFiles in docDetail.ImageFiles)
                {
                    var imageFile    = imageDocFiles.DestinationFolder.Replace(exportFolderPath, "");
                    var volumeFolder = imageFile.Remove(0, 1).Split(new Char[] { '\\' }).FirstOrDefault();

                    sbImageHelperFileData.Append(Path.GetFileNameWithoutExtension(imageFile));  //ALIAS
                    sbImageHelperFileData.Append(Constants.CommaSeparator);
                    sbImageHelperFileData.Append(volumeFolder);                                 //Volume
                    sbImageHelperFileData.Append(Constants.CommaSeparator);
                    if (isRelativePath)
                    {
                        sbImageHelperFileData.Append(imageFile.Replace((exportFolderPath + "\\"), ""));     //PATH
                    }
                    else
                    {
                        var fullPath = exportFolderPath + imageFile;
                        sbImageHelperFileData.Append(fullPath);                                      //PATH
                    }
                    sbImageHelperFileData.Append(Constants.CommaSeparator);
                    if (fileCount == 0)
                    {
                        sbImageHelperFileData.Append(Constants.DocumentBreak);                 //DOC_BREAK
                    }
                    sbImageHelperFileData.Append(Constants.CommaSeparator);
                    //Not Applicable                                                          // FOLDER_BREAK
                    sbImageHelperFileData.Append(Constants.CommaSeparator);
                    //Not Applicable                                                           //BOX_BREAK
                    sbImageHelperFileData.Append(Constants.CommaSeparator);
                    if (fileCount == 0)
                    {
                        sbImageHelperFileData.Append(docDetail.ImageFiles.Count);             //PAGES
                    }
                    sbImageHelperFileData.AppendLine();
                    fileCount++;
                }
            }
            catch (Exception ex)
            {
                ex.AddDbgMsg("ExportOption Load File Writer Worker: Error occurred on construct image Helper File row for job run id:{0}",
                             PipelineId).Trace().Swallow();
                isERROR = true;
            }
            return(sbImageHelperFileData.ToString());
        }
        /// <summary>
        /// Construct Data for Load File(DAT/CSV/...) & Helper File (.opt)
        /// </summary>
        public void ConstructAllData(ExportDocumentDetail docDetail, out string loadFileDataRow, out string textHelperFileRow, out string imageHelperFileRow, out JobWorkerLog <ExportLoadFileWritterLogInfo> fileWriterLog)
        {
            fileWriterLog      = null;
            loadFileDataRow    = string.Empty;
            textHelperFileRow  = string.Empty;
            imageHelperFileRow = string.Empty;
            bool   isErrorInLoadFile  = false;
            bool   isErrorInTextFile  = false;
            bool   isErrorInImageFile = false;
            bool   sucess             = true;
            string errorMessage       = string.Empty;

            #region Load File
            var loadFileRow = ConstructLoadFileRow(docDetail, out isErrorInLoadFile);
            if (loadFileRow != string.Empty && loadFileRow.Length > 0)
            {
                loadFileDataRow = loadFileRow;
            }
            #endregion

            #region Text Helper File
            if (exportDocumentCollection.ExportOption.IsText && parametersExportLoadFile.ExportLoadFileInfo.ExportLoadFileOption.Nameselection == TextFileNameSelection.UseOPT)
            {
                if (docDetail.TextFiles != null && docDetail.TextFiles.Any())
                {
                    textHelperFileRow = ConstructTextHelperFileRow(docDetail, out isErrorInTextFile);
                }
            }
            #endregion

            #region Image Helper File
            if ((exportDocumentCollection.ExportOption.IsImage || exportDocumentCollection.ExportOption.IsProduction))
            {
                if (docDetail.ImageFiles != null && docDetail.ImageFiles.Any())
                {
                    imageHelperFileRow = ConstructImageHelperFileRow(docDetail, out isErrorInImageFile);
                }
            }
            #endregion

            #region Log
            if (isErrorInLoadFile)
            {
                sucess       = false;
                errorMessage = Constants.LoadFileWriteFailed;
            }
            fileWriterLog = ConstructLog(docDetail.CorrelationId, sucess, docDetail.DCN, isErrorInLoadFile, isErrorInTextFile, isErrorInImageFile, errorMessage);
            #endregion
        }
예제 #8
0
        /// <summary>
        /// Create folder in export path
        /// </summary>
        private void CreateFolders(ExportDocumentDetail documentDetail)
        {
            if (documentDetail.NativeFiles != null)
            {
                documentDetail.NativeFiles.ForEach(file => Directory.CreateDirectory(file.DestinationFolder));
            }

            if (documentDetail.TextFiles != null)
            {
                documentDetail.TextFiles.ForEach(file => Directory.CreateDirectory(file.DestinationFolder));
            }

            if (documentDetail.ImageFiles != null)
            {
                documentDetail.ImageFiles.ForEach(file => Directory.CreateDirectory(file.DestinationFolder));
            }
        }
예제 #9
0
        /// <summary>
        /// Gets the image file volume details.
        /// </summary>
        /// <param name="documentDetail">The document detail.</param>
        private void GetImageFileVolumeDetails(ExportDocumentDetail documentDetail)
        {
            long imageFileCount = 0;

            imageFileCount += documentDetail.ImageFiles.Count;
            var volumeFolderName = (!string.IsNullOrEmpty(_volume.VolumeFoldersName)) ? _volume.VolumeFoldersName : string.Empty;
            var volumeName       = volumeFolderName;

            if (_volume.VolumeFolders && _volume.IsIncreaseVolumeFolder)
            {
                var folderRunningIndex = _volume.IsMemorySize
                    ? GetVolumeFolderImageRunningIndexWithFileSize(
                    imageFileCount, documentDetail.ImageFiles).ToString(_volumeSubFolderFormat)
                    : GetVolumeImageFolderRunningIndexWithFileCount(imageFileCount).ToString(
                    _volumeSubFolderFormat);
                volumeName = volumeFolderName + folderRunningIndex;
            }
            SetDestinationFolder(documentDetail.ImageFiles, volumeName, _imageFolderName);
        }
        /// <summary>
        /// Copy document files(Native, Text & Image)
        /// </summary>
        private ExportDocumentDetail CopyFiles(ExportDocumentDetail documentDetail, out JobWorkerLog <ExportFileCopyLogInfo> fileCopyLog)
        {
            var sucess       = true;
            var message      = string.Empty;
            var errorBuilder = new StringBuilder();

            try
            {
                string messageInNativeFile;
                var    isErrorInNative = !(CopyNativeFiles(documentDetail, out messageInNativeFile));

                string messageInTextFile;
                var    isErrorInText = !(CopyTextFiles(documentDetail, out messageInTextFile));

                string messageInImageFile = string.Empty;
                bool   isErrorInImage     = false;

                if (_includeImages) //Copy the image file only when the include image option selected
                {
                    isErrorInImage = !(CopyImageFiles(documentDetail, out messageInImageFile));
                }

                if (isErrorInNative || isErrorInText || isErrorInImage)
                {
                    sucess = false;
                    errorBuilder.Append(Constants.ExportDCNMessage);
                    errorBuilder.Append(documentDetail.DCN);
                    errorBuilder.Append(Constants.ExportBreak);
                    errorBuilder.Append(messageInNativeFile);
                    errorBuilder.Append(messageInTextFile);
                    errorBuilder.Append(messageInImageFile);
                    message = errorBuilder.ToString();
                }

                fileCopyLog = ConstructLog(documentDetail.CorrelationId, sucess, documentDetail.DCN, isErrorInNative, isErrorInText, isErrorInImage, message);
            }
            catch (Exception ex)
            {
                ex.AddUsrMsg("Failed to copy document files for job run id:{0}", PipelineId).Trace().Swallow();
                fileCopyLog = ConstructLog(documentDetail.CorrelationId, false, documentDetail.DCN, true, true, true, Constants.ExportFileCopyErrorMessage);
            }
            return(documentDetail);
        }
        /// <summary>
        /// Construct Helper File (.OPT) row based on Helper file format for Content File
        /// </summary>
        private string ConstructTextHelperFileRow(ExportDocumentDetail docDetail, out bool isERROR)
        {
            isERROR = false;
            StringBuilder sbTextHelperFileData = new StringBuilder();

            try
            {
                string textFile = string.Empty;
                textFile = docDetail.TextFiles.FirstOrDefault().DestinationFolder.Replace(exportFolderPath, "");
                string volumeName = textFile.Remove(0, 1).Split(new Char[] { '\\' }).FirstOrDefault();

                sbTextHelperFileData.Append(Path.GetFileNameWithoutExtension(textFile));  //ALIAS
                sbTextHelperFileData.Append(Constants.CommaSeparator);
                sbTextHelperFileData.Append(volumeName);                                  //Volume
                sbTextHelperFileData.Append(Constants.CommaSeparator);
                if (isRelativePath)
                {
                    sbTextHelperFileData.Append(textFile.Replace((exportFolderPath + "\\"), ""));     //PATH
                }
                else
                {
                    var fullPath = exportFolderPath + textFile;
                    sbTextHelperFileData.Append(fullPath);                                    //PATH
                }
                sbTextHelperFileData.Append(Constants.CommaSeparator);
                sbTextHelperFileData.Append(Constants.DocumentBreak);                     //DOC_BREAK
                sbTextHelperFileData.Append(Constants.CommaSeparator);
                //Not Applicable                                                          // FOLDER_BREAK
                sbTextHelperFileData.Append(Constants.CommaSeparator);
                //Not Applicable                                                           //BOX_BREAK
                sbTextHelperFileData.Append(Constants.CommaSeparator);
                sbTextHelperFileData.Append("1");                                         //PAGES
                sbTextHelperFileData.AppendLine();
            }
            catch (Exception ex)
            {
                ex.AddDbgMsg("ExportOption Load File Writer Worker: Error occurred on construct text Helper File row for job run id:{0}",
                             PipelineId).Trace().Swallow();
                isERROR = true;
            }
            return(sbTextHelperFileData.ToString());
        }
예제 #12
0
        /// <summary>
        /// Set Image source files
        /// </summary>
        public void SetImageSourceFiles(ExportDocumentDetail documentDetail, ExportOption exportOption)
        {
            if (!exportOption.IsImage && !exportOption.IsProduction)
            {
                return;
            }

            var imageCollectionId = exportOption.IsImage
                ? exportOption.ImageSetCollectionId
                : exportOption.ProductionSetCollectionId;

            var documentFiles = DocumentBO.GetImagesForExportLoadFile(documentDetail.DocumentId,
                                                                      exportOption.IsImage,
                                                                      exportOption.IsProduction,
                                                                      imageCollectionId, Convert.ToInt32(_exportLoadJobDetailBeo.MatterId));

            if ((documentDetail.ImageFiles != null && documentDetail.ImageFiles.Any()) && documentFiles.Any())
            {
                var sourceFiles = documentFiles.OrderBy(p => p.Path).ToList();
                var pathIndex   = 0;
                foreach (var image in documentDetail.ImageFiles)
                {
                    if (pathIndex > sourceFiles.Count)
                    {
                        break;
                    }
                    image.SourceFilePath    = sourceFiles[pathIndex].Path;
                    image.DestinationFolder = string.Format("{0}{1}", documentDetail.ExportBasePath, image.DestinationFolder);
                    pathIndex++;
                }
            }
            else
            {
                var lstImgFiles = new List <ExportFileInformation>();
                if (documentFiles != null)
                {
                    lstImgFiles.AddRange(ConvertToExportFileInformation(documentFiles));
                }
                documentDetail.ImageFiles = lstImgFiles;
            }
        }
예제 #13
0
        /// <summary>
        /// Get the volume name
        /// </summary>
        /// <param name="documentDetail">The document details</param>
        /// <returns></returns>
        private void GetVolumeName(ExportDocumentDetail documentDetail)
        {
            if (_exportDocumentCollection.ExportOption.IsNative &&
                documentDetail.NativeFiles != null &&
                documentDetail.NativeFiles.Count > 0)
            {
                GetNativeFileVolumeDetails(documentDetail);
            }

            if ((_exportDocumentCollection.ExportOption.IsImage ||
                 _exportDocumentCollection.ExportOption.IsProduction) &&
                documentDetail.ImageFiles != null &&
                documentDetail.ImageFiles.Count > 0)
            {
                GetImageFileVolumeDetails(documentDetail);
            }

            if (_exportDocumentCollection.ExportOption.IsText &&
                documentDetail.TextFiles != null &&
                documentDetail.TextFiles.Count > 0)
            {
                GetTextFileVolumeDetails(documentDetail);
            }
        }
        /// <summary>
        ///  Get ContentFields
        /// </summary>
        private string GetContentFieldsValue(ExportDocumentDetail docDetail)
        {
            string fieldValue = string.Empty;

            try
            {
                if (exportFieldsSelection != null)
                {
                    var contentField = exportFieldsSelection.FirstOrDefault(f => f.DataSetFieldName.ToUpper() == "CONTENT");
                    if (contentField != null)
                    {
                        fieldValue = DocumentBO.GetDocumentContentFieldsForExportJob(Convert.ToInt64(_exportLoadJobDetailBeo.MatterId), _dataset.CollectionId, docDetail.DocumentId);
                        fieldValue = DocumentBO.Base64DecodeForExportJob(fieldValue);  //Decode the content field
                        fieldValue = fieldValue.Replace(Constants.ConcordanceRecordSplitter, contentNewLine.ToString()).Replace(Constants.ConcordanceFieldSplitter, contentNewLine.ToString()).Replace(Constants.ConcordanceRowSplitter, contentNewLine.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
            }

            return(fieldValue);
        }
        private bool CopyNativeFiles(ExportDocumentDetail documentDetail, out string messageInNativeFile)
        {
            bool   result = true;
            string updatedTargeFiletPath = null;
            var    nativeErrorBuilder    = new StringBuilder();

            try
            {
                if (documentDetail.NativeFiles != null && documentDetail.NativeFiles.Count > 0)
                {
                    foreach (var file in documentDetail.NativeFiles)
                    {
                        if (file.SourceFilePath == null)
                        {
                            continue;
                        }

                        var nativeFileName = documentDetail.NativeFileName;

                        if (string.IsNullOrEmpty(nativeFileName))
                        {
                            nativeErrorBuilder.Append(NativeFileError);
                            result = false;
                        }
                        else
                        {
                            nativeFileName = Regex.Replace(nativeFileName, Constants.FileSpecialCharactersRegex, string.Empty); //Remove the illegal character in the filename
                            nativeFileName = string.Concat(nativeFileName, Path.GetExtension(file.SourceFilePath));
                        }
                        if (!result)
                        {
                            continue;
                        }
                        var  targetPath = Path.Combine(file.DestinationFolder, nativeFileName);
                        bool retry;
                        do
                        {
                            try
                            {
                                updatedTargeFiletPath = string.Empty;
                                var startIncrementIndex = 2;
                                //Check file exists or not, if we have an overlapping file the second record with the same name would get a (2) after the file name.
                                //Example: if sample.txt already exists then it will copy the second, third,... with name as sample (2).txt, sample (3).txt, ...
                                var isFileExists = IsFileExists(targetPath, out updatedTargeFiletPath, ref startIncrementIndex);
                                if (!isFileExists)
                                {
                                    File.Copy(file.SourceFilePath, updatedTargeFiletPath);
                                }
                                retry = false;
                            }
                            catch (IOException ioEx)
                            {
                                var hResult = System.Runtime.InteropServices.Marshal.GetHRForException(ioEx);
                                if (hResult == ExceptionHr)  //Capture "File already exists" exception only
                                {
                                    var fileName = GetFileNameForDuplicates(Path.GetFileName(updatedTargeFiletPath), file.DestinationFolder);
                                    targetPath = Path.Combine(file.DestinationFolder, fileName);
                                    retry      = true;
                                }
                                else
                                {
                                    nativeErrorBuilder.Append(Constants.ExportNativeTextCopyErrorMessage);
                                    nativeErrorBuilder.Append(file.SourceFilePath);
                                    nativeErrorBuilder.Append(Constants.ExportBreakMessage);
                                    throw;
                                }
                            }
                        } while (retry);
                        file.DestinationFolder = updatedTargeFiletPath;
                    }
                }
                else if (_isIncludeNative && documentDetail.IsNativeTagExists)
                {
                    //If IncludeNative option and Inlucde Native for Taged document option is selected and this document belogs to that tag and it has no native file then we log it as error.
                    nativeErrorBuilder.Append(Constants.MsgMissingNativeFiles);
                    result = false;
                }
                else if (_isIncludeNative && !_isNativeTag)
                {
                    //If include native option selected and not selected the include native for tagged doc only option, then we have to check native exists for all the selected documents ot not.
                    nativeErrorBuilder.Append(NativeFileError);
                    result = false;
                }
            }
            catch (Exception ex)
            {
                ex.AddUsrMsg("Export File Copy Worker: Unable to copy native files for job run id: {0}", PipelineId).Trace().Swallow();
                result = false;
            }
            messageInNativeFile = nativeErrorBuilder.ToString();
            return(result);
        }
        private bool CopyTextFiles(ExportDocumentDetail documentDetail, out string errorMessage)
        {
            var result           = true;
            var textErrorBuilder = new StringBuilder();

            try
            {
                if (documentDetail.TextFiles != null && documentDetail.TextFiles.Count > 0)
                {
                    foreach (var file in documentDetail.TextFiles)
                    {
                        var targetPath = string.Empty;
                        GetFileName(documentDetail, ref result, textErrorBuilder, file, ref targetPath);
                        if (!result)
                        {
                            continue;
                        }
                        bool retry;
                        do
                        {
                            try
                            {
                                if (file.IsTextFieldExportEnabled)
                                {
                                    var contentFieldValue = string.Empty;
                                    var textFieldId       = DocumentBO.GetFieldIdByNameForExportJob(_dataset, _exportDocumentCollection.ExportOption.TextFieldToExport, false);
                                    var field             = _dataset.DatasetFieldList.FirstOrDefault(f => f.Name.ToLower().Equals(_exportDocumentCollection.ExportOption.TextFieldToExport.ToLower()));

                                    if (field != null && field.FieldType != null)
                                    {
                                        if (field.FieldType.DataTypeId == ContentFieldTypeID)
                                        {
                                            contentFieldValue =
                                                DocumentBO.GetDocumentContentFieldsForExportJob(Convert.ToInt64(_exportLoadJobDetailBeo.MatterId), _dataset.CollectionId, documentDetail.DocumentId);
                                            contentFieldValue = DocumentBO.Base64DecodeForExportJob(contentFieldValue);   //Decode the content field
                                        }
                                        else
                                        {
                                            contentFieldValue =
                                                DocumentBO.GetFieldValueForExportJob(Convert.ToInt64(_exportLoadJobDetailBeo.MatterId), _dataset.CollectionId, documentDetail.DocumentId, textFieldId);
                                        }
                                    }

                                    File.WriteAllText(targetPath, contentFieldValue, _encodingType);
                                }
                                else
                                {
                                    File.Copy(file.SourceFilePath, targetPath);
                                }
                                retry = false;
                            }
                            catch (IOException ioEx)
                            {
                                result = false;
                                var hResult = System.Runtime.InteropServices.Marshal.GetHRForException(ioEx);
                                if (hResult == ExceptionHr)  //Capture "File already exists" exception only and generate the new filename and retry to copy it again
                                {
                                    var fileName = GetFileNameForDuplicates(Path.GetFileName(targetPath), file.DestinationFolder);
                                    targetPath = Path.Combine(file.DestinationFolder, fileName);
                                    retry      = true;
                                }
                                else
                                {
                                    textErrorBuilder.Append(Constants.ExportNativeTextCopyErrorMessage);
                                    textErrorBuilder.Append(file.SourceFilePath);
                                    textErrorBuilder.Append(Constants.ExportBreakMessage);
                                    retry = false;
                                }
                            }
                            catch (Exception)
                            {
                                result = false;
                                textErrorBuilder.Append(Constants.ExportNativeTextCopyErrorMessage);
                                textErrorBuilder.Append(file.SourceFilePath);
                                textErrorBuilder.Append(Constants.ExportBreakMessage);
                                retry = false;
                            }
                        } while (retry);
                        file.DestinationFolder = targetPath;
                    }
                }
                else if (_isIncludeText)
                {
                    textErrorBuilder.Append(TextFileError);
                    result = false;
                }
            }
            catch (Exception ex)
            {
                ex.AddUsrMsg("Export File Copy Worker: Unable to copy text files for job run id: {0}", PipelineId).Trace().Swallow();
                result = false;
            }
            errorMessage = textErrorBuilder.ToString();
            return(result);
        }
        private ExportDocumentDetail ConstructDocumentData(ExportDocumentCollection exportDocumentCollection,
            string documentId, string correlationId, out JobWorkerLog<ExportMetadataLogInfo> metadataLog)
        {
            var exportDocument = new ExportDocumentDetail();
            try
            {
                exportDocument.DocumentId = documentId;
                exportDocument.CorrelationId = correlationId;
                bool isError;
                bool isErrorInTag = false;
              
                var document = DocumentBO.GetDocumentDataForExportJob(matterId, _dataset.CollectionId, documentId, out isError);
                if (document != null)
                {
                     exportDocument.DCN = document.DocumentControlNumber;

                    if (!String.IsNullOrEmpty(exportDocumentCollection.ExportOption.FieldForTextFileName))
                    {
                        var textFieldId = DocumentBO.GetFieldIdByNameForExportJob(_dataset,
                            exportDocumentCollection.ExportOption.FieldForTextFileName, false);
                        exportDocument.TextFileName = DocumentBO.GetFieldValueForExportJob(matterId,
                            _dataset.CollectionId, documentId, textFieldId);
                    }

                    if (!String.IsNullOrEmpty(exportDocumentCollection.ExportOption.FieldForNativeFileName))
                    {
                        var nativeFieldId = DocumentBO.GetFieldIdByNameForExportJob(_dataset,
                            exportDocumentCollection.ExportOption.FieldForNativeFileName, false);
                        exportDocument.NativeFileName = DocumentBO.GetFieldValueForExportJob(matterId,
                            _dataset.CollectionId, documentId, nativeFieldId);
                    }

                    #region "Recreate family group"
                    //2)Attachment Range
                    if (_beginsEnds != null)
                    {
                        Tuple<string, string> beginEnd;
                        _beginsEnds.TryGetValue(document.Id.ToString(), out beginEnd);
                        if (beginEnd != null)
                        {
                            exportDocument.BeginDoc = beginEnd.Item1;
                            exportDocument.EndDoc = beginEnd.Item2;
                        }
                    }
                    #endregion

                    //3) File Path (Native File & Text)
                    if (document.DocumentBinary.FileList != null)
                    {
                        if (exportDocumentCollection.ExportOption.IsNative)
                        {
                            //Get the tag name to check the tag exists for the document. If exists then export the native files.
                            string tagNameToIncludeNative = exportDocumentCollection.ExportOption.IncludeNativeTagName;
                            if (!string.IsNullOrEmpty(tagNameToIncludeNative)) //If "Include native for tagged document only" option is selected
                            {
                                //Check whether the document tagged with the selected tag. If yes, set the IsNativeTagExists property as true and get all native files to export out.
                                exportDocument.IsNativeTagExists = CheckTagExistsToIncludeNative(document.CollectionId, document.DocumentId, tagNameToIncludeNative);
                                if (exportDocument.IsNativeTagExists) //If document tagged then get the native files list to export.
                                    exportDocument.NativeFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.NativeFileTypeId).ToList());
                            }
                            else //If "Include native for tagged document only" option not selected, get native files to export out.
                            {
                                exportDocument.NativeFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.NativeFileTypeId).ToList());
                            }
                        }
                        if (exportDocumentCollection.ExportOption.IsText)
                        {
                            if (exportDocumentCollection.ExportOption.IsTextFieldToExportSelected && !string.IsNullOrEmpty(exportDocumentCollection.ExportOption.TextFieldToExport))
                            {
                                var fileList = new List<ExportFileInformation>
                                {
                                    new ExportFileInformation()
                                    {
                                        IsTextFieldExportEnabled = true
                                    }
                                };
                                exportDocument.TextFiles = fileList;
                            }
                            else
                            {
                                if (exportDocumentCollection.ExportOption.IsProduction && !string.IsNullOrEmpty(exportDocumentCollection.ExportOption.ProductionSetCollectionId))
                                {
                                    string[] lstOfProductionSets = exportDocumentCollection.ExportOption.ProductionSetCollectionId.Split(',');
                                    foreach (string productionSetId in lstOfProductionSets)
                                    {
                                        var productionDocumentData = GetDocumentData(documentId, productionSetId, out isError);
                                        if (exportDocumentCollection.ExportOption.TextOption1 == Constants.ScrubbedText) //If Text Prority 1 is Printed/Scrubbed text
                                        {
                                            //Get the scrubbed text files for one or more productions...
                                            if (exportDocument.TextFiles == null)
                                            {
                                                //Get the scrubbed text files for the first time....
                                                exportDocument.TextFiles = GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList());
                                            }
                                            else
                                            {
                                                //Appnd to existing text files in case user chooses more than one production 
                                                exportDocument.TextFiles.AddRange(GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList()));
                                            }
                                            if ((exportDocument.TextFiles == null || exportDocument.TextFiles.Count == 0 || !File.Exists(exportDocument.TextFiles.FirstOrDefault().SourceFilePath)) && exportDocumentCollection.ExportOption.TextOption2 == Constants.ExtractedText) //If scrubbed text not exists for this document then get the Extracted text
                                            {
                                                exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                                exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath);
                                            }
                                            else
                                                exportDocument.TextFiles.ForEach(s => s.IsScrubbedText = true);
                                        }
                                        else //Else If Text Prority 1 is Extracted text
                                        {
                                            //Get the extracted text files
                                            exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                            exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath); //Remove the querystring
                                            if ((exportDocument.TextFiles == null || exportDocument.TextFiles.Count == 0 || !File.Exists(exportDocument.TextFiles.FirstOrDefault().SourceFilePath)) && exportDocumentCollection.ExportOption.TextOption2 == Constants.ScrubbedText) //If extracted text not exists for this document then get the Scrubbed text if exists
                                            {
                                                exportDocument.TextFiles = GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList());
                                                exportDocument.TextFiles.ForEach(s => s.IsScrubbedText = true);
                                            }
                                        }
                                    }

                                }
                                else
                                {
                                    exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                    exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath); //Remove the querystring
                                }
                            }
                        }
                    }
                    //2.1) File Path (Images for Imageset or Production Set)
                    exportDocument.ImageFiles = new List<ExportFileInformation>();
                }
                //3) Tag
                if (exportDocumentCollection.ExportOption.IsTag && exportDocumentCollection.ExportOption.TagList != null && exportDocumentCollection.ExportOption.TagList.Count > 0)
                {
                    var tag = GetDocumentTags(documentId, out isErrorInTag);
                    if (tag != null && tag.Count > 0)
                    {
                        exportDocument.Tags = tag.Where(t => exportDocumentCollection.ExportOption.TagList.Contains(t.TagId.ToString(CultureInfo.InvariantCulture)) && t.Status).ToList();
                    }
                }

                #region Log
                metadataLog = ConstructLog(correlationId, (!isError), (!string.IsNullOrEmpty(exportDocument.DCN) ? exportDocument.DCN : string.Empty), isError, isErrorInTag, string.Empty);
                #endregion
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                metadataLog = ConstructLog(correlationId, false, string.Empty, true, true, "Error in get Metadata.");
            }
            return exportDocument;
        }
        /// <summary>
        /// Construct Load File (.dat/csv/...) row
        /// </summary>
        private string ConstructLoadFileRow(ExportDocumentDetail docDetail, out bool isERROR)
        {
            isERROR = false;
            StringBuilder sbLoadFileData = new StringBuilder();

            try
            {
                #region Fields
                if (exportFieldsSelection != null && exportFieldsSelection.Any())
                {
                    var fieldValue = GetFieldsValue(docDetail);
                    sbLoadFileData.Append(fieldValue);
                }
                #endregion

                #region "Recreate Family Group"
                if (docDetail.Fields != null && parametersExportLoadFile.RecreateFamilyGroup)
                {
                    switch (parametersExportLoadFile.AttachmentField)
                    {
                    case "Beg Attach and End attach":
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(docDetail.BeginDoc);
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(columnDelimiter);
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(docDetail.EndDoc);
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(columnDelimiter);
                        break;

                    default:
                        sbLoadFileData.Append(quoteCharacter);
                        if (!string.IsNullOrEmpty(docDetail.BeginDoc) && !string.IsNullOrEmpty(docDetail.EndDoc))
                        {
                            sbLoadFileData.Append(docDetail.BeginDoc + " - " + docDetail.EndDoc);
                        }
                        else
                        {
                            sbLoadFileData.Append(string.Empty);
                        }
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(columnDelimiter);
                        break;
                    }
                }

                #endregion

                #region Native File
                if (parametersExportLoadFile.ExportLoadFileInfo.ExportLoadFileOption.IncludeNativeFile)
                {
                    string nativeFilepath = string.Empty;
                    if (docDetail.NativeFiles != null && docDetail.NativeFiles.Any())
                    {
                        nativeFilepath = (!string.IsNullOrEmpty(docDetail.NativeFiles.FirstOrDefault().DestinationFolder) ? docDetail.NativeFiles.FirstOrDefault().DestinationFolder : string.Empty);
                        if (isRelativePath)
                        {
                            nativeFilepath = nativeFilepath.Replace(exportFolderPath, "");
                        }
                    }
                    sbLoadFileData.Append(quoteCharacter);
                    if (!string.IsNullOrEmpty(nativeFilepath) && !Path.HasExtension(nativeFilepath))
                    {
                        nativeFilepath = string.Empty;
                    }
                    sbLoadFileData.Append(nativeFilepath);
                    sbLoadFileData.Append(quoteCharacter);
                    sbLoadFileData.Append(columnDelimiter);
                }
                #endregion
                #region Text File
                if (parametersExportLoadFile.ExportLoadFileInfo.ExportLoadFileOption.IncludeTextFile && parametersExportLoadFile.ExportLoadFileInfo.ExportLoadFileOption.Nameselection == TextFileNameSelection.UseLoadFIle)
                {
                    string textFilePath = string.Empty;
                    if (docDetail.TextFiles != null && docDetail.TextFiles.Any())
                    {
                        textFilePath = (!string.IsNullOrEmpty(docDetail.TextFiles.FirstOrDefault().DestinationFolder) ? docDetail.TextFiles.FirstOrDefault().DestinationFolder : string.Empty);
                        if (isRelativePath)
                        {
                            textFilePath = textFilePath.Replace(exportFolderPath, "");
                        }
                    }
                    sbLoadFileData.Append(quoteCharacter);
                    sbLoadFileData.Append(textFilePath);
                    sbLoadFileData.Append(quoteCharacter);
                    sbLoadFileData.Append(columnDelimiter);
                }
                #endregion
                #region Tag
                if (exportDocumentCollection.ExportOption.IsTag)
                {
                    if (docDetail.Tags != null && docDetail.Tags.Any())
                    {
                        var tagInfo = String.Join(tagSeparator.ToString(), docDetail.Tags.Select(t => t.TagDisplayName).ToArray());
                        sbLoadFileData.Append(quoteCharacter);
                        //Tag also one of the field, if tag contains record spliter(/n), Need to replace as newline delimiter
                        tagInfo = tagInfo.Replace(Constants.ConcordanceFieldSplitter, contentNewLine.ToString());
                        sbLoadFileData.Append(tagInfo);
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(columnDelimiter);
                    }
                    else                                    //For No tag for a document - add empty columns
                    {
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(columnDelimiter);
                    }
                }
                #endregion

                sbLoadFileData.Remove(sbLoadFileData.ToString().Length - 1, 1);
                sbLoadFileData.Append(newLine);
            }
            catch (Exception ex)
            {
                ex.AddDbgMsg("ExportOption Load File Writer Worker: Error occurred on construct Load File (.DAT/.CSV....) row for job run id:{0}",
                             PipelineId).Trace().Swallow();
                isERROR = true;
            }
            return(sbLoadFileData.ToString());
        }
        /// <summary>
        ///  Get fields value to write in .DAT file
        /// </summary>
        private string GetFieldsValue(ExportDocumentDetail docDetail)
        {
            StringBuilder sbLoadFileData = new StringBuilder();

            if (exportFieldsSelection != null && docDetail != null && docDetail.Fields != null)
            {
                foreach (
                    var resultField in
                    exportFieldsSelection.Select(
                        selectedFields =>
                        docDetail.Fields.FirstOrDefault(o => o.FieldName == selectedFields.DataSetFieldName)))
                {
                    string fieldValue = string.Empty;
                    if (resultField != null && !string.IsNullOrEmpty(resultField.FieldValue) &&
                        resultField.FieldTypeId != Constants.ContentFieldType)
                    {
                        fieldValue = resultField.FieldValue;

                        #region Date Format

                        if (resultField.FieldTypeId == 61 &&
                            dateFormatForData != string.Empty)
                        {
                            fieldValue = DocumentBO.ConvertFieldsValueIntoDateFormatForExportJob(resultField,
                                                                                                 dateFormatForData);
                        }

                        #endregion
                    }
                    sbLoadFileData.Append(quoteCharacter);
                    if (!string.IsNullOrEmpty(fieldValue))
                    {
                        sbLoadFileData.Append(fieldValue);
                    }
                    sbLoadFileData.Append(quoteCharacter);
                    sbLoadFileData.Append(columnDelimiter);
                }
            }

            var contentField = exportFieldsSelection.FirstOrDefault(f => f.DataSetFieldName.ToUpper() == "CONTENT");
            if (contentField != null)
            {
                if (documentContentFieldsValueCollection != null && documentContentFieldsValueCollection.Any() &&
                    !string.IsNullOrEmpty(docDetail.DocumentId))
                {
                    if (documentContentFieldsValueCollection.ContainsKey(docDetail.DocumentId))
                    {
                        var fieldValue = documentContentFieldsValueCollection[docDetail.DocumentId];

                        sbLoadFileData.Append(quoteCharacter);
                        if (!string.IsNullOrEmpty(fieldValue))
                        {
                            sbLoadFileData.Append(fieldValue.Replace(Constants.ConcordanceFieldSplitter,
                                                                     contentNewLine.ToString()));
                        }
                        sbLoadFileData.Append(quoteCharacter);
                        sbLoadFileData.Append(columnDelimiter);
                    }
                }
            }

            return(sbLoadFileData.ToString());
        }
예제 #20
0
        private ExportDocumentDetail ConstructDocumentData(ExportDocumentCollection exportDocumentCollection,
                                                           string documentId, string correlationId, out JobWorkerLog <ExportMetadataLogInfo> metadataLog)
        {
            var exportDocument = new ExportDocumentDetail();

            try
            {
                exportDocument.DocumentId    = documentId;
                exportDocument.CorrelationId = correlationId;
                bool isError;
                bool isErrorInTag = false;

                var document = DocumentBO.GetDocumentDataForExportJob(matterId, _dataset.CollectionId, documentId, out isError);
                if (document != null)
                {
                    exportDocument.DCN = document.DocumentControlNumber;

                    if (!String.IsNullOrEmpty(exportDocumentCollection.ExportOption.FieldForTextFileName))
                    {
                        var textFieldId = DocumentBO.GetFieldIdByNameForExportJob(_dataset,
                                                                                  exportDocumentCollection.ExportOption.FieldForTextFileName, false);
                        exportDocument.TextFileName = DocumentBO.GetFieldValueForExportJob(matterId,
                                                                                           _dataset.CollectionId, documentId, textFieldId);
                    }

                    if (!String.IsNullOrEmpty(exportDocumentCollection.ExportOption.FieldForNativeFileName))
                    {
                        var nativeFieldId = DocumentBO.GetFieldIdByNameForExportJob(_dataset,
                                                                                    exportDocumentCollection.ExportOption.FieldForNativeFileName, false);
                        exportDocument.NativeFileName = DocumentBO.GetFieldValueForExportJob(matterId,
                                                                                             _dataset.CollectionId, documentId, nativeFieldId);
                    }

                    #region "Recreate family group"
                    //2)Attachment Range
                    if (_beginsEnds != null)
                    {
                        Tuple <string, string> beginEnd;
                        _beginsEnds.TryGetValue(document.Id.ToString(), out beginEnd);
                        if (beginEnd != null)
                        {
                            exportDocument.BeginDoc = beginEnd.Item1;
                            exportDocument.EndDoc   = beginEnd.Item2;
                        }
                    }
                    #endregion

                    //3) File Path (Native File & Text)
                    if (document.DocumentBinary.FileList != null)
                    {
                        if (exportDocumentCollection.ExportOption.IsNative)
                        {
                            //Get the tag name to check the tag exists for the document. If exists then export the native files.
                            string tagNameToIncludeNative = exportDocumentCollection.ExportOption.IncludeNativeTagName;
                            if (!string.IsNullOrEmpty(tagNameToIncludeNative)) //If "Include native for tagged document only" option is selected
                            {
                                //Check whether the document tagged with the selected tag. If yes, set the IsNativeTagExists property as true and get all native files to export out.
                                exportDocument.IsNativeTagExists = CheckTagExistsToIncludeNative(document.CollectionId, document.DocumentId, tagNameToIncludeNative);
                                if (exportDocument.IsNativeTagExists) //If document tagged then get the native files list to export.
                                {
                                    exportDocument.NativeFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.NativeFileTypeId).ToList());
                                }
                            }
                            else //If "Include native for tagged document only" option not selected, get native files to export out.
                            {
                                exportDocument.NativeFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.NativeFileTypeId).ToList());
                            }
                        }
                        if (exportDocumentCollection.ExportOption.IsText)
                        {
                            if (exportDocumentCollection.ExportOption.IsTextFieldToExportSelected && !string.IsNullOrEmpty(exportDocumentCollection.ExportOption.TextFieldToExport))
                            {
                                var fileList = new List <ExportFileInformation>
                                {
                                    new ExportFileInformation()
                                    {
                                        IsTextFieldExportEnabled = true
                                    }
                                };
                                exportDocument.TextFiles = fileList;
                            }
                            else
                            {
                                if (exportDocumentCollection.ExportOption.IsProduction && !string.IsNullOrEmpty(exportDocumentCollection.ExportOption.ProductionSetCollectionId))
                                {
                                    string[] lstOfProductionSets = exportDocumentCollection.ExportOption.ProductionSetCollectionId.Split(',');
                                    foreach (string productionSetId in lstOfProductionSets)
                                    {
                                        var productionDocumentData = GetDocumentData(documentId, productionSetId, out isError);
                                        if (exportDocumentCollection.ExportOption.TextOption1 == Constants.ScrubbedText) //If Text Prority 1 is Printed/Scrubbed text
                                        {
                                            //Get the scrubbed text files for one or more productions...
                                            if (exportDocument.TextFiles == null)
                                            {
                                                //Get the scrubbed text files for the first time....
                                                exportDocument.TextFiles = GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList());
                                            }
                                            else
                                            {
                                                //Appnd to existing text files in case user chooses more than one production
                                                exportDocument.TextFiles.AddRange(GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList()));
                                            }
                                            if ((exportDocument.TextFiles == null || exportDocument.TextFiles.Count == 0 || !File.Exists(exportDocument.TextFiles.FirstOrDefault().SourceFilePath)) && exportDocumentCollection.ExportOption.TextOption2 == Constants.ExtractedText) //If scrubbed text not exists for this document then get the Extracted text
                                            {
                                                exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                                exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath);
                                            }
                                            else
                                            {
                                                exportDocument.TextFiles.ForEach(s => s.IsScrubbedText = true);
                                            }
                                        }
                                        else //Else If Text Prority 1 is Extracted text
                                        {
                                            //Get the extracted text files
                                            exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                            exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath);               //Remove the querystring
                                            if ((exportDocument.TextFiles == null || exportDocument.TextFiles.Count == 0 || !File.Exists(exportDocument.TextFiles.FirstOrDefault().SourceFilePath)) && exportDocumentCollection.ExportOption.TextOption2 == Constants.ScrubbedText) //If extracted text not exists for this document then get the Scrubbed text if exists
                                            {
                                                exportDocument.TextFiles = GetFileList(productionDocumentData.DocumentBinary.FileList.Where(f => f.Type == Constants.ScrubbedFileTypeId).ToList());
                                                exportDocument.TextFiles.ForEach(s => s.IsScrubbedText = true);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    exportDocument.TextFiles = GetFileList(document.DocumentBinary.FileList.Where(f => f.Type == Constants.TextFileTypeId).ToList());
                                    exportDocument.TextFiles.SafeForEach(x => x.SourceFilePath = x.SourceFilePath.Contains(Constants.QuestionMark) ? x.SourceFilePath.Substring(0, x.SourceFilePath.LastIndexOf(Constants.QuestionMark)) : x.SourceFilePath); //Remove the querystring
                                }
                            }
                        }
                    }
                    //2.1) File Path (Images for Imageset or Production Set)
                    exportDocument.ImageFiles = new List <ExportFileInformation>();
                }
                //3) Tag
                if (exportDocumentCollection.ExportOption.IsTag && exportDocumentCollection.ExportOption.TagList != null && exportDocumentCollection.ExportOption.TagList.Count > 0)
                {
                    var tag = GetDocumentTags(documentId, out isErrorInTag);
                    if (tag != null && tag.Count > 0)
                    {
                        exportDocument.Tags = tag.Where(t => exportDocumentCollection.ExportOption.TagList.Contains(t.TagId.ToString(CultureInfo.InvariantCulture)) && t.Status).ToList();
                    }
                }

                #region Log
                metadataLog = ConstructLog(correlationId, (!isError), (!string.IsNullOrEmpty(exportDocument.DCN) ? exportDocument.DCN : string.Empty), isError, isErrorInTag, string.Empty);
                #endregion
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
                metadataLog = ConstructLog(correlationId, false, string.Empty, true, true, "Error in get Metadata.");
            }
            return(exportDocument);
        }