internal static LocalDirectory[] ListByParentId(Nullable <int> parent_id) { return(Core.FileSystem.UseConnection <LocalDirectory[]>(delegate(IDbConnection connection) { IDbCommand command = connection.CreateCommand(); string query = null; if (parent_id.Equals(null)) { query = "SELECT * FROM directoryitems WHERE parent_id ISNULL AND type = 'D'"; } else { query = "SELECT * FROM directoryitems WHERE parent_id = @parent_id AND type = 'D'"; Core.FileSystem.AddParameter(command, "@parent_id", (int)parent_id); } command.CommandText = query; DataSet ds = Core.FileSystem.ExecuteDataSet(command); LocalDirectory[] results = new LocalDirectory[ds.Tables[0].Rows.Count]; for (int x = 0; x < ds.Tables[0].Rows.Count; x++) { results[x] = LocalDirectory.FromDataRow(ds.Tables[0].Rows[x]); } return results; })); }
public LocalDirectory GetLocalDirectory(string path) { if (path.Length > 1 && path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); } string[] parts = path.Split('/'); if (parts.Length < 3) { return((LocalDirectory)GetDirectory(path)); } else { return(UseConnection <LocalDirectory>(delegate(IDbConnection connection) { string query = "SELECT * FROM directoryitems WHERE type = 'D' AND full_path = @full_path LIMIT 1"; IDbCommand command = connection.CreateCommand(); command.CommandText = query; AddParameter(command, "@full_path", path); DataSet data = ExecuteDataSet(command); if (data.Tables[0].Rows.Count > 0) { return LocalDirectory.FromDataRow(data.Tables[0].Rows[0]); } else { return null; } })); } }
public SearchResultInfo SearchFiles(string query) { IDbCommand command; DataSet ds; int x; SearchResultInfo result; var directories = new List <string>(); var files = new List <SharedFileListing>(); result = new SearchResultInfo(); var queryNode = UserQueryParser.Parse(query, FieldSet); var queryFragment = queryNode.ToSql(FieldSet); var sb = new StringBuilder(); sb.Append("SELECT * FROM directoryitems WHERE "); sb.Append(queryFragment); sb.AppendFormat(" LIMIT {0}", MAX_RESULTS.ToString()); UseConnection(connection => { command = connection.CreateCommand(); command.CommandText = sb.ToString(); ds = ExecuteDataSet(command); for (x = 0; x < ds.Tables[0].Rows.Count; x++) { if (ds.Tables[0].Rows[x]["type"].ToString() == "F") { files.Add(new SharedFileListing(LocalFile.FromDataRow(ds.Tables[0].Rows[x]), false)); } else { LocalDirectory dir = LocalDirectory.FromDataRow(ds.Tables[0].Rows[x]); // FIXME: Ugly: Remove '/local' from begining of path string path = "/" + string.Join("/", dir.FullPath.Split('/').Slice(2)); directories.Add(path); } } }); result.Files = files.ToArray(); result.Directories = directories.ToArray(); return(result); }
public static LocalDirectory ById(int id) { return(Core.FileSystem.UseConnection <LocalDirectory>(delegate(IDbConnection connection) { IDbCommand cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM directoryitems WHERE id=@id AND type = 'D' LIMIT 1"; Core.FileSystem.AddParameter(cmd, "@id", id); DataSet ds = Core.FileSystem.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { return LocalDirectory.FromDataRow(ds.Tables[0].Rows[0]); } else { return null; } })); }