Compare commits
239 Commits
v1.0.0-alp
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
271f2df7f9 | ||
|
|
d550ad44df | ||
|
|
4f8aeaead8 | ||
|
|
a424b6f7a2 | ||
|
|
27c322d759 | ||
|
|
8cda716487 | ||
|
|
3bf30af52f | ||
|
|
85c6f25721 | ||
|
|
c139b80459 | ||
|
|
300158ec25 | ||
|
|
f79dd88cc7 | ||
|
|
56c7725f56 | ||
|
|
d96d1f972b | ||
|
|
d8be0846fc | ||
|
|
2c5dea12df | ||
|
|
52f6a2b731 | ||
|
|
51b41fc9f7 | ||
|
|
6319cc7693 | ||
|
|
df7e6f9c5e | ||
|
|
19fdbc21f6 | ||
|
|
9afb9af9f6 | ||
|
|
7daf61c6bd | ||
|
|
3c154ed8aa | ||
|
|
e7c11778ee | ||
|
|
d989c5c840 | ||
|
|
a87237fbf0 | ||
|
|
0b182cb08c | ||
|
|
1046293c9e | ||
|
|
f62abbd1e5 | ||
|
|
c96b6eda56 | ||
|
|
32be141e44 | ||
|
|
e1a2cb8b1b | ||
|
|
ff690dc836 | ||
|
|
f1dc060545 | ||
|
|
ab2096492c | ||
|
|
5dacebdffd | ||
|
|
27080ce36c | ||
|
|
b618041489 | ||
|
|
8f364fb521 | ||
|
|
fe4b2f891b | ||
|
|
699de5a7e6 | ||
|
|
8a6e4c8541 | ||
|
|
2bf0341668 | ||
|
|
f11ed7d6ad | ||
|
|
8d49e66a90 | ||
|
|
b2217dee34 | ||
|
|
c403278f9f | ||
|
|
6e8e2f9756 | ||
|
|
cd7f94a5e0 | ||
|
|
a709675c99 | ||
|
|
1a265f8239 | ||
|
|
3c4a413917 | ||
|
|
6689b91e70 | ||
|
|
9bba0ebcc1 | ||
|
|
03cfb10c10 | ||
|
|
a2c5e0a1f9 | ||
|
|
66e3aed842 | ||
|
|
2ef2d3c919 | ||
|
|
4cf16cce93 | ||
|
|
de8dd8a583 | ||
|
|
6bf376802d | ||
|
|
cef3c4114c | ||
|
|
e012dde28c | ||
|
|
68b8439256 | ||
|
|
04f5d9856b | ||
|
|
1f84ec0a8d | ||
|
|
136505be71 | ||
|
|
97cc4369bd | ||
|
|
20cbf225ff | ||
|
|
9c0472f061 | ||
|
|
14dec71367 | ||
|
|
510ea55421 | ||
|
|
bca0875ec7 | ||
|
|
c9f60c2f76 | ||
|
|
95f762552f | ||
|
|
084e0de6ec | ||
|
|
89eda68a6c | ||
|
|
ceabdc9161 | ||
|
|
ba6db79f09 | ||
|
|
7575354797 | ||
|
|
cc71d41cca | ||
|
|
53aaf77c6b | ||
|
|
484c725ba8 | ||
|
|
a4a133b0cd | ||
|
|
6f9c6f0f12 | ||
|
|
487138890a | ||
|
|
9b2b38620b | ||
|
|
cdba27ee12 | ||
|
|
dfb32b0e26 | ||
|
|
7f9e278266 | ||
|
|
ca51159bc6 | ||
|
|
4ecbb14940 | ||
|
|
34dac0e3b9 | ||
|
|
c021d5f04f | ||
|
|
5224841dac | ||
|
|
e3c3ef4b83 | ||
|
|
c100a73b39 | ||
|
|
80cd5c3de9 | ||
|
|
d8bf615b02 | ||
|
|
5866a0a860 | ||
|
|
65d41e0faa | ||
|
|
3074044777 | ||
|
|
9e1ef7bcab | ||
|
|
b2a627a9c7 | ||
|
|
c72af8ccb6 | ||
|
|
4f2f4c8fce | ||
|
|
6414c9feed | ||
|
|
55ab7c6cf2 | ||
|
|
f67b172f8d | ||
|
|
c118c908f1 | ||
|
|
f452b599e3 | ||
|
|
99c3a7eb4a | ||
|
|
a76603f00c | ||
|
|
e8d42bf98f | ||
|
|
4a2bd5b38f | ||
|
|
57f6e4f9d8 | ||
|
|
000c3aed41 | ||
|
|
af21f771d0 | ||
|
|
2e4c898c89 | ||
|
|
c7815d215c | ||
|
|
ef025afe0f | ||
|
|
e6a751db31 | ||
|
|
79426a2ce2 | ||
|
|
01711fe223 | ||
|
|
4e970f28b6 | ||
|
|
8999a71a97 | ||
|
|
b89e4f69c4 | ||
|
|
421637bda7 | ||
|
|
9db6ab7db7 | ||
|
|
0f825ca4bd | ||
|
|
feb2c0abe5 | ||
|
|
121dace628 | ||
|
|
5e24218d94 | ||
|
|
698aa45318 | ||
|
|
f8bafc8b6d | ||
|
|
d76a389b9e | ||
|
|
0b3c5df2b8 | ||
|
|
f79f0e6adc | ||
|
|
38a7195040 | ||
|
|
567bf71720 | ||
|
|
ace8f88ec1 | ||
|
|
a811a98b6f | ||
|
|
ba273228ac | ||
|
|
e5ef385b18 | ||
|
|
9e098b064f | ||
|
|
a98a5fc3f6 | ||
|
|
3f7597e1eb | ||
|
|
598197d542 | ||
|
|
ba6ae16a05 | ||
|
|
8825a94301 | ||
|
|
cacb66ef83 | ||
|
|
29a773560c | ||
|
|
0cc7a4a7c3 | ||
|
|
38549d9209 | ||
|
|
d682c463a4 | ||
|
|
a7d1679332 | ||
|
|
c759799c20 | ||
|
|
122db1cf47 | ||
|
|
0cbb43fd97 | ||
|
|
93b8e9a327 | ||
|
|
74be5c5c9b | ||
|
|
a695bd5cac | ||
|
|
79bd9f0e64 | ||
|
|
3f4d78dae3 | ||
|
|
916ddc888f | ||
|
|
3d37a31072 | ||
|
|
639d738dba | ||
|
|
5887f4d06d | ||
|
|
3797701563 | ||
|
|
27dc15577e | ||
|
|
aafad06ecf | ||
|
|
90b97ea98d | ||
|
|
e94e772970 | ||
|
|
a392265a42 | ||
|
|
91bae8f8fc | ||
|
|
fa5282b074 | ||
|
|
ae0d3db59c | ||
|
|
012af8f5d7 | ||
|
|
13204721b2 | ||
|
|
05a58ee907 | ||
|
|
78c31ad6c5 | ||
|
|
1828f5acbb | ||
|
|
e0af27a177 | ||
|
|
92ad047db2 | ||
|
|
82047e09e3 | ||
|
|
034336fbf2 | ||
|
|
96224ef96f | ||
|
|
bcfedfec60 | ||
|
|
2dabab9b53 | ||
|
|
9f5cd80d0c | ||
|
|
ec8634cd16 | ||
|
|
4efa5bc585 | ||
|
|
77790110bd | ||
|
|
296f7756ce | ||
|
|
5be774e5ab | ||
|
|
a78b0b8f10 | ||
|
|
641e43030e | ||
|
|
179083fc80 | ||
|
|
50bc3aab5f | ||
|
|
a29ac2a030 | ||
|
|
c321a5f89e | ||
|
|
d859998c9d | ||
|
|
61189d8377 | ||
|
|
3e17663bf7 | ||
|
|
6bd4cbb8ab | ||
|
|
95c0da0cc0 | ||
|
|
62aa383032 | ||
|
|
1e1c379930 | ||
|
|
4815fb669b | ||
|
|
d9f626b24b | ||
|
|
17894dc984 | ||
|
|
21db2dac37 | ||
|
|
78ea998d8b | ||
|
|
80f1890092 | ||
|
|
dee10535e2 | ||
|
|
86b0801ab7 | ||
|
|
26916aea44 | ||
|
|
11d5c604d3 | ||
|
|
12e5c3354b | ||
|
|
c009635c44 | ||
|
|
c5f024051b | ||
|
|
ca4a7c316b | ||
|
|
471003588e | ||
|
|
8ff866fff0 | ||
|
|
049416fab4 | ||
|
|
44bd964f65 | ||
|
|
9e7d3cb89b | ||
|
|
463635a5e5 | ||
|
|
4be21b06d1 | ||
|
|
084cdc4923 | ||
|
|
299a1751ac | ||
|
|
d205e29a2c | ||
|
|
65770e91cd | ||
|
|
429429b7af | ||
|
|
49f44862bb | ||
|
|
3764ae62b4 | ||
|
|
e30f9c21b4 | ||
|
|
ba268f3c53 | ||
|
|
09814b1672 |
429
.gitignore
vendored
@ -1,4 +1,431 @@
|
||||
*.idea
|
||||
venv/
|
||||
HaskellCode/.vscode/tasks.json
|
||||
Notes/
|
||||
Notes/
|
||||
|
||||
|
||||
.vscode/*
|
||||
!.vscode/launch.json
|
||||
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
|
||||
[Ww][Ii][Nn]32/
|
||||
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
[Ll]ogs/
|
||||
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
|
||||
*.tlog
|
||||
|
||||
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Nuget personal access tokens and Credentials
|
||||
# nuget.config
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# ASP.NET Core default setup: bower directory is configured as wwwroot/lib/ and bower restore is true
|
||||
**/wwwroot/lib/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
.vscode/launch.json
|
||||
.vscode/tasks.json
|
||||
Source Code/.vscode/tasks.json
|
||||
Source Code/.vscode/launch.json
|
||||
Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/bin/Debug/net6.0/CoverletSourceRootsMapping
|
||||
Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.UserManagement.xTests/bin/Debug/net6.0/CoverletSourceRootsMapping
|
||||
Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/bin/Debug/net6.0/CoverletSourceRootsMapping
|
||||
Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.UserManagement.xTests/bin/Debug/net6.0/CoverletSourceRootsMapping
|
||||
|
||||
41
Source Code/FileExtract.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||
|
||||
namespace main
|
||||
{
|
||||
internal class FileExtract
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string[] lines = { "First line", "Second line", "Third line" };
|
||||
using StreamWriter file = new ("BulkRequest.txt");
|
||||
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=hobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Create a file
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", DateTime.Now);
|
||||
file.Write(serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
||||
{
|
||||
public interface IDataSource<T>
|
||||
{
|
||||
// Method for reading data, return 0 for sucessful operation
|
||||
Object ReadData(T model);
|
||||
|
||||
// Method for Writing data to a data source
|
||||
bool WriteData(T model);
|
||||
|
||||
//Method for deleteing data from a data source, 0 for successful
|
||||
bool DeleteData(T model);
|
||||
|
||||
// Method for updating data from a data source, 0 for sucessful
|
||||
bool UpdateData(T model);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,275 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO.Compression;
|
||||
using System.Data.Odbc;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
||||
{
|
||||
public class SqlDAO : IDataSource<string>
|
||||
{
|
||||
private OdbcConnection _conn;
|
||||
|
||||
public SqlDAO(string info)
|
||||
{
|
||||
try {
|
||||
//Console.WriteLine("Establising Connection...");
|
||||
_conn = new OdbcConnection(info);
|
||||
//Console.WriteLine("Connection established.");
|
||||
}
|
||||
catch {
|
||||
//_conn = null;
|
||||
Console.WriteLine("Error when creating a connection");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Getter and setter for Odbc
|
||||
public OdbcConnection Connection { get; set; }
|
||||
|
||||
public OdbcConnection GetConnection()
|
||||
{
|
||||
return _conn;
|
||||
}
|
||||
|
||||
// TODO: Closing a connection here will cause a problem
|
||||
// Make sure whoever called this need to close the connection until we can fixed it.
|
||||
public Object? ReadData(string cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
_conn.Open();
|
||||
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||
OdbcDataReader reader = command.ExecuteReader();
|
||||
|
||||
//_conn.Close();
|
||||
return reader;
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error when Reading data from databse.");
|
||||
Console.WriteLine(e.Message);
|
||||
return null;
|
||||
}
|
||||
//finally
|
||||
//{
|
||||
// _conn.Close();
|
||||
//}
|
||||
}
|
||||
|
||||
// The also Identical to update data, maybe only one method is enough
|
||||
public bool DeleteData(string cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
_conn.Open();
|
||||
|
||||
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
_conn.Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error when deleting data from database!!");
|
||||
Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: No idea how to check if the command is valid or where to check it
|
||||
public bool UpdateData(string cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
_conn.Open();
|
||||
|
||||
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
_conn.Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error when updating data from database!!");
|
||||
Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// Very similar to UpdataData if not identical
|
||||
public bool WriteData(string cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
_conn.Open();
|
||||
|
||||
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
_conn.Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error when Writing data from database!!");
|
||||
Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool CompressFile(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the stream of the original file
|
||||
using FileStream origFile = File.Open(fileName, FileMode.Open);
|
||||
|
||||
// Get the attribute of the file
|
||||
FileAttributes atrribute = File.GetAttributes(fileName);
|
||||
|
||||
// Check to see if the file is hidden or already compressed before compressing the file.
|
||||
if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed)
|
||||
{
|
||||
var compFileName = Path.ChangeExtension(fileName, ".gz");
|
||||
//using FileStream outputFile = File.Create(fileName + ".gz");
|
||||
using FileStream outputFile = File.Create(compFileName);
|
||||
|
||||
using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress);
|
||||
origFile.CopyTo(compressor);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error when compressing a file !!, will be handled higher up the call stack");
|
||||
Console.WriteLine(ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy the Sql data to the a text file
|
||||
public bool CopyToFile(string filePath){
|
||||
try
|
||||
{
|
||||
_conn.Open();
|
||||
// Conver backward slash in to forward slash
|
||||
filePath = filePath.Replace("\\", "/");
|
||||
string sqlQuery = "SELECT 'LtimeStamp', 'logID', 'LvName', 'catName', 'userOP', 'logMessage' " +
|
||||
"UNION ALL " +
|
||||
"SELECT* FROM log " +
|
||||
"WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30 " +
|
||||
"INTO OUTFILE '" + filePath + "'" +
|
||||
"FIELDS ENCLOSED BY ''" +
|
||||
"TERMINATED BY ',' " +
|
||||
"LINES TERMINATED BY '\r\n';";
|
||||
|
||||
Console.WriteLine(sqlQuery);
|
||||
|
||||
OdbcCommand command = new OdbcCommand(sqlQuery, _conn);
|
||||
//command.Parameters.AddWithValue("@filePath", filePath);
|
||||
//command.Prepare();
|
||||
|
||||
Console.WriteLine("Output to a file started. ");
|
||||
command.ExecuteNonQuery();
|
||||
Console.WriteLine("Output to a file completed. ");
|
||||
|
||||
|
||||
_conn.Close();
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_conn.Close();
|
||||
Console.WriteLine("Error when copying query to a file !!, will be handled higher up the call stack");
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public bool RemoveOutputFile(string filePath){
|
||||
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!!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove data from the database, if failed, let the controller handle it.
|
||||
public bool RemoveEntries() {
|
||||
|
||||
string sqlCmd = "DELETE FROM log WHERE DATEDIFF(current_timestamp, log.LtimeStamp) > 30";
|
||||
|
||||
if (DeleteData(sqlCmd) == false)
|
||||
{
|
||||
throw new Exception("Error in removing entries,not to worry, will be handled higher up the call stack");
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//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;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
// Print Statements used throughout the program.
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
||||
{
|
||||
public class UiPrint
|
||||
{
|
||||
public void UserManagementMenu(string username)
|
||||
{
|
||||
// File must be within the main folder path
|
||||
// Get the current directory.
|
||||
string path = Directory.GetCurrentDirectory();
|
||||
// Menu for all UserManagement options
|
||||
int menu = 0;
|
||||
Console.WriteLine("-------------------------------------\n");
|
||||
Console.WriteLine($"\nWelcome {username} to User Management.\n");
|
||||
Console.WriteLine("What would you like to do?\n");
|
||||
Console.WriteLine(menu + ") To exit User Management.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") Create a new account.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") Edit an account.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") Delete an account.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") Disable an account.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") Enable an account.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + $") Bulk operation from file within the directory.\n{path}\\BulkOps\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") View log path.\n");
|
||||
menu += 1;
|
||||
Console.WriteLine(menu + ") View archive path.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.DataAccessLayer
|
||||
{
|
||||
public class RDSFactory
|
||||
{
|
||||
// Mehthod to create a specific data source suitable to the need
|
||||
public IDataSource<string> getDataSource(string name, string info)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (String.Equals(name, "SQL", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new SqlDAO(info);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("RelationDataFactory: Data Access object creation failed!");
|
||||
Console.WriteLine(ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Data.Odbc" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||
|
||||
// Print Statements used throughout the program.
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator
|
||||
{
|
||||
public class UiPrint
|
||||
{
|
||||
public void InitialMenu()
|
||||
{
|
||||
// Create intial menu
|
||||
Console.WriteLine("What would you like to access?");
|
||||
int num = 1;
|
||||
Console.WriteLine(num + ".User Management");
|
||||
num += 1;
|
||||
Console.WriteLine(num + ".Logging");
|
||||
}
|
||||
public void SystemAccountMenu()
|
||||
{
|
||||
UserAccount user = new UserAccount();
|
||||
// Menu for all UserManagement options
|
||||
int menu = 0;
|
||||
Console.WriteLine($"Welcome {user.username} to User Management.\n");
|
||||
Console.WriteLine("What would you like to do?\n");
|
||||
Console.WriteLine((menu + 1) + ". Create a new account.");
|
||||
Console.WriteLine((menu + 1) + ". Edit an account.");
|
||||
Console.WriteLine((menu + 1) + ". Delete an account.");
|
||||
Console.WriteLine((menu + 1) + ". Disable an account.");
|
||||
Console.WriteLine((menu + 1) + ". Enable an account.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,378 @@
|
||||
using System;
|
||||
using System.Data.Odbc;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace TeamHobby.Archiving.xTests
|
||||
|
||||
|
||||
{
|
||||
public class ArchivingXUnitTest
|
||||
{
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
|
||||
ITestOutputHelper output;
|
||||
public ArchivingXUnitTest(ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsArchiveFolderCreated()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
bool expectedVal = true;
|
||||
|
||||
// Act
|
||||
archiveManager.CreateArchiveFolder();
|
||||
|
||||
|
||||
// Assert
|
||||
bool actualVal = Directory.Exists(folderPath);
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
// Cleaning up directory after test
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed. ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsFileNameCreated()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
string foldPath = @"C:\HobbyArchive";
|
||||
string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv";
|
||||
string expectedFilePath = System.IO.Path.Combine(foldPath, fileName);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
|
||||
// Act
|
||||
string actualFilePath = archiveManager.CreateOutFileName();
|
||||
|
||||
// Assert
|
||||
|
||||
Assert.Equal(expectedFilePath, actualFilePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsCSVFileExist()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
SqlDAO sqlDS = null;
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
|
||||
try
|
||||
{
|
||||
bool folderRes = archiveManager.CreateArchiveFolder();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Folder creation for copying failed");
|
||||
}
|
||||
string filePath = archiveManager.CreateOutFileName();
|
||||
bool expectedVal = true;
|
||||
|
||||
if (sqlDAO.GetType() == typeof(SqlDAO))
|
||||
{
|
||||
sqlDS = (SqlDAO)sqlDAO;
|
||||
}
|
||||
|
||||
// Act
|
||||
if (sqlDS != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
sqlDS.CopyToFile(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Copying to a file failed !!");
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
bool actualVal = File.Exists(filePath);
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed. ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsEntriesRemoved()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
OdbcDataReader odbcObj = null;
|
||||
Object resultData = null;
|
||||
bool expectedVal = false;
|
||||
|
||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||
|
||||
// Act
|
||||
sqlDAO.RemoveEntries();
|
||||
|
||||
// Assert
|
||||
bool actualVal;
|
||||
|
||||
resultData = sqlDAO.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||
if ((resultData != null) && (resultData.GetType() == typeof(OdbcDataReader)))
|
||||
{
|
||||
odbcObj = (OdbcDataReader)resultData;
|
||||
}
|
||||
OdbcConnection conn = sqlDAO.GetConnection();
|
||||
actualVal = odbcObj.HasRows;
|
||||
conn.Close();
|
||||
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void IsOutputFileRemoved()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
bool expectedVal = false;
|
||||
//Thread.Sleep(5000);
|
||||
|
||||
// Create the folder and the csv file for compressing
|
||||
archiveManager.CreateArchiveFolder();
|
||||
string filepath = archiveManager.CreateOutFileName();
|
||||
sqlDAO.CopyToFile(filepath);
|
||||
|
||||
// Act
|
||||
if (sqlDAO != null)
|
||||
{
|
||||
sqlDAO.RemoveOutputFile(filepath);
|
||||
}
|
||||
|
||||
// Assert
|
||||
bool actualVal = File.Exists(filepath);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsFileCompressed()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
|
||||
// Create the folder and the csv file to be compressed.
|
||||
archiveManager.CreateArchiveFolder();
|
||||
string filePath = archiveManager.CreateOutFileName();
|
||||
sqlDAO.CopyToFile(filePath);
|
||||
FileAttributes expectedAttribute = FileAttributes.Archive;
|
||||
string compFilePath = Path.ChangeExtension(filePath, ".gz");
|
||||
|
||||
// Act
|
||||
sqlDAO.CompressFile(filePath);
|
||||
|
||||
// Assert
|
||||
FileAttributes actualAttribute = File.GetAttributes(compFilePath);
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualAttribute, expectedAttribute);
|
||||
Assert.Equal(expectedAttribute, actualAttribute);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsArchive_Under_60s_10kRecords()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
var timer = new Stopwatch();
|
||||
double expectedVal = 60;
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
|
||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||
|
||||
for (int i = 0; i <= 11; i++)
|
||||
{
|
||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||
}
|
||||
|
||||
// Act
|
||||
timer.Start();
|
||||
archiveManager.Controller();
|
||||
timer.Stop();
|
||||
|
||||
// Assert
|
||||
var actualVal = timer.Elapsed.Seconds;
|
||||
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
||||
Assert.True(actualVal < expectedVal);
|
||||
|
||||
// Clean up resources after testing
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed... ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsArchive_Under_60s_1mRecords()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
var timer = new Stopwatch();
|
||||
double expectedVal = 60;
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
|
||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||
|
||||
for (int i = 0; i <= 18; i++)
|
||||
{
|
||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||
}
|
||||
|
||||
// Act
|
||||
timer.Start();
|
||||
archiveManager.Controller();
|
||||
timer.Stop();
|
||||
|
||||
// Arrange
|
||||
double actualVal = timer.Elapsed.Seconds;
|
||||
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
||||
Assert.True(actualVal < expectedVal);
|
||||
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
//Clean up resources after testing
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed... ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
// [Test Method]
|
||||
public void IsProcessFlowCompleted()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archive = new ArchiveManager(sqlDAO);
|
||||
bool expectedVal = true;
|
||||
bool actualVal = false;
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
|
||||
// Adding 10000 records to database for testing
|
||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||
|
||||
for (int j = 0; j <= 11; j++)
|
||||
{
|
||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||
}
|
||||
|
||||
// Act
|
||||
// Testing archive Manager
|
||||
int i = -10;
|
||||
while (i < 20)
|
||||
{
|
||||
DateTime date1 = new DateTime(2021, 12, 1, 0, 0, 0);
|
||||
string currentTime = "00:00:00 AM";
|
||||
string currentDate = i.ToString();
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
currentDate = date1.ToString("dd");
|
||||
}
|
||||
|
||||
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||
if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM"))
|
||||
{
|
||||
Console.WriteLine("Archiving process Start");
|
||||
actualVal = archive.Controller();
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// Assert
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed... ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
public interface IRelationArchivable
|
||||
{
|
||||
bool CreateArchived(string fileName);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,170 @@
|
||||
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
public class ArchiveManager
|
||||
{
|
||||
private IDataSource<string> _conn;
|
||||
|
||||
// Constructor to take in the connection.
|
||||
public ArchiveManager(IDataSource<string> dataSource) {
|
||||
_conn = dataSource;
|
||||
}
|
||||
|
||||
//public IDataSource<string> GetConnection()
|
||||
//{
|
||||
// return _conn;
|
||||
//}
|
||||
|
||||
// Create the folder where the compress file will be stored
|
||||
public bool CreateArchiveFolder(){
|
||||
//string curPath = Directory.GetCurrentDirectory();
|
||||
string curPath = @"C:\";
|
||||
string folderName = "\\HobbyArchive";
|
||||
|
||||
// Find the root drive of the program
|
||||
string drive = Path.GetPathRoot(path: curPath);
|
||||
// Check if Drive exists or not
|
||||
try {
|
||||
if (!Directory.Exists(drive))
|
||||
{
|
||||
Console.WriteLine("Drive {0} not found", drive);
|
||||
return false;
|
||||
}
|
||||
|
||||
string archiveFolder = curPath + folderName;
|
||||
//Console.WriteLine("Creating a new folder at: {0}", archiveFolder);
|
||||
if (!Directory.Exists(archiveFolder))
|
||||
{
|
||||
Console.WriteLine("Creating a new folder at: {0}", archiveFolder);
|
||||
Directory.CreateDirectory(archiveFolder);
|
||||
//return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex){
|
||||
// If the creating a folder failed, return false
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Return the name of the new output file with Path
|
||||
public string CreateOutFileName() {
|
||||
try {
|
||||
// Creating a file name:
|
||||
string path = @"C:\HobbyArchive";
|
||||
//string path = Directory.GetCurrentDirectory() + "\\HobbyArchive";
|
||||
Console.WriteLine("The current directory is {0}", path);
|
||||
string date = DateTime.Now.ToString("M_d_yyyy");
|
||||
string fileName = date + "_archive.csv";
|
||||
string filePath = System.IO.Path.Combine(path, fileName);
|
||||
|
||||
Console.WriteLine("Date: {0}", date);
|
||||
Console.WriteLine("Filepath: {0}", filePath);
|
||||
return filePath;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("ArchiveCon: Creating a file name failed. ");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// put everything toget here
|
||||
public bool Controller(){
|
||||
|
||||
SqlDAO sqlDS = null;
|
||||
if (_conn.GetType() == typeof(SqlDAO))
|
||||
{
|
||||
sqlDS = (SqlDAO)_conn;
|
||||
}
|
||||
|
||||
// Check to make sure that Sql Data source connection is not null
|
||||
if (sqlDS == null){
|
||||
return false;
|
||||
}
|
||||
// TODO: Remember to add try catch block here to make sure it is completed.
|
||||
|
||||
//Creating the folder Archive
|
||||
Console.WriteLine("Creating a new folder ...");
|
||||
CreateArchiveFolder();
|
||||
Console.WriteLine("Creating a new folder completed ...");
|
||||
Console.WriteLine("----------------");
|
||||
Console.WriteLine("");
|
||||
|
||||
// Creating a file name:
|
||||
//string filePath = @"C:\HobbyArchive";
|
||||
//Console.WriteLine("Creating file name ... ");
|
||||
//string curPath = archive.CreateOutFileName();
|
||||
Console.WriteLine("Creating Output file name ...");
|
||||
string outPath = CreateOutFileName();
|
||||
Console.WriteLine("Output file name created ...");
|
||||
Console.WriteLine("----------------");
|
||||
Console.WriteLine("");
|
||||
|
||||
//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";
|
||||
|
||||
// Try catch block to delete abort the compressing process
|
||||
try{
|
||||
//Output SQL to a text file
|
||||
Console.WriteLine("Copying to a text file ...");
|
||||
sqlDS.CopyToFile(outPath);
|
||||
Console.WriteLine("Copying completed ...");
|
||||
Console.WriteLine("----------------");
|
||||
Console.WriteLine("");
|
||||
|
||||
// Compress the file
|
||||
Console.WriteLine("Copressing the text file ...");
|
||||
sqlDS.CompressFile(outPath);
|
||||
Console.WriteLine("Copression completed ...");
|
||||
Console.WriteLine("----------------");
|
||||
Console.WriteLine("");
|
||||
|
||||
//Remove output file
|
||||
Console.WriteLine("Removing the text file ...");
|
||||
sqlDS.RemoveOutputFile(outPath);
|
||||
Console.WriteLine("Text File removal completed ...");
|
||||
Console.WriteLine("----------------");
|
||||
Console.WriteLine("");
|
||||
|
||||
// Remove entries fromt the database
|
||||
Console.WriteLine("Removing the text file ...");
|
||||
sqlDS.RemoveEntries();
|
||||
Console.WriteLine("Entries removal completed ...");
|
||||
Console.WriteLine("----------------");
|
||||
Console.WriteLine("");
|
||||
|
||||
// Return true if compressing sequence is successful
|
||||
return true;
|
||||
}
|
||||
catch (Exception e){
|
||||
// Abort the compressing sequence and clean up uneccesary files.
|
||||
Console.WriteLine("Archiving Sequenced failed. Cleaning up resources.");
|
||||
|
||||
// Delete the text output file if any of the process failed
|
||||
if (File.Exists(outPath)){
|
||||
File.Delete(outPath);
|
||||
}
|
||||
|
||||
// Delete the compressed file if Removing entries and removing text file output failed
|
||||
string compFile = outPath + ".gz";
|
||||
if (File.Exists(compFile)){
|
||||
File.Delete(compFile);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// Testing date time patters
|
||||
//string date = DateTime.Now.ToString("d");
|
||||
//Console.WriteLine(date);
|
||||
//Console.WriteLine(DateTime.Now.ToString("M_d_yyyy_H:mm:ss"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
// private IDataSource<string> _datasource = T;
|
||||
// attempts to connect to the data source provided by the type T
|
||||
// returns true if the connection is successful
|
||||
|
||||
// public bool Connect();
|
||||
public bool Log(LogEntry Log);
|
||||
|
||||
// IList<string> GetAllLogs();
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer.Contracts
|
||||
{
|
||||
public interface ILoggerFactory
|
||||
{
|
||||
|
||||
ILogger CreateLogger();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
public class ConsoleLogger : ILogger
|
||||
{
|
||||
public bool Log(LogEntry log)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.Data.Odbc;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
public class DBLogger : ILogger
|
||||
{
|
||||
private SqlDAO _datasource;
|
||||
public DBLogger()
|
||||
{
|
||||
}
|
||||
|
||||
// SELECT * FROM log
|
||||
// public IList<LogEntry> GetAllLogs()
|
||||
// {
|
||||
// throw new NotImplementedException();
|
||||
// }
|
||||
|
||||
//INSERT INTO log(LvName, catName, userOP, logMessage) VALUES ('Debug','Data', 'SYSTEM', 'testing insert method')
|
||||
|
||||
// public bool Connect(SqlDAO logDatabase) {
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
public bool IsActive() {
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=ocalhost;" +
|
||||
"DATABASE=hbby;" +
|
||||
"UID=ot;" + // omit password to force SQLException for incorrect passeword
|
||||
"PASSWORD=wrong" +
|
||||
"OPTION=3";
|
||||
// bool isActive = true;
|
||||
OdbcConnection active = new OdbcConnection(dbInfo);
|
||||
try {
|
||||
active.Open();
|
||||
return false;
|
||||
}
|
||||
catch (OdbcException ex) {
|
||||
// Console.WriteLine(ex.Message);
|
||||
if (ex.ErrorCode == -2146232009 ) {
|
||||
//Console.WriteLine(ex.ErrorCode);
|
||||
Console.WriteLine("Database is active");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
Console.WriteLine("Database is inactive");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
// Console.WriteLine("closed1");
|
||||
active.Close();
|
||||
}
|
||||
// return false;
|
||||
}
|
||||
|
||||
public bool IsAccessible() {
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
OdbcConnection access = new OdbcConnection(dbInfo);
|
||||
try {
|
||||
access.Open();
|
||||
Console.WriteLine("Database is active and accessible by the system");
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
Console.WriteLine("Database is active but inaccessible to the system at this time.");
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
access.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasCapacity() {
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
OdbcConnection conn = new OdbcConnection(dbInfo);
|
||||
|
||||
// get the current capacity of the database in MB using the query:
|
||||
// SELECT SUM(storage.MB) as CURRENT_CAPACITY_MB FROM (SELECT table_schema as name, ROUND(SUM(data_length + index_length)/1024/1024,1) as MB FROM information_schema.tables GROUP BY table_schema) as storage;
|
||||
|
||||
string sqlCurrentCap = $"SELECT SUM(storage.mb) as currentCap FROM (SELECT table_schema as name, ROUND(SUM(data_length + index_length)/1024/1024,1) as mb FROM information_schema.tables GROUP BY table_schema) as storage;";
|
||||
|
||||
// get the max capacity in GB; too big to be shown as MB
|
||||
string sqlMaxCap = $"SELECT SUM(storage.mb) as maxCap FROM (SELECT table_schema as name, ROUND(SUM(max_data_length + max_index_length)/1024,1) as mb FROM information_schema.tables GROUP BY table_schema) as storage;";
|
||||
|
||||
// query the data base to get currentCap; the current storage capacity of the system's database (in megabytes)
|
||||
conn.Open();
|
||||
OdbcCommand command1 = new OdbcCommand(sqlCurrentCap, conn);
|
||||
OdbcDataReader result1 = command1.ExecuteReader();
|
||||
double currentCap = 0;
|
||||
while (result1.Read()) {
|
||||
//Console.WriteLine(result1[0].GetType());
|
||||
//Console.WriteLine("currentCap = {0}", result1[0]);
|
||||
currentCap = result1.GetDouble(0);
|
||||
}
|
||||
|
||||
// Console.WriteLine(currentCap);
|
||||
//float currentCap1 = (float) currentCap;
|
||||
result1.Close();
|
||||
command1.Dispose();
|
||||
conn.Close();
|
||||
// Console.WriteLine("close conn");
|
||||
|
||||
// query the data base again to get maxCap; the maximum possible storage capacity of the system's database (in megabytes)
|
||||
conn.Open();
|
||||
// Console.WriteLine("open conn");
|
||||
OdbcCommand command2 = new OdbcCommand(sqlMaxCap, conn);
|
||||
OdbcDataReader result2 = command2.ExecuteReader();
|
||||
// Console.WriteLine("open reader 1");
|
||||
double maxCap = 0;
|
||||
try {
|
||||
while (result2.Read()) {
|
||||
//Console.WriteLine(result2[0].GetType());
|
||||
maxCap = result2.GetDouble(0);
|
||||
// Console.WriteLine("maxCap = {0}", result2[0]);
|
||||
}
|
||||
// compare currentCap to maxCap
|
||||
// return true if there is at least 1MB of free space available
|
||||
// decrement max by 1 MB to allow for any required space from new logs
|
||||
if ( (currentCap * 1024) < (maxCap - 1024) ) {
|
||||
// Console.WriteLine(maxCap);
|
||||
Console.WriteLine("Database has sufficient storage capacity to be written to at this time.\n Current Capacity: {0} MB\n Max Capacity: {1} MB\n", currentCap, maxCap);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Console.WriteLine("Insufficient Storage Capacity to log entry to database.\n Current Capacity: {0} MB \n Max Capacity: {1} MB \n", currentCap, maxCap);
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
result2.Close();
|
||||
command2.Dispose();
|
||||
conn.Close();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Console.WriteLine("close conn 2");
|
||||
//Console.WriteLine(maxCap);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public bool Log(LogEntry log)
|
||||
{
|
||||
log.ShowLog();
|
||||
|
||||
//bool status = HasCapacity();
|
||||
if ( (IsActive() == false || IsAccessible() == false) || (HasCapacity() == false) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
else {
|
||||
// SqlDAO sqlDS = (SqlDAO)_datasource;
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
_datasource = new SqlDAO(dbInfo);
|
||||
|
||||
//bool storage = HasCapacity();
|
||||
try
|
||||
{
|
||||
// once connection is confirmed, try inserting the log via SQL statements
|
||||
string sqlLog = $"INSERT INTO log (Lvname, catName, userOP, logMessage) VALUES ('{log.GetLevel()}','{log.GetCategory()}', " + $"'{log.GetUser()}', '{log.GetDescription()}');";
|
||||
|
||||
bool insertNewLog = _datasource.WriteData(sqlLog);
|
||||
//Console.WriteLine($"Logging Succeeded: The following entry was written to the database: {log}");
|
||||
// Console.WriteLine(_datasource.ReadData($"SELECT * FROM log;"));
|
||||
return insertNewLog;
|
||||
}
|
||||
// if failed, that means the connection was a sucess but actually writing to the database failed
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Failed to write log to database; likely due to error in SQL syntax");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer.Contracts;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer.Implementations
|
||||
{
|
||||
public class DBLoggerFactory : ILoggerFactory
|
||||
{
|
||||
public DBLoggerFactory()
|
||||
{
|
||||
//this._logDatabase = logDatabase;
|
||||
}
|
||||
|
||||
public ILogger CreateLogger() {
|
||||
return new DBLogger();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer.Contracts;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
public class FileLogger : ILogger
|
||||
{
|
||||
public FileLogger()
|
||||
{
|
||||
}
|
||||
|
||||
public IList<string> GetAllLogs()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Log(LogEntry log)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
Info, Debug, Warning, Error
|
||||
}
|
||||
|
||||
public enum LogCategory
|
||||
{
|
||||
View, Business, Server, Data, Datastore
|
||||
}
|
||||
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.Logging.Contracts
|
||||
{
|
||||
// LogEntry is a record type with init properties for each field
|
||||
// ensures that log entries are immutable after initialization
|
||||
// LogEntry is a record type with init properties for each field
|
||||
// ensures that log entries are immutable after initialization
|
||||
public record LogEntry
|
||||
{
|
||||
private LogLevel _level { get; init; }
|
||||
private LogCategory _category { get; init; }
|
||||
private string _user { get; init; }
|
||||
private string _description { get; init; }
|
||||
|
||||
// Constructor with args for all fields except timestamp
|
||||
// timestamp is always set to the UTC time at the time of initialization
|
||||
public LogEntry(LogLevel level, LogCategory category, string user, string description)
|
||||
{
|
||||
this._level = level;
|
||||
this._category = category;
|
||||
this._user = user;
|
||||
this._description = description;
|
||||
}
|
||||
|
||||
// Constructor requiring only the description as an arg
|
||||
// Assigns default values for LogLevel (Info), LogCategory (Server), user ("System"), and the UTC time at initialization for timestamp
|
||||
// public LogEntry(string description)
|
||||
// {
|
||||
// this._level = LogLevel.Debug;
|
||||
// this._category = LogCategory.Server;
|
||||
// this._user = "SYSTEM";
|
||||
// this._description = description;
|
||||
// }
|
||||
|
||||
public LogLevel GetLevel() {
|
||||
return this._level;
|
||||
}
|
||||
|
||||
public LogCategory GetCategory() {
|
||||
return this._category;
|
||||
}
|
||||
|
||||
public string GetUser() {
|
||||
return this._user;
|
||||
}
|
||||
|
||||
public string GetDescription() {
|
||||
return this._description;
|
||||
}
|
||||
|
||||
public void ShowLog() {
|
||||
Console.WriteLine("Timestamp: {0} | Level: {1}, | Category: {2}, | User: {3}, | Description: '{4}' ", DateTime.Now, this._level.ToString(),this._category.ToString(), this._user, this._description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
using TeamHobby.HobbyProjectGenerator.Logging.Contracts;
|
||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer.Contracts;
|
||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer.Implementations;
|
||||
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
|
||||
public class LoggingManager
|
||||
{
|
||||
// private static IDataSource<string> _datasource;
|
||||
private ILogger _logger;
|
||||
private ILoggerFactory _factory;
|
||||
private LogEntry _logEntry;
|
||||
|
||||
// assign default values for LogEntry fields
|
||||
// these are not readonly because they can be overwritten to specify logging at specific field(s) from the main controller by using the public setters for each field
|
||||
private LogLevel _level = LogLevel.Debug;
|
||||
private LogCategory _category = LogCategory.Server;
|
||||
private string _user = "System";
|
||||
|
||||
// Both Constructors take an IDataSource arg to make logging extensible to future data sources
|
||||
// first constructor has no additional args - defaults to using a DBLoggerFactory to log to database
|
||||
public LoggingManager()
|
||||
{
|
||||
// _datasource = datasource;
|
||||
_logEntry = new LogEntry(_level, _category, _user, "Logging Manager instantiated");
|
||||
_factory = new DBLoggerFactory();
|
||||
_logger = _factory.CreateLogger();
|
||||
}
|
||||
// second constructor takes an additional ILoggerFactory arg - allows for extensible logger types
|
||||
public LoggingManager(ILoggerFactory factory)
|
||||
{
|
||||
//_datasource = datasource;
|
||||
_logEntry = new LogEntry(_level, _category, _user, "Logging Manager instantiated");
|
||||
_factory = factory;
|
||||
_logger = _factory.CreateLogger();
|
||||
|
||||
}
|
||||
|
||||
// // used to create a template entry with the desired fields to write entries at
|
||||
// public void CreateLog(LogLevel level, LogCategory category, string user, string description) {
|
||||
// _logEntry = new LogEntry(level,
|
||||
// category, user, description);
|
||||
// _logger.Log(_logEntry);
|
||||
// }
|
||||
|
||||
// creates a LogEntry object using a description arg
|
||||
// uses whateever the current assignments for the other fields ares
|
||||
public bool CreateLog(string description) {
|
||||
// creates a LogEntry using the passed in description and current assignements from the necessary fields
|
||||
_logEntry = new LogEntry(_level, _category, _user, description);
|
||||
|
||||
// attempt to log the LogEntry by calling the _logger's Log() method
|
||||
try {
|
||||
_logger.Log(_logEntry);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Level(LogLevel level) {
|
||||
this._level = level;
|
||||
}
|
||||
|
||||
public void Category(LogCategory category) {
|
||||
this._category = category;
|
||||
}
|
||||
|
||||
public void User(string user) {
|
||||
this._user = user;
|
||||
}
|
||||
|
||||
// public static void Source(IDataSource<string> datasource) {
|
||||
// _datasource = datasource;
|
||||
// }
|
||||
|
||||
// public static IDataSource<string> GetDataSource() {
|
||||
// return _datasource;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="UserManagement\Contracts\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.DataAccessLayer\TeamHobby.HobbyProjectGenerator.DataAccessLayer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,301 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.Odbc;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
public class AccountService
|
||||
{
|
||||
public bool CreateUserRecord(UserAccount newUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Insert into users table
|
||||
if (newUser.email == null || newUser.email == "NULL")
|
||||
{
|
||||
string sqlUser = $"INSERT INTO users (UserName, Password, Role, IsActive," +
|
||||
$"CreatedBy, CreatedDate, Email) VALUES ('{newUser.username}', " +
|
||||
$"'{newUser.password}','{newUser.role}', 1," +
|
||||
$"'{CreatedBy}', NOW(),{newUser.email});";
|
||||
|
||||
bool insertNewUser = dbSource.WriteData(sqlUser);
|
||||
return insertNewUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
string sqlUser = $"INSERT INTO users (UserName, Password, Role, IsActive," +
|
||||
$"CreatedBy, CreatedDate, Email) VALUES ('{newUser.username}', " +
|
||||
$"'{newUser.password}','{newUser.role}', 1," +
|
||||
$"'{CreatedBy}', NOW(),'{newUser.email}');";
|
||||
|
||||
bool insertNewUser = dbSource.WriteData(sqlUser);
|
||||
return insertNewUser;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool EditUserRecord(UserAccount editUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Insert into users table
|
||||
if (editUser.email == null || editUser.email == "NULL")
|
||||
{
|
||||
string sqlUser = $"UPDATE users t SET t.Password = '{editUser.password}', " +
|
||||
$"t.Role = '{editUser.role}',t.Email = '{editUser.email}' " +
|
||||
$"WHERE t.UserName = {editUser.username};";
|
||||
|
||||
bool updateNewUser = dbSource.UpdateData(sqlUser);
|
||||
return updateNewUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
string sqlUser = $"UPDATE users t SET t.Password = '{editUser.password}', " +
|
||||
$"t.Role = '{editUser.role}',t.Email = '{editUser.email}' " +
|
||||
$"WHERE t.UserName = '{editUser.username}';";
|
||||
|
||||
bool updateNewUser = dbSource.UpdateData(sqlUser);
|
||||
return updateNewUser;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool DeleteUserRecord(UserAccount deleteUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Insert into users table
|
||||
string sqlUser = $"DELETE from users WHERE UserName = '{deleteUser.username}' " +
|
||||
$"and Password = '{deleteUser.password}';";
|
||||
|
||||
bool deleteNewUser = dbSource.DeleteData(sqlUser);
|
||||
return deleteNewUser;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool DisableUser(UserAccount disableUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Insert into users table
|
||||
string sqlUser = $"UPDATE users u SET u.IsActive = 0 WHERE u.UserName = '{disableUser.username}'" +
|
||||
$"and u.Role = '{disableUser.role}';";
|
||||
|
||||
bool disableNewUser = dbSource.UpdateData(sqlUser);
|
||||
return disableNewUser;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool EnableUser(UserAccount enableUser, string CreatedBy, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Insert into users table
|
||||
string sqlUser = $"UPDATE users u SET u.IsActive = 1 WHERE u.UserName = '{enableUser.username}'" +
|
||||
$"and u.Role = '{enableUser.role}';";
|
||||
|
||||
bool disableNewUser = dbSource.UpdateData(sqlUser);
|
||||
return disableNewUser;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool BulkOperation(string signedUser, string path, IDataSource<string> dbSource)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the current directory.
|
||||
//string path = Directory.GetCurrentDirectory();
|
||||
// Open file reader stream
|
||||
using StreamReader fileRead = new(path); // path + + "\\BulkOps\\Bulk.txt"
|
||||
// Show location of the file being written
|
||||
//Console.WriteLine(path);
|
||||
|
||||
// List choices of operations
|
||||
List<string> ops = new List<string> {"Create Account", "Edit Account",
|
||||
"Delete Account", "Disable Account", "Enable Account"};
|
||||
|
||||
// List to hold file operation and credentials
|
||||
List<string> fileList = new List<string>();
|
||||
string operation = "";
|
||||
string UN = "";
|
||||
string PWD = "";
|
||||
string Role = "";
|
||||
string Email = "";
|
||||
|
||||
// Loop through file rows
|
||||
while (!fileRead.EndOfStream)
|
||||
{
|
||||
// Create variable to hold current line
|
||||
string line = fileRead.ReadLine();
|
||||
|
||||
// Check if line is not empty and contains the separator
|
||||
if (line != null && line.Contains(":"))
|
||||
{
|
||||
// Assign value to hold current line parameter
|
||||
string value = line.Split(':')[1].Trim();
|
||||
|
||||
// Check what operation is being called
|
||||
if (ops.Contains(value))
|
||||
{
|
||||
// Add operation into temp
|
||||
//Console.WriteLine("Found operation");
|
||||
//Console.WriteLine(value);
|
||||
operation = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
string checkCredential = line.Split(':')[0].Trim();
|
||||
//Console.WriteLine("Found credential");
|
||||
switch (checkCredential)
|
||||
{
|
||||
case "Username":
|
||||
UN = value;
|
||||
break;
|
||||
case "Password":
|
||||
PWD = value;
|
||||
break;
|
||||
case "Role":
|
||||
Role = value;
|
||||
break;
|
||||
case "Email":
|
||||
Email = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(line != null)
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case "Create Account":
|
||||
//Console.WriteLine(operation);
|
||||
if (!String.IsNullOrEmpty(UN))
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
break;
|
||||
case "Edit Account":
|
||||
//Console.WriteLine(operation);
|
||||
//Console.WriteLine(operation);
|
||||
if (String.IsNullOrEmpty(UN))
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
break;
|
||||
case "Delete Account":
|
||||
//Console.WriteLine(operation);
|
||||
//Console.WriteLine(operation);
|
||||
if (String.IsNullOrEmpty(UN))
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
break;
|
||||
case "Disable Account":
|
||||
//Console.WriteLine(operation);
|
||||
//Console.WriteLine(operation);
|
||||
if (String.IsNullOrEmpty(Role) && UN != null)
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
else if (String.IsNullOrEmpty(Email) && UN != null)
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Role);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
else if (String.IsNullOrEmpty(Role) && String.IsNullOrEmpty(Email) && UN != null)
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
break;
|
||||
case "Enable Account":
|
||||
//Console.WriteLine(operation);
|
||||
//Console.WriteLine(operation);
|
||||
if (String.IsNullOrEmpty(Role) && UN != null)
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Email, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
else if (String.IsNullOrEmpty(Email) && UN != null)
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, Role);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
else if (String.IsNullOrEmpty(Role) && String.IsNullOrEmpty(Email) && UN != null)
|
||||
{
|
||||
// Create UserAccount object
|
||||
UserAccount user = new UserAccount(UN, PWD, DateTime.UtcNow);
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
serviceTest.CreateUserRecord(user, signedUser, dbSource);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fileRead.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error reading file");
|
||||
Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,366 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data.Odbc;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{
|
||||
public class SystemAccountManager
|
||||
{
|
||||
public string IsInputValid(string checkUN, string checkPWD)
|
||||
{
|
||||
// Create bool variables to check if username and password are valid
|
||||
bool validUN = checkUN.All(un=>Char.IsLetterOrDigit(un) || un=='@'
|
||||
|| un == '.' || un == ',' || un == '!');
|
||||
|
||||
bool validPwd = checkPWD.All(Char.IsLetterOrDigit);
|
||||
|
||||
|
||||
// Check if any are empty
|
||||
if (checkUN == null || checkPWD == null)
|
||||
{
|
||||
return "Invalid input\n";
|
||||
}
|
||||
// Check if username is within the restricted length
|
||||
else if (checkUN.Length > 15 || checkUN.Length <= 0
|
||||
|| validUN is false)
|
||||
{
|
||||
return "Invalid Username\n";
|
||||
}
|
||||
// Check if password is within the restricted length
|
||||
else if (checkPWD.Length > 18 || checkPWD.Length <= 0
|
||||
|| validPwd is false)
|
||||
{
|
||||
return "Invalid Password\n";
|
||||
}
|
||||
// Check if username and password are valid
|
||||
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||
&& validUN is true && checkPWD.Length <= 18
|
||||
&& checkPWD.Length > 0 && validPwd is true)
|
||||
{
|
||||
return "Username and password is valid.\n";
|
||||
}
|
||||
// Check if username and password and email are valid
|
||||
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||
&& validUN is true && checkPWD.Length <= 18
|
||||
&& checkPWD.Length > 0 && validPwd is true)
|
||||
{
|
||||
return "Username and password is valid.\n";
|
||||
}
|
||||
// For testing to make sure username is valid
|
||||
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||
&& validUN is true)
|
||||
{
|
||||
return "Valid Username\n";
|
||||
}
|
||||
// For testing to make sure password is valid
|
||||
else if (checkPWD.Length <= 18 && checkPWD.Length > 0
|
||||
&& validPwd is true)
|
||||
{
|
||||
return "Valid Password\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Invalid input\n";
|
||||
}
|
||||
}
|
||||
public string IsInputValid(string checkUN, string checkPWD, string email, string role)
|
||||
{
|
||||
// Create bool variables to check if username and password and email are valid
|
||||
bool validUN = checkUN.All(un => Char.IsLetterOrDigit(un) || un == '@'
|
||||
|| un == '.' || un == ',' || un == '!');
|
||||
|
||||
bool validPwd = checkPWD.All(Char.IsLetterOrDigit);
|
||||
|
||||
bool validEmail = email.All(email => Char.IsLetterOrDigit(email) && email == '@'
|
||||
&& email == '.');
|
||||
|
||||
bool validRole = role.All(role => Char.IsLetter(role));
|
||||
|
||||
// Check if any are empty
|
||||
if (checkUN == null || checkPWD == null || email == null)
|
||||
{
|
||||
return "Invalid input\n";
|
||||
}
|
||||
// Check if username is within the restricted length
|
||||
else if (checkUN.Length > 15 || checkUN.Length <= 0
|
||||
|| validUN is false)
|
||||
{
|
||||
return "Invalid Username\n";
|
||||
}
|
||||
// Check if password is within the restricted length
|
||||
else if (checkPWD.Length > 18 || checkPWD.Length <= 0
|
||||
|| validPwd is false)
|
||||
{
|
||||
return "Invalid Password\n";
|
||||
}
|
||||
// Check if email is within the restricted length
|
||||
else if (email.Length > 18 || email.Length <= 0
|
||||
|| validEmail is false)
|
||||
{
|
||||
return "Invalid Email.\n";
|
||||
}
|
||||
// Check if username and password are valid
|
||||
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||
&& validUN is true && checkPWD.Length <= 18
|
||||
&& checkPWD.Length > 0 && validPwd is true)
|
||||
{
|
||||
return "Username and password is valid.\n";
|
||||
}
|
||||
// Check if username and password and email are valid
|
||||
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||
&& validUN is true && checkPWD.Length <= 18
|
||||
&& checkPWD.Length > 0 && validPwd is true
|
||||
&& email.Length > 18 && email.Length <= 0
|
||||
&& validEmail is true)
|
||||
{
|
||||
return "Username and password is valid.\n";
|
||||
}
|
||||
// For testing to make sure username is valid
|
||||
else if (checkUN.Length <= 15 && checkUN.Length > 0
|
||||
&& validUN is true)
|
||||
{
|
||||
return "Valid Username\n";
|
||||
}
|
||||
// For testing to make sure password is valid
|
||||
else if (checkPWD.Length <= 18 && checkPWD.Length > 0
|
||||
&& validPwd is true)
|
||||
{
|
||||
return "Valid Password\n";
|
||||
}
|
||||
// For testing to make sure email is valid
|
||||
else if (email.Length > 18 && email.Length <= 0
|
||||
&& validEmail is true)
|
||||
{
|
||||
return "Valid Password\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Invalid input\n";
|
||||
}
|
||||
}
|
||||
// Check with database if user is an admin
|
||||
public bool isAdmin(UserAccount user, IDataSource<string> dbSource)
|
||||
{
|
||||
// string checkAdmin = $"Select * from users where username = {user.username} and password = {user.password};";
|
||||
string checkAdmin = $"select r.Role from roles r, users u where " +
|
||||
$"UserName = '{user.username}' and Password = '{user.password}' and r.Role = u.Role;";
|
||||
Object confirmAdmin = dbSource.ReadData(checkAdmin);
|
||||
//Console.WriteLine("type of Reesult:" + confirmAdmin.GetType());
|
||||
OdbcDataReader reader = null;
|
||||
|
||||
if (confirmAdmin.GetType() == typeof(OdbcDataReader))
|
||||
{
|
||||
reader = (OdbcDataReader)confirmAdmin;
|
||||
}
|
||||
|
||||
// Create String to hold sql output
|
||||
string checkSql = "";
|
||||
|
||||
// Read Sql query results
|
||||
while (reader.Read())
|
||||
{
|
||||
checkSql = reader.GetString(0);
|
||||
}
|
||||
|
||||
SqlDAO sqlDS = (SqlDAO)dbSource;
|
||||
Console.WriteLine("");
|
||||
|
||||
// Closing the connection
|
||||
sqlDS.GetConnection().Close();
|
||||
|
||||
if (checkSql == "Admin")
|
||||
{
|
||||
Console.WriteLine("-- Logged in successfully.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public string CreateUserRecord(UserAccount user, IDataSource<string> dbSource)
|
||||
{
|
||||
// Check Login inputs
|
||||
IsInputValid(user.username, user.password);
|
||||
|
||||
bool Admin = isAdmin(user, dbSource);
|
||||
|
||||
// Give access if the user is and Admin
|
||||
if (Admin is false)
|
||||
{
|
||||
return "Access Denied: Unauthorized\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
// db.users layout (UserName, Password, RoleID, IsActive, CreatedBy, CreatedDate)
|
||||
// db.roles layout (RoleID(AutoGen), Role, CreatedBy, CreatedDate)
|
||||
// Create UiPrint Object
|
||||
UiPrint ui = new UiPrint();
|
||||
// Create Account Service object
|
||||
AccountService accountService = new AccountService();
|
||||
// Create credentials object for new inptus
|
||||
GetCredentials newCredentials = new GetCredentials();
|
||||
// Create bool object for menu loop
|
||||
bool menuLoop = true;
|
||||
// Create loop for menu
|
||||
while (menuLoop is true) {
|
||||
// Print User Management menu
|
||||
ui.UserManagementMenu(user.username);
|
||||
// Get user choice
|
||||
int menuChoice = Convert.ToInt32(Console.ReadLine());
|
||||
// Complete the appropriate action
|
||||
switch (menuChoice)
|
||||
{
|
||||
// Exit menu
|
||||
case 0:
|
||||
return "Back to Login";
|
||||
// Create account
|
||||
case 1:
|
||||
// Get all credentials and create newUser
|
||||
UserAccount newUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.ConfirmPassword(), newCredentials.GetEmail(),
|
||||
newCredentials.GetRole(), DateTime.UtcNow);
|
||||
bool accountValid = accountService.CreateUserRecord(newUser, user.username, dbSource);
|
||||
if (accountValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount created Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Database Timed out";
|
||||
}
|
||||
// Edit account
|
||||
case 2:
|
||||
// State what account is being edited
|
||||
string userName = newCredentials.GetUserName();
|
||||
|
||||
// Notify the user of what can be edited
|
||||
Console.WriteLine($"\n****The following information will be used to update {userName}");
|
||||
|
||||
// Get updated parameters
|
||||
UserAccount newEditUser = new UserAccount(userName,
|
||||
newCredentials.GetPassword(), newCredentials.GetEmail(),
|
||||
newCredentials.GetRole(), DateTime.UtcNow);
|
||||
bool editValid = accountService.EditUserRecord(newEditUser, user.username, dbSource);
|
||||
if (editValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount updated Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Database Timed out";
|
||||
}
|
||||
break;
|
||||
// Delete account
|
||||
case 3:
|
||||
UserAccount newDeleteUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.GetPassword(), DateTime.UtcNow);
|
||||
bool deleteValid = accountService.DeleteUserRecord(newDeleteUser, user.username , dbSource);
|
||||
if (deleteValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount deleted Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "User does not exist";
|
||||
}
|
||||
break;
|
||||
// Disable account
|
||||
case 4:
|
||||
UserAccount newDisableUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.GetRole());
|
||||
bool disableValid = accountService.DisableUser(newDisableUser, user.username , dbSource);
|
||||
if (disableValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount disabled Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "User does not exist";
|
||||
}
|
||||
break;
|
||||
// Enable account
|
||||
case 5:
|
||||
UserAccount newEnableUser = new UserAccount(newCredentials.GetUserName(),
|
||||
newCredentials.GetRole());
|
||||
bool enableValid = accountService.EnableUser(newEnableUser, user.username , dbSource);
|
||||
if (enableValid is true)
|
||||
{
|
||||
Console.WriteLine("\nAccount enabled Successfully");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "User does not exist";
|
||||
}
|
||||
break;
|
||||
// Bulk operation through file
|
||||
case 6:
|
||||
AccountService bulkOP = new AccountService();
|
||||
// Get path to defualt bin location
|
||||
string path = Directory.GetCurrentDirectory();
|
||||
while (true)
|
||||
{
|
||||
// Get name of file and update path to correct folder
|
||||
Console.WriteLine("Please input the name of the file:(Example.txt)");
|
||||
string filename = $"{path}\\{Console.ReadLine()}";
|
||||
//Console.WriteLine(filename)
|
||||
|
||||
// Get filesize
|
||||
long fileSize = filename.Length;
|
||||
long fileSizeGB = fileSize / (1024 * 1024);
|
||||
//Console.WriteLine($"File size is {fileSize}kb");
|
||||
|
||||
// Check if input is empty
|
||||
if (filename == null)
|
||||
{
|
||||
Console.WriteLine("Invalid file name.\n");
|
||||
}
|
||||
// Check if file is over 2GB
|
||||
else if (fileSizeGB > 2)
|
||||
{
|
||||
Console.WriteLine($"File size is {fileSizeGB}GB\n");
|
||||
Console.WriteLine("File is too large, please enter a smaller file.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Begin bulk operation
|
||||
Console.WriteLine("Running bulk operation...");
|
||||
bool bulkReq = bulkOP.BulkOperation(user.username, filename, dbSource);
|
||||
if (bulkReq is true)
|
||||
{
|
||||
Console.WriteLine("\nBulk operation complete");
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Bulk operation failed";
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
// View logs
|
||||
case 7:
|
||||
break;
|
||||
// View archive
|
||||
case 8:
|
||||
Console.WriteLine("C:/HobbyArchive");
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Invalid input.\nPlease enter a valid option.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return "Back to Login";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.ServiceLayer
|
||||
{ // Class for getting user credentials
|
||||
public class GetCredentials
|
||||
{
|
||||
public string? GetUserName()
|
||||
{
|
||||
Console.WriteLine("Please enter a username:");
|
||||
string? userName = Console.ReadLine();
|
||||
return userName;
|
||||
}
|
||||
public string? GetPassword()
|
||||
{
|
||||
Console.WriteLine("Please enter a password:");
|
||||
string? userPassword = Console.ReadLine();
|
||||
return userPassword;
|
||||
}
|
||||
public string ConfirmPassword()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine("Please enter a password:");
|
||||
string? userPassword = Console.ReadLine();
|
||||
// Confirm Password
|
||||
Console.WriteLine("Please re-enter the password:");
|
||||
string checkPsswd = Console.ReadLine();
|
||||
// Check if passwords match
|
||||
if (userPassword == checkPsswd)
|
||||
{
|
||||
return userPassword;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Passwords do not match.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
public string GetEmail()
|
||||
{
|
||||
Console.WriteLine("Please enter an email:");
|
||||
return Console.ReadLine();
|
||||
}
|
||||
public string GetRole()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
// List of possible roles
|
||||
List<string> roles = new List<string> {"Admin", "regular" };
|
||||
// Get role
|
||||
Console.WriteLine("Please enter the role of the user:(Admin or regular)");
|
||||
string? userRole = Console.ReadLine();
|
||||
// Check if passwords match
|
||||
if (roles.Contains(userRole))
|
||||
{
|
||||
return userRole;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Not an available role.\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Console.ReadLine();
|
||||
}
|
||||
}
|
||||
public class UserAccount
|
||||
{
|
||||
// Admin Credentials
|
||||
private string _userName;
|
||||
private string _password;
|
||||
private DateTime _Time;
|
||||
// New User Credentials
|
||||
private string _Email;
|
||||
private string _Role;
|
||||
|
||||
public UserAccount(string un, string pwd, DateTime TimeStamp)
|
||||
{
|
||||
_userName = un;
|
||||
_password = pwd;
|
||||
_Role = "regular";
|
||||
_Email = "NULL";
|
||||
_Time = TimeStamp;
|
||||
}
|
||||
public UserAccount(string un, string pwd, string role)
|
||||
{
|
||||
if (String.IsNullOrEmpty(role))
|
||||
{
|
||||
_Role = "regular";
|
||||
}
|
||||
else { _Role = role; }
|
||||
_userName = un;
|
||||
_password = pwd;
|
||||
_Email = "NULL";
|
||||
_Time = DateTime.UtcNow;
|
||||
}
|
||||
public UserAccount(string un, string role)
|
||||
{
|
||||
_userName = un;
|
||||
_Role = role;
|
||||
_Email = "NULL";
|
||||
_Time = DateTime.UtcNow;
|
||||
}
|
||||
public UserAccount(string un, string pwd, string Email, DateTime TimeStamp)
|
||||
{
|
||||
if (String.IsNullOrEmpty(Email))
|
||||
{
|
||||
_Email = "NULL";
|
||||
}
|
||||
else { _Email = Email; }
|
||||
_userName = un;
|
||||
_password = pwd;
|
||||
_Role = "regular";
|
||||
_Time = TimeStamp;
|
||||
}
|
||||
public UserAccount(string newUN, string newPWD, string Email, string role, DateTime newTime)
|
||||
{
|
||||
if (String.IsNullOrEmpty(role))
|
||||
{
|
||||
_Role = "regular";
|
||||
}
|
||||
else { _Role = role; }
|
||||
if (String.IsNullOrEmpty(Email))
|
||||
{
|
||||
_Email = "NULL";
|
||||
}
|
||||
else { _Email = Email; }
|
||||
_userName = newUN;
|
||||
_password = newPWD;
|
||||
_Time = newTime;
|
||||
}
|
||||
public UserAccount()
|
||||
{
|
||||
_Role = "regular";
|
||||
_Email = "NULL";
|
||||
_Time = DateTime.Now;
|
||||
}
|
||||
|
||||
public string username { get { return _userName; } }
|
||||
public string password { get { return _password; } }
|
||||
public string email { get { return _Email; } }
|
||||
public string role { get { return _Role; } }
|
||||
public DateTime Time { get { return _Time; } }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,378 @@
|
||||
using System;
|
||||
using System.Data.Odbc;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace TeamHobby.Archiving.xTests
|
||||
|
||||
|
||||
{
|
||||
public class ArchivingXUnitTest
|
||||
{
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
|
||||
ITestOutputHelper output;
|
||||
public ArchivingXUnitTest(ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsArchiveFolderCreated()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
bool expectedVal = true;
|
||||
|
||||
// Act
|
||||
archiveManager.CreateArchiveFolder();
|
||||
|
||||
|
||||
// Assert
|
||||
bool actualVal = Directory.Exists(folderPath);
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
// Cleaning up directory after test
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed. ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsFileNameCreated()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
string foldPath = @"C:\HobbyArchive";
|
||||
string fileName = DateTime.Now.ToString("M_d_yyyy") + "_archive.csv";
|
||||
string expectedFilePath = System.IO.Path.Combine(foldPath, fileName);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
|
||||
// Act
|
||||
string actualFilePath = archiveManager.CreateOutFileName();
|
||||
|
||||
// Assert
|
||||
|
||||
Assert.Equal(expectedFilePath, actualFilePath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsCSVFileExist()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
SqlDAO sqlDS = null;
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
|
||||
try
|
||||
{
|
||||
bool folderRes = archiveManager.CreateArchiveFolder();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Folder creation for copying failed");
|
||||
}
|
||||
string filePath = archiveManager.CreateOutFileName();
|
||||
bool expectedVal = true;
|
||||
|
||||
if (sqlDAO.GetType() == typeof(SqlDAO))
|
||||
{
|
||||
sqlDS = (SqlDAO)sqlDAO;
|
||||
}
|
||||
|
||||
// Act
|
||||
if (sqlDS != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
sqlDS.CopyToFile(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Copying to a file failed !!");
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
bool actualVal = File.Exists(filePath);
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed. ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsEntriesRemoved()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
OdbcDataReader odbcObj = null;
|
||||
Object resultData = null;
|
||||
bool expectedVal = false;
|
||||
|
||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||
|
||||
// Act
|
||||
sqlDAO.RemoveEntries();
|
||||
|
||||
// Assert
|
||||
bool actualVal;
|
||||
|
||||
resultData = sqlDAO.ReadData("SELECT * FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||
if ((resultData != null) && (resultData.GetType() == typeof(OdbcDataReader)))
|
||||
{
|
||||
odbcObj = (OdbcDataReader)resultData;
|
||||
}
|
||||
OdbcConnection conn = sqlDAO.GetConnection();
|
||||
actualVal = odbcObj.HasRows;
|
||||
conn.Close();
|
||||
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void IsOutputFileRemoved()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
bool expectedVal = false;
|
||||
//Thread.Sleep(5000);
|
||||
|
||||
// Create the folder and the csv file for compressing
|
||||
archiveManager.CreateArchiveFolder();
|
||||
string filepath = archiveManager.CreateOutFileName();
|
||||
sqlDAO.CopyToFile(filepath);
|
||||
|
||||
// Act
|
||||
if (sqlDAO != null)
|
||||
{
|
||||
sqlDAO.RemoveOutputFile(filepath);
|
||||
}
|
||||
|
||||
// Assert
|
||||
bool actualVal = File.Exists(filepath);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsFileCompressed()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
|
||||
// Create the folder and the csv file to be compressed.
|
||||
archiveManager.CreateArchiveFolder();
|
||||
string filePath = archiveManager.CreateOutFileName();
|
||||
sqlDAO.CopyToFile(filePath);
|
||||
FileAttributes expectedAttribute = FileAttributes.Archive;
|
||||
string compFilePath = Path.ChangeExtension(filePath, ".gz");
|
||||
|
||||
// Act
|
||||
sqlDAO.CompressFile(filePath);
|
||||
|
||||
// Assert
|
||||
FileAttributes actualAttribute = File.GetAttributes(compFilePath);
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualAttribute, expectedAttribute);
|
||||
Assert.Equal(expectedAttribute, actualAttribute);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsArchive_Under_60s_10kRecords()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
var timer = new Stopwatch();
|
||||
double expectedVal = 60;
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
|
||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||
|
||||
for (int i = 0; i <= 11; i++)
|
||||
{
|
||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||
}
|
||||
|
||||
// Act
|
||||
timer.Start();
|
||||
archiveManager.Controller();
|
||||
timer.Stop();
|
||||
|
||||
// Assert
|
||||
var actualVal = timer.Elapsed.Seconds;
|
||||
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
||||
Assert.True(actualVal < expectedVal);
|
||||
|
||||
// Clean up resources after testing
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed... ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsArchive_Under_60s_1mRecords()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archiveManager = new ArchiveManager(sqlDAO);
|
||||
var timer = new Stopwatch();
|
||||
double expectedVal = 60;
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
|
||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||
|
||||
for (int i = 0; i <= 18; i++)
|
||||
{
|
||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||
}
|
||||
|
||||
// Act
|
||||
timer.Start();
|
||||
archiveManager.Controller();
|
||||
timer.Stop();
|
||||
|
||||
// Arrange
|
||||
double actualVal = timer.Elapsed.Seconds;
|
||||
output.WriteLine("Actual value: {0}s, Expected value: {1}s", actualVal, expectedVal);
|
||||
Assert.True(actualVal < expectedVal);
|
||||
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
//Clean up resources after testing
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed... ");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
// [Test Method]
|
||||
public void IsProcessFlowCompleted()
|
||||
{
|
||||
// Arrange
|
||||
SqlDAO sqlDAO = new SqlDAO(dbInfo);
|
||||
ArchiveManager archive = new ArchiveManager(sqlDAO);
|
||||
bool expectedVal = true;
|
||||
bool actualVal = false;
|
||||
string folderPath = @"C:/HobbyArchive";
|
||||
|
||||
// Adding 10000 records to database for testing
|
||||
sqlDAO.WriteData("INSERT into log(LtimeStamp, LvName, catname, userop, logmessage) values" +
|
||||
"('2021-08-07 23:00:00', 'Info', 'View', 'create some projects', 'new account created')," +
|
||||
"('2021-06-04 23:00:00', 'Info', 'Business', 'create some projects', 'new projects made')," +
|
||||
"('2021-07-02 23:00:00', 'Info', 'View', 'log out', 'log out successful')," +
|
||||
"('2021-09-03 23:00:00', 'Info', 'Business', 'log in', 'log in successfully')," +
|
||||
"('2021-10-20 23:00:00', 'Info', 'View', 'search for projects', 'result return');");
|
||||
|
||||
for (int j = 0; j <= 11; j++)
|
||||
{
|
||||
sqlDAO.WriteData("INSERT INTO log(LtimeStamp, LvName, catName, userOP, logMessage) " +
|
||||
"SELECT LtimeStamp, LvName, catName, userOP, logMessage FROM log WHERE DATEDIFF(CURRENT_TIMESTAMP, log.LtimeStamp) > 30;");
|
||||
}
|
||||
|
||||
// Act
|
||||
// Testing archive Manager
|
||||
int i = -10;
|
||||
while (i < 20)
|
||||
{
|
||||
DateTime date1 = new DateTime(2021, 12, 1, 0, 0, 0);
|
||||
string currentTime = "00:00:00 AM";
|
||||
string currentDate = i.ToString();
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
currentDate = date1.ToString("dd");
|
||||
}
|
||||
|
||||
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||
Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||
if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM"))
|
||||
{
|
||||
Console.WriteLine("Archiving process Start");
|
||||
actualVal = archive.Controller();
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// Assert
|
||||
output.WriteLine("Actual value: {0}, Expected value: {1}", actualVal, expectedVal);
|
||||
Assert.Equal(expectedVal, actualVal);
|
||||
output.WriteLine("Cleaning up Folder and File used for testing... ");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folderPath, true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Folder failed to be deleted");
|
||||
}
|
||||
output.WriteLine("Cleaning up completed... ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\main\TeamHobby.HobbyProjectGenerator.Main.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,264 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using System.Threading;
|
||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
using System.IO;
|
||||
|
||||
namespace TeamHobby.UserManagement.xTests
|
||||
{
|
||||
public class UseerManagementTests
|
||||
{
|
||||
|
||||
ITestOutputHelper output;
|
||||
public UseerManagementTests(ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
// User is able to perform any single UM operation within 5 seconds upon invocation.A system message displays “UM operation was successful”
|
||||
[Fact]
|
||||
public void SingleOperationinFiveSec()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
// Assert
|
||||
if (sec > 5)
|
||||
{
|
||||
output.WriteLine("Single Operation was unsuccessful");
|
||||
Assert.True(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(true);
|
||||
output.WriteLine("Single Operation was successful");
|
||||
}
|
||||
}
|
||||
|
||||
// Single UM operation takes longer than 5 seconds
|
||||
[Fact]
|
||||
public void FailSingleOperationinFiveSec()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
||||
Thread.Sleep(6000);
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
// Assert
|
||||
if (sec > 5)
|
||||
{
|
||||
output.WriteLine("Single Operation was unsuccessful");
|
||||
Assert.False(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(false);
|
||||
output.WriteLine("Single Operation was successful");
|
||||
}
|
||||
}
|
||||
// Single UM operation completes within 5 seconds, but no system message is shown or inaccurate system message is shown
|
||||
[Fact]
|
||||
public void SingleOperationwithMessage()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
var TestAcc = new UserAccount("newUserMessage", "4567", "email@a.com", "regular", sTime);
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
var checkMess = false;
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
// Assert
|
||||
if (sec > 5)
|
||||
{
|
||||
var message = "Single Operation was unsuccessful";
|
||||
Assert.False(true);
|
||||
output.WriteLine(message);
|
||||
if (checkMess)
|
||||
{
|
||||
Assert.False(true);
|
||||
throw new Exception("Message was not printed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(true);
|
||||
var message2 = "Single Operation was successful";
|
||||
output.WriteLine(message2);
|
||||
if (!checkMess)
|
||||
{
|
||||
output.WriteLine("Message was printed");
|
||||
Assert.True(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bulk UM operations completes within 60 seconds, but no system message is shown or inaccurate system message is shown
|
||||
[Fact]
|
||||
public void BulkOperationwithMessage()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
var checkMess = false;
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
string path = Directory.GetCurrentDirectory();
|
||||
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
//for (int i = 0; i < 10000; i++)
|
||||
//{
|
||||
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
||||
serviceTest.BulkOperation("Rifat", path + "\\Bulk.txt", datasource);
|
||||
//}
|
||||
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
|
||||
// Assert
|
||||
if (sec > 60)
|
||||
{
|
||||
var message = "Bulk Operation was unsuccessful";
|
||||
Assert.True(false);
|
||||
output.WriteLine(message);
|
||||
if (checkMess)
|
||||
{
|
||||
Assert.True(false);
|
||||
throw new Exception("Message was not printed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(true);
|
||||
var message2 = "Bulk Operation was successful";
|
||||
output.WriteLine(message2);
|
||||
if (!checkMess)
|
||||
{
|
||||
output.WriteLine("Message was printed");
|
||||
Assert.True(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// User is able to perform less than 10K UM operations in bulk within 60 seconds. A system message displays “Bulk UM operation was successful”
|
||||
[Fact]
|
||||
public void BulkOperationforSixty()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
string dir = Directory.GetCurrentDirectory();
|
||||
string path = dir + "\\Bulk.txt";
|
||||
output.WriteLine(path);
|
||||
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
//for (int i = 0; i < 10000; i++)
|
||||
//{
|
||||
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
||||
serviceTest.BulkOperation("Rifat", path, datasource);
|
||||
//}
|
||||
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
|
||||
// Assert
|
||||
if (sec > 60)
|
||||
{
|
||||
output.WriteLine("Bulk Operation was unsuccessful");
|
||||
Assert.True(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(true);
|
||||
output.WriteLine("Bulk Operation was successful");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
namespace TeamHobby.HobbyProjectGenerator.View
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,7 @@
|
||||
namespace TeamHobby.HobbyProjectGenerator.ViewModel
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Contracts\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,86 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31919.166
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Main", "..\main\TeamHobby.HobbyProjectGenerator.Main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D29D9225-3748-4067-AF07-E677A525EF39}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
TeamHobby.HobbyProjectGenerator.csproj = TeamHobby.HobbyProjectGenerator.csproj
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Tests", "TeamHobby.HobbyProjectGenerator.Tests\TeamHobby.HobbyProjectGenerator.Tests.csproj", "{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.ServiceLayer", "TeamHobby.HobbyProjectGenerator.ServiceLayer\TeamHobby.HobbyProjectGenerator.ServiceLayer.csproj", "{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DataAccessLayer", "..\TeamHobby.HobbyProjectGenerator.DataAccessLayer\TeamHobby.HobbyProjectGenerator.DataAccessLayer.csproj", "{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.ViewModel", "TeamHobby.HobbyProjectGenerator.ViewModel\TeamHobby.HobbyProjectGenerator.ViewModel.csproj", "{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.View", "TeamHobby.HobbyProjectGenerator.View\TeamHobby.HobbyProjectGenerator.View.csproj", "{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{30C7EBF3-3957-46E5-86C1-C13356841ECA}.Release|x86.Build.0 = Release|Any CPU
|
||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{2E9DC0A0-D9A1-40A5-9684-ECC8EDCD8DAD}.Release|x86.Build.0 = Release|Any CPU
|
||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{EF90CC6C-0C44-4E39-AAB6-96F9F34F0784}.Release|x86.Build.0 = Release|Any CPU
|
||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{6DBAC411-AC0E-4129-AE57-C8D1DA1DF9B2}.Release|x86.Build.0 = Release|Any CPU
|
||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{092F7372-3CBA-49A2-A7A8-EC3FF97E3082}.Release|x86.Build.0 = Release|Any CPU
|
||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{2E401E9D-731B-425D-B0BD-FF1E72D5D23C}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {B2517200-A9F9-468C-B0EB-280FF9B9FBC9}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||
<ProjectReference Include="..\..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,264 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using System.Threading;
|
||||
using TeamHobby.HobbyProjectGenerator.UserManagement;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||
using System.IO;
|
||||
|
||||
namespace TeamHobby.UserManagement.xTests
|
||||
{
|
||||
public class UseerManagementTests
|
||||
{
|
||||
|
||||
ITestOutputHelper output;
|
||||
public UseerManagementTests(ITestOutputHelper output)
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
// User is able to perform any single UM operation within 5 seconds upon invocation.A system message displays “UM operation was successful”
|
||||
[Fact]
|
||||
public void SingleOperationinFiveSec()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
// Assert
|
||||
if (sec > 5)
|
||||
{
|
||||
output.WriteLine("Single Operation was unsuccessful");
|
||||
Assert.True(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(true);
|
||||
output.WriteLine("Single Operation was successful");
|
||||
}
|
||||
}
|
||||
|
||||
// Single UM operation takes longer than 5 seconds
|
||||
[Fact]
|
||||
public void FailSingleOperationinFiveSec()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
var TestAcc = new UserAccount("newUser", "4567", "email@a.com", "regular", sTime);
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
||||
Thread.Sleep(6000);
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
// Assert
|
||||
if (sec > 5)
|
||||
{
|
||||
output.WriteLine("Single Operation was unsuccessful");
|
||||
Assert.False(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(false);
|
||||
output.WriteLine("Single Operation was successful");
|
||||
}
|
||||
}
|
||||
// Single UM operation completes within 5 seconds, but no system message is shown or inaccurate system message is shown
|
||||
[Fact]
|
||||
public void SingleOperationwithMessage()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
var TestAcc = new UserAccount("newUserMessage", "4567", "email@a.com", "regular", sTime);
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
var checkMess = false;
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
serviceTest.CreateUserRecord(TestAcc, "Rifat", datasource);
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
// Assert
|
||||
if (sec > 5)
|
||||
{
|
||||
var message = "Single Operation was unsuccessful";
|
||||
Assert.False(true);
|
||||
output.WriteLine(message);
|
||||
if (checkMess)
|
||||
{
|
||||
Assert.False(true);
|
||||
throw new Exception("Message was not printed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(true);
|
||||
var message2 = "Single Operation was successful";
|
||||
output.WriteLine(message2);
|
||||
if (!checkMess)
|
||||
{
|
||||
output.WriteLine("Message was printed");
|
||||
Assert.True(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bulk UM operations completes within 60 seconds, but no system message is shown or inaccurate system message is shown
|
||||
[Fact]
|
||||
public void BulkOperationwithMessage()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
var checkMess = false;
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
string path = Directory.GetCurrentDirectory();
|
||||
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
//for (int i = 0; i < 10000; i++)
|
||||
//{
|
||||
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
||||
serviceTest.BulkOperation("Rifat", path + "\\Bulk.txt", datasource);
|
||||
//}
|
||||
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
|
||||
// Assert
|
||||
if (sec > 60)
|
||||
{
|
||||
var message = "Bulk Operation was unsuccessful";
|
||||
Assert.True(false);
|
||||
output.WriteLine(message);
|
||||
if (checkMess)
|
||||
{
|
||||
Assert.True(false);
|
||||
throw new Exception("Message was not printed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(true);
|
||||
var message2 = "Bulk Operation was successful";
|
||||
output.WriteLine(message2);
|
||||
if (!checkMess)
|
||||
{
|
||||
output.WriteLine("Message was printed");
|
||||
Assert.True(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// User is able to perform less than 10K UM operations in bulk within 60 seconds. A system message displays “Bulk UM operation was successful”
|
||||
[Fact]
|
||||
public void BulkOperationforSixty()
|
||||
{
|
||||
// Arrange
|
||||
DateTime sTime = DateTime.Now;
|
||||
|
||||
var serviceTest = new AccountService();
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
string dir = Directory.GetCurrentDirectory();
|
||||
string path = dir + "\\Bulk.txt";
|
||||
output.WriteLine(path);
|
||||
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Act
|
||||
// Create a file
|
||||
//for (int i = 0; i < 10000; i++)
|
||||
//{
|
||||
//var TestAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@a.com", "regular", sTime);
|
||||
serviceTest.BulkOperation("Rifat", path, datasource);
|
||||
//}
|
||||
|
||||
DateTime eTime = DateTime.Now;
|
||||
TimeSpan timeDiff = (eTime - sTime);
|
||||
var sec = timeDiff.TotalSeconds;
|
||||
|
||||
|
||||
// Assert
|
||||
if (sec > 60)
|
||||
{
|
||||
output.WriteLine("Bulk Operation was unsuccessful");
|
||||
Assert.True(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.True(true);
|
||||
output.WriteLine("Bulk Operation was successful");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Source Code/TeamHobby/Class1.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace TeamHobby
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
9
Source Code/TeamHobby/TeamHobby.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
108
Source Code/main/Controller.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Data.Odbc;
|
||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
|
||||
namespace TeamHobby.HobbyProjectGenerator.Main
|
||||
{
|
||||
public class Controller
|
||||
{
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Console customization
|
||||
// Change the look of the console
|
||||
Console.Title = "HobbyProjectGenerator";
|
||||
// Change console text color
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
// Change terminal height
|
||||
Console.WindowHeight = 40;
|
||||
|
||||
// Creating the Factory class
|
||||
// Logger log = new Logger();
|
||||
//Logger.PrintTest();
|
||||
|
||||
// Loop login terminal
|
||||
bool mainMenu = true;
|
||||
|
||||
// Loop Admin login
|
||||
while (mainMenu is true)
|
||||
{
|
||||
// Create credentials object
|
||||
GetCredentials credentials = new GetCredentials();
|
||||
|
||||
// Get DB credentials ***Both values currently hard coded, will update to user input later on.***
|
||||
string dbUserName = "root";
|
||||
string dbPassword = "Teamhobby";
|
||||
|
||||
// Admin Sign in
|
||||
Console.WriteLine("\nPlease Enter Admin Credentials " +
|
||||
"or enter 0 to exit the machine\n");
|
||||
string? username = credentials.GetUserName();
|
||||
//int menuExit = Convert.ToInt32(username);
|
||||
// Exit Infinite Menu
|
||||
if (username == "0")
|
||||
{
|
||||
break;
|
||||
}
|
||||
string? password = credentials.GetPassword();
|
||||
|
||||
// Get time of login attempt
|
||||
DateTime TimeStamp = DateTime.UtcNow;
|
||||
|
||||
// String for checking query return type
|
||||
string dbType = "sql";
|
||||
// Creating the Factory class
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
$"UID={dbUserName};" +
|
||||
$"PASSWORD={dbPassword};" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// While loop to keep this running forever with UserManagement
|
||||
// Testing archive Manager
|
||||
//while (true)
|
||||
//{
|
||||
string currentDate = DateTime.Now.ToString("dd");
|
||||
string currentTime = DateTime.Now.ToString("T");
|
||||
//Console.WriteLine("Current date: {0}, Current Time: {1}", currentDate, currentTime);
|
||||
if (String.Equals(currentDate, "01") && String.Equals(currentTime, "00:00:00 AM"))
|
||||
{
|
||||
ArchiveManager archive = new ArchiveManager(datasource);
|
||||
archive.Controller();
|
||||
}
|
||||
//}
|
||||
|
||||
// Create manager class from UserManagement
|
||||
SystemAccountManager manager = new SystemAccountManager();
|
||||
|
||||
// Create UserAccount class
|
||||
UserAccount user = new UserAccount(username, password, TimeStamp);
|
||||
// Call user object and wait for return string
|
||||
string isLogin = manager.CreateUserRecord(user, datasource);
|
||||
|
||||
// If login is not incorrect and user is returning to login menu
|
||||
if (isLogin != "Access Denied: Unauthorized\n")
|
||||
{
|
||||
Console.WriteLine("Returning to login...\n");
|
||||
Console.WriteLine("-------------------------------------\n");
|
||||
}
|
||||
// If login is incorrect
|
||||
else
|
||||
{
|
||||
Console.WriteLine("******Access Denied: Unauthorized******");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
70
Source Code/main/GenerateOpFile.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TeamHobby.HobbyProjectGenerator.DataAccessLayer;
|
||||
using TeamHobby.HobbyProjectGenerator.ServiceLayer;
|
||||
|
||||
namespace main
|
||||
{
|
||||
public class GenerateOpFile
|
||||
{
|
||||
public void GenerateOPFile()
|
||||
//public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Get the current directory.
|
||||
string path = Directory.GetCurrentDirectory();
|
||||
// Open file stream
|
||||
using StreamWriter file = new(path + "\\BulkOps\\Bulk.txt", append: true);
|
||||
// Show location of the file being written
|
||||
Console.WriteLine(path + "\\BulkOps\\Bulk.txt");
|
||||
|
||||
// List choices of operations
|
||||
List<string> ops = new List<string> {"Create Account", "Edit Account",
|
||||
"Delete Account", "Disable Account", "Enable Account"};
|
||||
// Create Account service object
|
||||
AccountService serviceTest = new AccountService();
|
||||
|
||||
// Find database and connect to it
|
||||
string dbType = "sql";
|
||||
RDSFactory dbFactory = new RDSFactory();
|
||||
|
||||
// Testing Data Access Layer
|
||||
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||
"TCPIP=1;" +
|
||||
"SERVER=localhost;" +
|
||||
"DATABASE=hobby;" +
|
||||
"UID=root;" +
|
||||
"PASSWORD=Teamhobby;" +
|
||||
"OPTION=3";
|
||||
IDataSource<string> datasource = dbFactory.getDataSource(dbType, dbInfo);
|
||||
|
||||
// Create a file
|
||||
// Initialize value for random operation
|
||||
Random random = new Random();
|
||||
int index = 0;
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
// Choose random operation
|
||||
index = random.Next(ops.Count);
|
||||
// Create next dummy data
|
||||
UserAccount testAcc = new UserAccount("newUser" + $"{i}", "4567", $"email{i}@aol.com", "regular", DateTime.Now);
|
||||
// Write to file
|
||||
// Write Operation: for now it is only create accounts to avoid errors
|
||||
file.WriteLine($"Operation: {ops[0]}");
|
||||
// Write credentials in the format of: (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email)
|
||||
file.WriteLine($"Username: {testAcc.username}\nPassword: {testAcc.password}\nRole: {testAcc.role}\nEmail: {testAcc.email}\n");
|
||||
}
|
||||
file.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Error reading file");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Source Code/main/TeamHobby.HobbyProjectGenerator.Main.csproj
Normal file
@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccessLayer\TeamHobby.HobbyProjectGenerator.DataAccessLayer.csproj" />
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator\TeamHobby.HobbyProjectGenerator.ServiceLayer\TeamHobby.HobbyProjectGenerator.ServiceLayer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
23
Source Code/main/main - Backup.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Archive\TeamHobby.HobbyProjectGenerator.Archive.csproj" />
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.Logging\TeamHobby.HobbyProjectGenerator.Logging.csproj" />
|
||||
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.UserManagement\TeamHobby.HobbyProjectGenerator.UserManagement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
BIN
doc/Business Docs/Cloud_Service_Tech_Approval.pdf
Normal file
BIN
doc/Business Docs/Network_Diagram.pdf
Normal file
BIN
doc/Business Docs/Project Plan.pdf
Normal file
BIN
doc/Business Docs/Project Roadmap.drawio.png
Normal file
|
After Width: | Height: | Size: 314 KiB |
BIN
doc/Business Docs/Project Roadmap.pdf
Normal file
BIN
doc/Business Docs/Test_Plan.pdf
Normal file
BIN
doc/Business Docs/Testing_Library_Tech_Approval.pdf
Normal file
BIN
doc/Design Docs/HL Design.pdf
Normal file
BIN
doc/Design Docs/HLD_MVVM_v1.jpg
Normal file
|
After Width: | Height: | Size: 136 KiB |
2
doc/Design Docs/Hobby_Site_Map.drawio (1).xml
Normal file
|
Before Width: | Height: | Size: 331 KiB After Width: | Height: | Size: 430 KiB |
BIN
doc/Hobby.png
|
Before Width: | Height: | Size: 286 KiB |
BIN
doc/Images/Network_Diagram.drawio.pdf
Normal file
BIN
doc/Images/Network_Diagram.drawio.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
23
doc/Images/references.txt
Normal file
@ -0,0 +1,23 @@
|
||||
https://aws.amazon.com/rds/
|
||||
https://aws.amazon.com/rds/features/#administration
|
||||
https://docs.microsoft.com/en-us/azure/mariadb/concepts-supported-versions
|
||||
https://cloud.google.com/sql/pricing
|
||||
https://calculator.aws/#/createCalculator/RDSMariaDB
|
||||
https://azure.microsoft.com/en-us/pricing/calculator/
|
||||
https://aws.amazon.com/about-aws/whats-new/2019/06/rds-storage-auto-scaling/
|
||||
https://aws.amazon.com/blogs/database/scaling-your-amazon-rds-instance-vertically-and-horizontally/
|
||||
https://cloud.google.com/architecture/elastically-scaling-your-mysql-environment
|
||||
https://techcommunity.microsoft.com/t5/azure-database-support-blog/how-to-auto-scale-azure-sql-databases/ba-p/2235441
|
||||
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html
|
||||
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZ.html
|
||||
https://docs.microsoft.com/en-us/azure/security/fundamentals/encryption-overview
|
||||
https://cloud.google.com/security/encryption/default-encryption
|
||||
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Encryption.html
|
||||
https://cloud.google.com/compute/docs/regions-zones
|
||||
https://docs.microsoft.com/en-us/azure/availability-zones/az-overview
|
||||
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html
|
||||
https://azure.microsoft.com/en-us/pricing/details/bandwidth/
|
||||
https://aws.amazon.com/ec2/pricing/on-demand/
|
||||
https://cloud.google.com/vpc/network-pricing
|
||||
https://azure.microsoft.com/en-us/pricing/details/azure-sql-database/single/
|
||||
https://azure.microsoft.com/en-us/pricing/details/azure-sql-managed-instance/single/
|
||||
BIN
doc/LowLevel/ArchivingLL/ArchivingWithError.png
Normal file
|
After Width: | Height: | Size: 544 KiB |
1
doc/LowLevel/ArchivingLL/ArchivingWithError.svg
Normal file
|
After Width: | Height: | Size: 92 KiB |
146
doc/LowLevel/ArchivingLL/ArchivingWithError.txt
Normal file
@ -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
|
||||
|
||||
BIN
doc/LowLevel/ArchivingLL/ArchivingWithSingleton.pdf
Normal file
99
doc/LowLevel/ArchivingLL/ArchvingMasterCon.txt
Normal 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
|
||||
BIN
doc/LowLevel/ArchivingLL/archiving.pdf
Normal file
49
doc/LowLevel/ArchivingLL/archiving.txt
Normal file
@ -0,0 +1,49 @@
|
||||
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
|
||||
DataSourceFactory ->DataSourceFactory:DataSourceFactory()\nconstructor
|
||||
ArchiveController.cs <-- DataSourceFactory:return DataSourceFactory
|
||||
deactivate DataSourceFactory
|
||||
|
||||
activate SQLSource
|
||||
ArchiveController.cs->SQLSource: IDataSource DataSourceFact.GetDataSource(String sourceName)
|
||||
SQLSource->SQLSource: SQLSource()\nconstructor
|
||||
SQLSource --> ArchiveController.cs :return SQLSource
|
||||
|
||||
loop #lightblue while true
|
||||
alt #lightgreen date == 1
|
||||
ArchiveController.cs -> SQLSource: int Compress(DataConnection conn, IDataSource ds, String logList[])
|
||||
activate MariaDB
|
||||
alt #lightgreen archive == 0
|
||||
SQLSource -> MariaDB: int createArchive(DataConnection conn, String SQLcmd)
|
||||
MariaDB -->SQLSource:return 0
|
||||
end
|
||||
|
||||
SQLSource ->SQLSource: int updateArchive(DataConnection conn, String logList[])
|
||||
SQLSource ->MariaDB: int CopremovyEntries(DataConnection conn, String logList[])
|
||||
MariaDB --> SQLSource: return 0
|
||||
|
||||
SQLSource ->MariaDB: int RemoveEntries(DataConnection conn, String logList[])
|
||||
MariaDB-->SQLSource:return 0
|
||||
end
|
||||
|
||||
|
||||
deactivate MariaDB
|
||||
|
||||
SQLSource-->ArchiveController.cs:return 0
|
||||
end
|
||||
|
||||
deactivate ArchiveController.cs
|
||||
deactivate SQLSource
|
||||
BIN
doc/LowLevel/ArchivingLL/archiving2.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
46
doc/LowLevel/ArchivingLL/archiving2.txt
Normal file
@ -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
|
||||
BIN
doc/LowLevel/ArchivingLL/archivingMasterCon.pdf
Normal file
BIN
doc/LowLevel/ArchivingLL/archivingSubmission.pdf
Normal file
BIN
doc/LowLevel/ArchivingLL/archivingWithError.pdf
Normal file
BIN
doc/LowLevel/ArchivingLL/archivingWithError2.pdf
Normal file
44
doc/LowLevel/ArchivingLL/archiving_5.txt
Normal file
@ -0,0 +1,44 @@
|
||||
title Use Case: Archiving
|
||||
|
||||
participant ArchiveController.cs
|
||||
participant DataSourceFactory
|
||||
participant SQLSource
|
||||
participant MariaDB
|
||||
|
||||
activate ArchiveController.cs
|
||||
ArchiveController.cs->DataSourceFactory:new DataSourceFactory()
|
||||
activate DataSourceFactory
|
||||
DataSourceFactory ->DataSourceFactory:DataSourceFactory()\nconstructor
|
||||
ArchiveController.cs <-- DataSourceFactory:return DataSourceFactory
|
||||
deactivate DataSourceFactory
|
||||
|
||||
activate SQLSource
|
||||
ArchiveController.cs->SQLSource: IDataSource DataSourceFact.GetDataSource(String sourceName)
|
||||
SQLSource->SQLSource: SQLSource()\nconstructor
|
||||
SQLSource --> ArchiveController.cs :return SQLSource
|
||||
|
||||
loop #lightblue while true
|
||||
alt #lightgreen date == 1
|
||||
ArchiveController.cs -> SQLSource: int Compress(DataConnection conn, IDataSource ds, String logList[])
|
||||
activate MariaDB
|
||||
alt #lightgreen archive == 0
|
||||
SQLSource -> MariaDB: int createArchive(DataConnection conn, String SQLcmd)
|
||||
MariaDB -->SQLSource:return 0
|
||||
end
|
||||
|
||||
SQLSource ->SQLSource: int updateArchive(DataConnection conn, String logList[])
|
||||
SQLSource ->MariaDB: int CopremovyEntries(DataConnection conn, String logList[])
|
||||
MariaDB --> SQLSource: return 0
|
||||
|
||||
SQLSource ->MariaDB: int RemoveEntries(DataConnection conn, String logList[])
|
||||
MariaDB-->SQLSource:return 0
|
||||
end
|
||||
|
||||
|
||||
deactivate MariaDB
|
||||
|
||||
SQLSource-->ArchiveController.cs:return 0
|
||||
end
|
||||
|
||||
deactivate ArchiveController.cs
|
||||
deactivate SQLSource
|
||||
63
doc/LowLevel/ArchivingLL/archivngWithError.txt
Normal file
@ -0,0 +1,63 @@
|
||||
title Use Case: Archiving
|
||||
|
||||
participant ArchiveController.cs
|
||||
participant DataConnection
|
||||
participant DataSourceFactory
|
||||
participant SQLSource
|
||||
participant MariaDB
|
||||
|
||||
activate ArchiveController.cs
|
||||
ArchiveController.cs ->DataConnection:static DataConnection getDataConnection()
|
||||
DataConnection -->ArchiveController.cs:return DataConnection
|
||||
|
||||
ArchiveController.cs->DataSourceFactory:new DataSourceFactory()
|
||||
activate DataSourceFactory
|
||||
DataSourceFactory ->DataSourceFactory:DataSourceFactory()\nconstructor
|
||||
ArchiveController.cs <-- DataSourceFactory:return DataSourceFactory
|
||||
deactivate DataSourceFactory
|
||||
|
||||
activate SQLSource
|
||||
ArchiveController.cs->SQLSource: IDataSource DataSourceFact.GetDataSource(String sourceName)
|
||||
SQLSource->SQLSource: SQLSource()\nconstructor
|
||||
SQLSource --> ArchiveController.cs :return SQLSource
|
||||
|
||||
loop #lightblue while true
|
||||
alt #lightgreen date == 1
|
||||
ArchiveController.cs -> SQLSource: int Compress(DataConnection conn, IDataSource ds, String logList[])
|
||||
activate MariaDB
|
||||
alt #lightgreen archive == 0 (If Archive have not exist already
|
||||
SQLSource -> MariaDB: int createArchive(DataConnection conn, String SQLcmd)
|
||||
SQLSource <-- MariaDB:return 0
|
||||
end
|
||||
|
||||
alt #red No error when doing executing copy SQL command
|
||||
SQLSource ->SQLSource: int updateArchive(DataConnection conn, String logList[])
|
||||
SQLSource ->MariaDB: int CopremovyEntries(DataConnection conn, String logList[])
|
||||
MariaDB --> SQLSource: return 0
|
||||
SQLSource -->ArchiveController.cs: return 0
|
||||
else Error occur when executing copy SQL command on Database
|
||||
MariaDB -->SQLSource: throw SQLException
|
||||
SQLSource -->ArchiveController.cs: throw SQLException
|
||||
ArchiveController.cs ->ArchiveController.cs: Console.WriteLine(SQLException.Message) \n (As a form of handling error)
|
||||
end
|
||||
|
||||
alt #red No error when doing executing remove SQL command
|
||||
SQLSource ->MariaDB: int RemoveEntries(DataConnection conn, String logList[])
|
||||
MariaDB-->SQLSource:return 0
|
||||
SQLSource -->ArchiveController.cs: return 0
|
||||
|
||||
else Error occur when executing removing SQL command on Database
|
||||
MariaDB -->SQLSource: throw SQLException
|
||||
SQLSource -->ArchiveController.cs: throw SQLException
|
||||
ArchiveController.cs ->ArchiveController.cs: Console.WriteLine(SQLException.Message) \n (As a form of handling error)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
deactivate MariaDB
|
||||
|
||||
SQLSource-->ArchiveController.cs:return 0
|
||||
end
|
||||
|
||||
deactivate ArchiveController.cs
|
||||
deactivate SQLSource
|
||||
BIN
doc/LowLevel/ArchivingLL/arcvhingMasterCon.pdf
Normal file
BIN
doc/LowLevel/Logging/Logging_LLD_v6.png
Normal file
|
After Width: | Height: | Size: 274 KiB |
BIN
doc/LowLevel/UMLforArchving.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
doc/LowLevel/UserManagement/UserManagementCreateAccount.png
Normal file
|
After Width: | Height: | Size: 474 KiB |
172
doc/LowLevel/UserManagement/UserManagementCreateAccount.txt
Normal file
@ -0,0 +1,172 @@
|
||||
title Create User Record
|
||||
actor User
|
||||
participant Controller.cs #90EE90
|
||||
participant RDSFactory #26abff
|
||||
participant UserAccount #CBC3E3
|
||||
participant SystemAccountManager #ffffe0
|
||||
participant AccountService #ff8b3d
|
||||
participant SqlDAO #D3D3D3
|
||||
//SqlDAO
|
||||
database SqlServer(MariaDB) #00FFFF
|
||||
|
||||
//activate User
|
||||
activate Controller.cs #90EE90
|
||||
User->Controller.cs: ++Create new User++
|
||||
|
||||
//RelatDSFactory
|
||||
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 DbName, string connInfo)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlDAO:++Constructor(string connInfo)++
|
||||
group #red Data Store Timed Out #white
|
||||
SqlDAO->SqlDAO: ++Catch SqlException++
|
||||
Controller.cs<--SqlDAO:++return "Data Source Timed Out"++
|
||||
end
|
||||
group #blue Data Store Online #white
|
||||
Controller.cs<--SqlDAO: ++return SqlDAO++
|
||||
deactivate SqlDAO
|
||||
|
||||
|
||||
// Create new Admin
|
||||
Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++
|
||||
Controller.cs<--SystemAccountManager:++ New SystemAccountManager++
|
||||
deactivate SystemAccountManager
|
||||
|
||||
// GetUserName
|
||||
Controller.cs->Controller.cs:++string GetUserName()++
|
||||
|
||||
// GetPassword
|
||||
Controller.cs->Controller.cs:++string GetPassword()++
|
||||
//
|
||||
Controller.cs->UserAccount:++ new UserAccount(string username,\n string password,\n DateTime TimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount:++Constructor(string username,\n string password,\n DateTime TimeStamp)++
|
||||
Controller.cs<--UserAccount:++New UserAccount++
|
||||
deactivate UserAccount
|
||||
//
|
||||
Controller.cs->SystemAccountManager:++manager.CreateUserRecord(user:UserAccount)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++
|
||||
|
||||
group #red Invalid Information #white
|
||||
Controller.cs<--SystemAccountManager:++return "Invalid input"++
|
||||
User<--Controller.cs:++ return "Invalid input"++
|
||||
end
|
||||
group #green Information Valid #white
|
||||
|
||||
//check if there is an admin user
|
||||
SystemAccountManager->SqlDAO:++bool isAdmin(user:UserAccount)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++
|
||||
activate SqlServer(MariaDB)#00FFFF
|
||||
//authorized
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++
|
||||
//Unauthorized role section
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
end
|
||||
//Unauthorized role section
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return false++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
end
|
||||
|
||||
|
||||
//Authorized role section
|
||||
group #blue Authorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return true++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SystemAccountManager<--SqlDAO:++return true++
|
||||
deactivate SqlDAO
|
||||
deactivate SystemAccountManager
|
||||
|
||||
group #green Valid Information #white
|
||||
activate SystemAccountManager #ffffe0
|
||||
// GetUserName
|
||||
SystemAccountManager->SystemAccountManager:++string NewUserName()++
|
||||
// Enter UserName
|
||||
User->SystemAccountManager:++string NewUserName++
|
||||
// GetPassword
|
||||
SystemAccountManager->SystemAccountManager:++string NewPassword()++
|
||||
// Enter Password
|
||||
User->SystemAccountManager:++string NewPassword++
|
||||
// GetEmail
|
||||
SystemAccountManager->SystemAccountManager:++string NewEmail()++
|
||||
// Enter Email
|
||||
User->SystemAccountManager:++string NewEmail++
|
||||
// GetRole
|
||||
SystemAccountManager->SystemAccountManager:++string NewRole()++
|
||||
// Enter Role
|
||||
User->SystemAccountManager:++string NewRole++
|
||||
// Create NewUser object
|
||||
UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring NewPassword,\nstring New Email,\nDateTime TimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount:++Constructor(string NewUserName,\nstring NewPassword,\nstring New Email,\nDateTime TimeStamp)++
|
||||
UserAccount-->SystemAccountManager:++return NewUser++
|
||||
deactivate UserAccount
|
||||
//Create User Record
|
||||
SystemAccountManager->AccountService:++AccountService\n.CreateUserRecord(user:NewUser)++
|
||||
activate AccountService #ff8b3d
|
||||
AccountService->SqlDAO:++SqlDAO\n.CreateUserRecord(user:NewUser)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++SqlRead \nisUser(user:NewUser)++
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++ Select *\nFrom Users\nwhere Username\n= @UserName OR\nemail = @Email++
|
||||
group #red data store timed out #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
AccountService<--SqlDAO:++return "Database timed out"++
|
||||
|
||||
SystemAccountManager<--AccountService:++ return "Database timed out"++
|
||||
Controller.cs<--SystemAccountManager:++ return "Database timed out"++
|
||||
User<--Controller.cs:++ return "Database timed out"++
|
||||
end
|
||||
group #blue data store is online #white
|
||||
// User exists
|
||||
group #green User does exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return True++
|
||||
deactivate SqlServer(MariaDB)
|
||||
AccountService<--SqlDAO:++return "User is already registered"++
|
||||
SystemAccountManager<--AccountService:++return "User is already registered"++
|
||||
Controller.cs<--SystemAccountManager:++return "User is already registered"++
|
||||
User<--Controller.cs:++ return \n"User is already registered"++
|
||||
|
||||
end
|
||||
// User doesn't exist
|
||||
group #green User does not exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return False++
|
||||
SqlDAO->SqlServer(MariaDB):++ SQL insert\nuser credentials++
|
||||
SqlDAO<--SqlServer(MariaDB):++ return 1++
|
||||
deactivate SqlServer(MariaDB)
|
||||
AccountService<--SqlDAO:++return "User is now registered"++
|
||||
deactivate SqlDAO
|
||||
SystemAccountManager<--AccountService:++return "User is now registered"++
|
||||
deactivate AccountService
|
||||
Controller.cs<--SystemAccountManager:++return "User is now registered"++
|
||||
deactivate SystemAccountManager
|
||||
User<--Controller.cs:++ return \n"User is now registered"++
|
||||
|
||||
deactivate Controller.cs
|
||||
end
|
||||
//deactivate User
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
BIN
doc/LowLevel/UserManagement/UserManagementDeleteUser.png
Normal file
|
After Width: | Height: | Size: 477 KiB |
161
doc/LowLevel/UserManagement/UserManagementDeleteUser.txt
Normal file
@ -0,0 +1,161 @@
|
||||
title Delete User Record
|
||||
actor User
|
||||
participant Controller.cs #90EE90
|
||||
participant RDSFactory #26abff
|
||||
participant UserAccount #CBC3E3
|
||||
participant SystemAccountManager #ffffe0
|
||||
participant AccountService #ff8b3d
|
||||
participant SqlDAO #D3D3D3
|
||||
//SqlDAO
|
||||
database SqlServer(MariaDB) #00FFFF
|
||||
|
||||
//activate User
|
||||
activate Controller.cs #90EE90
|
||||
User->Controller.cs: ++Request to delete user++
|
||||
|
||||
//RelatDSFactory
|
||||
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 DbName, string connInfo)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlDAO:++Constructor(string connInfo)++
|
||||
group #red Data Store Timed Out #white
|
||||
SqlDAO->SqlDAO: ++Catch SqlException++
|
||||
Controller.cs<--SqlDAO:++return "Data Source Timed Out"++
|
||||
end
|
||||
group #blue Data Store Online #white
|
||||
Controller.cs<--SqlDAO: ++return SqlDAO++
|
||||
deactivate SqlDAO
|
||||
|
||||
// Create new Admin
|
||||
Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++
|
||||
Controller.cs<--SystemAccountManager:++ New SystemAccountManager++
|
||||
deactivate SystemAccountManager
|
||||
|
||||
// GetUserName
|
||||
Controller.cs->Controller.cs:++string GetUserName()++
|
||||
|
||||
// GetPassword
|
||||
Controller.cs->Controller.cs:++string GetPassword()++
|
||||
|
||||
//
|
||||
Controller.cs->UserAccount:++ new UserAccount(string username,\n string password\n DateTime RegistrationTimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount: ++Constructor(string username,\n string password,\n DateTime RegistrationTimeStamp)++
|
||||
Controller.cs<--UserAccount:++New UserAccount++
|
||||
deactivate UserAccount
|
||||
Controller.cs->SystemAccountManager: ++manager.DeleteUserRecord(user:UserAccount)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++
|
||||
group #red Invalid Information #white
|
||||
Controller.cs<--SystemAccountManager:++return "Invalid input"++
|
||||
User<--Controller.cs:++ return "Invalid input"++
|
||||
end
|
||||
|
||||
//
|
||||
group #green Information Valid #white
|
||||
//check if there is an admin user
|
||||
SystemAccountManager->SqlDAO:++isAdmin(user:UserAccount)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++
|
||||
activate SqlServer(MariaDB)#00FFFF
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++
|
||||
//Unauthorized role section
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
end
|
||||
//Unauthorized role section
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return false++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
end
|
||||
|
||||
|
||||
//Authorized role section
|
||||
group #blue Authorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return true++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SystemAccountManager<--SqlDAO:++return true++
|
||||
deactivate SqlDAO
|
||||
deactivate SystemAccountManager
|
||||
group #green Valid Information #white
|
||||
activate SystemAccountManager #ffffe0
|
||||
// GetUserName
|
||||
SystemAccountManager->SystemAccountManager:++string NewUserName()++
|
||||
// Enter UserName
|
||||
User->SystemAccountManager:++string NewUserName++
|
||||
// GetPassword
|
||||
SystemAccountManager->SystemAccountManager:++string NewPassword()++
|
||||
// Enter Password
|
||||
User->SystemAccountManager:++string NewPassword++
|
||||
// GetRole
|
||||
SystemAccountManager->SystemAccountManager:++string NewRole()++
|
||||
// Enter Role
|
||||
User->SystemAccountManager:++string NewRole++
|
||||
// Create NewUser object
|
||||
UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring NewPassword,\nstring role,\nDateTime TimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount:++Constructor(\nstring NewUserName,\nstring NewPassword,\nstring role,\nDateTime TimeStamp)++
|
||||
UserAccount-->SystemAccountManager:++return NewUser++
|
||||
deactivate UserAccount
|
||||
SystemAccountManager->AccountService:++AccountService\n.DeleteUserRecord(user:NewUser,\nUpdateType: userDelete)++
|
||||
activate AccountService #ff8b3d
|
||||
AccountService->SqlDAO:++SqlDAO\n.DeleteUserRecord(user:NewUser,\nUpdateType: userDelete)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++isUser(user:NewUser)++
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++ Select *\nFrom Users\nwhere Username\n= @UserName OR\nemail = @Email++
|
||||
group #red data store timed out #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
AccountService<--SqlDAO:++return "Database timed out"++
|
||||
|
||||
SystemAccountManager<--AccountService:++ return "Database timed out"++
|
||||
Controller.cs<--SystemAccountManager:++ return "Database timed out"++
|
||||
User<--Controller.cs:++ return "Database timed out"++
|
||||
end
|
||||
group #blue data store is online #white
|
||||
// User exists
|
||||
group #green User does exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return True++
|
||||
SqlDAO->SqlServer(MariaDB):++Delete from users\nwhere Username = @UserName \nand Password = @PWD++
|
||||
SqlDAO<--SqlServer(MariaDB):++ return 1++
|
||||
AccountService<--SqlDAO:++return "User deleted successfully"++
|
||||
SystemAccountManager<--AccountService:++return "User deleted successfully"++
|
||||
Controller.cs<--SystemAccountManager:++return "User deleted successfully"++
|
||||
User<--Controller.cs:++ return \n"User deleted successfully"++
|
||||
deactivate SqlServer(MariaDB)
|
||||
end
|
||||
// User doesn't exist
|
||||
group #red User does not exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return False++
|
||||
AccountService<--SqlDAO:++return "User does not exist"++
|
||||
SystemAccountManager<--AccountService:++return "User does not exist"++
|
||||
Controller.cs<--SystemAccountManager:++return "User does not exist"++
|
||||
User<--Controller.cs:++ return \n"User does not exist"++
|
||||
deactivate AccountService
|
||||
deactivate SqlDAO
|
||||
deactivate SqlServer(MariaDB)
|
||||
deactivate SystemAccountManager
|
||||
deactivate Controller.cs
|
||||
end
|
||||
//deactivate User
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
BIN
doc/LowLevel/UserManagement/UserManagementDisableUser.png
Normal file
|
After Width: | Height: | Size: 462 KiB |
160
doc/LowLevel/UserManagement/UserManagementDisableUser.txt
Normal file
@ -0,0 +1,160 @@
|
||||
title Disable Specfied User
|
||||
actor User
|
||||
participant Controller.cs #90EE90
|
||||
participant RDSFactory #26abff
|
||||
participant UserAccount #CBC3E3
|
||||
participant SystemAccountManager #ffffe0
|
||||
participant AccountService #ff8b3d
|
||||
participant SqlDAO #D3D3D3
|
||||
//SqlDAO
|
||||
database SqlServer(MariaDB) #00FFFF
|
||||
|
||||
//activate User
|
||||
activate Controller.cs #90EE90
|
||||
User->Controller.cs: ++Request to disable user\n by a different user++
|
||||
|
||||
//RelatDSFactory
|
||||
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 DbName, string connInfo)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlDAO:++Constructor(string connInfo)++
|
||||
group #red Data Store Timed Out #white
|
||||
SqlDAO->SqlDAO: ++Catch SqlException++
|
||||
Controller.cs<--SqlDAO:++return "Data Source Timed Out"++
|
||||
end
|
||||
group #blue Data Store Online #white
|
||||
Controller.cs<--SqlDAO: ++return SqlDAO++
|
||||
deactivate SqlDAO
|
||||
|
||||
// Create new Admin
|
||||
Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++
|
||||
Controller.cs<--SystemAccountManager:++ New SystemAccountManager++
|
||||
deactivate SystemAccountManager
|
||||
|
||||
// GetUserName
|
||||
Controller.cs->Controller.cs:++string GetUserName()++
|
||||
|
||||
// GetPassword
|
||||
Controller.cs->Controller.cs:++string GetPassword()++
|
||||
|
||||
// Pass object
|
||||
Controller.cs->UserAccount:++ new UserAccount(string username,\n string password\n DateTime RegistrationTimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount: ++Constructor(string username,\n string password,\n DateTime RegistrationTimeStamp)++
|
||||
Controller.cs<--UserAccount:++New UserAccount++
|
||||
deactivate UserAccount
|
||||
Controller.cs->SystemAccountManager: ++manager.DisableUserRecord(user:UserAccount)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++
|
||||
group #red Invalid Information #white
|
||||
Controller.cs<--SystemAccountManager:++return "Invalid input"++
|
||||
User<--Controller.cs:++ return "Invalid input"++
|
||||
end
|
||||
group #green Information Valid #white
|
||||
|
||||
//
|
||||
|
||||
//check if there is an admin user
|
||||
|
||||
SystemAccountManager->SqlDAO:++isAdmin(user:UserAccount)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++
|
||||
activate SqlServer(MariaDB)#00FFFF
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++
|
||||
//Unauthorized role section
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
//Unauthorized role section
|
||||
end
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return false++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
end
|
||||
|
||||
|
||||
//Authorized role section
|
||||
group #blue Authorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return true++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SystemAccountManager<--SqlDAO:++return true++
|
||||
deactivate SqlDAO
|
||||
deactivate SystemAccountManager
|
||||
|
||||
group #green Valid Information #white
|
||||
activate SystemAccountManager #ffffe0
|
||||
// GetUserName
|
||||
SystemAccountManager->SystemAccountManager:++string NewUserName()++
|
||||
// Enter UserName
|
||||
User->SystemAccountManager:++string NewUserName++
|
||||
// GetRole
|
||||
SystemAccountManager->SystemAccountManager:++string NewRole()++
|
||||
// Enter Role
|
||||
User->SystemAccountManager:++string NewRole++
|
||||
// Create NewUser object
|
||||
UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring role,\nDateTime TimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount:++Constructor(\nstring NewUserName,\nstring role,\nDateTime TimeStamp)++
|
||||
UserAccount-->SystemAccountManager:++return NewUser++
|
||||
deactivate UserAccount
|
||||
SystemAccountManager->AccountService:++AccountService\n.DisableUserRecord(user:NewUser,\nUpdateType:userDisable)++
|
||||
activate AccountService #ff8b3d
|
||||
AccountService->SqlDAO:++SqlDAO\n.DisableUser(user:NewUser,\nUpdateType:userDisable)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++isUser(user:NewUser)++
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++ Select *\nFrom Users\nwhere Username\n= @UserName and\nRole = @UserRole\n
|
||||
group #red data store timed out #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
AccountService<--SqlDAO:++return "Database timed out"++
|
||||
|
||||
SystemAccountManager<--AccountService:++ return "Database timed out"++
|
||||
Controller.cs<--SystemAccountManager:++ return "Database timed out"++
|
||||
User<--Controller.cs:++ return "Database timed out"++
|
||||
end
|
||||
group #blue data store is online #white
|
||||
// User exists
|
||||
group #green User does exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return True++
|
||||
SqlDAO->SqlServer(MariaDB):++Update users Set isActive = 0\nwhere UserName = @UserName++
|
||||
SqlDAO<--SqlServer(MariaDB):++ return 1++
|
||||
deactivate SqlServer(MariaDB)
|
||||
AccountService<--SqlDAO:++return "User is now disabled"++
|
||||
SystemAccountManager<--AccountService:++return "User is now disabled"++
|
||||
Controller.cs<--SystemAccountManager:++return "User is now disabled"++
|
||||
User<--Controller.cs:++ return \n"User is now disabled"++
|
||||
end
|
||||
// User doesn't exist
|
||||
group #red User does not exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return False++
|
||||
deactivate SqlServer(MariaDB)
|
||||
AccountService<--SqlDAO:++return "User does not exist"++
|
||||
deactivate SqlDAO
|
||||
SystemAccountManager<--AccountService:++return "User does not exist"++
|
||||
deactivate AccountService
|
||||
Controller.cs<--SystemAccountManager:++return "User does not exist"++
|
||||
deactivate SystemAccountManager
|
||||
User<--Controller.cs:++ return \n"User does not exist"++
|
||||
deactivate Controller.cs
|
||||
end
|
||||
//deactivate User
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
BIN
doc/LowLevel/UserManagement/UserManagementEditUserRecords.png
Normal file
|
After Width: | Height: | Size: 441 KiB |
170
doc/LowLevel/UserManagement/UserManagementEditUserRecords.txt
Normal file
@ -0,0 +1,170 @@
|
||||
title Edit User Record
|
||||
actor User
|
||||
participant Controller.cs #90EE90
|
||||
participant RDSFactory #26abff
|
||||
participant UserAccount #CBC3E3
|
||||
participant SystemAccountManager #ffffe0
|
||||
participant AccountService #ff8b3d
|
||||
participant SqlDAO #D3D3D3
|
||||
//SqlDAO
|
||||
database SqlServer(MariaDB) #00FFFF
|
||||
|
||||
//activate User
|
||||
activate Controller.cs #90EE90
|
||||
User->Controller.cs: ++Request to edit user\nby a different user++
|
||||
|
||||
//RelatDSFactory
|
||||
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 DbName, string connInfo)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlDAO:++Constructor(string connInfo)++
|
||||
group #red Data Store Timed Out #white
|
||||
SqlDAO->SqlDAO: ++Catch Exception++
|
||||
Controller.cs<--SqlDAO:++return "Data Source Timed Out"++
|
||||
end
|
||||
group #blue Data Store Online #white
|
||||
Controller.cs<--SqlDAO: ++return SqlDAO++
|
||||
deactivate SqlDAO
|
||||
|
||||
// Create new Admin
|
||||
Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++
|
||||
Controller.cs<--SystemAccountManager:++ New SystemAccountManager++
|
||||
deactivate SystemAccountManager
|
||||
|
||||
// GetUserName
|
||||
Controller.cs->Controller.cs:++string GetUserName()++
|
||||
|
||||
// GetPassword
|
||||
Controller.cs->Controller.cs:++string GetPassword()++
|
||||
|
||||
//
|
||||
|
||||
Controller.cs->UserAccount:++ new UserAccount(string username,\n string password,\n DateTime RegistrationTimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount: ++string username,\n string password,\n DateTime RegistrationTimeStamp++
|
||||
Controller.cs<--UserAccount:++New UserAccount++
|
||||
deactivate UserAccount
|
||||
Controller.cs->SystemAccountManager:++manager.UpdateUserRecord(user:UserAccount)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++
|
||||
group #red Invalid Information #white
|
||||
Controller.cs<--SystemAccountManager:++return "Invalid input"++
|
||||
User<--Controller.cs:++ return "Invalid input"++
|
||||
end
|
||||
group #green Information Valid #white
|
||||
|
||||
//look over
|
||||
|
||||
//check if there is an admin user
|
||||
SystemAccountManager->SqlDAO:++bool isAdmin(user:UserAccount)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++
|
||||
activate SqlServer(MariaDB)#00FFFF
|
||||
//authorized
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++
|
||||
//Unauthorized role section
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
end
|
||||
//Unauthorized role section
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return false++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
end
|
||||
|
||||
|
||||
//Authorized role section
|
||||
group #blue Authorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return true++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SystemAccountManager<--SqlDAO:++return true++
|
||||
deactivate SqlDAO
|
||||
deactivate SystemAccountManager
|
||||
group #green Valid Information #white
|
||||
activate SystemAccountManager #ffffe0
|
||||
// GetUserName
|
||||
SystemAccountManager->SystemAccountManager:++string NewUserName()++
|
||||
// Enter UserName
|
||||
User->SystemAccountManager:++string NewUserName++
|
||||
// GetPassword
|
||||
SystemAccountManager->SystemAccountManager:++string NewPassword()++
|
||||
// Enter Password
|
||||
User->SystemAccountManager:++string NewPassword++
|
||||
// GetEmail
|
||||
SystemAccountManager->SystemAccountManager:++string NewEmail()++
|
||||
// Enter Email
|
||||
User->SystemAccountManager:++string NewEmail++
|
||||
// GetRole
|
||||
SystemAccountManager->SystemAccountManager:++string NewRole()++
|
||||
// Enter Role
|
||||
User->SystemAccountManager:++string NewRole++
|
||||
// Create NewUser object
|
||||
UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring NewPassword,\nstring New Email,\nstring NewRole\nDateTime TimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount:++Constructor(\nstring NewUserName,\nstring NewPassword,\nstring New Email,\nstring NewRole\nDateTime TimeStamp)++
|
||||
UserAccount-->SystemAccountManager:++return NewUser++
|
||||
deactivate UserAccount
|
||||
SystemAccountManager->AccountService:++AccountService\n.UpdateUserRecord(user:NewUser,\nUpdateType: userUpdate)++
|
||||
activate AccountService #ff8b3d
|
||||
AccountService->SqlDAO:++SqlDAO\n.UpdateUserRecord(user:NewUser,\nUpdateType: userUpdate)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++isUser(user:NewUser)++
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++Update *\nFrom Users\nwhere Username\n= @UserName OR\nemail = @Email++
|
||||
group #red data store timed out #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
AccountService<--SqlDAO:++return "Database timed out"++
|
||||
|
||||
SystemAccountManager<--AccountService:++ return "Database timed out"++
|
||||
Controller.cs<--SystemAccountManager:++ return "Database timed out"++
|
||||
User<--Controller.cs:++ return "Database timed out"++
|
||||
end
|
||||
group #blue data store is online #white
|
||||
// User exists
|
||||
group #green User does exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return True++
|
||||
SqlDAO->SqlServer(MariaDB):++ SQL insert\nupdate credentials++
|
||||
SqlDAO<--SqlServer(MariaDB):++ return 1++
|
||||
AccountService<--SqlDAO:++return "User information updated successfully"++
|
||||
SystemAccountManager<--AccountService:++return "User information updated successfully"++
|
||||
Controller.cs<--SystemAccountManager:++return "User information updated successfully"++
|
||||
User<--Controller.cs:++ return "User information\n updated successfully"++
|
||||
deactivate SqlServer(MariaDB)
|
||||
end
|
||||
// User doesn't exist
|
||||
group #green User does not exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return False++
|
||||
SqlDAO->SqlServer(MariaDB):++ SQL insert\nuser credentials++
|
||||
SqlDAO<--SqlServer(MariaDB):++ return 1++
|
||||
AccountService<--SqlDAO:++return "User is now registered"++
|
||||
SystemAccountManager<--AccountService:++return "User is now registered"++
|
||||
Controller.cs<--SystemAccountManager:++return "User is now registered"++
|
||||
User<--Controller.cs:++ return \n"User is now registered"++
|
||||
deactivate AccountService
|
||||
deactivate SqlDAO
|
||||
deactivate SqlServer(MariaDB)
|
||||
deactivate SystemAccountManager
|
||||
deactivate Controller.cs
|
||||
end
|
||||
//deactivate User
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
BIN
doc/LowLevel/UserManagement/UserManagementEnableUser.png
Normal file
|
After Width: | Height: | Size: 464 KiB |
158
doc/LowLevel/UserManagement/UserManagementEnableUser.txt
Normal file
@ -0,0 +1,158 @@
|
||||
title Disable Specfied User
|
||||
actor User
|
||||
participant Controller.cs #90EE90
|
||||
participant RDSFactory #26abff
|
||||
participant UserAccount #CBC3E3
|
||||
participant SystemAccountManager #ffffe0
|
||||
participant AccountService #ff8b3d
|
||||
participant SqlDAO #D3D3D3
|
||||
//SqlDAO
|
||||
database SqlServer(MariaDB) #00FFFF
|
||||
|
||||
//activate User
|
||||
activate Controller.cs #90EE90
|
||||
User->Controller.cs: ++Request to enable user\n by a different user++
|
||||
|
||||
//RelatDSFactory
|
||||
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 DbName, string connInfo)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlDAO:++Constructor(string connInfo)++
|
||||
group #red Data Store Timed Out #white
|
||||
SqlDAO->SqlDAO: ++Catch SqlException++
|
||||
Controller.cs<--SqlDAO:++return "Data Source Timed Out"++
|
||||
end
|
||||
group #blue Data Store Online #white
|
||||
Controller.cs<--SqlDAO: ++return SqlDAO++
|
||||
deactivate SqlDAO
|
||||
// Create new Admin
|
||||
Controller.cs->SystemAccountManager:++ manager = new SystemAccountManager(IDataSource conn)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++Constructor(IDataSource conn)++
|
||||
Controller.cs<--SystemAccountManager:++ New SystemAccountManager++
|
||||
deactivate SystemAccountManager
|
||||
|
||||
// GetUserName
|
||||
Controller.cs->Controller.cs:++string GetUserName()++
|
||||
|
||||
// GetPassword
|
||||
Controller.cs->Controller.cs:++string GetPassword()++
|
||||
|
||||
// Pass object
|
||||
Controller.cs->UserAccount:++ new UserAccount(string username,\n string password\n DateTime RegistrationTimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount: ++Constructor(string username,\n string password,\n DateTime RegistrationTimeStamp)++
|
||||
Controller.cs<--UserAccount:++New UserAccount++
|
||||
deactivate UserAccount
|
||||
Controller.cs->SystemAccountManager:++manager.EnableUserRecord(user:UserAccount)++
|
||||
activate SystemAccountManager #ffffe0
|
||||
SystemAccountManager->SystemAccountManager:++isInputValid(user: UserAccount)++
|
||||
group #red Invalid Information #white
|
||||
Controller.cs<--SystemAccountManager:++return "Invalid input"++
|
||||
User<--Controller.cs:++ return "Invalid input"++
|
||||
end
|
||||
|
||||
//
|
||||
|
||||
group #green Information Valid #white
|
||||
//check if there is an admin user
|
||||
SystemAccountManager->SqlDAO:++isAdmin(user:UserAccount)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++SqlRead confirmAdmin()++
|
||||
activate SqlServer(MariaDB)#00FFFF
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++Select * from Admins\n where Username = @UserName \nand Password = @Pwd++
|
||||
//Unauthorized role section
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
//Unauthorized role section
|
||||
end
|
||||
group #red Unauthorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return false++
|
||||
SystemAccountManager<--SqlDAO:++return false++
|
||||
Controller.cs<--SystemAccountManager:++ return "Access Denied: \nUnauthorized"++
|
||||
User<--Controller.cs:++return "Access Denied: \nUnauthorized"++
|
||||
end
|
||||
|
||||
|
||||
//Authorized role section
|
||||
group #blue Authorized User #white
|
||||
SqlDAO<--SqlServer(MariaDB):++return true++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SystemAccountManager<--SqlDAO:++return true++
|
||||
deactivate SqlDAO
|
||||
deactivate SystemAccountManager
|
||||
|
||||
group #green Valid Information #white
|
||||
activate SystemAccountManager #ffffe0
|
||||
// GetUserName
|
||||
SystemAccountManager->SystemAccountManager:++string NewUserName()++
|
||||
// Enter UserName
|
||||
User->SystemAccountManager:++string NewUserName++
|
||||
// GetRole
|
||||
SystemAccountManager->SystemAccountManager:++string NewRole()++
|
||||
// Enter Role
|
||||
User->SystemAccountManager:++string NewRole++
|
||||
// Create NewUser object
|
||||
UserAccount<-SystemAccountManager:++new NewUser(\nstring NewUserName,\nstring role,\nDateTime TimeStamp)++
|
||||
activate UserAccount #CBC3E3
|
||||
UserAccount->UserAccount:++Constructor(\nstring NewUserName,\nstring role,\nDateTime TimeStamp)++
|
||||
UserAccount-->SystemAccountManager:++return NewUser++
|
||||
deactivate UserAccount
|
||||
SystemAccountManager->AccountService:++AccountService\n.EnableUserRecord(user:NewUser,\nUpdateType:userEnable)++
|
||||
activate AccountService #ff8b3d
|
||||
AccountService->SqlDAO:++SqlDAO\n.EnableUser(user:NewUser,\nUpdateType:userEnable)++
|
||||
activate SqlDAO #D3D3D3
|
||||
SqlDAO->SqlServer(MariaDB):++isUser(user:NewUser)++
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlServer(MariaDB)->SqlServer(MariaDB):++ Select *\nFrom Users\nwhere Username\n= @UserName and\nRole = @UserRole
|
||||
group #red data store timed out #white
|
||||
SqlDAO<--SqlServer(MariaDB):++SqlException++
|
||||
deactivate SqlServer(MariaDB)
|
||||
SqlDAO->SqlDAO: ++Catch\nSqlException++
|
||||
AccountService<--SqlDAO:++return "Database timed out"++
|
||||
|
||||
SystemAccountManager<--AccountService:++ return "Database timed out"++
|
||||
Controller.cs<--SystemAccountManager:++ return "Database timed out"++
|
||||
User<--Controller.cs:++ return "Database timed out"++
|
||||
end
|
||||
group #blue data store is online #white
|
||||
// User exists
|
||||
group #green User does exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return True++
|
||||
SqlDAO->SqlServer(MariaDB):++Update users Set isActive = 1\nwhere UserName = @UserName++
|
||||
SqlDAO<--SqlServer(MariaDB):++ return 1++
|
||||
deactivate SqlServer(MariaDB)
|
||||
AccountService<--SqlDAO:++return "User is now enabled"++
|
||||
SystemAccountManager<--AccountService:++return "User is now enabled"++
|
||||
Controller.cs<--SystemAccountManager:++return "User is now enabled"++
|
||||
User<--Controller.cs:++ return \n"User is now enabled"++
|
||||
end
|
||||
// User doesn't exist
|
||||
group #red User does not exist #white
|
||||
activate SqlServer(MariaDB) #00FFFF
|
||||
SqlDAO<--SqlServer(MariaDB):++ return False++
|
||||
deactivate SqlServer(MariaDB)
|
||||
AccountService<--SqlDAO:++return "User does not exist"++
|
||||
deactivate SqlDAO
|
||||
SystemAccountManager<--AccountService:++return "User does not exist"++
|
||||
deactivate AccountService
|
||||
Controller.cs<--SystemAccountManager:++return "User does not exist"++
|
||||
deactivate SystemAccountManager
|
||||
User<--Controller.cs:++ return \n"User does not exist"++
|
||||
deactivate Controller.cs
|
||||
end
|
||||
//deactivate User
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
BIN
doc/Resources/1565-Article Text-4599-1-10-20200320.pdf
Normal file
BIN
doc/Resources/BENCHMARKING_POPULAR_OPEN_SOURCE_RDBMS_A1.pdf
Normal file
BIN
doc/Resources/Graph/insert.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
doc/Resources/Graph/joinQuery.png
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
doc/Resources/Graph/multiquery.png
Normal file
|
After Width: | Height: | Size: 122 KiB |
BIN
doc/Resources/Graph/rangeQuery.png
Normal file
|
After Width: | Height: | Size: 98 KiB |
BIN
doc/Resources/Graph/rangeTable.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
doc/Resources/Graph/read.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
doc/Resources/Graph/singleQuery.png
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
doc/Resources/Graph/update.png
Normal file
|
After Width: | Height: | Size: 42 KiB |