Commit 5f900c13 authored by nguyenvu's avatar nguyenvu

Update test-cicd-project-ngvu

parent e67b0e58
Pipeline #6747 failed with stages
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
# Created by https://www.gitignore.io/api/windows,visualstudiocode,aspnetcore,dotnetcore
# Edit at https://www.gitignore.io/?templates=windows,visualstudiocode,aspnetcore,dotnetcore
### ASPNETCore ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.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
# 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
# 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
# TODO: 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
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# 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
# 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
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# 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
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# 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
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/
### DotnetCore ###
# .NET Core build folders
/bin
/obj
# Common node modules locations
/node_modules
/wwwroot/node_modules
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/windows,visualstudiocode,aspnetcore,dotnetcore
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
stages:
- build
- deploy
- build_model
variables:
project_name: erp-task-management-backend
image_name: registry.gitlab.com/meusolutions/erp-task-management-backend
port_mapping: 5002
mount_data_folder: /var/data
fe_git_address: 27.74.255.96:8088/hungbui/erp-task-management-frontend
fe_git_project_name: erp-task-management-frontend
fe_model_branch: develop-model
environment_name: staging
environment_json_path: MEU.API/Config/.env.staging.json
build:
stage: build
before_script:
- echo "Please remember that for dev environment, we use the tag 'dev' only !!!"
- tag=dev
- current_file_path=$(pwd)/MEU.API/Resources/ReleaseNotes/releasenotes.txt
- release_note_folder=/var/www/release_note
- |
if [ ! -d "$release_note_folder" ]; then
sudo mkdir $release_note_folder
fi
if [ ! -d "$release_note_folder/$project_name" ]; then
sudo mkdir $release_note_folder/$project_name
fi
script:
# Change release date
- |
if [ -f "$release_note_folder/$project_name/releasenotes.txt" ] ;
then
sudo bash -c "cat $release_note_folder/$project_name/releasenotes.txt > $current_file_path"
else
sudo cp $current_file_path $release_note_folder/$project_name
fi
old_version=$(sudo cat $current_file_path | base64 --decode)
version=$(echo $old_version | sed -r 's/\s.*$//')
c=$(echo "${version: -1}")
# Increase by 1
d=$(expr $c + 1)
new_version=$(echo $version | sed "s/.$/$d/")
current_date=$(date "+%d/%m/%Y %H:%M:%S")
release_date=$(echo "$new_version ($current_date)")
value_base64=$(echo "$release_date" | base64)
sudo bash -c "echo $value_base64 > $current_file_path"
sudo bash -c "cat $current_file_path > $release_note_folder/$project_name/releasenotes.txt"
- sudo docker build -t $image_name:$tag -f Dockerfile .
- sudo docker logout registry.gitlab.com
- echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
- sudo docker push $image_name:$tag
- sudo docker rmi $image_name:$tag
only:
- develop
tags:
- runner-builder
deploy:
stage: deploy
before_script:
- whoami
- ifconfig
- sudo apt-get install jq -y
- |
if [ ! -f /usr/bin/docker ]; then
sudo curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
fi
- |
if [ ! -f /usr/bin/docker-compose ]; then
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
fi
- |
if [ ! -d $mount_data_folder ]; then
sudo mkdir $mount_data_folder
sudo chown -R gitlab-runner.gitlab-runner $mount_data_folder
fi
- |
if [ ! -d $mount_data_folder/$project_name ]; then
sudo mkdir $mount_data_folder/$project_name
sudo chown -R gitlab-runner.gitlab-runner $mount_data_folder/$project_name
fi
script:
- tag=dev
- jq -r 'keys[] as $k | "\($k)=\(.[$k])"' $environment_json_path > .env
- sed -i 's|PROJECT-NAME|'$project_name'|' docker-compose.yaml
- sed -i 's|ENVIRONMENT-NAME|'$environment_name'|' docker-compose.yaml
- sed -i 's|IMAGE-NAME|'$image_name'|' docker-compose.yaml
- sed -i 's|IMAGE-TAG|'$tag'|' docker-compose.yaml
- sed -i 's|P-MAPPING|'$port_mapping'|' docker-compose.yaml
- sed -i 's|MOUNT-DATA-FOLDER|'$mount_data_folder'|' docker-compose.yaml
- echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
- sudo docker-compose down
- sudo docker-compose pull
- sudo docker-compose --env-file .env up -d
only:
- develop
tags:
- ci-cd
build_model:
stage: build_model
before_script:
- sudo apt install default-jre -y
- chmod +x -R CICD
- if [ ! -d /home/gitlab-runner ]; then mkdir /home/gitlab-runner; fi
- git config --global user.email "cicd@meu-solutions.com"
- git config --global user.name "CICD"
script:
- echo "Waiting for the application goes online..."
- sleep 10
- swaggerUrl="http://localhost:$port_mapping/swagger/v1/swagger.json"
- api=$(curl $swaggerUrl)
- api=$(jq 'del(.components.securitySchemes)' <<<$api)
- api=$(jq 'del(.security)' <<<$api)
- echo $api > apiFinal.json
- request='{"spec":{},"type":"CLIENT","lang":"typescript-angular"}'
- request=$(jq --argfile apiFinal apiFinal.json '.spec = $apiFinal' <<<$request)
- echo $request > ts.json
- rm -rf client
- java -jar CICD/swagger-codegen-cli.jar generate -i apiFinal.json -l typescript-angular -o client --additional-properties modelPropertyNaming=original
- rm -rf ts.json;
- rm -rf production_file;
- rm -rf apiFinal.json;
- temp_path=$(pwd);
- mkdir production_file;
- cp -r client/*.ts production_file/; cp -r client/api production_file/; cp -r client/model production_file/; rm -rf client; mv production_file client
- bash CICD/swagger_download client
- cd ~
- rm -rf ~/$fe_git_project_name/
- git clone --single-branch --branch $fe_model_branch "http://${GIT_USER}:${GIT_USER_PW}@$fe_git_address.git"
- cd $fe_git_project_name
- git pull origin $fe_model_branch;
- bash $temp_path/CICD/cp_ad $temp_path/client ~/$fe_git_project_name/src/app $temp_path/client
- rm -rf $temp_path/client
- git add --all; git commit -m "Update model auto" --allow-empty; git push "http://${GIT_USER}:${GIT_USER_PW}@$fe_git_address.git" HEAD:$fe_model_branch
- rm -rf ~/$fe_git_project_name/
only:
- develop
tags:
- ci-cd
\ No newline at end of file
stages:
- release
variables:
project_name: erp-task-management-backend
image_name: registry.gitlab.com/meusolutions/erp-task-management-backend
port_mapping: 5002
mount_data_folder: /var/data
fe_git_address: 27.74.255.96:8088/hungbui/erp-task-management-frontend
fe_git_project_name: erp-task-management-frontend
fe_model_branch: develop-model
release:
stage: release
before_script:
- tag=$(echo $CI_COMMIT_MESSAGE | sed -r 's/.*(\[tag\])//')
- check=$(echo $CI_COMMIT_MESSAGE | sed -r 's/^.*(\[tag\]).*/\1/')
- echo "To release new docker image, tagname should be '0.1', your tag is:$tag"
script:
- |
if [ "$check" == "[tag]" ]; then
sudo docker build -t $image_name:$tag -f Dockerfile .
sudo docker logout registry.gitlab.com
echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
sudo docker push $image_name:$tag
sudo docker rmi $image_name:$tag
fi
only:
- release/staging
tags:
- runner-builder
\ No newline at end of file
stages:
- build
- deploy
- build_model
- release
variables:
project_name: erp-task-management-backend
image_name: registry.gitlab.com/meusolutions/erp-task-management-backend
port_mapping: 5002
mount_data_folder: /var/data
fe_git_address: 27.74.255.96:8088/hungbui/erp-task-management-frontend
fe_git_project_name: erp-task-management-frontend
fe_model_branch: develop-model
environment_name: staging
environment_json_path: MEU.API/Config/.env.staging.json
build:
stage: build
before_script:
- echo "Please remember that for dev environment, we use the tag 'dev' only !!!"
- tag=dev
- current_file_path=$(pwd)/MEU.API/Resources/ReleaseNotes/releasenotes.txt
- release_note_folder=/var/www/release_note
- |
if [ ! -d "$release_note_folder" ]; then
sudo mkdir $release_note_folder
fi
if [ ! -d "$release_note_folder/$project_name" ]; then
sudo mkdir $release_note_folder/$project_name
fi
script:
# Change release date
- |
if [ -f "$release_note_folder/$project_name/releasenotes.txt" ] ;
then
sudo bash -c "cat $release_note_folder/$project_name/releasenotes.txt > $current_file_path"
else
sudo cp $current_file_path $release_note_folder/$project_name
fi
old_version=$(sudo cat $current_file_path | base64 --decode)
version=$(echo $old_version | sed -r 's/\s.*$//')
c=$(echo "${version: -1}")
# Increase by 1
d=$(expr $c + 1)
new_version=$(echo $version | sed "s/.$/$d/")
current_date=$(date "+%d/%m/%Y %H:%M:%S")
release_date=$(echo "$new_version ($current_date)")
value_base64=$(echo "$release_date" | base64)
sudo bash -c "echo $value_base64 > $current_file_path"
sudo bash -c "cat $current_file_path > $release_note_folder/$project_name/releasenotes.txt"
- sudo docker build -t $image_name:$tag -f Dockerfile .
- sudo docker logout registry.gitlab.com
- echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
- sudo docker push $image_name:$tag
- sudo docker rmi $image_name:$tag
only:
- develop
tags:
- runner-builder
deploy:
stage: deploy
before_script:
- whoami
- ifconfig
- sudo apt-get install jq -y
- |
if [ ! -f /usr/bin/docker ]; then
sudo curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
fi
- |
if [ ! -f /usr/bin/docker-compose ]; then
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
fi
- |
if [ ! -d $mount_data_folder ]; then
sudo mkdir $mount_data_folder
sudo chown -R gitlab-runner.gitlab-runner $mount_data_folder
fi
- |
if [ ! -d $mount_data_folder/$project_name ]; then
sudo mkdir $mount_data_folder/$project_name
sudo chown -R gitlab-runner.gitlab-runner $mount_data_folder/$project_name
fi
script:
- tag=dev
- jq -r 'keys[] as $k | "\($k)=\(.[$k])"' $environment_json_path > .env
- sed -i 's|PROJECT-NAME|'$project_name'|' docker-compose.yaml
- sed -i 's|ENVIRONMENT-NAME|'$environment_name'|' docker-compose.yaml
- sed -i 's|IMAGE-NAME|'$image_name'|' docker-compose.yaml
- sed -i 's|IMAGE-TAG|'$tag'|' docker-compose.yaml
- sed -i 's|P-MAPPING|'$port_mapping'|' docker-compose.yaml
- sed -i 's|MOUNT-DATA-FOLDER|'$mount_data_folder'|' docker-compose.yaml
- echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
- sudo docker-compose down
- sudo docker-compose pull
- sudo docker-compose --env-file .env up -d
only:
- develop
tags:
- ci-cd
build_model:
stage: build_model
before_script:
- sudo apt install default-jre -y
- chmod +x -R CICD
- if [ ! -d /home/gitlab-runner ]; then mkdir /home/gitlab-runner; fi
- git config --global user.email "cicd@meu-solutions.com"
- git config --global user.name "CICD"
script:
- echo "Waiting for the application goes online..."
- sleep 10
- swaggerUrl="http://localhost:$port_mapping/swagger/v1/swagger.json"
- api=$(curl $swaggerUrl)
- api=$(jq 'del(.components.securitySchemes)' <<<$api)
- api=$(jq 'del(.security)' <<<$api)
- echo $api > apiFinal.json
- request='{"spec":{},"type":"CLIENT","lang":"typescript-angular"}'
- request=$(jq --argfile apiFinal apiFinal.json '.spec = $apiFinal' <<<$request)
- echo $request > ts.json
- rm -rf client
- java -jar CICD/swagger-codegen-cli.jar generate -i apiFinal.json -l typescript-angular -o client --additional-properties modelPropertyNaming=original
- rm -rf ts.json;
- rm -rf production_file;
- rm -rf apiFinal.json;
- temp_path=$(pwd);
- mkdir production_file;
- cp -r client/*.ts production_file/; cp -r client/api production_file/; cp -r client/model production_file/; rm -rf client; mv production_file client
- bash CICD/swagger_download client
- cd ~
- rm -rf ~/$fe_git_project_name/
- git clone --single-branch --branch $fe_model_branch "http://${GIT_USER}:${GIT_USER_PW}@$fe_git_address.git"
- cd $fe_git_project_name
- git pull origin $fe_model_branch;
- bash $temp_path/CICD/cp_ad $temp_path/client ~/$fe_git_project_name/src/app $temp_path/client
- rm -rf $temp_path/client
- git add --all; git commit -m "Update model auto" --allow-empty; git push "http://${GIT_USER}:${GIT_USER_PW}@$fe_git_address.git" HEAD:$fe_model_branch
- rm -rf ~/$fe_git_project_name/
only:
- develop
tags:
- ci-cd
release:
stage: release
before_script:
- tag=$(echo $CI_COMMIT_MESSAGE | sed -r 's/.*(\[tag\])//')
- check=$(echo $CI_COMMIT_MESSAGE | sed -r 's/^.*(\[tag\]).*/\1/')
- echo "To release new docker image, tagname should be '0.1', your tag is:$tag"
script:
- |
if [ "$check" == "[tag]" ]; then
sudo docker build -t $image_name:$tag -f Dockerfile .
sudo docker logout registry.gitlab.com
echo "$CI_REGISTRY_PW" | sudo docker login registry.gitlab.com -u "$CI_REGISTRY_USER" --password-stdin
sudo docker push $image_name:$tag
sudo docker rmi $image_name:$tag
fi
only:
- release/staging
tags:
- runner-builder
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MEU.API\MEU.API.csproj" />
</ItemGroup>
</Project>
//using MEU.API.ObjectDefinitions.Common;
//using MEU.API.ObjectDefinitions.WorkingTime;
//using MEU.API.Providers;
//using MEU.API.Services.CronJobs;
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace MEU.API.TEST
{
public class Unit_WorkingTime
{
//private readonly ITestOutputHelper output;
//public Unit_WorkingTime(ITestOutputHelper output)
//{
// this.output = output;
//}
//[Fact]
//public void TestWorkingTimeFrame()
//{
// TimeDuration wroking = new TimeDuration(new DateTime(2020, 12, 10, 7, 20, 00), new DateTime(2020, 12, 10, 17, 20, 00));
// TimeDuration shift = new TimeDuration(new DateTime(2020, 12, 10, 8, 00, 00), new DateTime(2020, 12, 10, 17, 30, 00));
// WorkingTimeFrame wtf = new WorkingTimeFrame(wroking, shift);
// output.WriteLine("LateComming: {0}", wtf.LateComming);
// output.WriteLine("SoonComeback: {0}", wtf.SoonComeback);
// output.WriteLine("WorkingTimes: {0}", wtf.WorkingTimes);
// output.WriteLine("ActualLateComming: {0}", wtf.ActualLateComming);
// output.WriteLine("ActualSoonComeback: {0}", wtf.ActualSoonComeback);
// output.WriteLine("StartTime: {0}", wtf.StartTime);
// output.WriteLine("EndTime: {0}", wtf.EndTime);
// Assert.True(wtf.LateComming == new TimeSpan(0));
// Assert.True(wtf.SoonComeback == new TimeSpan(0,10,0));
// Assert.True(wtf.WorkingTimes == new TimeSpan(9, 20, 0));
//}
}
}
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
# Created by https://www.gitignore.io/api/windows,visualstudiocode,aspnetcore,dotnetcore
# Edit at https://www.gitignore.io/?templates=windows,visualstudiocode,aspnetcore,dotnetcore
### ASPNETCore ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.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
# 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
# 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
# TODO: 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
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# 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
# 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
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# 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
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# 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
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/
### DotnetCore ###
# .NET Core build folders
/bin
/obj
# Common node modules locations
/node_modules
/wwwroot/node_modules
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
### VisualStudioCode Patch ###
# Ignore all local history of files
.history
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.gitignore.io/api/windows,visualstudiocode,aspnetcore,dotnetcore
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace MEU.API
{
public class ApplyCustomSchemaFilters : Swashbuckle.AspNetCore.SwaggerGen.ISchemaFilter
{
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
if (schema?.Properties == null)
{
return;
}
Dictionary<string, string> dcValue = new Dictionary<string, string>();
foreach (var property in context.Type.GetProperties())
{
if (property.Name.StartsWith("BODY_PART"))
{
//"System.Collections.Generic.List`1[[MEU.API.Models.working_shift_time"
string fullName = property.PropertyType.FullName.Split(',')[0];
string name = "";
//"MEU.API.Models.working_shift"
if (fullName.Contains("System.Collections.Generic.List"))
{
string[] names = fullName.Split('.');
name = "list_" + names.LastOrDefault().Replace("\"", "");
}
else
{
string[] names = fullName.Split('.');
name = names.LastOrDefault().Replace("\"", "");
}
dcValue.Add(property.Name.ToUpper(), name);
}
}
List<KeyValuePair<string, OpenApiSchema>> lstRemove = new List<KeyValuePair<string, OpenApiSchema>>();
List<KeyValuePair<string, OpenApiSchema>> lstAdd = new List<KeyValuePair<string, OpenApiSchema>>();
foreach (KeyValuePair<string, OpenApiSchema> item in schema.Properties)
{
if (item.Key.ToUpper().StartsWith("BODY_PART"))
{
if (dcValue.ContainsKey(item.Key.ToUpper()))
{
KeyValuePair<string, OpenApiSchema> ab = new KeyValuePair<string, OpenApiSchema>(dcValue[item.Key.ToUpper()], item.Value);
lstRemove.Add(item);
lstAdd.Insert(0,ab);
}
}
}
foreach (var item in lstRemove)
{
schema.Properties.Remove(item);
}
foreach (var item in lstAdd)
{
schema.Properties.Add(item);
}
var excludedProperties = context.Type.GetProperties().Where(c=>c.GetMethod.IsVirtual).ToArray();
foreach (PropertyInfo excludedProperty in excludedProperties)
{
if (schema.Properties.ContainsKey(excludedProperty.Name))
{
schema.Properties.Remove(excludedProperty.Name);
}
}
}
}
}
{
"ASPNETCORE_ENVIRONMENT": "development",
"STORAGE_ROOT": "D:/Storage",
"MAILSERVER_SMTPHOST": "smtp.yandex.com",
"MAILSERVER_SMTPPORT": "587",
"MAILSERVER_USERNAME": "intranet@meu-solutions.com",
"MAILSERVER_PASSWORD": "Meu@2019%$",
"FRONTEND_HOST": "http://27.74.255.96:8090",
"TOKEN_ENCRYPTED_KEY": "sah@kk#nn#v4,^121.,!@{}psassaasa",
"DATA_ENCRYPTED_KEY": "B546C8DF278CD5931069B522E695D4FA",
"DEFAULT_PAGE_SIZE": 10,
"PSQL_HOST": "27.74.255.96",
"PSQL_PORT": "5430",
"PSQL_PASSWORD": "meu@sds12@!#gh",
"PSQL_USER": "postgres",
"PSQL_DBNAME": "task_management"
}
{
"ASPNETCORE_ENVIRONMENT": "production",
"STORAGE_ROOT": "/data",
"MAILSERVER_SMTPHOST": "smtp.yandex.com",
"MAILSERVER_SMTPPORT": "587",
"MAILSERVER_USERNAME": "intranet@meu-solutions.com",
"MAILSERVER_PASSWORD": "Meu@2019%$",
"FRONTEND_HOST": "http://27.74.255.96:8090",
"TOKEN_ENCRYPTED_KEY": "sah@kk#nn#v4,^121.,!@{}psassaasa",
"DATA_ENCRYPTED_KEY": "B546C8DF278CD5931069B522E695D4FA",
"DEFAULT_PAGE_SIZE": 10,
"PSQL_HOST": "27.74.255.96",
"PSQL_PORT": "5430",
"PSQL_PASSWORD": "meu@sds12@!#gh",
"PSQL_USER": "postgres",
"PSQL_DBNAME": "task_management"
}
{
"ASPNETCORE_ENVIRONMENT": "staging",
"STORAGE_ROOT": "/data",
"MAILSERVER_SMTPHOST": "smtp.yandex.com",
"MAILSERVER_SMTPPORT": "587",
"MAILSERVER_USERNAME": "intranet@meu-solutions.com",
"MAILSERVER_PASSWORD": "Meu@2019%$",
"FRONTEND_HOST": "https://task.erp.meu-solutions.com",
"TOKEN_ENCRYPTED_KEY": "sah@kk#nn#v4,^121.,!@{}psassaasa",
"DATA_ENCRYPTED_KEY": "B546C8DF278CD5931069B522E695D4FA",
"DEFAULT_PAGE_SIZE": 10,
"PSQL_HOST": "27.74.255.96",
"PSQL_PORT": "5430",
"PSQL_PASSWORD": "meu@sds12@!#gh",
"PSQL_USER": "postgres",
"PSQL_DBNAME": "task_management"
}
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace MEU.API.Config
{
public class ConfigEnvironment
{
/// <summary>
/// development/production
/// </summary>
/// <param name="environmentName"></param>
public static void load(string environmentName)
{
//On prodction we will use all config from environment
if (environmentName.ToLower().Trim().Equals("production"))
{
return;
}
var envPath = Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Config/.env." + environmentName + ".json");
if (!File.Exists(envPath))
{
return;
}
using (StreamReader file = File.OpenText(envPath))
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o2 = (JObject)JToken.ReadFrom(reader);
foreach (var property in o2.Properties())
{
Environment.SetEnvironmentVariable(property.Name, property.Value.ToString());
}
}
}
public static string STORAGE_ROOT = Environment.GetEnvironmentVariable("STORAGE_ROOT");
public static string STORAGE_RELATIVE_DRAFT_PATH = "/drafts"; //files_draftPath //STORAGE_RELATIVE_DRAFT_PATH
public static string STORAGE_RELATIVE_USERS = "/users"; //files_userPath //STORAGE_RELATIVE_USERS
public static string STORAGE_RALATIVE_AVATAR = "/avatars"; //files_avatarPath //STORAGE_RALATIVE_AVATAR
public static string STORAGE_RELATIVE_ATTACHMENT = "/general_attchments"; //files_generalAttachment //STORAGE_RELATIVE_ATTACHMENT
public static string STORAGE_PUBLIC = "/public"; //files_publicPath //STORAGE_PUBLIC
public static string STORAGE_RALATIVE_COMPANYINFO = "/company_info";
public static string STORAGE_RELATIVE_CV = "/cvs";
public static string STORAGE_RELATIVE_CONTRACT = "/contracts"; //files_publicPath //file_contractPath
public static string STORAGE_RELATIVE_SUBFORM_TEMPLATE = "/subforms"; //files_publicPath //file_subformTemplatePath
public static string STORAGE_RELATIVE_COMMENT_ATTACHMENT = "/comment_attachments"; //files_publicPath //file_commentAttachment
public static string STORAGE_RELATIVE_WORKFLOW_ATTACHMENT = "/workflow_attachments"; //files_publicPath //file_workflowAttachment
public static string STORAGE_RELATIVE_SIGNATURE_ATTACHMENT = "/signature_attachments"; //files_publicPath //file_signaturePath
public static string STORAGE_RELATIVE_SALARY_EXCEL_FILE = "/salary_excel_files"; //files_publicPath //salary_excel_file
public static string STORAGE_RELATIVE_HR_APPLICATION_TEMPLATE = "/hr_application_templates"; //files_publicPath //hr_application_templates
public static string MAILSERVER_SMTPHOST = Environment.GetEnvironmentVariable("MAILSERVER_SMTPHOST");// Environment.GetEnvironmentVariable("MAILSERVER_SMTPHOST"); //mailServer_smtpHost //MAILSERVER_SMTPHOST
public static string MAILSERVER_SMTPPORT = Environment.GetEnvironmentVariable("MAILSERVER_SMTPPORT");// Environment.GetEnvironmentVariable("MAILSERVER_SMTPPORT"); //mailServer_smtpPort //MAILSERVER_SMTPPORT
public static string MAILSERVER_USERNAME = Environment.GetEnvironmentVariable("MAILSERVER_USERNAME");// Environment.GetEnvironmentVariable("MAILSERVER_USERNAME"); //mailAdminAccount_Username //MAILSERVER_USERNAME
public static string MAILSERVER_PASSWORD = Environment.GetEnvironmentVariable("MAILSERVER_PASSWORD");// Environment.GetEnvironmentVariable("MAILSERVER_PASSWORD"); //mailAdminAccount_Passwordword //MAILSERVER_PASSWORD
public static string FRONTEND_HOST = Environment.GetEnvironmentVariable("FRONTEND_HOST"); //frontend_host //FRONTEND_HOST
public static string TOKEN_ENCRYPTED_KEY = "sah@kk#nn#v4,^121.,!@{}psassaasa";// Environment.GetEnvironmentVariable("TOKEN_ENCRYPTED_KEY");// encryptKeys_tokenKey;
public static string DATA_ENCRYPTED_KEY = "B546C8DF278CD5931069B522E695D4FA";// Environment.GetEnvironmentVariable("DATA_ENCRYPTED_KEY");// encryptKeys_dataKey;
public static int DEFAULT_PAGE_SIZE = 10;// Int32.Parse(Environment.GetEnvironmentVariable("DEFAULT_PAGE_SIZE"));
//DB Connection
public static string PSQL_HOST = Environment.GetEnvironmentVariable("PSQL_HOST");
public static string PSQL_PORT = Environment.GetEnvironmentVariable("PSQL_PORT");
public static string PSQL_PASSWORD = Environment.GetEnvironmentVariable("PSQL_PASSWORD");
public static string PSQL_USER = Environment.GetEnvironmentVariable("PSQL_USER");
public static string PSQL_DBNAME = Environment.GetEnvironmentVariable("PSQL_DBNAME");
public static string ENVIRONMENT = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
public static string CONECTION_STRING = "Persist Security Info=True;Password="
+ ConfigEnvironment.PSQL_PASSWORD + ";Username="
+ ConfigEnvironment.PSQL_USER + ";Database="
+ ConfigEnvironment.PSQL_DBNAME + ";Host="
+ ConfigEnvironment.PSQL_HOST + ";Port="
+ ConfigEnvironment.PSQL_PORT;
}
}
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Globalization;
using System.Threading.Tasks;
namespace MEU.API
{
public class DateTimeModelBinderProvider : IModelBinderProvider
{
// You could make this a property to allow customization
internal static readonly DateTimeStyles SupportedStyles = DateTimeStyles.AdjustToUniversal | DateTimeStyles.AllowWhiteSpaces;
/// <inheritdoc />
public IModelBinder GetBinder(ModelBinderProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var modelType = context.Metadata.UnderlyingOrModelType;
var loggerFactory = context.Services.GetRequiredService<ILoggerFactory>();
if (modelType == typeof(DateTime))
{
return new UtcAwareDateTimeModelBinder(SupportedStyles, loggerFactory);
}
return null;
}
}
public class UtcAwareDateTimeModelBinder : IModelBinder
{
private readonly DateTimeStyles _supportedStyles;
private readonly ILogger _logger;
public UtcAwareDateTimeModelBinder(DateTimeStyles supportedStyles, ILoggerFactory loggerFactory)
{
if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(loggerFactory));
}
_supportedStyles = supportedStyles;
_logger = loggerFactory.CreateLogger<UtcAwareDateTimeModelBinder>();
}
public Task BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
var modelName = bindingContext.ModelName;
var valueProviderResult = bindingContext.ValueProvider.GetValue(modelName);
if (valueProviderResult == ValueProviderResult.None)
{
// no entry
return Task.CompletedTask;
}
var modelState = bindingContext.ModelState;
modelState.SetModelValue(modelName, valueProviderResult);
var metadata = bindingContext.ModelMetadata;
var type = metadata.UnderlyingOrModelType;
var value = valueProviderResult.FirstValue;
var culture = valueProviderResult.Culture;
object model;
if (string.IsNullOrWhiteSpace(value))
{
model = null;
}
else if (type == typeof(DateTime))
{
// You could put custom logic here to sniff the raw value and call other DateTime.Parse overloads, e.g. forcing UTC
model = DateTime.Parse(value, culture, _supportedStyles);
}
else
{
// unreachable
throw new NotSupportedException();
}
// When converting value, a null model may indicate a failed conversion for an otherwise required
// model (can't set a ValueType to null). This detects if a null model value is acceptable given the
// current bindingContext. If not, an error is logged.
if (model == null && !metadata.IsReferenceOrNullableType)
{
modelState.TryAddModelError(
modelName,
metadata.ModelBindingMessageProvider.ValueMustNotBeNullAccessor(
valueProviderResult.ToString()));
}
else
{
bindingContext.Result = ModelBindingResult.Success(model);
}
return Task.CompletedTask;
}
}
}
\ No newline at end of file

