Redesign Archiving

Change archiving so that it will now work with a master main
This commit is contained in:
Lunastra 2021-12-08 17:34:00 -08:00
parent ae0d3db59c
commit 3d37a31072
7 changed files with 150 additions and 38 deletions

View File

@ -12,15 +12,15 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
{
public class SQLSource : IDataSource, IRelationArchivable
{
private SqlConnection conn;
//private SqlConnection conn;
public SQLSource(string info)
{
// Do I put using here to make sure the connection closed once the object is gone?
conn = new SqlConnection(info);
// Perhaps open the connection here?
// conn.Open();
}
//public SQLSource(string info)
//{
// // Do I put using here to make sure the connection closed once the object is gone?
// conn = new SqlConnection(info);
// // Perhaps open the connection here?
// // conn.Open();
//}
// The also Identical to update data, maybe only one method is enough
public bool DeleteData(string cmd)
@ -33,22 +33,23 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
{
try
{
conn.Open();
//conn.Open();
//SqlCommand command = new SqlCommand(null, conn);
SqlCommand command = new SqlCommand(cmd, conn);
//SqlCommand command = new SqlCommand(cmd, conn);
// conn.Execute();
Console.WriteLine("Access a SQL database");
Console.WriteLine("Select * from archive");
// Execute the command to query the data
using SqlDataReader sqlReader = command.ExecuteReader();
//using SqlDataReader sqlReader = command.ExecuteReader();
// while (myReader)
// Print to console
conn.Close();
conn.Dispose();
return sqlReader;
//conn.Close();
//conn.Dispose();
//return sqlReader;
return new SqlConnection();
}
catch (Exception e)
{
@ -62,16 +63,16 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
{
try
{
conn.Open();
//conn.Open();
// Create the SQL command object
SqlCommand command = new SqlCommand(cmd, conn);
//SqlCommand command = new SqlCommand(cmd, conn);
// Execute the command to change the rows in a table
command.ExecuteNonQuery();
//command.ExecuteNonQuery();
conn.Close();
conn.Dispose();
//conn.Close();
//conn.Dispose();
return true;
}
catch (Exception e)
@ -124,28 +125,28 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
}
}
public Object ReadPreparedStmt(string table){
conn.Open();
//SqlCommand command = new SqlCommand(null, conn);
SqlCommand command = new SqlCommand("SELECT * from @table;", conn);
SqlParameter tableParam = new SqlParameter("@table", System.Data.SqlDbType.Text, 50);
//public Object ReadPreparedStmt(string table){
// //conn.Open();
// //SqlCommand command = new SqlCommand(null, conn);
// SqlCommand command = new SqlCommand("SELECT * from @table;", conn);
// SqlParameter tableParam = new SqlParameter("@table", System.Data.SqlDbType.Text, 50);
tableParam.Value = table;
command.Parameters.Add(tableParam);
// tableParam.Value = table;
// command.Parameters.Add(tableParam);
// conn.Execute();
Console.WriteLine("Access a SQL database");
Console.WriteLine("Select * from archive");
// // conn.Execute();
// Console.WriteLine("Access a SQL database");
// Console.WriteLine("Select * from archive");
// Make the Prepare statement and excute the query:
command.Prepare();
SqlDataReader sqlReader = command.ExecuteReader();
// // Make the Prepare statement and excute the query:
// command.Prepare();
// SqlDataReader sqlReader = command.ExecuteReader();
// while (myReader)
// Print to console
// conn.close();
return sqlReader;
}
// // while (myReader)
// // Print to console
// // conn.close();
// return sqlReader;
//}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TeamHobby.Main
{
internal class text
{
}
}

Binary file not shown.

View File

@ -0,0 +1,99 @@
title Use Case: Archiving
participant Controller.cs #90EE90
participant RDSFactory #26abff
participant ArchiveManager #ffffe0
participant SqlDAO #D3D3D3
participant MariaDB
activate Controller.cs
// Create a new factory
Controller.cs->RDSFactory:factory = new RDSFactory()
activate RDSFactory #26abff
RDSFactory->RDSFactory:Constructor()
Controller.cs<--RDSFactory:return RDSFactory
deactivate RDSFactory
Controller.cs->SqlDAO: ++IDataSource factory.GetDataSource(string name, string connInfo)++
activate SqlDAO #D3D3D3
SqlDAO->SqlDAO:++Constructor(string connInfo)++
Controller.cs<--SqlDAO: ++return SqlDAO++
deactivate SqlDAO
// Create Archive Manager
activate ArchiveManager
Controller.cs ->ArchiveManager:new ArchiveManager(IDataSource conn)
ArchiveManager ->ArchiveManager: ArchiveManager(IDatasSource conn)
// Calling the main:
ArchiveManager -->Controller.cs: return ArchiveManager
Controller.cs ->ArchiveManager: bool ArchiveManager.Controller( )
// Keep looping
loop #lightblue while true
alt #lightgreen The First Day of the month at 00:00:00 AM
// Check if the directory exist or not
alt #lightgreen Archive folder does not exist already in the current directory
ArchiveManager -> ArchiveManager:int CreateArchiveFolder(string path)
end
// Create the file name
ArchiveManager ->ArchiveManager: string filePath = string CreateFileName( )
ArchiveManager ->SqlDAO:bool Compress(string filePath)
activate SqlDAO
activate MariaDB
SqlDAO ->MariaDB: bool CopyToArchive(string filePath)
alt #red No error when doing executing copy SQL command
MariaDB --> SqlDAO: return True
else #red Error occur when executing copy SQL command on Database
MariaDB -->SqlDAO: throw SQLException
deactivate MariaDB
SqlDAO -->ArchiveManager: throw SqlException
deactivate SqlDAO
ArchiveManager ->ArchiveManager: Catch SqlException
end
activate SqlDAO
// Compress the file
SqlDAO ->SqlDAO: bool CompressArchive(string filePath)
// Remove output file
SqlDAO ->SqlDAO:bool RemoveOutputFile(string filePath)
alt #red File was created succesffuly
SqlDAO -->SqlDAO: new file
else File Exception
SqlDAO ->SqlDAO: Catch FileException
SqlDAO -->ArchiveManager: throw FileException
deactivate SqlDAO
ArchiveManager ->ArchiveManager: catch FileException
end
activate SqlDAO
SqlDAO ->MariaDB: bool RemoveEntries( )
activate MariaDB
alt #red No error when doing executing remove old logs SQL command
MariaDB-->SqlDAO:return True
else Error occur when executing removing SQL command on Database
MariaDB -->SqlDAO: throw SQLException
deactivate MariaDB
SqlDAO-->ArchiveManager: throw SQLException
deactivate SqlDAO
ArchiveManager ->ArchiveManager:Catch SqlException
end
activate SqlDAO
SqlDAO-->ArchiveManager:return True
deactivate SqlDAO
end
deactivate MariaDB
end
deactivate ArchiveManager
deactivate SqlDAO

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.