From b89e4f69c4192b986419f2b8cf37e8533034e717 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Sat, 11 Dec 2021 23:40:39 -0800 Subject: [PATCH] Process flowed testing for compress sequence --- .../ArchiveController.cs | 3 ++- .../Implementations/SqlDAO.cs | 17 +++++++++++++++-- Source Code/main/Controller.cs | 18 ++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs index 4ea6841..54ebad0 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.Archive/ArchiveController.cs @@ -65,9 +65,10 @@ namespace TeamHobby.HobbyProjectGenerator.Archive { //string path = archivePath + "\\HobbyArchive"; Console.WriteLine("The current directory is {0}", archivePath); + //string date = DateTime.Now.ToString("M_d_yyyy_H:mm:ss"); string date = DateTime.Now.ToString("M_d_yyyy"); string fileName = date + "_archive.csv"; - string filePath = System.IO.Path.Combine(archivePath, fileName); + string filePath = Path.Combine(archivePath, fileName); Console.WriteLine("Date: {0}", date); Console.WriteLine("Filepath: {0}", filePath); diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index c2ae271..1843b50 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -217,13 +217,26 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess } public bool RemoveOutputFile(string filePath){ - return true; + try + { + if (File.Exists(filePath)) + { + Console.WriteLine("File at: {0} exist, proceed to remove.", filePath); + File.Delete(filePath); + return true; + } + return false; + } + catch { + Console.WriteLine("Removing file failed!!"); + return false; + } } // 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"; + string sqlCmd = "DELETE FROM log WHERE DATEDIFF(current_timestamp, log.LtimeStamp) > 30"; try{ DeleteData(sqlCmd); diff --git a/Source Code/main/Controller.cs b/Source Code/main/Controller.cs index c63324a..6f6d0d8 100644 --- a/Source Code/main/Controller.cs +++ b/Source Code/main/Controller.cs @@ -78,18 +78,32 @@ namespace TeamHobby.HobbyProjectGenerator.Main // Creating a file name: string filePath = @"C:\HobbyArchive"; - Console.WriteLine("Creating file name ... "); + //Console.WriteLine("Creating file name ... "); //string curPath = archive.CreateOutFileName(); string curPath = archive.CreateOutFileName(filePath); //string pathForward = @"C:\Users\Chunchunmaru\Documents\csulbFall2021\HobbyProject\Source Code\main\bin\Debug\net6.0\HobbyArchive"; //string pathTemp = "C:/Temp/oldlogs10.txt"; //string pathTempBack = @"C:\Temp\oldlogs10.txt"; - //Console.WriteLine("----------------"); + Console.WriteLine("----------------"); //Output SQL to a text file sqlDS.CopyToFile(curPath); + // Compress the file + sqlDS.CompressFile(curPath); + + //Remove output file + sqlDS.RemoveOutputFile(curPath); + + // Remove entries fromt the database + sqlDS.RemoveEntries(); + + // Testing date time patters + //string date = DateTime.Now.ToString("d"); + //Console.WriteLine(date); + //Console.WriteLine(DateTime.Now.ToString("M_d_yyyy_H:mm:ss")); + // 2.Inserting Data into the database: //string sqlWrite = "INSERT into log(lvname, catname, userop, logmessage) values " +