-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new interface and class for storing the include folders
- Loading branch information
Kevin Willford
committed
Aug 5, 2019
1 parent
aa786f9
commit f3527b6
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace GVFS.Common.Database | ||
{ | ||
public interface IIncludedFolderCollection | ||
{ | ||
List<string> GetAll(); | ||
|
||
void Add(string directory); | ||
void Remove(string directory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace GVFS.Common.Database | ||
{ | ||
public class IncludedFolderTable : IIncludedFolderCollection | ||
{ | ||
private IGVFSConnectionPool connectionPool; | ||
|
||
public IncludedFolderTable(IGVFSConnectionPool connectionPool) | ||
{ | ||
this.connectionPool = connectionPool; | ||
} | ||
|
||
public static void CreateTable(IDbConnection connection) | ||
{ | ||
using (IDbCommand command = connection.CreateCommand()) | ||
{ | ||
command.CommandText = "CREATE TABLE IF NOT EXISTS [IncludedFolder] (path TEXT PRIMARY KEY COLLATE NOCASE) WITHOUT ROWID;"; | ||
command.ExecuteNonQuery(); | ||
} | ||
} | ||
|
||
public void Add(string directory) | ||
{ | ||
try | ||
{ | ||
using (IDbConnection connection = this.connectionPool.GetConnection()) | ||
using (IDbCommand command = connection.CreateCommand()) | ||
{ | ||
command.CommandText = "INSERT OR REPLACE INTO IncludedFolder (path) VALUES (@path);"; | ||
command.AddParameter("@path", DbType.String, directory); | ||
command.ExecuteNonQuery(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new GVFSDatabaseException($"{nameof(IncludedFolderTable)}.{nameof(this.Add)}({directory}) Exception: {ex.ToString()}", ex); | ||
} | ||
} | ||
|
||
public List<string> GetAll() | ||
{ | ||
try | ||
{ | ||
using (IDbConnection connection = this.connectionPool.GetConnection()) | ||
using (IDbCommand command = connection.CreateCommand()) | ||
{ | ||
List<string> directories = new List<string>(); | ||
command.CommandText = $"SELECT path FROM IncludedFolder;"; | ||
using (IDataReader reader = command.ExecuteReader()) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
directories.Add(reader.GetString(0)); | ||
} | ||
} | ||
|
||
return directories; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new GVFSDatabaseException($"{nameof(PlaceholderTable)}.{nameof(this.GetAll)} Exception: {ex.ToString()}", ex); | ||
} | ||
} | ||
|
||
public void Remove(string directory) | ||
{ | ||
try | ||
{ | ||
using (IDbConnection connection = this.connectionPool.GetConnection()) | ||
using (IDbCommand command = connection.CreateCommand()) | ||
{ | ||
command.CommandText = "DELETE FROM IncludedFolder WHERE path = @path;"; | ||
command.AddParameter("@path", DbType.String, directory); | ||
command.ExecuteNonQuery(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new GVFSDatabaseException($"{nameof(IncludedFolderTable)}.{nameof(this.Remove)}({directory}) Exception: {ex.ToString()}", ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters