Exemple #1
0
        private void processSingleMsgFile(string inFile, string outFile)
        {
            FileInfo nwFileInfo = new FileInfo(outFile);

            if (!nwFileInfo.Exists)
            {
                Directory.CreateDirectory(nwFileInfo.Directory.FullName);
            }

            string outFileTxt = outFile + ".txt",
                   outFilePdf = outFile + ".pdf";

            Output.AddJournalEntry($"Original: {inFile}. New: {outFile}");
            var parser = new OutlookMsgParser(inFile);

            if (parser.Parse())
            {
                IParsedContent parsedContent = parser.ParsedContent.Single <IParsedContent>();
                string         result        = parsedContent.ContentAsString;
                File.WriteAllText(outFileTxt, result);
                Converter.ConvertFromCom(outFileTxt, outFilePdf);

                if (!KeepIntermediateFiles)
                {
                    File.Delete(outFileTxt);
                }

                //extractAndConvertAttachements(inFile, outFile);
            }
            else
            {
                Output.AddLogEntry($"Failed to parse file {inFile}", true);
            }
        }
        private async Task processOfficeFiles(string rootPath, string outputPath, string[] filePatterns)
        {
            // TODO: refactor so all background work is done in one thread instead of multiple async methods-->
            await Task.Run(async() =>
            {
                FileAttributes attr = File.GetAttributes(rootPath);

                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (!outputPath.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                    {
                        outputPath += System.IO.Path.DirectorySeparatorChar;
                    }

                    List <string> matchingFiles = FileWalker.WalkDir(rootPath, filePatterns, true);

                    foreach (var filename in matchingFiles)
                    {
                        Output.AddJournalEntry($"Found matching file: {filename}");

                        string nwFilename = filename.Replace(rootPath, outputPath) + ".pdf";
                        processSingleOfficeFile(filename, nwFilename);
                    }
                }
                else
                {
                    Output.AddJournalEntry($"Processing single file: {rootPath}");
                    string nwFilename = rootPath.Replace(rootPath, outputPath) + ".pdf";
                    processSingleOfficeFile(rootPath, nwFilename);
                }
            });
        }
Exemple #3
0
        public override async Task ProcessInBackgroundAsync(ConvertConfig config)
        {
            if (!Directory.Exists(config.OutputDir))
            {
                Directory.CreateDirectory(config.OutputDir);
            }

            Output.AddJournalEntry("Converting Image files.");
            await processImageFiles(config.RootDir, config.OutputDir);
        }
Exemple #4
0
        public override async Task ProcessInBackgroundAsync(ConvertConfig config)
        {
            KeepIntermediateFiles = config.KeepIntermediateFiles;

            if (!Directory.Exists(config.OutputDir))
            {
                Directory.CreateDirectory(config.OutputDir);
            }

            Output.AddJournalEntry("Converting Outlook message files.");
            await processMsgFiles(config.RootDir, config.OutputDir);
        }
        private void processSingleOfficeFile(string filename, string nwFilename)
        {
            Output.AddJournalEntry($"Converting {filename} to {nwFilename}");

            FileInfo nwFileInfo = new FileInfo(nwFilename);

            if (!nwFileInfo.Exists)
            {
                Directory.CreateDirectory(nwFileInfo.Directory.FullName);
            }


            try
            {
                // no parsing needed, convert directly -->
                Converter.ConvertFromCom(filename, nwFilename);
            }
            catch (Exception ex)
            {
                Output.AddJournalAndLog($"Conversion failed for file {filename}", $"ERROR: {filename}: {ex.Message}", true);
            }
        }