public ActionResult UploadPlugin() { try { AdminPluginsModel m = new AdminPluginsModel(); //TODO: do not directly access request object foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) throw new Exception("Empty file uploaded"); LogService.Info("Plugin uploaded filename={0} contentType={1} contentLength={2}", hpf.FileName, hpf.ContentType, hpf.ContentLength); PluginState ps = AdminService.LoadAndInstallPlugin(hpf.InputStream, Path.GetFileName(hpf.FileName), hpf.ContentType, Server.MapPath("~/")); if (ps.Status == PluginStatus.Incompatible) m.Notifications.Add("Warning,", "the plugin was successfully uploaded but not installed because it " + "may not be compatible. If you'd like to proceed, you can <strong>force</strong> the installation."); m.ChangedType = ps.Type; } m.Plugins = AdminService.GetPlugins(); TempData["model"] = m; } catch (Exception ex) { LogService.Error(ex); TempData["error"] = ex.Message; } return RedirectToAction("Plugins"); }
public ViewResult Plugins() { AdminPluginsModel m = TempData["model"] as AdminPluginsModel; if (m == null) { m = new AdminPluginsModel(); m.Plugins = AdminService.GetPlugins(); if (TempData["error"] != null) m.Errors.Add((string)TempData["error"]); } return View("AdminPlugins", "Admin", m); }
protected ActionResult PluginAction(Action action, string type, string message) { try { action(); //return a refreshed view of plugins AdminPluginsModel m = new AdminPluginsModel(); m.Plugins = AdminService.GetPlugins(); m.ChangedType = type; m.MessageForType = message; return PartialView("AdminPluginListing", m); } catch (Exception ex) { LogService.Error(ex); return Json(new { success = false, error = ex.Message }); } }