Skip to content

Commit fe1712c

Browse files
init commit
0 parents  commit fe1712c

File tree

12 files changed

+443
-0
lines changed

12 files changed

+443
-0
lines changed

.gitignore

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# Download this file using PowerShell v3 under Windows with the following comand:
2+
# Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore
3+
# or wget:
4+
# wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore
5+
6+
# User-specific files
7+
*.suo
8+
*.user
9+
*.sln.docstates
10+
11+
# Build results
12+
[Dd]ebug/
13+
[Rr]elease/
14+
x64/
15+
[Bb]in/
16+
[Oo]bj/
17+
# build folder is nowadays used for build scripts and should not be ignored
18+
#build/
19+
20+
# NuGet Packages
21+
*.nupkg
22+
# The packages folder can be ignored because of Package Restore
23+
**/packages/*
24+
# except build/, which is used as an MSBuild target.
25+
!**/packages/build/
26+
# Uncomment if necessary however generally it will be regenerated when needed
27+
#!**/packages/repositories.config
28+
29+
# MSTest test Results
30+
[Tt]est[Rr]esult*/
31+
[Bb]uild[Ll]og.*
32+
33+
*_i.c
34+
*_p.c
35+
*.ilk
36+
*.meta
37+
*.obj
38+
*.pch
39+
*.pdb
40+
*.pgc
41+
*.pgd
42+
*.rsp
43+
*.sbr
44+
*.tlb
45+
*.tli
46+
*.tlh
47+
*.tmp
48+
*.tmp_proj
49+
*.log
50+
*.vspscc
51+
*.vssscc
52+
.builds
53+
*.pidb
54+
*.log
55+
*.scc
56+
57+
# OS generated files #
58+
.DS_Store*
59+
Icon?
60+
61+
# Visual C++ cache files
62+
ipch/
63+
*.aps
64+
*.ncb
65+
*.opensdf
66+
*.sdf
67+
*.cachefile
68+
69+
# Visual Studio profiler
70+
*.psess
71+
*.vsp
72+
*.vspx
73+
74+
# Guidance Automation Toolkit
75+
*.gpState
76+
77+
# ReSharper is a .NET coding add-in
78+
_ReSharper*/
79+
*.[Rr]e[Ss]harper
80+
81+
# TeamCity is a build add-in
82+
_TeamCity*
83+
84+
# DotCover is a Code Coverage Tool
85+
*.dotCover
86+
87+
# NCrunch
88+
*.ncrunch*
89+
.*crunch*.local.xml
90+
91+
# Installshield output folder
92+
[Ee]xpress/
93+
94+
# DocProject is a documentation generator add-in
95+
DocProject/buildhelp/
96+
DocProject/Help/*.HxT
97+
DocProject/Help/*.HxC
98+
DocProject/Help/*.hhc
99+
DocProject/Help/*.hhk
100+
DocProject/Help/*.hhp
101+
DocProject/Help/Html2
102+
DocProject/Help/html
103+
104+
# Click-Once directory
105+
publish/
106+
107+
# Publish Web Output
108+
*.Publish.xml
109+
110+
# Windows Azure Build Output
111+
csx
112+
*.build.csdef
113+
114+
# Windows Store app package directory
115+
AppPackages/
116+
117+
# Others
118+
*.Cache
119+
ClientBin/
120+
[Ss]tyle[Cc]op.*
121+
~$*
122+
*~
123+
*.dbmdl
124+
*.[Pp]ublish.xml
125+
*.pfx
126+
*.publishsettings
127+
modulesbin/
128+
tempbin/
129+
130+
# EPiServer Site file (VPP)
131+
AppData/
132+
133+
# RIA/Silverlight projects
134+
Generated_Code/
135+
136+
# Backup & report files from converting an old project file to a newer
137+
# Visual Studio version. Backup files are not needed, because we have git ;-)
138+
_UpgradeReport_Files/
139+
Backup*/
140+
UpgradeLog*.XML
141+
UpgradeLog*.htm
142+
143+
# vim
144+
*.txt~
145+
*.swp
146+
*.swo
147+
148+
# svn
149+
.svn
150+
151+
# Remainings from resolvings conflicts in Source Control
152+
*.orig
153+
154+
# SQL Server files
155+
**/App_Data/*.mdf
156+
**/App_Data/*.ldf
157+
**/App_Data/*.sdf
158+
159+
160+
#LightSwitch generated files
161+
GeneratedArtifacts/
162+
_Pvt_Extensions/
163+
ModelManifest.xml
164+
165+
# =========================
166+
# Windows detritus
167+
# =========================
168+
169+
# Windows image file caches
170+
Thumbs.db
171+
ehthumbs.db
172+
173+
# Folder config file
174+
Desktop.ini
175+
176+
# Recycle Bin used on file shares
177+
$RECYCLE.BIN/
178+
179+
# Mac desktop service store files
180+
.DS_Store
181+
182+
# SASS Compiler cache
183+
.sass-cache
184+
185+
# Visual Studio 2014 CTP
186+
**/*.sln.ide
187+
188+
# Visual Studio temp something
189+
.vs/
190+
191+
# dotnet stuff
192+
project.lock.json
193+
194+
# VS 2015+
195+
*.vc.vc.opendb
196+
*.vc.db
197+
198+
# Rider
199+
.idea/
200+
201+
# Output folder used by Webpack or other FE stuff
202+
**/node_modules/*
203+
204+
# SpecFlow specific
205+
*.feature.cs
206+
*.feature.xlsx.*
207+
*.Specs_*.html
208+
209+
210+
/SPEC
211+
VCS_Release
212+
/GPMVehicleControlSystem/param/IO_Wago.ini
213+
/GPMVehicleControlSystem/task_name.txt
214+
/GPMVehicleControlSystem/VMS.db
215+
/GPMVehicleControlSystem/uploads
216+
/GPMVehicleControlSystem/cst_read_id.txt
217+
/.editorconfig
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"dotnet-ef": {
6+
"version": "7.0.13",
7+
"commands": [
8+
"dotnet-ef"
9+
]
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/bash
2+
TIME_FROM_SERVER=$(curl -s "http://192.168.0.1:8000")
3+
if [ $? -ne 0 ]; then
4+
echo -e "\033[31mError fetching time from server.\033[0m"
5+
exit 1
6+
fi
7+
sudo date -s "$TIME_FROM_SERVER"
8+
9+
if [ $? -ne 0 ]; then
10+
echo -e "\033[31mError setting system time..\033[0m"
11+
fi
12+
echo -e "\033[38;2;46;139;87mSystem time updated successfully.\033[0m"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@echo off
2+
setlocal enabledelayedexpansion
3+
4+
powershell -Command "$serverDateTime = Invoke-RestMethod 'http://192.168.0.1:8000'; Set-Date -Date $serverDateTime; Write-Output $serverDateTime"
5+
6+
pause
7+
endlocal

SysTimeServer/Log.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2023/10/28 下午 02:20:03 127.0.0.1 call api to get server system time.
2+
2023/10/28 下午 02:20:05 127.0.0.1 call api to get server system time.
3+
2023/10/28 下午 02:20:06 127.0.0.1 call api to get server system time.
4+
2023/10/28 下午 02:20:07 127.0.0.1 call api to get server system time.
5+
2023/10/28 下午 02:20:08 127.0.0.1 call api to get server system time.
6+
2023/10/28 下午 02:20:08 127.0.0.1 call api to get server system time.
7+
2023/10/28 下午 02:20:08 127.0.0.1 call api to get server system time.
8+
2023/10/28 下午 02:20:08 127.0.0.1 call api to get server system time.
9+
2023/10/28 下午 02:20:08 127.0.0.1 call api to get server system time.
10+
2023/10/28 下午 02:20:09 127.0.0.1 call api to get server system time.
11+
2023/10/28 下午 02:20:09 127.0.0.1 call api to get server system time.
12+
2023/10/28 下午 02:20:09 127.0.0.1 call api to get server system time.
13+
2023/10/28 下午 02:20:09 127.0.0.1 call api to get server system time.
14+
2023/10/28 下午 02:20:09 127.0.0.1 call api to get server system time.
15+
2023/10/28 下午 02:20:09 127.0.0.1 call api to get server system time.
16+
2023/10/28 下午 02:20:10 127.0.0.1 call api to get server system time.
17+
2023/10/28 下午 02:34:17 127.0.0.1 call api to get server system time.
18+
Detect same program running...Process-13420 is killed
19+
2023-10-28 14:49:54.3311 [16064] Time Server Start-[16064]

SysTimeServer/Program.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Microsoft.Extensions.Logging.EventLog;
2+
using System.Diagnostics;
3+
4+
var currentProcess = Process.GetCurrentProcess();
5+
var _process_name = currentProcess.ProcessName;
6+
var _process_id = currentProcess.Id;
7+
8+
Log($"Time Server Start-[{_process_id}]");
9+
var porcessList = Process.GetProcessesByName(_process_name);
10+
if (porcessList.Count() > 1)
11+
{
12+
var otherProcess = porcessList.FirstOrDefault(pro => pro.Id != _process_id);
13+
var idOfOtherProcess = otherProcess.Id;
14+
otherProcess.Kill();
15+
Log($"Detect same program running...Process-{idOfOtherProcess} is killed");
16+
}
17+
18+
19+
20+
var builder = WebApplication.CreateBuilder(args);
21+
builder.Services.AddEndpointsApiExplorer();
22+
builder.Services.AddSwaggerGen();
23+
builder.Logging.AddEventLog(new EventLogSettings()
24+
{
25+
SourceName = "SysTimeServer",
26+
LogName = "Application"
27+
});
28+
var app = builder.Build();
29+
30+
if (app.Environment.IsDevelopment())
31+
{
32+
app.UseSwagger();
33+
app.UseSwaggerUI();
34+
}
35+
36+
app.UseHttpsRedirection();
37+
38+
app.MapGet("/", (ILogger<Program> logger, HttpContext context) =>
39+
{
40+
var msg = $"{context.Connection.RemoteIpAddress?.ToString()} call api to get server system time.";
41+
Log(msg);
42+
return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
43+
}).WithName("");
44+
45+
app.Run();
46+
47+
48+
void Log(string msg)
49+
{
50+
using (StreamWriter sw = new StreamWriter($"{Environment.CurrentDirectory}/Log.txt", true))
51+
{
52+
sw.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff")} [{_process_id}] {msg}");
53+
}
54+
Console.WriteLine(msg);
55+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project>
6+
<PropertyGroup>
7+
<DeleteExistingFiles>false</DeleteExistingFiles>
8+
<ExcludeApp_Data>false</ExcludeApp_Data>
9+
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
10+
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
11+
<LastUsedPlatform>Any CPU</LastUsedPlatform>
12+
<PublishProvider>FileSystem</PublishProvider>
13+
<PublishUrl>C:\Users\jinwei\Documents\TimeServer</PublishUrl>
14+
<WebPublishMethod>FileSystem</WebPublishMethod>
15+
<_TargetId>Folder</_TargetId>
16+
<SiteUrlToLaunchAfterPublish />
17+
<TargetFramework>net6.0</TargetFramework>
18+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
19+
<PublishSingleFile>true</PublishSingleFile>
20+
<PublishTrimmed>false</PublishTrimmed>
21+
<ProjectGuid>ce8b1bf9-6c9b-41aa-bbdc-b5e62e162b98</ProjectGuid>
22+
<SelfContained>true</SelfContained>
23+
</PropertyGroup>
24+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:47572",
8+
"sslPort": 44358
9+
}
10+
},
11+
"profiles": {
12+
"WebApplication1": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "http://localhost:8000",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"IIS Express": {
23+
"commandName": "IISExpress",
24+
"launchBrowser": true,
25+
"launchUrl": "swagger",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)