コード例 #1
0
        private void SetAbbyInFile(SalesEstimator model, AttachmentUnit unit, String fullAbbyInPath)
        {
            String fileName  = Path.GetFileNameWithoutExtension(unit.PhisicalName);
            String extension = Path.GetExtension(unit.PhisicalName);

            if (!String.IsNullOrWhiteSpace(fileName))
            {
                unit.AbbyFilePath = String.Format("{0}\\{1}{2}{3}", fullAbbyInPath, fileName, DateTime.UtcNow.Ticks, extension);

                File.Move(unit.PhisicalName, unit.AbbyFilePath);
            }
            else
            {
                model.AddError(String.Format("Incorect file name: {0}\n file:{1}", fileName, unit.PhisicalName));
            }
        }
コード例 #2
0
        private SalesEstimator EmailMessageItemProcessed(EmailMessageItem message, IEnumerable <LanguageMapping> fromEnglishMappings, IEnumerable <LanguageMapping> toEnglishMappings, IProgress <EstimatorBaseProgress> progress)
        {
            String  tempFolder = _settingsService.TempAttachmentFilePath;
            Boolean exists     = Directory.Exists(tempFolder);

            if (!exists)
            {
                Directory.CreateDirectory(tempFolder);
            }

            String tempPath = String.Format("{0}{1}\\", tempFolder, DateTime.UtcNow.Ticks);

            exists = Directory.Exists(tempPath);
            if (!exists)
            {
                Directory.CreateDirectory(tempPath);
            }
            SalesEstimator model = new SalesEstimator();
            String         body  = _emailExchangeService.GetEmailBody(message);

            ProgressLogTask(progress, String.Format("Parsing email {0}.", message.Subject));
            WaitTask();
            InputInformation inputInformation = _parsingService.ParseEmailBody(body, fromEnglishMappings, toEnglishMappings, model);
            String           status           = inputInformation.NonCorrectStatus;

            if (!String.IsNullOrWhiteSpace(status))
            {
                String error = String.Format("Incorrect parsing email with Body: '{0}' <br>Error: {1}", body, status);
                throw new ApplicationException(error);
            }

            IList <Attachment> attach = _emailExchangeService.GetEmailAttachments(message);

            _fileService.FileProcessed(attach, progress, tempPath);
            ProgressLogTask(progress, String.Format("Sorting attachments {0}.", message.Subject));

            IList <AttachmentUnit> units = _fileService.GetAttachmentUnits(tempPath);

            try
            {
                _zipService.UnzipProcessed(units, tempPath, progress);
            }
            catch (Exception exception)
            {
                model.AddError(exception.Message);
            }

            try
            {
                _imageService.AbbyProcessed(model, units, tempPath, progress);
            }
            catch (Exception exception)
            {
                model.AddError(exception.Message);
            }

            //convert all Xlsx and xls files to docx
            try
            {
                foreach (var unit in units.Where(u => u.CurrentType == FileType.Xlsx))
                {
                    ConvertExcelToText(unit, progress);
                }
            }
            catch (Exception ex)
            {
                model.AddError(ex.Message);
            }

            //convert all Pptx and Ppt files to docx
            try
            {
                foreach (var unit in units.Where(u => u.CurrentType == FileType.Pptx))
                {
                    ConvertPresentToText(unit, progress);
                }
            }
            catch (Exception ex)
            {
                model.AddError(ex.Message);
            }

            try
            {
                foreach (AttachmentUnit unit in units.Where(u => u.CurrentType == FileType.Docx))
                {
                    var statistic = GetStatistic(unit.PhisicalName, progress);

                    String fileName = Path.GetFileName(unit.PhisicalName);
                    model.WordCounterList.Add(new WordCounter
                    {
                        FileName              = fileName,
                        WordCount             = statistic.Words,
                        CharWithSpaceCount    = statistic.CharsWithSpaces,
                        CharWithoutSpaceCount = statistic.CharsWithoutSpaces,
                        FullFilePath          = unit.ZipFileName
                    });
                }
            }
            catch (Exception exception)
            {
                model.AddError(exception.Message);
            }
            foreach (AttachmentUnit unit in units.Where(u => u.CurrentType == FileType.None))
            {
                String fileName = Path.GetFileName(unit.PhisicalName);
                model.NotSupportedFileList.Add(new WordCounter
                {
                    FileName     = fileName,
                    WordCount    = 0,
                    FullFilePath = unit.ZipFileName
                });
            }

            Directory.Delete(tempPath, true);
            return(model);
        }