using Microsoft.VisualBasic.CompilerServices;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace MEU.API
{
[JsonConverter(typeof(PagedDataConverter))]
public class FromBodyGenericType<T, U>
where T : class
where U : class
{
public T BODY_PART_T { get; set; }
public U BODY_PART_U { get; set; }
}
public class PagedDataConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
var instance = Activator.CreateInstance(objectType);
//MyCustomType myCustomType = new MyCustomType();//for null values
Dictionary<string, KeyValuePair< string, Type>> dcValue = new Dictionary<string, KeyValuePair<string, Type>>();
foreach (var prop in objectType.GetProperties())
{
string fullName = prop.PropertyType.FullName.Split(',')[0];
string name = "";
//"MEU.API.Models.working_shift"
if (fullName.Contains("System.Collections.Generic.List"))
{
string[] names = fullName.Split('.');
name = "list_" + names.LastOrDefault().Replace("\"", "");
}
else
{
string[] names = fullName.Split('.');
name = names.LastOrDefault().Replace("\"", "");
}
dcValue.Add(name, new KeyValuePair<string,Type>( prop.Name.ToUpper(),prop.PropertyType));
//var result = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(addrayData[name]), prop.PropertyType);
}
if (reader.TokenType != JsonToken.Null)
{
Dictionary<string, JToken> addrayData = new Dictionary<string, JToken>();
JToken token1 = JToken.Load(reader);
Dictionary<string, JToken> addkey = new Dictionary<string, JToken>();
Dictionary<string, JToken> removedkey = new Dictionary<string, JToken>();
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (var pair in token1 as JObject)
{
if (pair.Key.StartsWith("BODY_PART"))
{
continue;
}
dict.Add(pair.Key, dcValue[pair.Key].Key);
var data = JsonConvert.DeserializeObject(pair.Value.ToString(), dcValue[pair.Key].Value);
PropertyInfo prop = instance.GetType().GetProperty(dcValue[pair.Key].Key);
prop.SetValue(instance, data, null);
}
return instance;
}
return null;// myCustomType;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new Exception("Have not implment");
}
}
}
using MEU.API.MiddleWare;
using Microsoft.Extensions.Configuration;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Logs
{
public class LoggerFactory
{
//private static logger = NLog.Config.con Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
private static Logger logger = LogManager.GetCurrentClassLogger();
public static void ErrorLog(String messenge, String title)
{
logger.Error(messenge, title);
var currentContext = AppHttpContext.Current;
if (currentContext == null)
{
return;
}
if (currentContext.Items.ContainsKey("LOG_DATA"))
{
currentContext.Items["LOG_DATA"] += messenge;
}
else
{
currentContext.Items.Add("LOG_DATA", messenge);
}
}
public static void DebugLog(String messenge, String title = "")
{
}
public static void TraceLog(String messenge, String title = "")
{
}
public static void InfoLog(String messenge, String title = "")
{
logger.Error(messenge, title);
}
public static void WarnLog(String messenge, String title = "")
{
}
public static void FatalLog(String messenge, String title = "")
{
}
}
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>MEU.API</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Controller Test\**" />
<Content Remove="Controller Test\**" />
<EmbeddedResource Remove="Controller Test\**" />
<None Remove="Controller Test\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspose.Words" Version="20.7.0" />
<PackageReference Include="CorePush" Version="2.1.2" />
<PackageReference Include="Cronos" Version="0.7.0" />
<PackageReference Include="EntityFramework" Version="6.4.0" />
<PackageReference Include="EPPlus" Version="5.2.1" />
<PackageReference Include="GeoCoordinate.NetCore" Version="1.0.0.1" />
<PackageReference Include="Hangfire" Version="1.7.9" />
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.9" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.6.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NLog" Version="4.7.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.0" />
<PackageReference Include="Swashbuckle" Version="5.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.6.3" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.6.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
<PackageReference Include="System.IO.Packaging" Version="4.7.0" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.23" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sieve\Sieve\Sieve.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Connected Services\" />
<Folder Include="Controllers\" />
<Folder Include="ExtendModels\" />
<Folder Include="Models\" />
<Folder Include="Test Controllers\" />
<Folder Include="Providers\" />
<Folder Include="Resources\EmailTemplates\" />
<Folder Include="Services\CronJobs\" />
<Folder Include="Services\NotificationHub\" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Reference Include="EncryptDataLib">
<HintPath>ExternalLib\EncryptDataLib.dll</HintPath>
</Reference>
<Reference Include="EPPlus">
<HintPath>Plugins\EPPlus.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Update="Config\.env.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\js\entry.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\js\jquery-3.4.1.min.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\js\swagger-auth-custom.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\js\swashbuckle.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
<?xml version="1.0"?>
<doc>
<assembly>
<name>MEU.API</name>
</assembly>
<members>
<member name="M:MEU.API.Controllers.hrInOutLogController.ExportExcel(System.String,Sieve.Models.SieveModel)">
<summary>
This API support export excel file for HR In Out Log
</summary>
<remarks>
Use both to get data from my in out log or all in out log
</remarks>
<param name="key"> Use key 'AllHrInOutLogs' or 'MyHrInOutLogs' to download.</param>
<param name="sieveModel"> </param>
</member>
</members>
</doc>
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.MiddleWare
{
public class AddErrorLogToHeaderMiddelware
{
private readonly RequestDelegate next;
public AddErrorLogToHeaderMiddelware(RequestDelegate _next)
{
next = _next;
}
public async Task Invoke(HttpContext context )
{
if (ErrorHandlingMiddleware.enableDebug)
{
var watch = new Stopwatch();
watch.Start();
context.Response.OnStarting(state => {
var httpContext = (HttpContext)state;
httpContext.Response.Headers.Add("X-Response-Time-Milliseconds", new Microsoft.Extensions.Primitives.StringValues(watch.ElapsedMilliseconds.ToString() + " ms"));
var contextData = AppHttpContext.Current;
string Log = "No any log";
if (contextData != null && contextData.Items.ContainsKey("LOG_DATA"))
{
if (contextData.Items["LOG_DATA"]!=null)
{
Log = contextData.Items["LOG_DATA"].ToString();
Log = Log.Replace(Environment.NewLine, "");
}
}
httpContext.Response.Headers.Add("X-Log-Data", new Microsoft.Extensions.Primitives.StringValues(Log));
return Task.CompletedTask;
}, context);
}
await next(context);
}
}
}
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.MiddleWare
{
public class AppHttpContext
{
static IServiceProvider services = null;
/// <summary>
/// Provides static access to the framework's services provider
/// </summary>
public static IServiceProvider Services
{
get { return services; }
set
{
if (services != null)
{
throw new Exception("Can't set once a value has already been set.");
}
services = value;
}
}
/// <summary>
/// Provides static access to the current HttpContext
/// </summary>
public static HttpContext Current
{
get
{
IHttpContextAccessor httpContextAccessor = services.GetService(typeof(IHttpContextAccessor)) as IHttpContextAccessor;
return httpContextAccessor?.HttpContext;
}
}
}
}
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace MEU.API.MiddleWare
{
public class CorsMiddleware
{
private readonly RequestDelegate _next;
public CorsMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
context.Response.Headers.Add("Access-Control-Allow-Credentials", "true");
// Added "Accept-Encoding" to this list
context.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Accept-Encoding, Content-Length, Content-MD5, Date, X-Api-Version, X-File-Name");
context.Response.Headers.Add("Access-Control-Allow-Methods", "POST,GET,PUT,PATCH,DELETE,OPTIONS");
// New Code Starts here
if (context.Request.Method == "OPTIONS")
{
context.Response.StatusCode = (int)HttpStatusCode.OK;
await context.Response.WriteAsync(string.Empty);
}
// New Code Ends here
await _next(context);
}
}
}
using System;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using System.Text;
using Newtonsoft.Json;
namespace MEU.API.MiddleWare
{
public class CustomModelBinder: IModelBinder
{
public Task BindModelAsync(ModelBindingContext bindingContext)
{
var request = bindingContext.HttpContext.Request;
using (var reader = new StreamReader(request.Body, Encoding.UTF8))
{
try
{
var bodyString = reader.ReadToEnd();
var resultObject = JsonConvert.DeserializeObject<object>(bodyString);
RequestParams.setParam(bindingContext.FieldName, resultObject);
var result = JsonConvert.DeserializeObject(bodyString, bindingContext.ModelType);
bindingContext.Result = ModelBindingResult.Success(result);
}
catch (Exception ex)
{
}
}
return Task.CompletedTask;
}
}
}
using MEU.API.Utils;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace MEU.API.MiddleWare
{
public class ErrorHandlingMiddleware
{
public static bool enableDebug = true;
private readonly RequestDelegate next;
public ErrorHandlingMiddleware(RequestDelegate next)
{
this.next = next;
}
public async Task Invoke(HttpContext context /* other dependencies */)
{
try
{
await next(context);
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex);
}
}
private static Task HandleExceptionAsync(HttpContext context, Exception ex)
{
if (ErrorHandlingMiddleware.enableDebug)
{
var code = System.Net.HttpStatusCode.InternalServerError;
var result = JsonConvert.SerializeObject(new { success = false, message = ex });
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)code;
return context.Response.WriteAsync(result);
}
else
{
var code = System.Net.HttpStatusCode.InternalServerError; // 500 if unexpected
var result = JsonConvert.SerializeObject(new { success = false, message = "Unexpected error, please contact admin" });
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)code;
return context.Response.WriteAsync(result);
}
}
}
}
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.MiddleWare
{
public class RequestParams
{
static string sPrefix = "_MIDDLEPARAMPREFIX_";
//static HttpContext context = null;
//public static void reset(HttpContext _context) {
// context = _context;
//}
public static object getParam(string ParamName)
{
HttpContext context = AppHttpContext.Current;
ParamName = sPrefix + ParamName;
if (context!=null && context.Items.ContainsKey(ParamName))
{
return context.Items[ParamName];
}
else
{
return null;
}
}
public static void setParam(string ParamName, object Value)
{
HttpContext context = AppHttpContext.Current;
ParamName = sPrefix + ParamName;
if (context.Items.ContainsKey(ParamName))
{
context.Items[ParamName] = Value;
}
else
{
context.Items.Add(ParamName, Value);
}
}
}
}
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using MEU.API.Config;
using MEU.API.Logs;
namespace MEU.API.MiddleWare
{
public class SignatureMiddleware
{
private readonly RequestDelegate next;
public SignatureMiddleware(RequestDelegate _next)
{
this.next = _next;
}
public static string MD5Signature(string input)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
return s.ToString();
}
public async Task Invoke(HttpContext context )
{
try
{
//var remoteIpAddress = context.Connection.RemoteIpAddress.ToString();
//if (!ConfigEnvironment.ENVIRONMENT.ToLower().Trim().Equals("production"))
//{
// if (!(remoteIpAddress == "27.74.255.96" || remoteIpAddress == "113.161.54.11"))
// {
// if (context.Request.Path.Value.ToString().ToLower().Contains("workflow"))
// {
// await context.Response.WriteAsync("Unknown");
// }
// }
//}
if (ConfigEnvironment.ENVIRONMENT.ToLower().Trim().Equals("production"))
{
if (!context.Request.Path.Value.ToString().ToLower().Contains("upload") &&
!context.Request.Path.Value.ToString().ToLower().Contains("notificationhub"))
{
string signature = context.Request.Headers["Signature"].ToString();
string time = context.Request.Headers["Time"].ToString();
string url = "." + context.Request.GetEncodedPathAndQuery();
string body = null;
if (context.Request.Method != HttpMethods.Get)
{
using (var reader = new StreamReader(
context.Request.Body,
encoding: Encoding.UTF8,
detectEncodingFromByteOrderMarks: false,
bufferSize: 1024 * 45,
leaveOpen: true))
{
body = await reader.ReadToEndAsync();
context.Request.Body.Position = 0;
}
}
if (string.IsNullOrEmpty(body))
{
body = "null";
}
object data = new
{
url = url,
body = body,
time = Int64.Parse(time)
};
string dataEncrypt = Newtonsoft.Json.JsonConvert.SerializeObject(data).ToLower() + "@123RAPTOR!@#&^";
string md5Data = MD5Signature(dataEncrypt);
if (signature != md5Data)
{
context.Response.Clear();
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
context.Response.Headers.Add("BACKEND_Signature", SignatureMiddleware.MD5Signature(md5Data));
if (dataEncrypt.Length < 500)
{
context.Response.Headers.Add("DATA", dataEncrypt);
}
await context.Response.WriteAsync("Forbiden");
}
else
{
await next(context);
}
}
else
{
await next(context);
}
}
else
{
await next(context);
}
}
catch (Exception ex)
{
context.Response.Clear();
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
LoggerFactory.ErrorLog(ex.ToString(), "Exception");
await context.Response.WriteAsync("Forbiden");
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<target name="errorLogTextFile" xsi:type="File" fileName="/home/MeUERP_Logs/Log_Error_${shortdate}.log" />
<target name="debugLogConsole" xsi:type="Console" />
</targets>
<rules>
<!-- add your logging rules here -->
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
<logger name="*" minlevel="Error" writeTo="errorLogTextFile" />
<logger name="*" minlevel="Debug" writeTo="debugLogConsole" />
</rules>
</nlog>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace MEU.API
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MEU.API.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MEU.API.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8089",
"sslPort": 0
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Development": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Production": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"Staging": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
MS4xLjAgKDMxLzMvMjAyMSAxNTowMDowMCk=
\ No newline at end of file
using MEU.API.Services.Emails.Templates;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Services.Emails
{
public class EmailTemplateFactory
{
public static EmailSetupNewPassword EmailSetupNewPassword(string EmailSubject, string Link, string Username, string RecieverUser)
{
return new EmailSetupNewPassword(EmailSubject, Link, Username, RecieverUser);
}
public static EmailForgotPassword EmailForgotPassword(string EmailSubject, string Link, string Username, string RecieverUser)
{
return new EmailForgotPassword(EmailSubject, Link, Username, RecieverUser);
}
public static EmailXMaxUnlockCode EmailXMaxUnlockCode(string UnlockCode, string Username, string RecieverUserEmail)
{
return new EmailXMaxUnlockCode(UnlockCode, Username, RecieverUserEmail);
}
public static EmailOTPCheckInTool EmailOTPCheckInTool(string EmailSubJect, string OTPCode, string UserName, string RecieverUserEmail)
{
return new EmailOTPCheckInTool(EmailSubJect,OTPCode, UserName, RecieverUserEmail);
}
}
}
using MEU.API.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
namespace MEU.API.Services.Emails.Templates
{
public abstract class EmailContent
{
public string EmailTemplatePath = Environment.CurrentDirectory + "/Resources/EmailTemplates";
public string Subject { get; set; }
public string Reciever { get; set; }
public abstract string GetContent();
public abstract bool Send();
public abstract Task SendAsync();
private string smtpserver = ConfigEnvironment.MAILSERVER_SMTPHOST;
private int smtpmailport = Int32.Parse(ConfigEnvironment.MAILSERVER_SMTPPORT);
private string username = ConfigEnvironment.MAILSERVER_USERNAME;
private string password = ConfigEnvironment.MAILSERVER_PASSWORD;
protected bool SendEmail(string Receiver, string Subject, string Body)
{
SmtpClient client = new SmtpClient(smtpserver, smtpmailport);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(this.username, this.password);
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(username);
mailMessage.To.Add(Receiver);
mailMessage.Body = Body;
mailMessage.Subject = Subject;
client.Send(mailMessage);
return true;
}
protected async Task<bool> SendEmailAsync(string Receiver, string Subject, string Body)
{
SmtpClient client = new SmtpClient(smtpserver, smtpmailport);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(this.username, this.password);
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(username);
mailMessage.To.Add(Receiver);
mailMessage.Body = Body;
mailMessage.IsBodyHtml = true;
mailMessage.Subject = Subject;
await client.SendMailAsync(mailMessage);
return true;
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Services.Emails.Templates
{
public class EmailForgotPassword:EmailContent
{
protected string _Link = "";
protected string _Username = "";
public EmailForgotPassword(string EmailSubject, string Link, string Username, string RecieverUser)
{
this.EmailTemplatePath += "/EmailForgotPassword.html";
_Link = Link;
_Username = Username;
this.Reciever = RecieverUser;
this.Subject = EmailSubject;
}
public override string GetContent()
{
string fullBody = "Đây là link cập nhật mật khẩu {{link}} for user {{username}}";
if (File.Exists(this.EmailTemplatePath))
{
fullBody = File.ReadAllText(this.EmailTemplatePath);
}
else
{
fullBody += "\r\nCannot find template email at path:" + this.EmailTemplatePath;
}
//
fullBody = fullBody.Replace("{{link}}", this._Link);
fullBody = fullBody.Replace("{{username}}", this.Reciever);
return fullBody;
}
public override bool Send()
{
this.SendEmail(this.Reciever, this.Subject, this.GetContent());
return true;
}
public override async Task SendAsync()
{
await Task.Run(() => this.SendEmailAsync(this.Reciever, this.Subject, this.GetContent()));
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Services.Emails.Templates
{
public class EmailOTPCheckInTool:EmailContent
{
protected string _OTPCode = "";
protected string _Username = "";
public EmailOTPCheckInTool(string EmailSubject, string OTPCode, string Username, string RecieverUser)
{
this.EmailTemplatePath += "/EmailOTPCheckInTool.html";
_OTPCode = OTPCode;
_Username = Username;
this.Reciever = RecieverUser;
this.Subject = EmailSubject;
}
public override string GetContent()
{
string fullBody = "Đây là mã OTP cho user {{username}}: {{otplogin}} ";
if (File.Exists(this.EmailTemplatePath))
{
fullBody = File.ReadAllText(this.EmailTemplatePath);
}
else
{
fullBody += "\r\nCannot find template email at path:" + this.EmailTemplatePath;
}
//
fullBody = fullBody.Replace("{{otplogin}}", this._OTPCode);
fullBody = fullBody.Replace("{{username}}", this._Username);
return fullBody;
}
public override bool Send()
{
this.SendEmail(this.Reciever, this.Subject, this.GetContent());
return true;
}
public override async Task SendAsync()
{
await Task.Run(() => this.SendEmailAsync(this.Reciever, this.Subject, this.GetContent()));
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Services.Emails.Templates
{
public class EmailSetupNewPassword: EmailContent
{
protected string _Link = "";
protected string _Username = "";
public EmailSetupNewPassword(string EmailSubject, string Link, string Username, string RecieverUser)
{
this.EmailTemplatePath += "/EmailSetupNewPassword.html";
_Link = Link;
_Username = Username;
this.Reciever = RecieverUser;
this.Subject = EmailSubject;
}
public override string GetContent()
{
string fullBody = File.ReadAllText(this.EmailTemplatePath);
fullBody = fullBody.Replace("{{link}}", this._Link);
fullBody = fullBody.Replace("{{username}}", this.Reciever);
return fullBody;
}
public override bool Send()
{
this.SendEmail(this.Reciever, this.Subject, this.GetContent());
return true;
}
public override async Task SendAsync()
{
await Task.Run(() => this.SendEmailAsync(this.Reciever, this.Subject, this.GetContent()));
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Services.Emails.Templates
{
public class EmailXMaxUnlockCode : EmailContent
{
string _UnlockCode;
string _Username;
public EmailXMaxUnlockCode(string UnlockCode, string Username, string RecieverUser)
{
this.EmailTemplatePath += "/EmailXMaxUnlockCode.html";
this._Username = Username;
this._UnlockCode = UnlockCode;
this.Reciever = RecieverUser;
this.Subject = "Mã mở khóa app Xmax Key";
}
public override string GetContent()
{
string fullBody = "Chào {{ten}}, Đây là mã mở khóa {{UNLOCK_CODE}}";
if (File.Exists(this.EmailTemplatePath))
{
fullBody = File.ReadAllText(this.EmailTemplatePath);
}
else
{
fullBody += "\r\nCannot find template email at path:" + this.EmailTemplatePath;
}
//
fullBody = fullBody.Replace("{{ten}}", this._Username);
fullBody = fullBody.Replace("{{UNLOCK_CODE}}", this._UnlockCode);
return fullBody;
}
public override bool Send()
{
this.SendEmail(this.Reciever, this.Subject, this.GetContent());
return true;
}
public override async Task SendAsync()
{
await Task.Run(() => this.SendEmailAsync(this.Reciever, this.Subject, this.GetContent()));
}
}
}
This diff is collapsed.
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API
{
public class SwaggerDocumentFilter : IDocumentFilter
{
//public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
//{
// swaggerDoc.Host = "some-url-that-is-hosted-on-azure.azurewebsites.net";
// swaggerDoc.BasePath = "/api";
// swaggerDoc.Schemes = new List<string> { "https" };
//}
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
//var sever = new OpenApiServer();
//sever.Url = "http://27.74.255.96:8089";
//swaggerDoc.Servers.Add(sever);
}
}
}
https://github.com/Biarity/Sieve, Sieve is a simple, clean, and extensible framework for .NET Core that adds sorting, filtering, and pagination functionality out of the box. Most common use case would be for serving ASP.NET Core GET queries.
using MEU.API.Config;
//using MEU.API.Models;
using Sieve.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Utils
{
public class CommonUtils
{
public static DateTime ConvertToClientStartDate(DateTime dtInput) {
if (dtInput.Hour > 12)
{
return dtInput.AddHours(24 - dtInput.Hour);
}
else
{
return dtInput.AddHours(-dtInput.Hour);
}
}
private static readonly string[] VietnameseSigns = new string[]
{
"aAeEoOuUiIdDyY",
"áàạảãâấầậẩẫăắằặẳẵ",
"ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",
"éèẹẻẽêếềệểễ",
"ÉÈẸẺẼÊẾỀỆỂỄ",
"óòọỏõôốồộổỗơớờợởỡ",
"ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",
"úùụủũưứừựửữ",
"ÚÙỤỦŨƯỨỪỰỬỮ",
"íìịỉĩ",
"ÍÌỊỈĨ",
"đ",
"Đ",
"ýỳỵỷỹ",
"ÝỲỴỶỸ"
};
//public static string getFullName(user usr)
//{
// if (usr==null)
// {
// return "";
// }
// return (usr?.first_name?.Trim() + " " + usr?.middle_name?.Trim() + " " + usr?.last_name?.Trim()).Replace(" ", " ");
//}
public static string RemoveSignAndLowerCase4VietnameseString(string str)
{
str = str.ToLower();
for (int i = 1; i < VietnameseSigns.Length; i++)
{
for (int j = 0; j < VietnameseSigns[i].Length; j++)
str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
}
return str;
}
public static DateTime FirstDateOfWeekISO8601(int year, int weekOfYear)
{
DateTime jan1 = new DateTime(year, 1, 1);
int daysOffset = DayOfWeek.Thursday - jan1.DayOfWeek;
// Use first Thursday in January to get first week of the year as
// it will never be in Week 52/53
DateTime firstThursday = jan1.AddDays(daysOffset);
var cal = CultureInfo.CurrentCulture.Calendar;
int firstWeek = cal.GetWeekOfYear(firstThursday, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
var weekNum = weekOfYear;
// As we're adding days to a date in Week 1,
// we need to subtract 1 in order to get the right date for week #1
if (firstWeek == 1)
{
weekNum -= 1;
}
// Using the first Thursday as starting week ensures that we are starting in the right year
// then we add number of weeks multiplied with days
var result = firstThursday.AddDays(weekNum * 7);
// Subtract 3 days from Thursday to get Monday, which is the first weekday in ISO8601
return result.AddDays(-3);
}
public static int? getTakeNumber(SieveModel sieveModel)
{
int? take = null;
if (string.IsNullOrEmpty(sieveModel.Filters) && string.IsNullOrEmpty(sieveModel.Sorts))
{
if (sieveModel.PageSize == null)
take = ConfigEnvironment.DEFAULT_PAGE_SIZE;
else
take = sieveModel.PageSize.Value;
}
return take;
}
}
}
This diff is collapsed.
using MEU.API.Config;
//using MEU.API.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using EncryptDataLib;
namespace MEU.API.Utils
{
public class CryptoUtils
{
private static String encryptDataKey = ConfigEnvironment.DATA_ENCRYPTED_KEY;
public static string CalculateMD5Hash(string input)
{
// step 1, calculate MD5 hash from input
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
// step 2, convert byte array to hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString();
}
protected static string Encrypt(string text, string keyString)
{
var key = Encoding.UTF8.GetBytes(keyString);
using (var aesAlg = Aes.Create())
{
using (var encryptor = aesAlg.CreateEncryptor(key, aesAlg.IV))
{
using (var msEncrypt = new MemoryStream())
{
using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
using (var swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(text);
}
var iv = aesAlg.IV;
var decryptedContent = msEncrypt.ToArray();
var result = new byte[iv.Length + decryptedContent.Length];
Buffer.BlockCopy(iv, 0, result, 0, iv.Length);
Buffer.BlockCopy(decryptedContent, 0, result, iv.Length, decryptedContent.Length);
return Convert.ToBase64String(result);
}
}
}
}
protected static string Decrypt(string cipherText, string keyString)
{
var fullCipher = Convert.FromBase64String(cipherText);
var iv = new byte[16];
var cipher = new byte[fullCipher.Length - iv.Length]; //changes here
Buffer.BlockCopy(fullCipher, 0, iv, 0, iv.Length);
// Buffer.BlockCopy(fullCipher, iv.Length, cipher, 0, cipher.Length);
Buffer.BlockCopy(fullCipher, iv.Length, cipher, 0, fullCipher.Length - iv.Length); // changes here
var key = Encoding.UTF8.GetBytes(keyString);
using (var aesAlg = Aes.Create())
{
using (var decryptor = aesAlg.CreateDecryptor(key, iv))
{
string result;
using (var msDecrypt = new MemoryStream(cipher))
{
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (var srDecrypt = new StreamReader(csDecrypt))
{
result = srDecrypt.ReadToEnd();
}
}
}
return result;
}
}
}
public static String EncryptData(String data)
{
return CryptoUtils.Encrypt(data, CryptoUtils.encryptDataKey);
}
public static String EncodeBase64(String data)
{
byte[] encodedBytes = System.Text.Encoding.UTF8.GetBytes(data);
return Convert.ToBase64String(encodedBytes);
}
public static String DecodeBase64(String data)
{
var base64EncodedBytes = System.Convert.FromBase64String(data);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
public static String DecryptData(String encryptedData)
{
return CryptoUtils.Decrypt(encryptedData, CryptoUtils.encryptDataKey);
}
}
}
using MEU.API.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Utils
{
public class DefaultConstant
{
public static string DefaultAvatar = "/StaticFiles/images/person.png";
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace MEU.API.Utils
{
public class FilterStringAttribute : Attribute
{
private string stringVal;
public FilterStringAttribute(string Data)
{
stringVal = Data;
}
public string StringValue
{
get { return stringVal; }
set { stringVal = value; }
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MEU.API.Utils
{
public class UUID : Attribute
{
public UUID()
{
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment