Change IDataSource, Add main controller file, add functions signatures.
This commit is contained in:
parent
29a773560c
commit
cacb66ef83
@ -2,6 +2,35 @@
|
||||
{
|
||||
public class ArchiveController
|
||||
{
|
||||
private IDataSource<string> _conn;
|
||||
|
||||
// Constructor to take in the connection.
|
||||
public ArchiveController(IDataSource<string> dataSource) {
|
||||
_conn = dataSource;
|
||||
}
|
||||
|
||||
public IDataSource<string> GetDataSource(){
|
||||
return _conn;
|
||||
}
|
||||
|
||||
// Create the folder where the compress file will be stored
|
||||
public bool CreateArchiveFolder(){
|
||||
return true;
|
||||
}
|
||||
|
||||
// Return the name of the new output file with Path
|
||||
public string CreateOutFileName(){
|
||||
return "hello";
|
||||
}
|
||||
|
||||
// put everything toget here
|
||||
public bool Controller(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -7,18 +7,18 @@ using System.Threading.Tasks;
|
||||
//namespace TeamHobby.HobbyProjectGenerator.Archive.Contracts
|
||||
namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
{
|
||||
public interface IDataSource
|
||||
public interface IDataSource<T>
|
||||
{
|
||||
// Method for reading data, return 0 for sucessful operation
|
||||
Object ReadData(string cmd);
|
||||
Object ReadData(T model);
|
||||
|
||||
// Method for Writing data to a data source
|
||||
bool WriteData(string cmd);
|
||||
bool WriteData(T model);
|
||||
|
||||
//Method for deleteing data from a data source, 0 for successful
|
||||
bool DeleteData(string cmd);
|
||||
bool DeleteData(T model);
|
||||
|
||||
// Method for updating data from a data source, 0 for sucessful
|
||||
bool UpdateData(string cmd);
|
||||
bool UpdateData(T model);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ using System.IO.Compression;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
{
|
||||
public class SQLSource : IDataSource, IRelationArchivable
|
||||
public class SQLSource : IDataSource<string>
|
||||
{
|
||||
//private SqlConnection conn;
|
||||
|
||||
@ -22,12 +22,6 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
// // conn.Open();
|
||||
//}
|
||||
|
||||
// The also Identical to update data, maybe only one method is enough
|
||||
public bool DeleteData(string cmd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// Makre sure to Check for instanceof() before casting to a SQLReader in the controller
|
||||
public Object ReadData(string cmd)
|
||||
{
|
||||
@ -58,6 +52,13 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
}
|
||||
}
|
||||
|
||||
// The also Identical to update data, maybe only one method is enough
|
||||
public bool DeleteData(string cmd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
// TODO: No idea how to check if the command is valid or where to check it
|
||||
public bool UpdateData(string cmd)
|
||||
{
|
||||
@ -88,11 +89,6 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// Method to archive data
|
||||
public bool CreateArchived(string fileName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool CompressFile(string fileName)
|
||||
{
|
||||
@ -125,6 +121,30 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the Sql data to the a text file
|
||||
public bool CopyToFile(string filePath){
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemoveOutputFile(string filePath){
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove data from the database, if failed, let the controller handle it.
|
||||
public bool RemoveEntries() {
|
||||
|
||||
string sqlCmd = "DELETE FROM log WHERE DATE_DIFF(current_timestamp, log.LtimeStamp) > 30";
|
||||
|
||||
try{
|
||||
DeleteData(sqlCmd);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
Console.WriteLine("Eeep! an error in Remove Entries, not to worry, will be handled higher up the call stack");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
//public Object ReadPreparedStmt(string table){
|
||||
// //conn.Open();
|
||||
// //SqlCommand command = new SqlCommand(null, conn);
|
||||
|
||||
@ -10,7 +10,7 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||
public class RelationalDataSourceFactory
|
||||
{
|
||||
// Mehthod to create a specific data source suitable to the need
|
||||
public IDataSource? getDataSource(string name)
|
||||
public IDataSource<string> getDataSource(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
33
Source Code/TeamHobby.Main/MasterController.cs
Normal file
33
Source Code/TeamHobby.Main/MasterController.cs
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
public class MasterController{
|
||||
|
||||
public static void main(string[] args){
|
||||
|
||||
//The main Controller of the program, It will run all services here
|
||||
|
||||
// While loop to run everything
|
||||
|
||||
// 1. Initialize the Data Factory here
|
||||
|
||||
// 2. Create the SqlConnection object
|
||||
|
||||
int userInput = 0;
|
||||
|
||||
while (userInput != -1) {
|
||||
|
||||
// Print the menu
|
||||
|
||||
//
|
||||
if (userInput == 1){
|
||||
// 1. User Managment goes here
|
||||
}
|
||||
|
||||
// Trigger Archiving automatically
|
||||
// Create new ArchiveManager object
|
||||
// if (currentDate == 1){
|
||||
// ArchiveManager.Controller()
|
||||
|
||||
// Logging also automatic
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user