1 Commits

Author SHA1 Message Date
Din VM e19e1e0137 Add API endpoint to kill process and update README 2025-01-25 12:58:13 +08:00
24 changed files with 86 additions and 24 deletions
+6 -1
View File
@@ -4,4 +4,9 @@ dotnet run
git add .
git commit -m "Add steam running games"
git push origin master
dotnet publish -c Release -o ./publish
dotnet publish -c Release -o ./publish
curl -X POST "http://<your-service-hostname-or-IP>:<port>/api/kill-process?id=<PID>"
+45
View File
@@ -50,11 +50,56 @@ namespace ResourceMonitorService
await context.Response.WriteAsync(json);
});
app.MapPost("/api/kill-process", async context =>
{
await Results.Ok($"Macam celaka Process ni. ").ExecuteAsync(context);
/* try
{
int pid;
if (!int.TryParse(context.Request.Query["id"], out pid))
{
await Results.BadRequest("Invalid process ID.").ExecuteAsync(context);
return;
}
var result = await KillProcessByIdAsync(pid); // Ensure KillProcessByIdAsync returns a Task<bool>
if (result)
{
await Results.Ok($"Process with PID {pid} has been terminated successfully.").ExecuteAsync(context);
}
else
{
await Results.NotFound($"No process found with PID {pid}.").ExecuteAsync(context);
}
}
catch (Exception ex)
{
// Log the exception or handle it as needed
await Results.Problem(ex.Message).ExecuteAsync(context);
} */
});
app.RunAsync(stoppingToken);
await Task.Delay(Timeout.Infinite, stoppingToken);
}
private async Task<bool> KillProcessByIdAsync(int pid)
{
using (Process process = Process.GetProcessById(pid))
{
if (process != null)
{
await Task.Run(() => process.Kill());
return true;
}
else
{
return false;
}
}
}
private object GetComputerInfo()
{
return new
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,7 +9,7 @@
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
"Url": "http://*:5000"
}
}
}
@@ -9,7 +9,7 @@
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
"Url": "http://*:5000"
}
}
}
@@ -9,7 +9,7 @@
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
"Url": "http://*:5000"
}
}
}
@@ -9,7 +9,7 @@
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:5000"
"Url": "http://localhost:5000"
}
}
}
@@ -9,7 +9,7 @@
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:5000"
"Url": "http://localhost:5000"
}
}
}
@@ -9,7 +9,7 @@
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:5000"
"Url": "http://localhost:5000"
}
}
}
@@ -8,7 +8,7 @@ build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = ResourceMonitorService
build_property.ProjectDir = C:\din\dev\ResourceUsageAPI\
build_property.ProjectDir = D:\din\dev\vmsvc\ResourceMonitorService\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.EffectiveAnalysisLevelStyle = 9.0
Binary file not shown.
@@ -62,3 +62,15 @@ D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.Development.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\appsettings.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.deps.json
D:\din\dev\vmsvc\ResourceMonitorService\bin\Debug\net9.0\publish\publish\publish\publish\publish\publish\publish\publish\publish\ResourceMonitorService.runtimeconfig.json
Binary file not shown.
@@ -1 +1 @@
c65d161a800b1338fd7f033a5bc5016a31718066a3178665c8d03d56bd044a0a
3c41a5e0f936ad1402ac65b413d5b378ce34a9573acfd72fc7ebde791d66f502
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,17 +1,17 @@
{
"format": 1,
"restore": {
"C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj": {}
"D:\\din\\dev\\vmsvc\\ResourceMonitorService\\ResourceMonitorService.csproj": {}
},
"projects": {
"C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj": {
"D:\\din\\dev\\vmsvc\\ResourceMonitorService\\ResourceMonitorService.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"projectUniqueName": "D:\\din\\dev\\vmsvc\\ResourceMonitorService\\ResourceMonitorService.csproj",
"projectName": "ResourceMonitorService",
"projectPath": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"projectPath": "D:\\din\\dev\\vmsvc\\ResourceMonitorService\\ResourceMonitorService.csproj",
"packagesPath": "C:\\Users\\dinxs\\.nuget\\packages\\",
"outputPath": "C:\\din\\dev\\ResourceUsageAPI\\obj\\",
"outputPath": "D:\\din\\dev\\vmsvc\\ResourceMonitorService\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\dinxs\\AppData\\Roaming\\NuGet\\NuGet.Config"
@@ -36,7 +36,7 @@
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
"auditMode": "all"
},
"SdkAnalysisLevel": "9.0.100"
},
@@ -81,7 +81,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.101/PortableRuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.100/PortableRuntimeIdentifierGraph.json"
}
}
}
@@ -7,7 +7,7 @@
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\dinxs\.nuget\packages\</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.2</NuGetToolVersion>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.12.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\dinxs\.nuget\packages\" />
+5 -5
View File
@@ -2087,11 +2087,11 @@
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"projectUniqueName": "D:\\din\\dev\\vmsvc\\ResourceMonitorService\\ResourceMonitorService.csproj",
"projectName": "ResourceMonitorService",
"projectPath": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"projectPath": "D:\\din\\dev\\vmsvc\\ResourceMonitorService\\ResourceMonitorService.csproj",
"packagesPath": "C:\\Users\\dinxs\\.nuget\\packages\\",
"outputPath": "C:\\din\\dev\\ResourceUsageAPI\\obj\\",
"outputPath": "D:\\din\\dev\\vmsvc\\ResourceMonitorService\\obj\\",
"projectStyle": "PackageReference",
"configFilePaths": [
"C:\\Users\\dinxs\\AppData\\Roaming\\NuGet\\NuGet.Config"
@@ -2116,7 +2116,7 @@
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
"auditMode": "all"
},
"SdkAnalysisLevel": "9.0.100"
},
@@ -2161,7 +2161,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.101/PortableRuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.100/PortableRuntimeIdentifierGraph.json"
}
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
{
"version": 2,
"dgSpecHash": "c9QUeYvHFTQ=",
"dgSpecHash": "pmjCqcyUh78=",
"success": true,
"projectFilePath": "C:\\din\\dev\\ResourceUsageAPI\\ResourceMonitorService.csproj",
"projectFilePath": "D:\\din\\dev\\vmsvc\\ResourceMonitorService\\ResourceMonitorService.csproj",
"expectedPackageFiles": [
"C:\\Users\\dinxs\\.nuget\\packages\\microsoft.aspnetcore.jsonpatch\\9.0.0\\microsoft.aspnetcore.jsonpatch.9.0.0.nupkg.sha512",
"C:\\Users\\dinxs\\.nuget\\packages\\microsoft.aspnetcore.mvc.newtonsoftjson\\9.0.0\\microsoft.aspnetcore.mvc.newtonsoftjson.9.0.0.nupkg.sha512",