Add Exception handling when failed

Remove any files created if any of the process failed during compression.
This commit is contained in:
Lunastra 2021-12-08 18:37:17 -08:00
parent 3d37a31072
commit 916ddc888f
2 changed files with 134 additions and 0 deletions

View File

@ -0,0 +1,134 @@
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++
deactivate SqlDAO
// Create Archive Manager
activate ArchiveManager #ffffe0
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)
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
SqlDAO ->MariaDB: bool RemoveEntries( )
activate MariaDB #00FFFF
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

Binary file not shown.