Esempio n. 1
0
        public bool NeedToOverwriteAttachments(Document document)
        {
            bool result          = false;
            int  attachmentCount = 0;

            if (!string.IsNullOrEmpty(document.AttachmentsFilesNames))
            {
                foreach (var fileName in document.AttachmentsFilesNames.Split(';'))
                {
                    string   attachmentFileFullPath = Path.Combine(appSettings.InputDirectoryPath, fileName.Trim());
                    FileInfo attachmentFileInfo     = new FileInfo(attachmentFileFullPath);
                    if (attachmentFileInfo.Exists)
                    {
                        attachmentCount++;
                        string newAttachmentFileName = Path.Combine(appSettings.OutputDirectoryPath,
                                                                    GetAttachDirName(document),
                                                                    $"Вложение{attachmentCount}{attachmentFileInfo.Extension}");
                        if (File.Exists(newAttachmentFileName))
                        {
                            result = true;
                            break;
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
 public string MakeNewScanFilePath(Document document)
 {
     return(document.ScanFileInfo != null?
            Path.Combine(appSettings.OutputDirectoryPath,
                         GetAttachDirName(document), document.ScanFileInfo.Name) :
                string.Empty);
 }
Esempio n. 3
0
 public string MakeNewTextPdfPath(Document document)
 {
     return(document.TextPdfFileInfo != null?
            Path.Combine(appSettings.OutputDirectoryPath,
                         GetTextDirName(document),
                         $"{document.Identifier}{document.TextPdfFileInfo.Extension}") :
                string.Empty);
 }
Esempio n. 4
0
 public string MakeNewMhtTextFilePath(Document document)
 {
     return(document.TextFileInfo != null
         ? Path.Combine(appSettings.OutputDirectoryPath,
                        GetTextDirName(document),
                        $"{document.Identifier}_7778.mht")
         : string.Empty);
 }
Esempio n. 5
0
        public bool TryToCopyAttachmentFiles(Document document, out string errorMessage)
        {
            errorMessage = string.Empty;

            if (!string.IsNullOrEmpty(document.AttachmentsFilesNames))
            {
                DirectoryInfo   documentAdditionalDirectoryInfo = CreateDirectoriesForAdditionalFiles(document);
                string[]        attachmentsFilesNames           = document.AttachmentsFilesNames.Split(';');
                List <FileInfo> attachmentFilesInfos            = new List <FileInfo>(attachmentsFilesNames.Length);
                List <FileInfo> copiedAttachments = new List <FileInfo>(attachmentsFilesNames.Length);
                int             attachmentCount   = 0;
                foreach (var fileName in attachmentsFilesNames)
                {
                    string   attachmentFileFullPath = Path.Combine(appSettings.InputDirectoryPath, fileName.Trim());
                    FileInfo attachmentFileInfo     = new FileInfo(attachmentFileFullPath);
                    if (attachmentFileInfo.Exists)
                    {
                        attachmentCount++;
                        attachmentFilesInfos.Add(attachmentFileInfo);
                        string newAttachmentFileName = Path.Combine(appSettings.OutputDirectoryPath,
                                                                    GetAttachDirName(document),
                                                                    $"Вложение{attachmentCount}{attachmentFileInfo.Extension}");
                        FileInfo newAttachmentFileInfo = new FileInfo(newAttachmentFileName);
                        if (newAttachmentFileInfo.Exists)
                        {
                            bool overwrite = FileExistOverwrite?.Invoke(newAttachmentFileInfo.FullName) ?? false;
                            if (overwrite)
                            {
                                newAttachmentFileInfo.Delete();
                                File.Copy(attachmentFileInfo.FullName, newAttachmentFileName);
                            }
                        }
                        else
                        {
                            File.Copy(attachmentFileInfo.FullName, newAttachmentFileName);
                        }

                        newAttachmentFileInfo.Refresh();
                        if (newAttachmentFileInfo.Exists)
                        {
                            copiedAttachments.Add(newAttachmentFileInfo);
                        }
                    }
                    else
                    {
                        errorMessage = $"Attachment file {attachmentFileFullPath} doesn't exsist. It can't be copied.";
                    }
                }
                document.AttachmentsFilesInfos       = attachmentFilesInfos.ToArray();
                document.CopiedAttachmentsFilesInfos = copiedAttachments.ToArray();
            }
            else
            {
                errorMessage = "Attachments files is null or empty. They can't be copied.";
            }
            return(false);
        }
Esempio n. 6
0
        public FileInfo GetTextFile(Document document)
        {
            if (string.IsNullOrEmpty(document.TextFileName))
            {
                throw new Exception($"{document.Identifier} haven't text file");
            }
            string textFilePath = Path.Combine(AppSettings.Instance.InputDirectoryPath, document.TextFileName);

            return(new FileInfo(textFilePath));
        }
Esempio n. 7
0
 public string GetTextDirName(Document document)
 {
     if (document is DocumentEdition)
     {
         DocumentEdition documentEdition = document as DocumentEdition;
         return(Path.Combine($"{documentEdition.MainEditionIdentifier}_editions",
                             $"{documentEdition.Identifier}_text"));
     }
     return($"{document.Identifier}_text");
 }
Esempio n. 8
0
        public IEnumerable <FileInfo> GetAttachmentFileInfos(Document document)
        {
            string[]        attachmentsFilesNames = document.AttachmentsFilesNames.Split(';');
            List <FileInfo> attachmentFilesInfos  = new List <FileInfo>(attachmentsFilesNames.Length);

            foreach (string fileName in attachmentsFilesNames)
            {
                string attachmentFileFullPath = Path.Combine(appSettings.InputDirectoryPath, fileName.Trim());
                yield return(new FileInfo(attachmentFileFullPath));
            }
        }
Esempio n. 9
0
        public bool TryToCopyTextFile(Document document, out string errorMessage)
        {
            errorMessage = string.Empty;
            DirectoryInfo documentTextDirectory = CreateDirectoriesForTextFiles(document);

            if (!string.IsNullOrEmpty(document.TextFileName))
            {
                if (document.TextFileInfo.Exists)
                {
                    string   newFilePath = MakeNewTextFilePath(document);
                    FileInfo newFileInfo = new FileInfo(newFilePath);
                    if (newFileInfo.Exists)
                    {
                        bool overwrite = FileExistOverwrite?.Invoke(newFileInfo.FullName) ?? false;
                        if (overwrite)
                        {
                            newFileInfo.Delete();
                            File.Copy(document.TextFileInfo.FullName, newFilePath);
                        }
                    }
                    else
                    {
                        File.Copy(document.TextFileInfo.FullName, newFilePath);
                    }

                    newFileInfo.Refresh();
                    if (newFileInfo.Exists)
                    {
                        document.CopiedTextFileInfo = newFileInfo;
                    }

                    if (document.TextFileInfo.Extension.Equals(".doc") ||
                        document.TextFileInfo.Extension.Equals(".docx") ||
                        document.TextFileInfo.Extension.Equals(".rtf"))
                    {
                        string   newMhtFilePath = MakeNewMhtTextFilePath(document);
                        FileInfo mhtFileInfo    = new FileInfo(newMhtFilePath);
                        ConvertDocToMht(document.TextFileInfo, mhtFileInfo);
                    }
                    return(true);
                }
                else
                {
                    errorMessage = $"Text file can't be copied. {document.TextFileInfo.Name} doesn't exist.";
                }
            }
            else
            {
                errorMessage = "Text file of document null or empty. It can't be copied.";
            }
            return(false);
        }
Esempio n. 10
0
        public bool TryToCopyScanFile(Document document, out string errorMessage)
        {
            errorMessage = string.Empty;
            DirectoryInfo documentAdditionalDirectory = CreateDirectoriesForAdditionalFiles(document);

            if (!string.IsNullOrEmpty(document.ScanFileName))
            {
                string scanFileFullPath = Path.Combine(appSettings.InputDirectoryPath, document.ScanFileName);
                document.ScanFileInfo = new FileInfo(scanFileFullPath);
                if (document.ScanFileInfo.Exists)
                {
                    string   newFilePath = MakeNewScanFilePath(document);
                    FileInfo newFileInfo = new FileInfo(newFilePath);
                    if (newFileInfo.Exists)
                    {
                        bool overwrite = FileExistOverwrite?.Invoke(newFileInfo.FullName) ?? false;
                        if (overwrite)
                        {
                            newFileInfo.Delete();
                            File.Copy(document.ScanFileInfo.FullName, newFilePath);
                        }
                    }
                    else
                    {
                        File.Copy(document.ScanFileInfo.FullName, newFilePath);
                    }

                    newFileInfo.Refresh();
                    if (newFileInfo.Exists)
                    {
                        document.CopiedScanFileInfo = newFileInfo;
                        return(true);
                    }
                }
                else
                {
                    errorMessage = $"Scan file can't be copied. {scanFileFullPath} doesn't exist.";
                }
            }
            else
            {
                errorMessage = $"Scan file of document null or empty. It can't be copied.";
            }

            return(false);
        }
Esempio n. 11
0
        public DirectoryInfo CreateDirectoriesForTextFiles(Document document)
        {
            string dirName = GetTextDirName(document);

            return(CreateDir(dirName));
        }
Esempio n. 12
0
        public DirectoryInfo CreateDirectoriesForAdditionalFiles(Document document)
        {
            string dirName = GetAttachDirName(document);

            return(CreateDir(dirName));
        }