コード例 #1
0
        public void PleaseDoTheNeedful()
        {
            Console.WriteLine(_configuration.IncludeOnlyFilesModifiedInLastNDays >= 0
                ? $"Taking changes from last {_configuration.IncludeOnlyFilesModifiedInLastNDays} days."
                : "Taking all files without date filtering.");

            var targetPath = _configuration.IntermediateZipDirectory;
            var filesToAdd = GetFilesToTransfer();
            var zipName    = $"bin_{DateTime.Now:yyyyMMdd_HHmmss}.zip";
            var zipPath    = Path.Combine(targetPath, zipName);

            _progressSupport.SetupProgress(filesToAdd.Length);

            PrepareDirectory(targetPath, zipPath);

            using (var zip = new ZipFile(zipPath))
            {
                zip.SaveProgress += (obj, spe) => { if (spe.EntriesSaved > 0)
                                                    {
                                                        _progressSupport.ChangeProgress(spe.EntriesSaved, spe.CurrentEntry.FileName);
                                                    }
                };
                zip.AddFiles(filesToAdd, string.Empty);
                zip.Save();
                Console.WriteLine("ZIP created");
            }
        }
コード例 #2
0
        public void PleaseDoTheNeedful()
        {
            var sourcePath = _configuration.IntermediateZipDirectory;
            var zipName    = new DirectoryInfo(sourcePath).GetFiles("bin_*.zip")
                             .OrderByDescending(fi => fi.CreationTime)
                             .FirstOrDefault()
                             ?.Name;
            string zipPath;

            if (string.IsNullOrWhiteSpace(zipName))
            {
                if (_configuration.TryRestoreDebugBinariesWhenZipNotFound)
                {
                    // TODO
                    throw new NotImplementedException("This is not implemented for now.");
                }
                else
                {
                    throw new InvalidOperationException("ZIP with debug binaries not found. Consider setting TryRestoreDebugBinariesWhenZipNotFound flag to True.");
                }
            }
            else
            {
                zipPath = Path.Combine(sourcePath, zipName);
            }

            var websitePath       = _configuration.RemoteWebsiteDirectory;
            var binProdFolderName = _configuration.BinDirectoryNameForProductionBinaries;
            var binProdPath       = Path.Combine(websitePath, binProdFolderName);
            var binPath           = Path.Combine(websitePath, "bin");

            // if binProd is already there, rename it
            if (Directory.Exists(binProdPath))
            {
                Directory.Move(binProdPath, Path.Combine(websitePath, $"{binProdFolderName}_{DateTime.Now:yyyyMMdd_hhmmss}"));
            }

            // move bin to binProd
            Directory.Move(binPath, binProdPath);

            // copy binProd to bin
            CreateDirectoryCopy(binProdPath, binPath);

            // unpack zip to bin
            using (var zip = new ZipFile(zipPath))
            {
                Console.WriteLine($"Starting unzip to {binPath}");
                _progressSupport.SetupProgress(zip.Count);
                zip.ExtractProgress += (obj, epe) => { if (epe.EntriesExtracted > 0)
                                                       {
                                                           _progressSupport.ChangeProgress(epe.EntriesExtracted, epe.CurrentEntry.FileName);
                                                       }
                };
                zip.ExtractAll(binPath, ExtractExistingFileAction.OverwriteSilently);
                Console.WriteLine("Finished unzip");
            }

            // refresh AppPool
            _systemUtils.RecycleAppPool();

            // start remote debugger
            if (!_systemUtils.StartRemoteDebugger())
            {
                throw new InvalidOperationException("Starting remote debugger failed.");
            }
        }