Esempio n. 1
0
 public void ReadSourceCatalog(CertificateSourceCatalog catalog, DataRow row)
 {
     catalog.SupplierCode   = row["matcode"].ToString();
     catalog.SerialNumber   = row["seria"].ToString();
     catalog.OriginFilePath = row["risfile"].ToString();
     catalog.Note           = row["tipdoc"].ToString();
 }
        public void Download_source()
        {
            var testProduct = new TestProduct("Тестовый продукт");

            session.Save(testProduct);
            var product = Product.Find(testProduct.Id);

            var source = new KatrenSource();

            var certificateSource = new CertificateSource();

            certificateSource.SourceClassName = source.GetType().Name;
            session.Save(certificateSource);

            var line = new DocumentLine {
                ProductEntity = product,
                SerialNumber  = "012011",
            };

            var sourceCatalog = new CertificateSourceCatalog {
                CertificateSource    = certificateSource,
                SerialNumber         = line.SerialNumber,
                CatalogProduct       = product.CatalogProduct,
                SupplierCode         = "34266440",
                SupplierProducerCode = "13483667",
                OriginFilePath       = KatrenSource.ToOriginFileName(0x1B9EFC8),
            };

            session.Save(sourceCatalog);

            var task  = new CertificateTask(certificateSource, line);
            var files = source.GetCertificateFiles(task, null);

            Assert.That(files.Count, Is.EqualTo(4));
        }
Esempio n. 3
0
        public void CertificateExists()
        {
            var rostaSource = new RostaCertificateSource();

            var product = Product.FindFirst();

            var line = new DocumentLine {
                Code          = "22651",
                SerialNumber  = "835495",
                ProductEntity = product
            };

            Assert.That(rostaSource.CertificateExists(line), Is.False);
            var catalog = new CertificateSourceCatalog {
                CertificateSource = _source,
                SerialNumber      = line.SerialNumber,
                //Код в накладной и в каталоге может не совпадать, сравниваем по CatalogId
                SupplierCode   = "C!" + line.Code,
                CatalogProduct = product.CatalogProduct,
                OriginFilePath = Path.GetRandomFileName()
            };

            catalog.Save();
            Assert.That(rostaSource.CertificateExists(line), Is.True);
        }
Esempio n. 4
0
        public void ReadSourceCatalog(CertificateSourceCatalog catalog, DataRow row)
        {
            catalog.SupplierCode         = row["GOODID"].ToString();
            catalog.SupplierProducerCode = row["VENDORID"].ToString();
            catalog.SerialNumber         = row["SERIA"].ToString();
            var id = Convert.ToInt64(row["DOC"]);

            catalog.OriginFilePath = ToOriginFileName(id);
        }
Esempio n. 5
0
        public void Read_catalog()
        {
            var source  = new AvestaSource();
            var table   = Dbf.Load(@"..\..\Data\avesta_cert_catalog.dbf");
            var catalog = new CertificateSourceCatalog();

            source.ReadSourceCatalog(catalog, table.Rows[0]);
            Assert.AreEqual("47599", catalog.SupplierCode);
            Assert.AreEqual("1961013", catalog.SerialNumber);
            Assert.AreEqual(@"\СЕРТИФИКАТЫ\КОРВАЛОЛ капли 25мл Ф-Лексредства (фл-кап инд уп)\1961013\Декларация.tif", catalog.OriginFilePath);
        }
        public void DeleteTempFolderTest()
        {
            var rostaSource = new RostaCertificateSource();
            var product     = session.Query <Product>().First(p => p.CatalogProduct != null);
            var documentLog = new TestDocumentLog {
                Supplier     = _testSupplier,
                Client       = _testUser.Client,
                DocumentType = DocumentType.Waybill,
                LogTime      = DateTime.Now,
                FileName     = Path.GetRandomFileName() + ".txt"
            };
            var document = new TestWaybill(documentLog);

            session.Save(document);

            var realDocument = session.Load <Document>(document.Id);

            var task = new CertificateTask {
                SerialNumber   = "123",
                CatalogProduct = product.CatalogProduct,
            };

            task.CertificateSource = _source;
            task.DocumentLine      = new DocumentLine {
                Code          = "000002",
                SerialNumber  = "C392764",
                Document      = realDocument,
                ProductEntity = product
            };
            Save(task.DocumentLine);
            Save(task);

            var certificsteCatalog = new CertificateSourceCatalog {
                CertificateSource = _source,
                SerialNumber      = task.DocumentLine.SerialNumber,
                SupplierCode      = task.DocumentLine.Code,
                OriginFilePath    = "005/0052602p-0.gif",
                CatalogProduct    = product.CatalogProduct
            };

            Save(certificsteCatalog);
            Reopen();
            rostaSource.GetCertificateFiles(task, session);
            // Проверяем, что временная папка удалена
            Assert.That(Directory.Exists(rostaSource.TMPDownloadDir), Is.False);
        }
        public void Load_file_without_dir()
        {
            FTP_Server server = null;

            try {
                server = new FTP_Server();
                var port = new Random().Next(10000, 20000);
                server.BindInfo = new[] { new BindInfo(BindInfoProtocol.TCP, IPAddress.Loopback, port), };
                server.StartServer();
                var testProduct = new TestProduct("Тестовый продукт");
                session.Save(testProduct);
                var product = session.Load <Product>(testProduct.Id);
                var line    = new DocumentLine {
                    ProductEntity = product,
                    SerialNumber  = "012011",
                };

                var source            = new KatrenSource();
                var certificateSource = new CertificateSource();
                certificateSource.SourceClassName = source.GetType().Name;
                session.Save(certificateSource);

                var sourceCatalog = new CertificateSourceCatalog {
                    CertificateSource    = certificateSource,
                    SerialNumber         = line.SerialNumber,
                    CatalogProduct       = product.CatalogProduct,
                    SupplierCode         = "34266440",
                    SupplierProducerCode = "13483667",
                    OriginFilePath       = KatrenSource.ToOriginFileName(0x1B9EFC8),
                };
                session.Save(sourceCatalog);
                certificateSource.LookupUrl = String.Format("ftp://127.0.0.1:{0}/", port);

                source.GetFilesFromSource(new CertificateTask(certificateSource, line), new List <CertificateFile>());
            }
            finally {
                if (server != null)
                {
                    server.Dispose();
                }
            }
        }
