public async Task <XStaticResult> DeployStaticSite(int staticSiteId) { var stopwatch = new Stopwatch(); stopwatch.Start(); var entity = _sitesRepo.Get(staticSiteId); if (entity == null) { throw new HttpException(404, "Site not found with id " + staticSiteId); } var path = _storer.GetStorageLocationOfSite(entity.Id); if (!Directory.Exists(path)) { throw new FileNotFoundException(); } var deployer = _deployerFactory.GetDeployer(entity.DeploymentTarget.id, entity.DeploymentTarget.fields); var result = await deployer.DeployWholeSite(path); stopwatch.Stop(); _sitesRepo.UpdateLastDeploy(staticSiteId, (int)(stopwatch.ElapsedMilliseconds / 1000)); return(result); }
public HttpResponseMessage DownloadStaticSite(int staticSiteId) { var entity = _sitesRepo.Get(staticSiteId); if (entity == null) { throw new HttpException(404, "Site not found with id " + staticSiteId); } var localFolderPath = _storer.GetStorageLocationOfSite(entity.Id); if (!Directory.Exists(localFolderPath)) { throw new FileNotFoundException(); } var localZipFilePath = localFolderPath.Trim('/').Trim('\\') + ".zip"; if (File.Exists(localZipFilePath)) { File.Delete(localZipFilePath); } ZipFile.CreateFromDirectory(localFolderPath, localZipFilePath); HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StreamContent(new FileStream(localZipFilePath, FileMode.Open, FileAccess.Read)); response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = $"{entity.Name}.{DateTime.Now.ToString("yyMMddHHmmss")}.zip"; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip"); return(response); }
public IEnumerable <ExtendedGeneratedSite> GetAll() { var sites = _sitesRepo.GetAll(); foreach (var site in sites) { var node = Umbraco.Content(site.RootNode); site.RootPath = node.Parent == null ? node.Name : node.Parent.Name + "/" + node.Name; var folder = _storer.GetStorageLocationOfSite(site.Id); var size = FileHelpers.GetDirectorySize(new DirectoryInfo(folder)); site.FolderSize = FileHelpers.BytesToString(size); } return(sites); }