private string Unzip(Stream stream, string saveDirectory = "", string fileName = "") { //#if DEBUG // return Path.Combine(saveDirectory, fileName); // //FileStream fileeStream = new FileStream(Path.Combine(saveDirectory, fileName), FileMode.Open, FileAccess.Read, FileShare.None); // //return fileeStream; //#endif var zipProc = new ZipProcessor(stream); var zippie = zipProc.File; zippie.ExtractProgress += new EventHandler <Ionic.Zip.ExtractProgressEventArgs>(zippie_ExtractProgress); if (saveDirectory != "") { // zippie.sa zippie[fileName].Extract(saveDirectory, ExtractExistingFileAction.OverwriteSilently); FileStream fileStream = new FileStream(Path.Combine(saveDirectory, fileName), FileMode.Open, FileAccess.Read, FileShare.None); //return fileStream; } //foreach (var file in zipProc) //{ // return file.Data; //} return(Path.Combine(saveDirectory, fileName)); }
public void BasePackagingWithCopyProcessorAndZipProcessorTest() { ICopier copier = new Copier(Context); IZipper zipper = new Zipper(Context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); DirectorySource test = new DirectorySource(Context, directoryFilesLister, "test", new FullPath("tmp/test")); DirectorySource test2 = new DirectorySource(Context, directoryFilesLister, "test2", new FullPath("tmp/test2")); packageDef.AddFilesSource(test); packageDef.AddFilesSource(test2); CopyProcessor copyProcessor = new CopyProcessor( Context, copier, new FullPath("tmp/output")); copyProcessor .AddTransformation("test", new LocalPath(@"test")) .AddTransformation("test2", new LocalPath(@"test2")); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); ZipProcessor zipProcessor = new ZipProcessor(Context, zipper, new FileFullPath("tmp/test.zip"), new FullPath("tmp/output"), false, null, "test", "test2"); zipProcessor.Process(copiedPackageDef); using (ZipArchive archive = ZipFile.OpenRead("tmp/test.zip")) { Assert.Equal(4, archive.Entries.Count); var list = archive.Entries.ToList <ZipArchiveEntry>(); Assert.Contains(list, x => x.FullName == $"test{_seperator}test.txt"); Assert.Contains(list, x => x.FullName == $"test{_seperator}test2.txt"); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test.txt"); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test2.txt"); } }
protected override void SyncProducts() { try { log.AuditInfo("Start Tech Data import"); var stopWatch = Stopwatch.StartNew(); FtpManager downloader = new FtpManager(GetConfiguration().AppSettings.Settings["TechDataFtpSite"].Value, string.Empty, GetConfiguration().AppSettings.Settings["TechDataFtpUserName"].Value, GetConfiguration().AppSettings.Settings["TechDataFtpPass"].Value, false, false, log); using (var file = downloader.OpenFile("prices.zip")) { using (ZipProcessor zipUtil = new ZipProcessor(file.Data)) { var zipEligible = (from z in zipUtil where z.FileName == "00136699.txt" select z); foreach (var zippedFile in zipEligible) { using (CsvParser parser = new CsvParser(zippedFile.Data, ColumnDefinitions, true)) { ProcessCsv(parser); } } } } log.AuditSuccess(string.Format("Total import process finished in: {0}", stopWatch.Elapsed), "Tech Data Import"); } catch (Exception e) { log.AuditFatal("Tech data import failed", e, "Tech Data Import"); } }
public void OptimizeZipTest() { ICopier copier = new Copier(Context); IZipper zipper = new Zipper(Context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); DirectorySource test = new DirectorySource(Context, directoryFilesLister, "test", new FullPath("tmp\\test")); DirectorySource test2 = new DirectorySource(Context, directoryFilesLister, "test2", new FullPath("tmp\\test2")); packageDef.AddFilesSource(test); packageDef.AddFilesSource(test2); CopyProcessor copyProcessor = new CopyProcessor( Context, copier, new FullPath("tmp\\output")); copyProcessor .AddTransformation("test", new LocalPath(@"test")) .AddTransformation("test2", new LocalPath(@"test2")); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); ZipProcessor zipProcessor = new ZipProcessor(Context, zipper, new FileFullPath("tmp\\test.zip"), new FullPath("tmp\\output"), true, null, "test", "test2"); zipProcessor.Process(copiedPackageDef); using (ZipArchive archive = ZipFile.OpenRead("tmp\\test.zip")) { Assert.Equal(4, archive.Entries.Count); Assert.Equal("test2\\test.txt", archive.Entries[1].FullName); Assert.Equal("test2\\test2.txt", archive.Entries[0].FullName); Assert.Equal("test\\test2.txt", archive.Entries[2].FullName); Assert.Equal("_zipmetadata.json", archive.Entries[3].FullName); } }
public void OneZipPerSearch_AddContainingFolder() { ZipProcessor processor = new ZipProcessor(); processor.SetParameter("OneZipFilePer", ProcessorScope.Search); processor.SetParameter("AddContainingFolder", true); processor.SetParameter("OutputPath", Path.Combine(CurrentTestResultsDirectoryPath, "output.zip")); processor.SetParameter("Overwrite", false); FileInfo file1 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "TextFile1ForZip.txt")); FileInfo file2 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile2ForZip.txt")); FileInfo file3 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile3ForZip.txt")); FileInfo[] generatedFiles = new FileInfo[0]; string[] values = new string[0]; processor.Init(RunInfo); processor.Process(file1, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.Process(file2, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.Process(file3, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.ProcessAggregated(CancellationToken.None); processor.Cleanup(); }
protected override void Process() { var config = GetConfiguration().AppSettings.Settings; var ftp = new FtpManager(config["VSNFtpUrl"].Value, "pub3/", config["VSNUser"].Value, config["VSNPassword"].Value, false, true, log); using (var unit = GetUnitOfWork()) { using (var synFile = ftp.OpenFile("XMLExportSynopsis.zip")) { using (var zipProc = new ZipProcessor(synFile.Data)) { foreach (var file in zipProc) { using (file) { using (DataSet ds = new DataSet()) { ds.ReadXml(file.Data); ProcessSynopsisTable(ds.Tables[0], unit); } } } } } } log.AuditComplete("Finished full VSN synopsis import", "VSN Synopsis Import"); }
public void OneZipPerSearch_DoesNotOverwrite() { ZipProcessor processor = new ZipProcessor(); string outputPath = Path.Combine(CurrentTestResultsDirectoryPath, "output.zip"); processor.SetParameter("OneZipFilePer", ProcessorScope.Search); processor.SetParameter("AddContainingFolder", false); processor.SetParameter("OutputPath", outputPath); processor.SetParameter("Overwrite", false); File.WriteAllText(outputPath, "This file will not be replaced. Also it's not really a zip file."); FileInfo file1 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "TextFile1ForZip.txt")); FileInfo file2 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile2ForZip.txt")); FileInfo file3 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile3ForZip.txt")); FileInfo[] generatedFiles = new FileInfo[0]; string[] values = new string[0]; processor.Init(RunInfo); processor.Process(file1, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.Process(file2, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); processor.Process(file3, MatchResultType.Yes, values, generatedFiles, ProcessInput.OriginalFile, CancellationToken.None); try { processor.ProcessAggregated(CancellationToken.None); Assert.Fail(); } catch (Exception) { } processor.Cleanup(); }
public void TestZipProcessor() { IZipper zipper = MockRepository.GenerateMock <IZipper>(); ZipProcessor zipProcessor = new ZipProcessor( logger, zipper, "some.zip", "test", null, "console", "win.service"); IPackageDef zippedPackageDef = zipProcessor.Process(package); Assert.AreEqual(1, zippedPackageDef.ListChildSources().Count); }
public void OptimizeZipThenUnzipTest() { ICopier copier = new Copier(Context); IZipper zipper = new Zipper(Context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); DirectorySource test = new DirectorySource(Context, directoryFilesLister, "test", new FullPath("tmp/test")); DirectorySource test2 = new DirectorySource(Context, directoryFilesLister, "test2", new FullPath("tmp/test2")); packageDef.AddFilesSource(test); packageDef.AddFilesSource(test2); CopyProcessor copyProcessor = new CopyProcessor( Context, copier, new FullPath("tmp/output")); copyProcessor .AddTransformation("test", new LocalPath(@"test")) .AddTransformation("test2", new LocalPath(@"test2")); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); ZipProcessor zipProcessor = new ZipProcessor(Context, zipper, new FileFullPath("tmp/test.zip"), new FullPath("tmp/output"), true, null, "test", "test2"); zipProcessor.Process(copiedPackageDef); string zf = "tmp/test.zip"; using (ZipArchive archive = ZipFile.OpenRead(zf)) { Assert.Equal(4, archive.Entries.Count); var list = archive.Entries.ToList <ZipArchiveEntry>(); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test.txt"); Assert.Contains(list, x => x.FullName == $"test2{_seperator}test2.txt"); Assert.Contains(list, x => x.FullName == $"test{_seperator}test2.txt"); Assert.Contains(list, x => x.FullName == "_zipmetadata.json"); } string unzipPath = "tmp/tt/"; UnzipTask unzip = new UnzipTask(zf, unzipPath); unzip.Execute(Context); var newLine = System.Environment.NewLine; CheckTestFile(Path.Combine(unzipPath, $"test2{_seperator}test.txt"), $"test.txt{newLine}"); CheckTestFile(Path.Combine(unzipPath, $"test2{_seperator}test2.txt"), $"test.txt{newLine}"); CheckTestFile(Path.Combine(unzipPath, $"test{_seperator}test.txt"), $"test.txt{newLine}"); CheckTestFile(Path.Combine(unzipPath, $"test{_seperator}test2.txt"), $"test2.txt{newLine}"); }
private static void TargetPackage(ITaskContext context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get <string>(BuildProps.BuildDir)); FullPath simplexPackageDir = packagesDir.CombineWith("Detergent"); FileFullPath zipFileName = packagesDir.AddFileName( "Detergent-{0}.zip", context.Properties.Get <Version>(BuildProps.BuildVersion)); StandardPackageDef packageDef = new StandardPackageDef("Detergent", context); VSSolution solution = context.Properties.Get <VSSolution>(BuildProps.Solution); VSProjectWithFileInfo projectInfo = (VSProjectWithFileInfo)solution.FindProjectByName("Detergent"); LocalPath projectOutputPath = projectInfo.GetProjectOutputPath( context.Properties.Get <string>(BuildProps.BuildConfiguration)); FullPath projectTargetDir = projectInfo.ProjectDirectoryPath.CombineWith(projectOutputPath); packageDef.AddFolderSource( "bin", projectTargetDir, false); ICopier copier = new Copier(context); CopyProcessor copyProcessor = new CopyProcessor( context, copier, simplexPackageDir); copyProcessor .AddTransformation("bin", new LocalPath(string.Empty)); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); Zipper zipper = new Zipper(context); ZipProcessor zipProcessor = new ZipProcessor( context, zipper, zipFileName, simplexPackageDir, null, "bin"); zipProcessor.Process(copiedPackageDef); }
public void GeneratedFiles_PerGeneratedFile() { ZipProcessor processor = new ZipProcessor(); processor.SetParameter("OneZipFilePer", ProcessorScope.GeneratedOutputFile); processor.SetParameter("AddContainingFolder", false); processor.SetParameter("OutputPath", Path.Combine(CurrentTestResultsDirectoryPath, "{NameWithoutExtension}.zip")); processor.SetParameter("Overwrite", false); FileInfo file = GetTestFile("BasicTextFile.txt"); FileInfo file1 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "TextFile1ForZip.txt")); FileInfo file2 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile2ForZip.txt")); FileInfo file3 = GetTestFile(Path.Combine("ZipHierarchy", "Subdir1", "Subdir2", "Subdir3", "TextFile3ForZip.txt")); FileInfo[] generatedFiles = new FileInfo[] { file1, file2, file3 }; string[] values = new string[0]; processor.Init(RunInfo); processor.Process(file, MatchResultType.Yes, values, generatedFiles, ProcessInput.GeneratedFiles, CancellationToken.None); processor.ProcessAggregated(CancellationToken.None); processor.Cleanup(); }
protected override void Process() { log.Info("ZipCode Import started"); var config = GetConfiguration(); string session = config.AppSettings.Settings["WinscpSession"].Value; string logPath = config.AppSettings.Settings["WinscpLogPath"].Value; string applicationPath = config.AppSettings.Settings["WinscpAppPath"].Value; string downloadLocation = config.AppSettings.Settings["WinscpDownloadPath"].Value; using (var unit = GetUnitOfWork()) { using (WinSCPDownloader downloader = new WinSCPDownloader(session, logPath, applicationPath, downloadLocation, "*.zip")) { log.Debug("Connected to Cendris."); foreach (var remoteFile in downloader) { log.DebugFormat("Try process file {0}", remoteFile.FileName); using (ZipProcessor processor = new ZipProcessor(remoteFile.Data)) { foreach (var zippedFile in processor) { using (StreamReader sr = new StreamReader(zippedFile.Data)) { int linecount = 0; int logline = 0; string line; while ((line = sr.ReadLine()) != null) { linecount++; if (linecount <= 1 || line.StartsWith("**")) { continue; } #region Parse PostCode ZipCode newzip = new ZipCode() { PCWIJK = line.Substring(17, 4).Trim(), PCLETTER = line.Substring(21, 2).Trim(), PCREEKSID = line.Substring(23, 1).Trim(), PCREEKSVAN = string.IsNullOrEmpty(line.Substring(24, 5).Trim()) ? 0 : int.Parse(line.Substring(24, 5).Trim()), PCREEKSTOT = string.IsNullOrEmpty(line.Substring(29, 5).Trim()) ? 0 : int.Parse(line.Substring(29, 5).Trim()), PCCITYTPG = line.Substring(34, 18).Trim(), PCCITYNEN = line.Substring(52, 24).Trim(), PCSTRTPG = line.Substring(76, 17).Trim(), PCSTRNEN = line.Substring(93, 24).Trim(), PCSTROFF = line.Substring(117, 43).Trim(), PCCITYEXT = line.Substring(160, 4).Trim(), PCSTREXT = line.Substring(164, 5).Trim(), PCGEMEENTEID = string.IsNullOrEmpty(line.Substring(169, 4).Trim()) ? 0 : int.Parse(line.Substring(169, 4).Trim()), PCGEMEENTENAAM = line.Substring(173, 24).Trim(), PCPROVINCIE = line.Substring(197, 1).Trim(), PCCEBUCO = string.IsNullOrEmpty(line.Substring(198, 3).Trim()) ? 0 : int.Parse(line.Substring(198, 3).Trim()) }; var existingVar = (from c in unit.Scope.Repository <ZipCode>().GetAll() where c.PCWIJK == newzip.PCWIJK && c.PCLETTER == newzip.PCLETTER && c.PCREEKSID == newzip.PCREEKSID && c.PCREEKSVAN == newzip.PCREEKSVAN && c.PCREEKSTOT == newzip.PCREEKSTOT && c.PCCITYTPG == newzip.PCCITYTPG && c.PCCITYNEN == newzip.PCCITYNEN && c.PCSTRTPG == newzip.PCSTRTPG && c.PCSTRNEN == newzip.PCSTRNEN && c.PCSTROFF == newzip.PCSTROFF && c.PCCITYEXT == newzip.PCCITYEXT && c.PCSTREXT == newzip.PCSTREXT && c.PCGEMEENTEID == newzip.PCGEMEENTEID && c.PCGEMEENTENAAM == newzip.PCGEMEENTENAAM && c.PCPROVINCIE == newzip.PCPROVINCIE && c.PCCEBUCO == newzip.PCCEBUCO select c).FirstOrDefault(); if (existingVar == null) { existingVar = new ZipCode() { PCWIJK = newzip.PCWIJK, PCLETTER = newzip.PCLETTER, PCREEKSID = newzip.PCREEKSID, PCREEKSVAN = newzip.PCREEKSVAN, PCREEKSTOT = newzip.PCREEKSTOT, PCCITYTPG = newzip.PCCITYTPG, PCCITYNEN = newzip.PCCITYNEN, PCSTRTPG = newzip.PCSTRTPG, PCSTRNEN = newzip.PCSTRNEN, PCSTROFF = newzip.PCSTROFF, PCCITYEXT = newzip.PCCITYEXT, PCSTREXT = newzip.PCSTREXT, PCGEMEENTEID = newzip.PCGEMEENTEID, PCGEMEENTENAAM = newzip.PCGEMEENTENAAM, PCPROVINCIE = newzip.PCPROVINCIE, PCCEBUCO = newzip.PCCEBUCO }; unit.Scope.Repository <ZipCode>().Add(existingVar); } #endregion } } try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress, TimeSpan.FromMinutes(3))) { unit.Save(); scope.Complete(); } //mark file as completed downloader.RenameRemoteFile(remoteFile.FileName, remoteFile.FileName + ".comp"); log.Info("Post code import process completed succesfully for file: " + remoteFile.FileName); } catch (Exception e) { log.Error("Import of zip codes for file: " + remoteFile.FileName + " failed", e); //mark as error downloader.RenameRemoteFile(remoteFile.FileName, remoteFile.FileName + ".err"); } } } } } } //delete all local files DirectoryInfo info = new DirectoryInfo(downloadLocation); FileInfo[] infos = info.GetFiles("*.zip"); foreach (var i in infos) { File.Delete(Path.Combine(downloadLocation, i.Name)); } log.AuditSuccess("Post Code import finished", "Post Code Import"); }
public void Process() { var config = GetConfiguration().AppSettings.Settings; var subFolderPath = Path.Combine(config["CentraalBoekhuisCoverPath"].Value, config["CentraalBoekhuisInitialPath"].Value); FtpManager ftp = new FtpManager(config["CentraalBoekhuisFtpUrl"].Value, subFolderPath, config["CentraalBoekhuisUser"].Value, config["CentraalBoekhuisPassword"].Value, false, true, log); using (var unit = GetUnitOfWork()) { string drive = GetConfiguration().AppSettings.Settings["FTPImageDirectory"].Value; bool networkDrive = false; bool.TryParse(GetConfiguration().AppSettings.Settings["IsNetworkDrive"].Value, out networkDrive); if (networkDrive) { NetworkDrive oNetDrive = new NetworkDrive(); try { oNetDrive.LocalDrive = "Z:"; oNetDrive.ShareName = drive; oNetDrive.MapDrive(); drive = "Z:"; drive = Path.Combine(drive, "Concentrator"); } catch (Exception err) { log.Error("Invalid network drive", err); } oNetDrive = null; } foreach (var zipFile in ftp) { try { using (var zipProc = new ZipProcessor(zipFile.Data)) { foreach (var file in zipProc) { ProcessMediaFile(file, unit, drive); } unit.Save(); } } catch (Exception ex) { log.AuditError(string.Format("Error import Centraal boekhuis media file {0}", zipFile.FileName), ex); } } if (networkDrive) { NetworkDrive oNetDrive = new NetworkDrive(); try { oNetDrive.LocalDrive = drive; oNetDrive.UnMapDrive(); } catch (Exception err) { log.Error("Error unmap drive" + err.InnerException); } oNetDrive = null; } } log.AuditComplete("Finished full Centraal Boekhuis image import", "Centraal Boekhuis Image Import"); }
private static void TargetPackage(ITaskContext context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get<string>(BuildProps.BuildDir)); FullPath simplexPackageDir = packagesDir.CombineWith("Detergent"); FileFullPath zipFileName = packagesDir.AddFileName( "Detergent-{0}.zip", context.Properties.Get<Version>(BuildProps.BuildVersion)); StandardPackageDef packageDef = new StandardPackageDef("Detergent", context); VSSolution solution = context.Properties.Get<VSSolution>(BuildProps.Solution); VSProjectWithFileInfo projectInfo = (VSProjectWithFileInfo)solution.FindProjectByName("Detergent"); LocalPath projectOutputPath = projectInfo.GetProjectOutputPath( context.Properties.Get<string>(BuildProps.BuildConfiguration)); FullPath projectTargetDir = projectInfo.ProjectDirectoryPath.CombineWith(projectOutputPath); packageDef.AddFolderSource( "bin", projectTargetDir, false); ICopier copier = new Copier(context); CopyProcessor copyProcessor = new CopyProcessor( context, copier, simplexPackageDir); copyProcessor .AddTransformation("bin", new LocalPath(string.Empty)); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); Zipper zipper = new Zipper(context); ZipProcessor zipProcessor = new ZipProcessor( context, zipper, zipFileName, simplexPackageDir, null, "bin"); zipProcessor.Process(copiedPackageDef); }
protected override int DoExecute(ITaskContextInternal context) { if (_sourcePackagingInfos.Count == 0) { return(0); } if (string.IsNullOrEmpty(_destinationRootDir)) { _destinationRootDir = context.Properties.GetOutputDir(); } FullPath df = new FullPath(_destinationRootDir); ICopier copier = new Copier(context, _logFiles); IZipper zipper = new Zipper(context); IDirectoryFilesLister directoryFilesLister = new DirectoryFilesLister(); StandardPackageDef packageDef = new StandardPackageDef(); CopyProcessor copyProcessor = new CopyProcessor(context, copier, df); List <string> sourceIds = new List <string>(); foreach (var sourceToPackage in _sourcePackagingInfos) { string sourceId; if (sourceToPackage.SourceType == SourceType.Directory) { var sourceFullPath = new FullPath(sourceToPackage.SourcePath); sourceId = sourceFullPath.GetHashCode().ToString(); DirectorySource directorySource = new DirectorySource(context, directoryFilesLister, sourceId, sourceFullPath, sourceToPackage.Recursive, sourceToPackage.DirectoryFilters); directorySource.SetFileFilter(sourceToPackage.FileFilters); packageDef.AddFilesSource(directorySource); } else { var fileFullPath = new FileFullPath(sourceToPackage.SourcePath); sourceId = fileFullPath.GetHashCode().ToString(); SingleFileSource fileSource = new SingleFileSource(sourceId, fileFullPath); packageDef.AddFilesSource(fileSource); } copyProcessor.AddTransformation(sourceId, sourceToPackage.DestinationPath); sourceIds.Add(sourceId); } IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); if (ShouldPackageBeZipped) { string zipFile = _zipFileName; if (string.IsNullOrEmpty(zipFile)) { zipFile = _zipPrefix; _addVersionAsPostFixToZipFileName = true; _versionFieldCount = 3; } if (zipFile.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) { zipFile = zipFile.Substring(0, zipFile.Length - 4); } string tmp = _addVersionAsPostFixToZipFileName ? $"{zipFile}_{context.Properties.GetBuildVersion().Version.ToString(_versionFieldCount)}.zip" : $"{zipFile}.zip"; zipFile = Path.Combine(_destinationRootDir, tmp); DoLogInfo($"Creating zip file {zipFile}"); ZipProcessor zipProcessor = new ZipProcessor(context, zipper, new FileFullPath(zipFile), df, _optimizeZip, sourceIds, _logFiles); zipProcessor.Process(copiedPackageDef); } return(0); }
protected override void Process() { var config = GetConfiguration().AppSettings.Settings; var ftp = new FtpManager(config["VSNFtpUrl"].Value, "pub2/images/recent/", config["VSNUser"].Value, config["VSNPassword"].Value, false, true, log); using (var unit = GetUnitOfWork()) { string drive = GetConfiguration().AppSettings.Settings["FTPImageDirectory"].Value; bool networkDrive = false; bool.TryParse(GetConfiguration().AppSettings.Settings["IsNetworkDrive"].Value, out networkDrive); if (networkDrive) { NetworkDrive oNetDrive = new NetworkDrive(); try { oNetDrive.LocalDrive = "Z:"; oNetDrive.ShareName = drive; //oNetDrive.MapDrive("diract", "D1r@ct379"); oNetDrive.MapDrive(); drive = "Z:"; drive = Path.Combine(drive, "Concentrator"); } catch (Exception err) { log.AuditError("Invalid network drive", err); } oNetDrive = null; } foreach (var zipFile in ftp) { try { using (var zipProc = new ZipProcessor(zipFile.Data)) { foreach (var file in zipProc) { ProcessImageFile(file, unit, drive); } unit.Save(); } } catch (Exception ex) { log.AuditError(string.Format("Error import VSN image file {0}", zipFile.FileName), ex); } } if (networkDrive) { NetworkDrive oNetDrive = new NetworkDrive(); try { oNetDrive.LocalDrive = drive; oNetDrive.UnMapDrive(); } catch (Exception err) { log.AuditError("Error unmap drive" + err.InnerException); } oNetDrive = null; } } log.AuditComplete("Finished full VSN image import", "VSN Image Import"); }
public void Process() { var config = GetConfiguration().AppSettings.Settings; var ftp = new FtpManager(config["VSNFtpUrl"].Value, "pub3/", config["VSNUser"].Value, config["VSNPassword"].Value, false, true, log); using (var unit = GetUnitOfWork()) { //DataLoadOptions options = new DataLoadOptions(); //options.LoadWith<Product>(p => p.ProductImages); //options.LoadWith<Product>(p => p.ProductDescription); //options.LoadWith<Product>(p => p.ProductBarcodes); //options.LoadWith<Product>(p => p.VendorAssortment); //options.LoadWith<VendorAssortment>(va => va.VendorPrice); //options.LoadWith<VendorAssortment>(va => va.VendorStock); //options.LoadWith<ProductAttributeMetaData>(p => p.ProductAttributeValues); //options.LoadWith<ProductGroupVendor>(x=>x.VendorProductGroupAssortments); //options.LoadWith<VendorAssortment>(x => x.VendorPrice); //options.LoadWith<VendorAssortment>(va => va.VendorStock); //ctx.LoadOptions = options; ProductStatusVendorMapper mapper = new ProductStatusVendorMapper(unit.Scope.Repository <VendorProductStatus>(), VendorID); ProductGroupSyncer syncer = new ProductGroupSyncer(VendorID, unit.Scope.Repository <ProductGroupVendor>()); BrandVendor brandVendor = null; List <ProductAttributeMetaData> attributes; SetupBrandAndAttributes(unit, out attributes, out brandVendor); //#if DEBUG // if (File.Exists("ExportProduct.xml")) // { // DataSet ds2 = new DataSet(); // ds2.ReadXml("ExportProduct.xml"); // ProcessProductsTable(ds2.Tables[0], brandVendor.BrandID, attributes, syncer, mapper); // } //#endif var inactiveAss = unit.Scope.Repository <VendorAssortment>().GetAll(x => x.VendorID == VendorID).ToDictionary(x => x.VendorAssortmentID, y => y); using (var prodFile = ftp.OpenFile("XMLExportProduct.zip")) { using (var zipProc = new ZipProcessor(prodFile.Data)) { foreach (var file in zipProc) { using (file) { #if DEBUG using (System.IO.FileStream fs = new FileStream(file.FileName, FileMode.OpenOrCreate)) { file.Data.WriteTo(fs); fs.Close(); } #endif using (DataSet ds = new DataSet()) { ds.ReadXml(file.Data); ProcessProductsTable(ds.Tables[0], brandVendor.BrandID, attributes, syncer, mapper, inactiveAss); } } } } } inactiveAss.Values.ForEach((x, idx) => { x.IsActive = false; }); unit.Save(); } log.AuditComplete("Finished full VSN product import", "VSN Product Import"); }