コード例 #1
0
        public object ItemEditSave(PluginAddress pluginAddress, PluginEditInput pluginEditInput, bool isEditingCode)
        {
            if (isEditingCode && !string.IsNullOrEmpty(pluginEditInput.VirtualPath))
            {
                pluginEditInput.VirtualPath.SaveFileText(pluginEditInput.Code, HttpContext);

                pluginEngine.ReloadPlugin(p => p.Tag == null && !(p.Tag is Plugin) && string.Compare(p.VirtualPath, pluginEditInput.VirtualPath, true) == 0, p => pluginEditInput.VirtualPath);

                return(EditNotInstalled(new PluginNotInstalledAddress(pluginEditInput.VirtualPath)));
            }

            ModelResult <Plugin> results = null;
            Plugin plugin = pluginService.GetPlugin(pluginAddress);

            if (isEditingCode && !string.IsNullOrEmpty(pluginEditInput.Code) && pluginEditInput.Code != plugin.GetFileText())
            {
                results = pluginService.EditPlugin(pluginAddress, pluginEditInput, true);
            }
            else if (!isEditingCode)
            {
                results = pluginService.EditPlugin(pluginAddress, pluginEditInput, false);
            }

            if (results != null && !results.IsValid)
            {
                ViewData["ValidationState"] = results.ValidationState;
            }

            if (isEditingCode || ViewData.ContainsKey("ValidationState"))
            {
                return(ItemEdit(pluginAddress, pluginEditInput));
            }

            return(Redirect(Url.Plugin(plugin)));
        }