public ActionResult UploadPackage(FormCollection form, string returnUrl = "") { if (returnUrl.IsEmpty()) { returnUrl = _services.WebHelper.GetUrlReferrer(); } bool isTheme = false; try { var file = Request.Files["packagefile"]; if (file != null && file.ContentLength > 0) { var requiredPermission = (isTheme = PackagingUtils.IsTheme(file.FileName)) ? StandardPermissionProvider.ManageThemes : StandardPermissionProvider.ManagePlugins; if (!_services.Permissions.Authorize(requiredPermission)) { return(AccessDeniedView()); } if (!Path.GetExtension(file.FileName).IsCaseInsensitiveEqual(".nupkg")) { NotifyError(T("Admin.Packaging.NotAPackage")); return(Redirect(returnUrl)); } var location = CommonHelper.MapPath("~/App_Data"); var appPath = CommonHelper.MapPath("~/"); var packageInfo = _packageManager.Install(file.InputStream, location, appPath); } else { NotifyError(T("Admin.Common.UploadFile")); return(Redirect(returnUrl)); } if (!isTheme) { _services.WebHelper.RestartAppDomain(); } NotifySuccess(T("Admin.Packaging.InstallSuccess")); return(Redirect(returnUrl)); } catch (Exception exc) { NotifyError(exc); return(Redirect(returnUrl)); } }
private FileInfo SavePackageFile(PackagingResult result) { var fileName = string.Format("{0}{1}.{2}.nupkg", PackagingUtils.GetExtensionPrefix(result.ExtensionType), result.PackageName, result.PackageVersion); if (!Directory.Exists(_outputPath)) { Directory.CreateDirectory(_outputPath); } fileName = Path.Combine(_outputPath, fileName); using (var stream = File.Create(fileName)) { result.PackageStream.CopyTo(stream); } var fileInfo = new FileInfo(fileName); return(fileInfo); }
public ActionResult UploadPackage(FormCollection form, string returnUrl = "") { if (returnUrl.IsEmpty()) { returnUrl = _services.WebHelper.GetUrlReferrer(); } bool isTheme = false; try { var file = Request.Files["packagefile"].ToPostedFileResult(); if (file != null) { var requiredPermission = (isTheme = PackagingUtils.IsTheme(file.FileName)) ? StandardPermissionProvider.ManageThemes : StandardPermissionProvider.ManagePlugins; if (!_services.Permissions.Authorize(requiredPermission)) { return(AccessDeniedView()); } if (!file.FileExtension.IsCaseInsensitiveEqual(".nupkg")) { NotifyError(T("Admin.Packaging.NotAPackage")); return(Redirect(returnUrl)); } var location = CommonHelper.MapPath("~/App_Data"); var appPath = CommonHelper.MapPath("~/"); if (isTheme) { // avoid getting terrorized by IO events _themeRegistry.Value.StopMonitoring(); } var packageInfo = _packageManager.Install(file.Stream, location, appPath); if (isTheme) { // create manifest if (packageInfo != null) { var manifest = ThemeManifest.Create(packageInfo.ExtensionDescriptor.Path); if (manifest != null) { _themeRegistry.Value.AddThemeManifest(manifest); } } // SOFT start IO events again _themeRegistry.Value.StartMonitoring(false); } } else { NotifyError(T("Admin.Common.UploadFile")); return(Redirect(returnUrl)); } if (!isTheme) { _services.WebHelper.RestartAppDomain(); } NotifySuccess(T("Admin.Packaging.InstallSuccess")); return(Redirect(returnUrl)); } catch (Exception exc) { NotifyError(exc); Logger.Error(exc); return(Redirect(returnUrl)); } }
public ActionResult UploadPackage(string returnUrl = "") { var isTheme = false; var success = false; string message = null; string tempFile = ""; try { var file = Request.ToPostedFileResult(); if (file != null) { var requiredPermission = (isTheme = PackagingUtils.IsTheme(file.FileName)) ? Permissions.Configuration.Theme.Upload : Permissions.Configuration.Plugin.Upload; if (!Services.Permissions.Authorize(requiredPermission)) { message = T("Admin.AccessDenied.Description"); return(Json(new { success, file.FileName, message })); } if (!file.FileExtension.IsCaseInsensitiveEqual(".nupkg")) { return(Json(new { success, file.FileName, T("Admin.Packaging.NotAPackage").Text, returnUrl })); } var location = CommonHelper.MapPath("~/App_Data"); var appPath = CommonHelper.MapPath("~/"); if (isTheme) { // Avoid getting terrorized by IO events. _themeRegistry.Value.StopMonitoring(); } var packageInfo = _packageManager.Install(file.Stream, location, appPath); if (isTheme) { // Create manifest. if (packageInfo != null) { var manifest = ThemeManifest.Create(packageInfo.ExtensionDescriptor.Path); if (manifest != null) { _themeRegistry.Value.AddThemeManifest(manifest); } } // SOFT start IO events again. _themeRegistry.Value.StartMonitoring(false); } } else { return(Json(new { success, file.FileName, T("Admin.Common.UploadFile").Text, returnUrl })); } if (!isTheme) { message = T("Admin.Packaging.InstallSuccess").Text; Services.WebHelper.RestartAppDomain(); } else { message = T("Admin.Packaging.InstallSuccess.Theme").Text; } success = true; } catch (Exception ex) { message = ex.Message; Logger.Error(ex); } return(Json(new { success, tempFile, message, returnUrl })); }
void AssertIsValid(string path) { Assert.IsTrue(PackagingUtils.CheckEntryForPackaging(path), $"{path} should be valid"); }
void AssertIsNotValid(string path) { Assert.IsFalse(PackagingUtils.CheckEntryForPackaging(path), $"{path} should *not* be valid"); }