Added a new structor to help make getting file and folder information much easier.

This commit is contained in:
Admin
2020-11-13 13:16:06 -06:00
parent 0af7111d08
commit cc3c87cb5d
6 changed files with 409 additions and 89 deletions
+87
View File
@@ -347,6 +347,80 @@ namespace DataOrganizer
return true;
}
public List<FileSnapshot> GetFilesForProfileByFolderGroup(int profileId, int folderGroupId)
{
var files = new List<FileSnapshot>();
var query = @"SELECT * FROM main.file INNER JOIN main.folder_root ON main.file.folder_root_id = main.folder_root.root_id WHERE main.file.profile_id = @ProfileId AND folder_root_id = @GroupId ORDER BY main.file.full_path ASC";
using (var connection = new SqliteConnection(ConnectionString))
{
using (var command = new SqliteCommand(query, connection))
{
command.Parameters.AddWithValue("ProfileId", profileId);
command.Parameters.AddWithValue("GroupId", folderGroupId);
connection.Open();
var reader = command.ExecuteReader();
while(reader.Read())
{
var fullPath = string.Format("{0}{1}", reader["path"], reader["full_path"]);
files.Add(new FileSnapshot
{
Id = Convert.ToInt32(reader["file_id"]),
FullPath = fullPath,
Name = reader["name"].ToString(),
ProfileId = profileId,
RootFolderId = folderGroupId,
Size = Convert.ToInt64(reader["size"]),
CreationDate = Convert.ToDateTime(reader["date_created"]),
ModifiedDate = Convert.ToDateTime(reader["date_modified"]),
PatternId = Convert.ToInt32(reader["pattern_override_id"])
});
}
}
}
return files;
}
public void InsertNewFileRecord(List<FileSnapshot> files, int profileId, int folderGroupId, string root)
{
var query = @"INSERT INTO main.file (full_path, name, size, date_created, date_modified, folder_root_id, profile_id, pattern_override_id) VALUES (@FullPath, @Name, @Size, @DateCreated, @DateModified, @FolderId, @ProfileId, @PatternId)";
var rootLength = root.Length;
using (var connection = new SqliteConnection(ConnectionString))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
using (var command = new SqliteCommand(query, connection, transaction))
{
foreach (var file in files)
{
command.Parameters.AddWithValue("FullPath", file.FullPath.Remove(0, rootLength));
command.Parameters.AddWithValue("Name", file.Name);
command.Parameters.AddWithValue("Size", file.Size);
command.Parameters.AddWithValue("DateCreated", file.CreationDate);
command.Parameters.AddWithValue("DateModified", file.ModifiedDate);
command.Parameters.AddWithValue("FolderId", folderGroupId);
command.Parameters.AddWithValue("ProfileId", profileId);
command.Parameters.AddWithValue("PatternId", file.PatternId);
command.ExecuteNonQuery();
command.Parameters.Clear();
}
}
transaction.Commit();
}
}
}
public struct Profile
{
public string Name;
@@ -371,5 +445,18 @@ namespace DataOrganizer
public string ExampleText;
public string Regex;
}
public struct FileSnapshot
{
public int Id;
public string FullPath;
public string Name;
public int ProfileId;
public int PatternId;
public int RootFolderId;
public DateTime CreationDate;
public DateTime ModifiedDate;
public long Size;
}
}
}