Esempio n. 8
0
        public void TestGetFiles()
        {
            var rostaSource = new RostaCertificateSource();
            var task        = new CertificateTask();

            task.CertificateSource = _source;
            task.DocumentLine      = new DocumentLine {
                Code         = "000002",
                SerialNumber = "C392764"
            };

            var catalog = new CertificateSourceCatalog {
                CertificateSource = _source,
                SerialNumber      = task.DocumentLine.SerialNumber,
                SupplierCode      = task.DocumentLine.Code,
                OriginFilePath    = "005/0052602p-0.gif"
            };

            catalog.Save();

            catalog = new CertificateSourceCatalog {
                CertificateSource = _source,
                SerialNumber      = task.DocumentLine.SerialNumber,
                SupplierCode      = task.DocumentLine.Code,
                OriginFilePath    = "005/0052602pd-0.gif"
            };
            catalog.Save();

            var files = rostaSource.GetCertificateFiles(task, session);

            Assert.That(files.Count, Is.EqualTo(2));
            var file = files[0];

            Assert.That(File.Exists(file.LocalFile), Is.True, "файл не существует {0}", file.LocalFile);
            Assert.That(file.ExternalFileId, Is.EqualTo(@"005/0052602p-0.gif"));
            Assert.That(file.OriginFilename, Is.EqualTo(@"0052602p-0.gif"));
            Assert.That(file.Extension, Is.EqualTo(".GIF").IgnoreCase);
        }
        public virtual void ImportCatalogFile(CertificateCatalogFile catalogFile, CertificateSource source, IRemoteFtpSource ftpSource)
        {
            _logger.InfoFormat("Загружен новый каталог сертификатов: date: {0},  fileName: {1}", catalogFile.FileDate, catalogFile.LocalFileName);

            var catalogTable = Dbf.Load(catalogFile.LocalFileName);
            var catalogList  = new List <CertificateSourceCatalog>();

            _logger.InfoFormat("Количество строк в новом каталоге сертификатов: {0}", catalogTable.Rows.Count);

            //Выбираем записи из Core для ассортиментных прайсов поставщиков, которые привязаны к нужному источнику сертификатов
            var filter = "";

            if (source.SearchInAssortmentPrice)
            {
                filter = "and pd.PriceType = 1";
            }
            var cores = SessionHelper.WithSession(
                c => c.CreateSQLQuery(@"
select
	{core.*}
from
	documents.SourceSuppliers ss
	inner join usersettings.PricesData pd on pd.FirmCode = ss.SupplierId
	inner join farm.Core0 {core} on core.PriceCode = pd.PriceCode
	inner join catalogs.Products p on p.Id = core.ProductId
where
	ss.CertificateSourceId = :sourceId
" + filter)
                .AddEntity("core", typeof(Offer))
                .SetParameter("sourceId", catalogFile.Source.Id)
                .List <Offer>());

            _logger.InfoFormat("Количество загруженных позиций из Core: {0}", cores.Count);

            foreach (DataRow row in catalogTable.Rows)
            {
                var catalog = new CertificateSourceCatalog {
                    CertificateSource = catalogFile.Source,
                };
                ftpSource.ReadSourceCatalog(catalog, row);

                var core = catalog.FindCore(cores);
                if (core != null && core.Product != null)
                {
                    catalog.CatalogProduct = core.Product.CatalogProduct;
                }

                catalogList.Add(catalog);

                if (catalogList.Count % 10000 == 0)
                {
                    Ping();
                    _logger.DebugFormat("Количество обработанных строк нового каталога сертификатов: {0}", catalogList.Count);
                }
            }

            _logger.InfoFormat("Начата транзакция по обновлению каталога сертификатов");
            using (var transaction = new TransactionScope(OnDispose.Rollback)) {
                var session = ActiveRecordMediator.GetSessionFactoryHolder().CreateSession(typeof(ActiveRecordBase));
                try {
                    session.CreateSQLQuery(@"
	delete from
		documents.CertificateSourceCatalogs
	where
		CertificateSourceId = :certificateSourceId
		"        )
                    .SetParameter("certificateSourceId", catalogFile.Source.Id)
                    .ExecuteUpdate();

                    session.SaveEach(catalogList);
                    source.LastDecodeTableDownload = catalogFile.FileDate;
                    session.Update(source);
                }
                finally {
                    ActiveRecordMediator.GetSessionFactoryHolder().ReleaseSession(session);
                }
                transaction.VoteCommit();
                _logger.InfoFormat("Транзакция по обновлению каталога сертификатов завершена успешно");
            }
        }
Esempio n. 10
0
 public void ReadSourceCatalog(CertificateSourceCatalog catalog, DataRow row)
 {
     catalog.SerialNumber   = row["BATCH_ID"].ToString();
     catalog.SupplierCode   = row["CODE"].ToString();
     catalog.OriginFilePath = row["GB_FILES"].ToString();
 }