예제 #1
0
    public void printPluginsToPage(List<PluginDAO> plugins, Literal pageLiteral, string zeroPluginCountMessage)
    {
        StringBuilder pluginBuilder = new StringBuilder();
        if (0 == plugins.Count)
        {
            pluginBuilder.Append(zeroPluginCountMessage);
        }
        else
        {
            foreach (PluginDAO plugin in plugins)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(string.Format(@"<li><a href=""ManagePlugin.aspx?pluginname={1}"">{0} ",
                    HttpUtility.HtmlEncode(plugin.Name),
                    HttpUtility.HtmlEncode(HttpUtility.UrlEncode(plugin.Name))));
                if (plugin.IsDisabled)
                {
                    sb.Append(string.Format(@"<span class=""label label-important pull-right"">Disabled</span>"));
                }
                else
                {
                    try
                    {
                        IDBController controller = new SqlController();
                        int errorCount = controller.GetPluginFailedAttemptCount(plugin.PluginID);
                        if (errorCount > 0)
                            sb.Append(string.Format(@"<span class=""badge badge-important pull-right"">{0}</span>", HttpUtility.HtmlEncode(errorCount)));
                    }
                    catch (Exception)
                    {
                        // Shh... nothing but tears.
                    }
                }
                sb.Append(string.Format(@"</a></li>"));
                pluginBuilder.Append(sb.ToString());
            }
        }

        pageLiteral.Text = pluginBuilder.ToString();
    }
예제 #2
0
    private bool doPOST()
    {
        UserDAO user = (UserDAO)Session["userDAO"];
        String pluginName = Request.Form["pluginName"];

        String successMessage = "";

        if (pluginName == null)
        {
            // Redirect them back
            SendErrorMessage("Please specify a plugin");
            return false;
        }

        IDBController controller = new SqlController();
        PluginDAO plugin = null;
        try
        {
            plugin = controller.RetrievePlugin(pluginName);

            if (!plugin.OwnerID.Equals(user.UserID))
            {
                SendErrorMessage("That is not a plugin you have written.");
                return false;
            }
            else
            {
                // Go ahead and save it
                String luacodeFileLoc = LUADefinitions.getLuaScriptLocation(plugin.Name);

                // See if it's there
                if (File.Exists(luacodeFileLoc))
                {
                    String luacode = Request.Form["editorText"];
                    try
                    {
                        File.WriteAllText(luacodeFileLoc, luacode);
                        controller.ResetPluginFailedAttemptCount(plugin.PluginID);
                        if (controller.GetPluginFailedAttemptCount(plugin.PluginID) == 0)
                        {
                            // Reenable the plugin
                            controller.EnableGlobalPlugin(plugin.PluginID);
                        }
                        successMessage = "Plugin has been updated.";
                    }
                    catch (Exception)
                    {
                        SendErrorMessage("Could not save plugin.");
                        return false;
                    }
                }
                else
                {
                    SendErrorMessage("Could not save plugin.");
                    return false;
                }
            }
        }
        catch (CouldNotFindException)
        {
            SendErrorMessage("That is not a valid plugin");
            return false;
        }

        // Always redirect on POST
        Response.Redirect(string.Format("EditPlugin.aspx?pluginname={0}&success={1}", HttpUtility.UrlEncode(pluginName), HttpUtility.UrlEncode(successMessage)));

        return false;
    }