本文整理汇总了C#中Connector.Query_Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Connector.Query_Execute方法的具体用法?C# Connector.Query_Execute怎么用?C# Connector.Query_Execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connector
的用法示例。
在下文中一共展示了Connector.Query_Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: cmsStart
public static string cmsStart(string pluginid, Connector conn)
{
// The directory where all of our files will be stored
downloadsPath = Core.basePath + "/_downloads";
// Check the local directory exists for downloads
if (!Directory.Exists(downloadsPath))
Directory.CreateDirectory(downloadsPath);
else
// Begin indexing pre-existing files for changes
indexMainFolder();
// Initialize file-watcher
watcherEnable();
// Check all the icons in the cache exist physically - else delete the db version
List<string> iconsFound = new List<string>();
StringBuilder deleteBuffer = new StringBuilder("DELETE FROM downloads_ext_icons WHERE ");
int dbLength = deleteBuffer.Length;
foreach (ResultRow icon in conn.Query_Read("SELECT extension FROM downloads_ext_icons"))
{
if (!File.Exists(Core.basePath + "\\Content\\Images\\downloads\\icons"))
deleteBuffer.Append("extension='" + Utils.Escape(icon["extension"]) + "' OR ");
else
iconsFound.Add(icon["extension"]);
}
if (deleteBuffer.Length != dbLength)
conn.Query_Execute(deleteBuffer.Remove(deleteBuffer.Length - 4, 4).Append(";").ToString());
// Add any new physical icons to the database
string ext;
Dictionary<string, object> attribs;
foreach (string file in Directory.GetFiles(Core.basePath + "\\Content\\Images\\downloads\\icons", "*.png", SearchOption.AllDirectories))
try
{
if (!iconsFound.Contains((ext = Path.GetFileNameWithoutExtension(file))))
{
attribs = new Dictionary<string, object>();
attribs.Add("extension", ext);
attribs.Add("icon", File.ReadAllBytes(file));
conn.Query_Execute_Parameters("INSERT INTO downloads_ext_icons (extension, icon) VALUES(@extension, @icon)", attribs);
}
}
catch { }
return null;
}
示例2: pageDownload_Move
public static void pageDownload_Move(string pluginid, Connector conn, ref Misc.PageElements pageElements, HttpRequest request, HttpResponse response, bool admin, ResultRow file)
{
if (!admin) return;
string error = null;
string folderid = request.Form["folderid"];
if (folderid != null)
{
// Validate the new folder
if (folderid.Length == 0)
error = "Invalid folder!";
else if (folderid == file["folderid"])
error = "The newly selected Folder is the same as the current folder!";
else
{
// Grab the folder's details to validate it exists
Result ff = conn.Query_Read("SELECT folderid, path, title FROM downloads_folders WHERE folderid='" + Utils.Escape(folderid) + "'");
if (ff.Rows.Count != 1)
error = "Folder does not exist!";
else
{
// Attempt to move the file, else we'll roll-back our actions and inform the user
try
{
string dest = ff[0]["path"] + (ff[0]["path"].Length > 0 ? "/" : string.Empty) + ff[0]["title"] + "/" + file["title"]; // Destination path of the file, including the filename
File.Move(downloadsPath.Replace("\\", "/") + "/" + file["physical_path"], downloadsPath.Replace("\\", "/") + "/" + dest);
conn.Query_Execute("UPDATE downloads_files SET folderid='" + Utils.Escape(ff[0]["folderid"]) + "', physical_path='" + Utils.Escape(dest) + "' WHERE downloadid='" + Utils.Escape(file["downloadid"]) + "'");
conn.Disconnect();
response.Redirect(pageElements["URL"] + "/download/" + file["downloadid"]);
}
catch(Exception ex)
{
error = "Failed to move file - " + ex.Message + " (" + ex.GetBaseException().Message + ") - " + ex.StackTrace + "!";
}
}
}
}
StringBuilder folders = new StringBuilder();
foreach (ResultRow folder in conn.Query_Read("SELECT folderid, CONCAT(CONCAT(path, '/'), title) AS path FROM downloads_folders ORDER BY path ASC"))
if(folder["folderid"] != file["folderid"])
folders.Append("<option value=\"").Append(folder["folderid"]).Append("\">").Append(HttpUtility.HtmlEncode(folder["path"])).Append("</option>");
// Render page
pageElements["CONTENT"] = Core.templates["downloads"]["download_move"]
.Replace("%ERROR%", error != null ? Core.templates[pageElements["TEMPLATE"]]["error"].Replace("<ERROR>", HttpUtility.HtmlEncode(error)) : string.Empty)
.Replace("%DOWNLOADID%", file["downloadid"])
.Replace("%FOLDERS%", folders.ToString());
pageElements["TITLE"] = "Download - " + HttpUtility.HtmlEncode(file["title"]) + " - Move";
}
示例3: pageProfile_Profile
public static void pageProfile_Profile(string pluginid, Connector conn, ref Misc.PageElements pageElements, HttpRequest request, HttpResponse response)
{
// Decide which user to display
string userid = null;
if (request.QueryString["userid"] != null) // Load via userid
{
// Ensure the userid is valid
if (conn.Query_Count("SELECT COUNT('') FROM bsa_users WHERE userid='" + Utils.Escape(request.QueryString["userid"]) + "'") != 1)
return;
userid = request.QueryString["userid"];
}
else if (request.QueryString["username"] != null) // Load via username
{
// Fetch the userid, if not found we'll 404 the request by returning
Result usernameToUserid = conn.Query_Read("SELECT userid FROM bsa_users WHERE username LIKE '" + Utils.Escape(request.QueryString["username"].Replace("%", "")) + "'");
if (usernameToUserid.Rows.Count != 1) return;
userid = usernameToUserid[0]["userid"];
}
else if (HttpContext.Current.User.Identity.IsAuthenticated) // Load the current logged-in user
userid = HttpContext.Current.User.Identity.Name;
else // No user specified, user is not authenticated - tell them to register
response.Redirect(pageElements["URL"] + "/register", true);
// By this point the userid should be valid and exist, hence we just need to grab the profile data
string rawProfileDataQuery = "SELECT p.*, u.username, u.registered, g.title AS group_title, g.access_admin FROM bsa_profiles AS p LEFT OUTER JOIN bsa_users AS u ON u.userid=p.userid LEFT OUTER JOIN bsa_user_groups AS g ON g.groupid=u.groupid WHERE p.userid='" + Utils.Escape(userid) + "'";
Result rawProfileData = conn.Query_Read(rawProfileDataQuery);
if (rawProfileData.Rows.Count == 0) // Profile doesn't exist, create it
{
conn.Query_Execute("INSERT INTO bsa_profiles (userid) VALUES('" + Utils.Escape(userid) + "')");
rawProfileData = conn.Query_Read(rawProfileDataQuery);
if (rawProfileData.Rows.Count == 0) return; // Something is wrong...
}
ResultRow profileData = rawProfileData[0];
// Check if admin or the owner of the profile - if so, we'll set the PROFILE_OWNER FLAG
bool owner = false;
if (HttpContext.Current.User.Identity.IsAuthenticated && (profileData["userid"] == HttpContext.Current.User.Identity.Name))
{
pageElements.setFlag("PROFILE_OWNER");
owner = true;
}
// Check the user is allowed to access the profile - if it's disabled, only the owner or an admin can access it
if (!owner && !profileData["disabled"].Equals("0"))
return;
// Check which page the user wants to access
switch (request.QueryString["1"])
{
default:
// -- About page is default
pageProfile_About(pluginid, ref profileData, conn, ref pageElements, request, response);
break;
case "settings":
pageProfile_Settings(pluginid, ref rawProfileDataQuery, ref profileData, conn, ref pageElements, request, response);
break;
case "upload":
pageProfile_Upload(pluginid, ref profileData, conn, ref pageElements, request, response);
break;
}
if (pageElements["PROFILE_CONTENT"] == null) return; // No content set, 404..
// Build frame
DateTime registered = profileData["registered"].Length > 0 ? DateTime.Parse(profileData["registered"]) : DateTime.MinValue;
pageElements["CONTENT"] =
Core.templates["bsa_profiles"]["profile_frame"]
.Replace("<USERID>", HttpUtility.HtmlEncode(profileData["userid"]))
.Replace("<PANE_BG_COLOUR>", profileData["colour_background"])
.Replace("<PANE_TEXT_COLOUR>", profileData["colour_text"])
.Replace("<BACKGROUND>", (profileData["background_url"].Length > 0 ? "url('" + HttpUtility.HtmlEncode(profileData["background_url"]) + "') " : string.Empty) + (profileData["background_colour"].Length > 0 ? "#" + profileData["background_colour"] : string.Empty))
.Replace("<USERNAME>", HttpUtility.HtmlEncode(profileData["username"]))
.Replace("<GROUP>", HttpUtility.HtmlEncode(profileData["group_title"]))
.Replace("<REGISTERED>", HttpUtility.HtmlEncode(registered.ToString("dd MMMM yyyy")))
.Replace("<REGISTERED_DAYS>", HttpUtility.HtmlEncode(Misc.Plugins.getTimeString(registered)))
.Replace("<COUNTRY_FLAG>", profileData["country_code"].Length > 0 ? profileData["country_code"] : "unknown")
.Replace("<COUNTRY_TITLE>", Common.Country.getCountryTitle(profileData["country_code"], conn) ?? "Unknown")
.Replace("<GENDER_CODE>", profileData["gender"])
.Replace("<GENDER>", profileData["gender"] == "1" ? "Male" : profileData["gender"] == "2" ? "Female" : "Not specified.")
.Replace("<OCCUPATION>", profileData["occupation"].Length > 0 ? HttpUtility.HtmlEncode(profileData["occupation"]) : "Not specified.");
;
pageElements["TITLE"] = "Profile - " + HttpUtility.HtmlEncode(profileData["username"]);
}
示例4: adminPage_Uninstall
public static void adminPage_Uninstall(string classpath, string method, Connector conn)
{
conn.Query_Execute("DELETE FROM admin_panel_pages WHERE classpath='" + Utils.Escape(classpath) + "' AND method='" + Utils.Escape(method) + "'");
}
示例5: addAlert
/// <summary>
/// Adds a notification/alert to the homepage of the admin panel; this is useful in the event of
/// a serious error or issue arising, as a way to inform the site administrator.
///
/// Maximum length is 255 bytes (TINYTEXT).
/// </summary>
/// <param name="conn"></param>
/// <param name="message"></param>
public static void addAlert(Connector conn, string message)
{
conn.Query_Execute("INSERT INTO admin_alerts (message, datetime) VALUES('" + Utils.Escape(message) + "', NOW())");
}
示例6: pageSettings
public static void pageSettings(Connector conn, ref Misc.PageElements pageElements, HttpRequest request, HttpResponse response)
{
string error = null;
bool successfullyUpdated = false;
// Check if the user has requested to delete a setting
string deleteCategory = request.QueryString["delete_category"];
string deleteKey = request.QueryString["delete_key"];
if (deleteCategory != null && deleteKey != null)
{
conn.Query_Execute("DELETE FROM settings WHERE category='" + Utils.Escape(deleteCategory) + "' AND keyname='" + Utils.Escape(deleteKey) + "'");
response.Redirect(pageElements["ADMIN_URL"]);
}
// Check if the user has posted updated settings
Dictionary<string[], string> updatedSettings = new Dictionary<string[], string>();
string category, key, value;
string[] rawKey;
for (int i = 0; i < request.Form.Count; i++)
{
rawKey = request.Form.Keys[i].Split('$');
value = request.Form[i];
if (rawKey.Length == 2 && rawKey[0].StartsWith("setting_") && rawKey[0].Length > 10 && validateAlphaNumericUnderscroll(key = rawKey[0].Substring(8)))
updatedSettings.Add(new string[] { key, rawKey[1] }, value);
}
if (updatedSettings.Count > 0)
{
StringBuilder updateQuery = new StringBuilder();
foreach (KeyValuePair<string[], string> setting in updatedSettings)
updateQuery.Append("UPDATE settings SET value='" + Utils.Escape(setting.Value) + "' WHERE category='" + Utils.Escape(setting.Key[0]) + "' AND keyname='" + Utils.Escape(setting.Key[1]) + "';");
try
{
conn.Query_Execute(updateQuery.ToString());
successfullyUpdated = true;
// Reload settings
Core.settings.reload(conn);
}
catch (Exception ex)
{
error = "Failed to update settings - " + ex.Message + "!";
}
}
// Display the settings
StringBuilder settingItems = new StringBuilder();
category = null;
foreach (ResultRow setting in conn.Query_Read("SELECT category, keyname, value, description FROM settings ORDER BY category ASC, keyname ASC"))
{
if (setting["category"] != category)
{
category = setting["category"];
settingItems.Append(
Core.templates["admin_panel"]["settings_category"]
.Replace("%CATEGORY%", HttpUtility.HtmlEncode(category))
);
}
settingItems.Append(
Core.templates["admin_panel"]["settings_item"]
.Replace("%KEYNAME%", HttpUtility.HtmlEncode(setting["keyname"]))
.Replace("%KEYNAME_URL%", HttpUtility.UrlEncode(setting["keyname"]))
.Replace("%CATEGORY%", HttpUtility.HtmlEncode(setting["category"]))
.Replace("%CATEGORY_URL%", HttpUtility.UrlEncode(setting["category"]))
.Replace("%VALUE%", HttpUtility.HtmlEncode(request.Form["setting_" + setting["keyname"]] ?? setting["value"]))
.Replace("%DESCRIPTION%", HttpUtility.HtmlEncode(setting["description"]))
);
}
pageElements["ADMIN_CONTENT"] =
Core.templates["admin_panel"]["settings"]
.Replace("%ITEMS%", settingItems.ToString())
.Replace("%SUCCESS%", successfullyUpdated ? Core.templates[pageElements["TEMPLATE"]]["success"].Replace("<SUCCESS>", "Successfully saved settings!") : string.Empty)
.Replace("%ERROR%", error != null ? Core.templates[pageElements["TEMPLATE"]]["error"].Replace("<ERROR>", HttpUtility.HtmlEncode(error)) : string.Empty);
pageElements["ADMIN_TITLE"] = "Core - Settings";
}
示例7: removeCategory
/// <summary>
/// Removes all of the settings associated with a pluginid.
/// </summary>
/// <param name="conn"></param>
/// <param name="pluginid"></param>
public void removeCategory(Connector conn, string category)
{
lock (categories)
{
conn.Query_Execute("DELETE FROM settings WHERE category='" + Utils.Escape(category) + "'");
reload(conn);
}
}
示例8: pageRegister
/// <summary>
/// Used to register new accounts; this supports activation as well.
/// </summary>
/// <param name="pluginid"></param>
/// <param name="conn"></param>
/// <param name="pageElements"></param>
/// <param name="request"></param>
/// <param name="response"></param>
private static void pageRegister(string pluginid, Connector conn, ref Misc.PageElements pageElements, HttpRequest request, HttpResponse response)
{
switch (request.QueryString["1"])
{
case "success":
// Check which template to display - welcome or activation-required
bool activationNeeded = conn.Query_Scalar("SELECT access_login FROM bsa_user_groups WHERE groupid='" + Utils.Escape(Core.settings[SETTINGS_CATEGORY][SETTINGS_USER_GROUP_DEFAULT]) + "'").ToString().Equals("0");
if (activationNeeded)
{
pageElements["TITLE"] = "Register - Success - Verification Required";
pageElements["CONTENT"] = Core.templates["basic_site_auth"]["register_success_activate"];
// Add CSS file
Misc.Plugins.addHeaderCSS("/Content/CSS/BasicSiteAuth.css", ref pageElements);
}
else
{
pageElements["TITLE"] = "Register - Success";
pageElements["CONTENT"] = Core.templates["basic_site_auth"]["register_success"];
// Add CSS file
Misc.Plugins.addHeaderCSS("/Content/CSS/BasicSiteAuth.css", ref pageElements);
}
break;
case "activate":
case "deactivate":
bool activate = request.QueryString["1"].Equals("activate");
string dkey = request.QueryString["key"];
if (dkey != null)
{
// Locate the user-group associated with the key
Result res = conn.Query_Read("SELECT a.keyid, a.userid, u.groupid, u.username FROM bsa_activations AS a LEFT OUTER JOIN bsa_users AS u ON u.userid=a.userid");
// Ensure the condition is valid
if (res.Rows.Count == 1 && res[0]["groupid"] == Core.settings[SETTINGS_CATEGORY][SETTINGS_USER_GROUP_DEFAULT])
{
// Ensure the user wants to activate/deactivate their account
if (request.Form["confirm"] == null)
{
if (activate)
{
pageElements["TITLE"] = "Register - Activate Account";
pageElements["CONTENT"] = Core.templates["basic_site_auth"]["activate"]
.Replace("%KEY%", request.QueryString["key"])
.Replace("%USERNAME%", HttpUtility.HtmlEncode(res[0]["username"]));
}
else
{
pageElements["TITLE"] = "Register - Deactivate Account";
pageElements["CONTENT"] = Core.templates["basic_site_auth"]["deactivate"]
.Replace("%KEY%", request.QueryString["key"])
.Replace("%USERNAME%", HttpUtility.HtmlEncode(res[0]["username"]));
}
// Add CSS file
Misc.Plugins.addHeaderCSS("/Content/CSS/BasicSiteAuth.css", ref pageElements);
}
else
{
if (activate)
{
// Remove the activation key and change the groupid
conn.Query_Execute("DELETE FROM bsa_activations WHERE keyid='" + Utils.Escape(res[0]["keyid"]) + "'; UPDATE bsa_users SET groupid='" + Utils.Escape(Core.settings[SETTINGS_CATEGORY][SETTINGS_USER_GROUP_USER]) + "' WHERE userid='" + Utils.Escape(res[0]["userid"]) + "';");
// Log the event
logEvent(res[0]["userid"], LogEvents.Registration_Activated, request.UserHostAddress, conn);
// Display confirmation
pageElements["TITLE"] = "Account Activated";
pageElements["CONTENT"] = Core.templates["basic_site_auth"]["activate_success"];
}
else
{
// Delete the account
conn.Query_Execute("DELETE FROM bsa_users WHERE userid='" + Utils.Escape(res[0]["userid"]) + "';");
// Display confirmation
pageElements["TITLE"] = "Account Deactivated";
pageElements["CONTENT"] = Core.templates["basic_site_auth"]["deactivate_success"];
}
// Add CSS file
Misc.Plugins.addHeaderCSS("/Content/CSS/BasicSiteAuth.css", ref pageElements);
}
}
}
break;
case null:
string error = null;
string username = request.Form["username"];
string password = request.Form["password"];
string confirmPassword = request.Form["confirm_password"];
string email = request.Form["email"];
string secretQuestion = request.Form["secret_question"];
string secretAnswer = request.Form["secret_answer"];
string captcha = request.Form["captcha"];
if (username != null && password != null && confirmPassword != null && email != null && secretQuestion != null && secretAnswer != null)
{
// Validate
if (!Common.Validation.validCaptcha(captcha))
//.........这里部分代码省略.........
示例9: uninstall
/// <summary>
/// Completely uninstalls a plugin.
/// </summary>
/// <param name="pluginid"></param>
/// <param name="deletePath">If true, the physical files for the plugin will be removed; if false, the plugin's database entry will remain for later installation with the physical files.</param>
/// <param name="conn"></param>
/// <returns></returns>
public static string uninstall(string pluginid, bool deletePath, Connector conn)
{
// Check if the plugin is enabled - else disable it
Result info = conn.Query_Read("SELECT state, directory, classpath FROM plugins WHERE pluginid='" + pluginid + "'");
if (info.Rows.Count != 1) return "Plugin does not exist!";
bool enabled = true;
try
{
enabled = (UberCMS.Plugins.Base.State)int.Parse(info[0]["state"]) == UberCMS.Plugins.Base.State.Enabled;
}
catch(Exception ex)
{
return "Could not determine state of plugin - " + ex.Message + "!";
}
if (enabled)
try
{
// Attempt to disable the plugin - else we'll continue the uninstallation process
disable(pluginid, conn);
}
catch
{
conn.Query_Execute("UPDATE plugins SET state='" + (int)UberCMS.Plugins.Base.State.Disabled + "' WHERE pluginid='" + Utils.Escape(pluginid) + "'");
}
// Attempt to invoke the uninstall method
try
{
string error = (string)invokeMethodReturn(info[0]["classpath"], "uninstall", new object[] { pluginid, conn });
if (error != null) return error;
}
catch (Exception ex)
{
return "Failed to uninstall plugin - " + ex.Message + " - " + ex.GetBaseException().Message + "!";
}
if (deletePath)
{
// Remove folder and database entry
try
{
Directory.Delete(Core.basePath + "\\App_Code\\Plugins\\" + info[0]["directory"], true);
}
catch (Exception ex)
{
return "Critical failure - failed to delete directory - " + ex.Message + "!";
}
conn.Query_Execute("DELETE FROM plugins WHERE pluginid='" + Utils.Escape(pluginid) + "'");
}
else
{
// Update the plugin to uninstalled
conn.Query_Execute("UPDATE plugins SET state='" + (int)UberCMS.Plugins.Base.State.Uninstalled + "' WHERE pluginid='" + Utils.Escape(pluginid) + "'");
}
return null;
}
示例10: templatesUninstall
/// <summary>
/// Uninstalls templates based on their pkey/parent-key and reloads the template collection.
/// </summary>
/// <param name="pkey"></param>
/// <param name="conn"></param>
/// <returns></returns>
public static string templatesUninstall(string pkey, Connector conn)
{
try
{
conn.Query_Execute("DELETE FROM html_templates WHERE pkey='" + Utils.Escape(pkey) + "'");
Core.templates.reloadDb(conn);
}
catch (Exception ex)
{
return "Error occurred uninstalling templates - '" + pkey + "' - " + ex.Message;
}
return null;
}
示例11: reserveURLs
/// <summary>
/// Reserves a specified array of URLs for a plugin.
/// </summary>
/// <param name="pluginid"></param>
/// <param name="parent"></param>
/// <param name="urls"></param>
/// <param name="conn"></param>
/// <returns></returns>
public static string reserveURLs(string pluginid, string parent, string[] urls, Connector conn)
{
// Check we have URLs to actually reserve
if (urls.Length == 0) return null;
try
{
// Build query
string escapedPluginid = Utils.Escape(pluginid);
string escapedParent = parent != null ? "'" + Utils.Escape(parent) + "'" : "NULL";
StringBuilder statement = new StringBuilder("INSERT INTO urlrewriting (pluginid, parent, title) VALUES");
foreach (string url in urls)
statement.Append("('" + escapedPluginid + "', " + escapedParent + ", '" + Utils.Escape(url) + "'),");
statement.Remove(statement.Length - 1, 1);
// Insert into the database
conn.Query_Execute(statement.ToString());
return null;
}
catch (Exception ex)
{
return "Failed to reserve URLs - " + ex.Message + " - " + ex.GetBaseException().Message + "!";
}
}
示例12: install
//.........这里部分代码省略.........
doc.LoadXml(File.ReadAllText(tempPath + "\\Config.xml"));
}
catch (Exception ex)
{
try { Directory.Delete(tempPath, true); } catch { }
return "Could not load plugin configuration - " + ex.Message + "!";
}
}
else
{
try
{
doc.LoadXml(File.ReadAllText(basePath + "\\Config.xml"));
}
catch (Exception ex)
{
return "Could not load plugin configuration - " + ex.Message + "!";
}
}
// Read config values if pluginid is null
string directory;
string title;
string classpath;
string cycleInterval;
string invokeOrder;
bool handles404;
bool handlesRequestStart;
bool handlesRequestEnd;
if (pluginid == null)
try
{
directory = doc["settings"]["directory"].InnerText;
title = doc["settings"]["title"].InnerText;
classpath = doc["settings"]["classpath"].InnerText;
cycleInterval = doc["settings"]["cycle_interval"].InnerText;
invokeOrder = doc["settings"]["invoke_order"].InnerText;
handles404 = doc["settings"]["handles_404"].InnerText.Equals("1");
handlesRequestStart = doc["settings"]["handles_request_start"].InnerText.Equals("1");
handlesRequestEnd = doc["settings"]["handles_request_end"].InnerText.Equals("1");
}
catch (Exception ex)
{
if (pathIsZipFile)
try { Directory.Delete(tempPath, true); }
catch { }
return "Could not read configuration, it's most likely a piece of data is missing; this could be a plugin designed for a different version of Uber CMS - " + ex.Message + "!";
}
else
{
directory = title = classpath = cycleInterval = invokeOrder = null;
handles404 = handlesRequestStart = handlesRequestEnd = false;
}
if (pathIsZipFile)
{
// Check plugin directory doesn't exist
pluginDir = Core.basePath + "\\App_code\\Plugins\\" + directory;
if (Directory.Exists(pluginDir))
{
try { Directory.Delete(tempPath, true); }
catch { }
return "Failed to create new plugin directory - '" + pluginDir + "' already exists! The plugin may already be installed...";
}
// Move extracted directory
try
{
Directory.Move(tempPath, pluginDir);
}
catch (Exception ex)
{
try { Directory.Delete(tempPath, true); }
catch { }
return "Failed to move extracted directory '" + tempPath + "' to '" + pluginDir + "' - " + ex.Message + "!";
}
}
// Update the database
try
{
if (pluginid == null) // Insert if the pluginid is null, else we'll just update the status
finalPluginid = conn.Query_Scalar("INSERT INTO plugins (title, directory, classpath, cycle_interval, invoke_order, state, handles_404, handles_request_start, handles_request_end) VALUES('" + Utils.Escape(title) + "', '" + Utils.Escape(directory) + "', '" + Utils.Escape(classpath) + "', '" + Utils.Escape(cycleInterval) + "', '" + Utils.Escape(invokeOrder) + "', '" + (int)(UberCMS.Plugins.Base.State.Disabled) + "', '" + (handles404 ? "1" : "0") + "', '" + (handlesRequestStart ? "1" : "0") + "', '" + (handlesRequestEnd ? "1" : "0") + "'); SELECT LAST_INSERT_ID();").ToString();
else
{
conn.Query_Execute("UPDATE plugins SET state='" + (int)UberCMS.Plugins.Base.State.Disabled + "' WHERE pluginid='" + Utils.Escape(pluginid) + "'");
finalPluginid = pluginid;
}
}
catch (Exception ex)
{
if (pathIsZipFile)
{
// Delete the directory we copied - error occurred during installation, no point of wasting space/risking probabal future issues
try
{
Directory.Delete(pluginDir, true);
}
catch { }
}
return "Failed to insert plugin into database - " + ex.Message + " - " + ex.GetBaseException().Message + "!";
}
return null;
}
示例13: executeSQL
/// <summary>
/// Executes an SQL query file.
/// </summary>
/// <param name="path"></param>
/// <param name="conn"></param>
/// <returns></returns>
public static string executeSQL(string path, Connector conn)
{
try
{
if (!File.Exists(path))
throw new Exception("SQL script '" + path + "' could not be found!");
else
{
StringBuilder statements = new StringBuilder();
// Build the new list of statements to be executed by stripping out any comments
string data = File.ReadAllText(path).Replace("\r", string.Empty);
int commentIndex;
foreach (string line in data.Split('\n'))
{
commentIndex = line.IndexOf("--");
if (commentIndex == -1)
statements.Append(line).Append("\r\n");
else if (commentIndex < line.Length)
statements.Append(line.Substring(0, commentIndex)).Append("\r\n");
}
// Execute the statements
conn.Query_Execute(statements.ToString());
return null;
}
}
catch (Exception ex)
{
return "Failed to execute SQL file '" + path + "' - " + ex.Message + " - " + ex.GetBaseException().Message + "!";
}
}
示例14: enable
/// <summary>
/// Enables a plugin.
/// </summary>
/// <param name="pluginid"></param>
/// <param name="conn"></param>
/// <returns></returns>
public static string enable(string pluginid, Connector conn)
{
// Grab classpath
Result info = conn.Query_Read("SELECT classpath FROM plugins WHERE pluginid='" + Utils.Escape(pluginid) + "'");
if (info.Rows.Count != 1)
return "Plugin does not exist!";
// Invoke enable method
try
{
string result = (string)invokeMethodReturn(info[0]["classpath"], "enable", new object[] { pluginid, conn });
if (result != null) return result;
}
catch (Exception ex)
{
return "Failed to enable plugin - " + ex.Message + " - " + ex.GetBaseException().Message + " - " + ex.GetBaseException().StackTrace + "!";
}
// Update status
conn.Query_Execute("UPDATE plugins SET state='" + (int)UberCMS.Plugins.Base.State.Enabled + "' WHERE pluginid='" + Utils.Escape(pluginid) + "'");
// Restart the core
Core.cmsStop();
Core.cmsStart();
return null;
}
示例15: pageDownload_ResetDownloads
public static void pageDownload_ResetDownloads(string pluginid, Connector conn, ref Misc.PageElements pageElements, HttpRequest request, HttpResponse response, bool admin, ResultRow file)
{
if (request.Form["confirm"] != null)
{
conn.Query_Execute("DELETE FROM downloads WHERE downloadid='" + Utils.Escape(file["downloadid"]) + "'");
conn.Disconnect();
response.Redirect(pageElements["URL"] + "/download/" + file["downloadid"]);
}
pageElements["CONTENT"] = Core.templates["downloads"]["download_reset"]
.Replace("%DOWNLOADID%", file["downloadid"]);
pageElements["TITLE"] = "Download - " + HttpUtility.HtmlEncode(file["title"]) + " - Reset Downloads";
}