Ejemplo n.º 1
0
        public static void CopyToClientDir(string srcFileName, string destFileNameFormatString)
        {
            if (MultifileDocument.IsMergedDocument(srcFileName))
            {
                var headerFile = MultifileDocument.GetHeaderFileName(srcFileName);
                var destFile   = String.Format(destFileNameFormatString, Path.GetFileNameWithoutExtension(headerFile));
                DeleteIfExists(destFile);
                File.Move(headerFile, destFile);

                var bodyFile = MultifileDocument.GetBodyFileName(srcFileName);
                destFile = String.Format(destFileNameFormatString, Path.GetFileNameWithoutExtension(bodyFile));
                DeleteIfExists(destFile);
                File.Move(bodyFile, destFile);

                destFile = String.Format(destFileNameFormatString, Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(srcFileName)));
                DeleteIfExists(destFile);
                File.Move(srcFileName, destFile);
            }
            else
            {
                File.Move(srcFileName, String.Format(destFileNameFormatString, Path.GetFileNameWithoutExtension(srcFileName)));
            }
        }
        private IEnumerable <Document> ParseWaybills(List <DocumentReceiveLog> logs)
        {
            var metaForRedmineErrorIssueList = new List <MetadataOfLog>();
            var rejects = logs.Where(l => l.DocumentType == DocType.Reject).ToArray();

            foreach (var reject in rejects)
            {
                if (WaybillExcludeFile(reject))
                {
                    continue;
                }

                try {
                    SessionHelper.WithSession(s => ProcessReject(s, reject, metaForRedmineErrorIssueList));
                } catch (Exception e) {
                    _log.Error(string.Format("Не удалось разобрать отказ {0}", reject.FileName), e);
                    //создаем задачу на Redmine, прикрепляя файлы
                    Redmine.CreateIssueForLog(ref metaForRedmineErrorIssueList, reject);
                }
            }

            var docsForParsing = MultifileDocument.Merge(logs);
            var docs           = docsForParsing.Select(d => {
                try {
                    if (WaybillExcludeFile(d.DocumentLog))
                    {
                        return(null);
                    }

                    var docToReturn = ProcessWaybill(d.DocumentLog, d.FileName);
                    //если не получилось распарсить документ
                    if (docToReturn == null && d.DocumentLog?.DocumentType == DocType.Waybill)
                    {
                        //создаем задачу на Redmine, прикрепляя файлы
                        Redmine.CreateIssueForLog(ref metaForRedmineErrorIssueList, d.DocumentLog);
                    }
                    return(docToReturn);
                } catch (Exception e) {
                    var filename   = d.FileName;
                    var errorTitle = string.Format("Не удалось разобрать накладную {0}", filename);
                    _log.Error(errorTitle, e);
                    SaveWaybill(filename);

                    if (d.DocumentLog?.DocumentType == DocType.Waybill)
                    {
                        //создаем задачу на Redmine, прикрепляя файлы
                        Redmine.CreateIssueForLog(ref metaForRedmineErrorIssueList, d.DocumentLog);
                    }
                    return(null);
                }
            }).Where(d => d != null).ToList();

            MultifileDocument.DeleteMergedFiles(docsForParsing);

            docs.Each(d => {
                if (d.Log.IsFake)
                {
                    d.Log.Save();
                }
                d.Save();
                d.CreateCertificateTasks();
            });
            return(docs);
        }