Beispiel #1
0
        public void WaitFileTest()
        {
            var docRoot      = Path.Combine(Settings.Default.DocumentPath, "12345");
            var waybillsPath = Path.Combine(docRoot, "Waybills");

            Directory.CreateDirectory(waybillsPath);
            var filename = Path.Combine(waybillsPath, "14356_4.dbf");

            File.Copy(@"..\..\Data\Waybills\14356_4.dbf", filename);
            bool exist = false;

            try {
                ShareFileHelper.WaitFile(filename);
                exist = true;
            }
            catch {
            }
            Assert.That(exist, Is.True);
            File.Delete(filename);
            try {
                ShareFileHelper.WaitFile(filename);
            }
            catch (Exception e) {
                Assert.That(e is WaitFileException, Is.True);
                Assert.That(e.Message, Is.EqualTo(String.Format("Файл {0} не появился в папке после 1000 мс ожидания.", filename)));
            }
            Thread thread = new Thread(() => {
                Thread.Sleep(2500);
                File.Copy(@"..\..\Data\Waybills\14356_4.dbf", filename);
            });

            try {
                exist = false;
                thread.Start();
                ShareFileHelper.WaitFile(filename, 5000);
                exist = true;
            }
            catch {
            }
            Assert.That(exist, Is.True);
        }
        private static Document ProcessWaybill(DocumentReceiveLog log, string filename)
        {
            if (log.DocumentType == DocType.Reject)
            {
                return(null);
            }

            var settings = WaybillSettings.Find(log.ClientCode.Value);

            if (log.DocumentSize == 0)
            {
                return(null);
            }

            // ждем пока файл появится в удаленной директории
            if (!log.FileIsLocal())
            {
                ShareFileHelper.WaitFile(filename, 5000);
            }

            var doc = SessionHelper.WithSession(s => {
                var detector = new WaybillFormatDetector();
                var result   = detector.Parse(s, filename, log);
                WaybillFormatDetector.Process(s, result);
                return(result);
            });

            // для мульти файла, мы сохраняем в источнике все файлы,
            // а здесь, если нужна накладная в dbf формате, то сохраняем merge-файл в dbf формате.
            if (doc != null)
            {
                Exporter.ConvertIfNeeded(doc, settings);
            }

            return(doc);
        }