public static NewQuery ( ICommandBuilder builder ) : |
||
builder | ICommandBuilder | The command builder. |
Résultat |
/// <summary> /// Lists the stored plugin assemblies. /// </summary> public string[] ListPluginAssemblies() { ICommandBuilder builder = GetCommandBuilder(); // Sort order is not relevant string query = QueryBuilder.NewQuery(builder).SelectFrom("PluginAssembly", new string[] { "Name" }); DbCommand command = builder.GetCommand(connString, query, new List <Parameter>()); DbDataReader reader = ExecuteReader(command); if (reader != null) { List <string> result = new List <string>(10); while (reader.Read()) { result.Add(reader["Name"] as string); } CloseReader(command, reader); return(result.ToArray()); } else { return(null); } }
/// <summary> /// Gets the all the setting values. /// </summary> /// <returns>All the settings.</returns> public IDictionary <string, string> GetAllSettings() { ICommandBuilder builder = GetCommandBuilder(); // Sorting order is not relevant string query = QueryBuilder.NewQuery(builder).SelectFrom("GlobalSetting"); DbCommand command = builder.GetCommand(connString, query, new List <Parameter>()); DbDataReader reader = ExecuteReader(command); if (reader != null) { Dictionary <string, string> result = new Dictionary <string, string>(50); while (reader.Read()) { result.Add(reader["Name"] as string, reader["Value"] as string); } CloseReader(command, reader); return(result); } else { return(null); } }
/// <summary> /// Clear the Log. /// </summary> public void ClearLog() { ICommandBuilder builder = GetCommandBuilder(); string query = QueryBuilder.NewQuery(builder).DeleteFrom("Log"); DbCommand command = builder.GetCommand(connString, query, new List <Parameter>()); ExecuteNonQuery(command); }
/// <summary> /// Stores a plugin's assembly, overwriting existing ones if present. /// </summary> /// <param name="filename">The file name of the assembly, such as "Assembly.dll".</param> /// <param name="assembly">The assembly content.</param> /// <returns><c>true</c> if the assembly is stored, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">If <b>filename</b> or <b>assembly</b> are <c>null</c>.</exception> /// <exception cref="ArgumentException">If <b>filename</b> or <b>assembly</b> are empty.</exception> public bool StorePluginAssembly(string filename, byte[] assembly) { if (filename == null) { throw new ArgumentNullException("filename"); } if (filename.Length == 0) { throw new ArgumentException("Filename cannot be empty", "filename"); } if (assembly == null) { throw new ArgumentNullException("assembly"); } if (assembly.Length == 0) { throw new ArgumentException("Assembly cannot be empty", "assembly"); } if (assembly.Length > MaxAssemblySize) { throw new ArgumentException("Assembly is too big", "assembly"); } // 1. Delete old plugin assembly, if any // 2. Store new assembly ICommandBuilder builder = GetCommandBuilder(); DbConnection connection = builder.GetConnection(connString); DbTransaction transaction = BeginTransaction(connection); DeletePluginAssembly(transaction, filename); string query = QueryBuilder.NewQuery(builder).InsertInto("PluginAssembly", new string[] { "Name", "Assembly" }, new string[] { "Name", "Assembly" }); List <Parameter> parameters = new List <Parameter>(2); parameters.Add(new Parameter(ParameterType.String, "Name", filename)); parameters.Add(new Parameter(ParameterType.ByteArray, "Assembly", assembly)); DbCommand command = builder.GetCommand(transaction, query, parameters); int rows = ExecuteNonQuery(command, false); if (rows == 1) { CommitTransaction(transaction); } else { RollbackTransaction(transaction); } return(rows == 1); }