public void PleaseDoTheNeedful() { var websitePath = _configuration.RemoteWebsiteDirectory; var userInitials = _configuration.UserInitials; var binInitialsPath = Path.Combine(websitePath, $"bin{userInitials}"); var binProdFolderName = _configuration.BinDirectoryNameForProductionBinaries; var binProdPath = Path.Combine(websitePath, binProdFolderName); var binPath = Path.Combine(websitePath, "bin"); // if bin<initials> is already there, delete or rename it if (Directory.Exists(binInitialsPath)) { if (_configuration.KeepRemoteBinWithInitials) { Directory.Move(binInitialsPath, Path.Combine(websitePath, $"{binInitialsPath}_{DateTime.Now:yyyyMMdd_hhmmss}")); } else { Directory.Delete(binInitialsPath, true); } } // ensure existance of production binaries if (!Directory.Exists(binProdPath)) { throw new InvalidOperationException("Cannot find a backup folder with production binaries."); } // delete development binaries Directory.Move(binPath, binInitialsPath); // move binProd to bin Directory.Move(binProdPath, binPath); // refresh AppPool _systemUtils.RecycleAppPool(); // close remote debugger _systemUtils.CloseRemoteDebugger(true); }
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."); } }