diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs index f173ba6..c2fcd16 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Contracts/IDataSource.cs @@ -16,9 +16,9 @@ namespace TeamHobby.HobbyProjectGenerator.Archive bool WriteData(string cmd); //Method for deleteing data from a data source, 0 for successful - bool DeleteData(); + bool DeleteData(string cmd); // Method for updating data from a data source, 0 for sucessful - bool UpdateData(); + bool UpdateData(string cmd); } } diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs index ab5b34a..f9c22e4 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/Implementations/SQLSource.cs @@ -16,27 +16,40 @@ namespace TeamHobby.HobbyProjectGenerator.Archive //public SQLSource(string info) //{ - // conn = new SqlConnection(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 bool DeleteData() + // 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) { try { - // conn.open(); + //conn.Open(); + //SqlCommand command = new SqlCommand(null, 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(); + // while (myReader) // Print to console - // conn.close(); - return null; + //conn.Close(); + //conn.Dispose(); + //return sqlReader; + return new SqlConnection(); } catch (Exception e) { @@ -45,11 +58,31 @@ namespace TeamHobby.HobbyProjectGenerator.Archive } } - public bool UpdateData() + // TODO: No idea how to check if the command is valid or where to check it + public bool UpdateData(string cmd) { - throw new NotImplementedException(); + try + { + //conn.Open(); + + // Create the SQL command object + //SqlCommand command = new SqlCommand(cmd, conn); + + // Execute the command to change the rows in a table + //command.ExecuteNonQuery(); + + //conn.Close(); + //conn.Dispose(); + return true; + } + catch (Exception e) + { + Console.WriteLine(e.Message); + return false; + } } + // Very similar to UpdataData if not identical public bool WriteData(string cmd) { throw new NotImplementedException(); @@ -81,9 +114,9 @@ namespace TeamHobby.HobbyProjectGenerator.Archive origFile.CopyTo(compressor); return true; - } + } - return true; + return false; } catch (Exception ex) { @@ -92,5 +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); + + // tableParam.Value = table; + // command.Parameters.Add(tableParam); + + // // 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(); + + // // while (myReader) + // // Print to console + // // conn.close(); + // return sqlReader; + //} + } } diff --git a/Source Code/TeamHobby.Main/HobbyMain.cs b/Source Code/TeamHobby.Main/HobbyMain.cs index 6d30a27..7e6146d 100644 --- a/Source Code/TeamHobby.Main/HobbyMain.cs +++ b/Source Code/TeamHobby.Main/HobbyMain.cs @@ -10,53 +10,23 @@ public class HobbyMain Console.WriteLine("Hello World!"); // Testing Compressing a file - string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\archiving2.txt"; + string fileName = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\TeamHobby.Main\rando"; //string fileName = @"arhiving2.txt"; FileInfo fileInfo = new FileInfo(fileName); Console.WriteLine("File Name: {0}", fileInfo.FullName); - //Console.WriteLine("Starting file compression: "); - //Compress(fileInfo); - //Console.WriteLine("Ending compression"); - //SqlConnection myconn = new SqlConnection(); - - - //IDataSource dataSource = new SQLSource(); - SQLSource sqlSource = new SQLSource(); bool res = sqlSource.CompressFile(fileName); //bool res = CompressFile(fileName); Console.WriteLine(res); + Console.WriteLine(CreateFileName()); } - - - public static void Compress(FileInfo fi) + + public static string CreateFileName() { - // Get the stream of the source file. - using (FileStream inFile = fi.OpenRead()) - { - // Prevent compressing hidden and - // already compressed files. - if ((File.GetAttributes(fi.FullName) & FileAttributes.Hidden) != FileAttributes.Hidden & fi.Extension != ".gz") - { - // Create the compressed file. - using (FileStream outFile = - File.Create(fi.FullName + ".gz")) - { - using (GZipStream Compress = new GZipStream(outFile, CompressionMode.Compress)) - { - // Copy the source file into - // the compression stream. - inFile.CopyTo(Compress); - - Console.WriteLine("Compressed {0} from {1} to {2} bytes.", - fi.Name, fi.Length.ToString(), outFile.Length.ToString()); - } - } - } - } + return DateTime.Now.ToString() + "archive.txt"; } } diff --git a/Source Code/TeamHobby.Main/rando b/Source Code/TeamHobby.Main/rando new file mode 100644 index 0000000..a2ba694 --- /dev/null +++ b/Source Code/TeamHobby.Main/rando @@ -0,0 +1,46 @@ +title Use Case: Archiving + +participant ArchiveController.cs +participant DataConnection +participant DataSourceFactory +participant SQLSource +participant MariaDB + +activate ArchiveController.cs +activate DataConnection +ArchiveController.cs ->DataConnection:static DataConnection getDataConnection() +DataConnection -->ArchiveController.cs:return DataConnection +deactivate DataConnection + +activate DataSourceFactory +ArchiveController.cs ->DataSourceFactory: new DataSourceFactory() +DataSourceFactory ->DataSourceFactory:DataSourceFactory()\nconstructor +ArchiveController.cs <-- DataSourceFactory:return DataSourceFactory +deactivate DataSourceFactory + +activate SQLSource +ArchiveController.cs->SQLSource: IDataSource DataSourceFact.GetDataSource(String sourceName, string info) +SQLSource->SQLSource: SQLSource(string info)\nconstructor +SQLSource --> ArchiveController.cs :return SQLSource + +loop #lightblue while true +alt #lightgreen date == 1 +ArchiveController.cs ->ArchiveController.cs: string fileName = string CreateFileName( ) +ArchiveController.cs -> SQLSource: int Compress(string fileName) +activate MariaDB + +SQLSource -> MariaDB: int createArchive(string fileLocation) +MariaDB -->SQLSource:return 0 + +SQLSource ->MariaDB: int RemoveEntries() +MariaDB-->SQLSource:return 0 +end + + +deactivate MariaDB + +SQLSource-->ArchiveController.cs:return 0 +end + +deactivate ArchiveController.cs +deactivate SQLSource \ No newline at end of file diff --git a/Source Code/TeamHobby.Main/text.cs b/Source Code/TeamHobby.Main/text.cs new file mode 100644 index 0000000..85362c8 --- /dev/null +++ b/Source Code/TeamHobby.Main/text.cs @@ -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 + { + } +} diff --git a/doc/LowLevel/ArchivingWithError.png b/doc/LowLevel/ArchivingWithError.png new file mode 100644 index 0000000..34d1db8 Binary files /dev/null and b/doc/LowLevel/ArchivingWithError.png differ diff --git a/doc/LowLevel/ArchivingWithError.svg b/doc/LowLevel/ArchivingWithError.svg new file mode 100644 index 0000000..ab49cd2 --- /dev/null +++ b/doc/LowLevel/ArchivingWithError.svg @@ -0,0 +1 @@ +%0Atitle%20Use%20Case%3A%20Archiving%0A%0Aparticipant%20Controller.cs%20%2390EE90%0Aparticipant%20RDSFactory%20%2326abff%0Aparticipant%20ArchiveManager%20%23ffffe0%0Aparticipant%20SqlDAO%20%23D3D3D3%0Aparticipant%20MariaDB%20%2300FFFF%0A%0Aactivate%20Controller.cs%20%2390EE90%0A%2F%2F%20Create%20a%20new%20factory%20%0AController.cs-%3ERDSFactory%3Afactory%20%3D%20new%20RDSFactory()%0Aactivate%20RDSFactory%20%2326abff%0ARDSFactory-%3ERDSFactory%3AConstructor()%0AController.cs%3C--RDSFactory%3Areturn%20RDSFactory%0Adeactivate%20RDSFactory%0AController.cs-%3ESqlDAO%3A%20%2B%2BIDataSource%20factory.GetDataSource(string%20name%2C%20string%20connInfo)%2B%2B%0Aactivate%20SqlDAO%20%23D3D3D3%0ASqlDAO-%3ESqlDAO%3A%2B%2BConstructor(string%20connInfo)%2B%2B%0AController.cs%3C--SqlDAO%3A%20%2B%2Breturn%20SqlDAO%2B%2B%0A%0A%0Aalt%20%23red%20%0ASqlDAO%20-%3ESqlDAO%3A%20Catch%20Exception%0ASqlDAO%20--%3EController.cs%3Areturn%20%22DataSourceTimeOut%22%0Aend%20%0Adeactivate%20SqlDAO%0A%0A%2F%2F%20Create%20Archive%20Manager%0A%0Aactivate%20ArchiveManager%20%23ffffe0%0Agroup%20%23lightblue%20Connection%20to%20DataSource%20successful%0AController.cs%20-%3EArchiveManager%3Anew%20ArchiveManager(IDataSource%20conn)%0AArchiveManager%20-%3EArchiveManager%3A%20ArchiveManager(IDatasSource%20conn)%0A%0A%2F%2F%20Calling%20the%20main%3A%0AArchiveManager%20--%3EController.cs%3A%20return%20ArchiveManager%0Aloop%20%23lightblue%20while%20true%0Aalt%20%23lightgreen%20The%20First%20Day%20of%20the%20month%20at%2000%3A00%3A00%20AM%0AController.cs%20-%3EArchiveManager%3A%20bool%20ArchiveManager.Controller(%20)%0A%0A%2F%2F%20Keep%20looping%0A%0A%2F%2F%20Check%20if%20the%20directory%20exist%20or%20not%0Aalt%20%23lightgreen%20Archive%20folder%20does%20not%20exist%20already%20in%20the%20current%20directory%0AArchiveManager%20-%3E%20ArchiveManager%3Abool%20CreateArchiveFolder(string%20path)%0A%0Aend%20%0A%2F%2F%20Create%20the%20file%20name%20%0AArchiveManager%20-%3EArchiveManager%3Astring%20filePath%20%3D%20string%20CreateOutFileName(%20)%0AArchiveManager%20-%3ESqlDAO%3Abool%20Compress(string%20filePath)%0A%0Aactivate%20SqlDAO%20%23D3D3D3%0Aactivate%20MariaDB%20%2300FFFF%0ASqlDAO%20-%3EMariaDB%3A%20bool%20CopyToArchive(string%20filePath)%0A%2F%2F%20Sql%20Command%20to%20add%20data%20to%20the%20table%0AMariaDB%20-%3EMariaDB%3A%20SELECT%20'LtimeStamp'%2C%20'logID'%2C%20'LvName'%2C%20'catName'%2C%20'userOP'%2C%20'logMessage'%20%5CnUNION%20ALL%5CnSELECT%20*%20FROM%20log%5CnWHERE%20DATEDIFF(CURRENT_TIMESTAMP%2C%20log.LtimeStamp)%20%3E%2030%5CnINTO%20OUTFILE%20%40filePath%5CnFIELDS%20ENCLOSED%20BY%20''%5CnTERMINATED%20BY%20'%2C'%5CnESCAPED%20BY%20'%22'%5CnLINES%20TERMINATED%20BY%20'%5Cr%5C%5Cn'%3B%0Aalt%20%23lightgreen%20No%20error%20when%20doing%20executing%20copy%20SQL%20command%0AMariaDB%20--%3E%20SqlDAO%3A%20return%20True%0ASqlDAO%20--%3EArchiveManager%3A%20return%20True%0Aend%20%0A%0Aalt%20%23red%20Error%20occur%20when%20executing%20copy%20SQL%20command%20on%20Database%0AMariaDB%20--%3ESqlDAO%3A%20throw%20SQLException%0Adeactivate%20MariaDB%0ASqlDAO%20--%3EArchiveManager%3A%20throw%20SqlException%0Adeactivate%20SqlDAO%0A%0A%0AArchiveManager%20-%3EArchiveManager%3A%20Catch%20Exception%0A%2F%2F%20Removing%20created%20files%20if%20the%20process%20failed%0Aalt%20%23red%20Log%20output%20text%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20filePath)%0Aend%0Aalt%20%23red%20Compressed%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20comFilePath)%0Aend%0Aend%20%0A%0Aactivate%20SqlDAO%20%23D3D3D3%0A%2F%2F%20Compress%20the%20file%20%0ASqlDAO%20-%3ESqlDAO%3A%20bool%20CompressArchive(string%20filePath)%0Aalt%20%23lightgreen%20File%20Compression%20was%20successful%0ASqlDAO%20--%3EArchiveManager%3A%20return%20True%0Aend%20%0Aalt%20%23red%20File%20Compresssion%20failed%0ASqlDAO%20--%3EArchiveManager%3A%20throw%20FileException%0AArchiveManager%20-%3EArchiveManager%3A%20Catch%20Exception%0Aalt%20%23red%20Log%20output%20text%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(filePath)%0Aend%0Aalt%20%23red%20Compressed%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20comFilePath)%0Aend%0Aend%0A%2F%2F%20Remove%20output%20file%0ASqlDAO%20-%3ESqlDAO%3Abool%20RemoveOutputFile(string%20filePath)%0Aalt%20%23lightgreen%20UncompressFile%20was%20removed%20successfully%0ASqlDAO%20--%3EArchiveManager%3A%20return%20true%0Aend%20%0A%0Aalt%20%23red%20Uncompressfile%20failed%20to%20be%20removed%0ASqlDAO%20--%3EArchiveManager%3A%20throw%20FileException%0Adeactivate%20SqlDAO%0AArchiveManager%20-%3EArchiveManager%3A%20catch%20Exception%0A%0Aalt%20%23red%20Log%20output%20text%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20filePath)%0Aend%0Aalt%20%23red%20Compressed%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20comFilePath)%0Aend%0Aend%20%0A%0Aactivate%20SqlDAO%20%23D3D3D3%0Aactivate%20MariaDB%20%2300FFFF%0ASqlDAO%20-%3EMariaDB%3A%20bool%20RemoveEntries(%20)%0AMariaDB%20-%3EMariaDB%3A%20DELETE%20from%20log%20%5CnWHERE%20%5CnDATEDIFF(CURRENT_TIMESTAMP%2C%20log.LtimeStamp)%20%3E%2030%3B%0A%0Aalt%20%23lightgreen%20No%20error%20when%20doing%20executing%20remove%20old%20logs%20SQL%20command%0AMariaDB--%3ESqlDAO%3Areturn%20True%0ASqlDAO%20--%3EArchiveManager%3A%20return%20True%0Aend%0A%0Aalt%20%23red%20Error%20occur%20when%20executing%20removing%20SQL%20command%20on%20Database%0AMariaDB%20--%3ESqlDAO%3A%20throw%20SQLException%0Adeactivate%20MariaDB%0ASqlDAO--%3EArchiveManager%3A%20throw%20SQLException%0Adeactivate%20SqlDAO%0AArchiveManager%20-%3EArchiveManager%3ACatch%20Exception%0Aalt%20%23red%20Log%20output%20text%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20filePath)%0Aend%0Aalt%20%23red%20Compressed%20file%20exist%0AArchiveManager%20-%3EArchiveManager%3A%20File.Delete(string%20comFilePath)%0Aend%0Aend%20%0A%0A%0AArchiveManager%20--%3E%20Controller.cs%3Areturn%20True%0Adeactivate%20ArchiveManager%0Aend%0A%0Aend%20%0Aend%20%0A%0AUse Case: ArchivingController.csRDSFactoryArchiveManagerSqlDAOMariaDBfactory = new RDSFactory()Constructor()return RDSFactoryIDataSource factory.GetDataSource(string name, string connInfo)Constructor(string connInfo)return SqlDAOCatch Exceptionreturn "DataSourceTimeOut"new ArchiveManager(IDataSource conn)ArchiveManager(IDatasSource conn)return ArchiveManagerbool ArchiveManager.Controller( )bool CreateArchiveFolder(string path)string filePath = string CreateOutFileName( )bool Compress(string filePath)bool CopyToArchive(string filePath)SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' UNION ALLSELECT * FROM logWHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30INTO OUTFILE @filePathFIELDS ENCLOSED BY ''TERMINATED BY ','ESCAPED BY '"'LINES TERMINATED BY '\r\n';return Truereturn Truethrow SQLExceptionthrow SqlExceptionCatch ExceptionFile.Delete(string filePath)File.Delete(string comFilePath)bool CompressArchive(string filePath)return Truethrow FileExceptionCatch ExceptionFile.Delete(filePath)File.Delete(string comFilePath)bool RemoveOutputFile(string filePath)return truethrow FileExceptioncatch ExceptionFile.Delete(string filePath)File.Delete(string comFilePath)bool RemoveEntries( )DELETE from log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;return Truereturn Truethrow SQLExceptionthrow SQLExceptionCatch ExceptionFile.Delete(string filePath)File.Delete(string comFilePath)return TruealtConnection to DataSource successfulloop[while true]alt[The First Day of the month at 00:00:00 AM]alt[Archive folder does not exist already in the current directory]alt[No error when doing executing copy SQL command]alt[Error occur when executing copy SQL command on Database]alt[Log output text file exist]alt[Compressed file exist]alt[File Compression was successful]alt[File Compresssion failed]alt[Log output text file exist]alt[Compressed file exist]alt[UncompressFile was removed successfully]alt[Uncompressfile failed to be removed]alt[Log output text file exist]alt[Compressed file exist]alt[No error when doing executing remove old logs SQL command]alt[Error occur when executing removing SQL command on Database]alt[Log output text file exist]alt[Compressed file exist] \ No newline at end of file diff --git a/doc/LowLevel/ArchivingWithError.txt b/doc/LowLevel/ArchivingWithError.txt new file mode 100644 index 0000000..8265491 --- /dev/null +++ b/doc/LowLevel/ArchivingWithError.txt @@ -0,0 +1,146 @@ + +title Use Case: Archiving + +participant Controller.cs #90EE90 +participant RDSFactory #26abff +participant ArchiveManager #ffffe0 +participant SqlDAO #D3D3D3 +participant MariaDB #00FFFF + +activate Controller.cs #90EE90 +// 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++ + + +alt #red +SqlDAO ->SqlDAO: Catch Exception +SqlDAO -->Controller.cs:return "DataSourceTimeOut" +end +deactivate SqlDAO + +// Create Archive Manager + +activate ArchiveManager #ffffe0 +group #lightblue Connection to DataSource successful +Controller.cs ->ArchiveManager:new ArchiveManager(IDataSource conn) +ArchiveManager ->ArchiveManager: ArchiveManager(IDatasSource conn) + +// Calling the main: +ArchiveManager -->Controller.cs: return ArchiveManager +loop #lightblue while true +alt #lightgreen The First Day of the month at 00:00:00 AM +Controller.cs ->ArchiveManager: bool ArchiveManager.Controller( ) + +// Keep looping + +// Check if the directory exist or not +alt #lightgreen Archive folder does not exist already in the current directory +ArchiveManager -> ArchiveManager:bool CreateArchiveFolder(string path) + +end +// Create the file name +ArchiveManager ->ArchiveManager:string filePath = string CreateOutFileName( ) +ArchiveManager ->SqlDAO:bool Compress(string filePath) + +activate SqlDAO #D3D3D3 +activate MariaDB #00FFFF +SqlDAO ->MariaDB: bool CopyToArchive(string filePath) +// Sql Command to add data to the table +MariaDB ->MariaDB: SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' \nUNION ALL\nSELECT * FROM log\nWHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30\nINTO OUTFILE @filePath\nFIELDS ENCLOSED BY ''\nTERMINATED BY ','\nESCAPED BY '"'\nLINES TERMINATED BY '\r\\n'; +alt #lightgreen No error when doing executing copy SQL command +MariaDB --> SqlDAO: return True +SqlDAO -->ArchiveManager: return True +end + +alt #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 Exception +// Removing created files if the process failed +alt #red Log output text file exist +ArchiveManager ->ArchiveManager: File.Delete(string filePath) +end +alt #red Compressed file exist +ArchiveManager ->ArchiveManager: File.Delete(string comFilePath) +end +end + +activate SqlDAO #D3D3D3 +// Compress the file +SqlDAO ->SqlDAO: bool CompressArchive(string filePath) +alt #lightgreen File Compression was successful +SqlDAO -->ArchiveManager: return True +end +alt #red File Compresssion failed +SqlDAO -->ArchiveManager: throw FileException +ArchiveManager ->ArchiveManager: Catch Exception +alt #red Log output text file exist +ArchiveManager ->ArchiveManager: File.Delete(filePath) +end +alt #red Compressed file exist +ArchiveManager ->ArchiveManager: File.Delete(string comFilePath) +end +end +// Remove output file +SqlDAO ->SqlDAO:bool RemoveOutputFile(string filePath) +alt #lightgreen UncompressFile was removed successfully +SqlDAO -->ArchiveManager: return true +end + +alt #red Uncompressfile failed to be removed +SqlDAO -->ArchiveManager: throw FileException +deactivate SqlDAO +ArchiveManager ->ArchiveManager: catch Exception + +alt #red Log output text file exist +ArchiveManager ->ArchiveManager: File.Delete(string filePath) +end +alt #red Compressed file exist +ArchiveManager ->ArchiveManager: File.Delete(string comFilePath) +end +end + +activate SqlDAO #D3D3D3 +activate MariaDB #00FFFF +SqlDAO ->MariaDB: bool RemoveEntries( ) +MariaDB ->MariaDB: DELETE from log \nWHERE \nDATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +alt #lightgreen No error when doing executing remove old logs SQL command +MariaDB-->SqlDAO:return True +SqlDAO -->ArchiveManager: return True +end + +alt #red Error occur when executing removing SQL command on Database +MariaDB -->SqlDAO: throw SQLException +deactivate MariaDB +SqlDAO-->ArchiveManager: throw SQLException +deactivate SqlDAO +ArchiveManager ->ArchiveManager:Catch Exception +alt #red Log output text file exist +ArchiveManager ->ArchiveManager: File.Delete(string filePath) +end +alt #red Compressed file exist +ArchiveManager ->ArchiveManager: File.Delete(string comFilePath) +end +end + + +ArchiveManager --> Controller.cs:return True +deactivate ArchiveManager +end + +end +end + diff --git a/doc/LowLevel/ArchivingWithSingleton.pdf b/doc/LowLevel/ArchivingWithSingleton.pdf new file mode 100644 index 0000000..bcc6af0 Binary files /dev/null and b/doc/LowLevel/ArchivingWithSingleton.pdf differ diff --git a/doc/LowLevel/ArchvingMasterCon.txt b/doc/LowLevel/ArchvingMasterCon.txt new file mode 100644 index 0000000..008c1e9 --- /dev/null +++ b/doc/LowLevel/ArchvingMasterCon.txt @@ -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 \ No newline at end of file diff --git a/doc/LowLevel/UMLforArchving.png b/doc/LowLevel/UMLforArchving.png new file mode 100644 index 0000000..1017095 Binary files /dev/null and b/doc/LowLevel/UMLforArchving.png differ diff --git a/doc/LowLevel/archivingMasterCon.pdf b/doc/LowLevel/archivingMasterCon.pdf new file mode 100644 index 0000000..7773c3d Binary files /dev/null and b/doc/LowLevel/archivingMasterCon.pdf differ diff --git a/doc/LowLevel/arcvhingMasterCon.pdf b/doc/LowLevel/arcvhingMasterCon.pdf new file mode 100644 index 0000000..b5e4564 Binary files /dev/null and b/doc/LowLevel/arcvhingMasterCon.pdf differ diff --git a/src/dbCode/ExportingRows.txt b/src/dbCode/ExportingRows.txt new file mode 100644 index 0000000..f7b2027 --- /dev/null +++ b/src/dbCode/ExportingRows.txt @@ -0,0 +1,64 @@ + +select * from log; + +-- Find logs that are older than 30 days of current time. +SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +-- Output logs to a file +SELECT * FROM log +WHERE + DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30 +INTO OUTFILE 'C:/Temp/oldlogs.csv' +FIELDS ENCLOSED BY '"' +TERMINATED BY ';' +ESCAPED BY '"' +LINES TERMINATED BY '\r\n'; + +-- Output into comma separated file +SELECT * INTO OUTFILE 'C:/Temp/oldlogs2.csv' +FIELDS ENCLOSED BY '"' +TERMINATED BY ',' +ESCAPED BY '"' +LINES TERMINATED BY '\r\n' +FROM log +WHERE + DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +-- Output into comma separated file +SELECT * +INTO OUTFILE 'C:/Temp/oldlogs4.csv' + FIELDS ENCLOSED BY '' + TERMINATED BY ',' + ESCAPED BY '"' + LINES TERMINATED BY '\r\n' +FROM log +WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +-- Find the name of each columns +SELECT `COLUMN_NAME` +FROM `information_schema`.`COLUMNS` +WHERE `TABLE_SCHEMA` = 'hobby' AND `TABLE_NAME` = 'log'; + +-- Add the column names to the heading of the file +SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' +UNION ALL +SELECT * FROM log +WHERE + DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30 +INTO OUTFILE 'C:/Temp/oldlogs5.csv' +FIELDS ENCLOSED BY '' +TERMINATED BY ',' +ESCAPED BY '"' +LINES TERMINATED BY '\r\n'; + +-- Remove old logs from the log table +DELETE from log where DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30; + +show columns from log; + +SELECT COLUMN_NAME FROM information_schema.COLUMNS; + + +-- Remove logs from the table + +SELECT DATEDIFF('2021-08-07 23:00:00', current_timestamp); \ No newline at end of file