ToolController.cs
4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using Hh.Mes.Common;
using Hh.Mes.Common.Http;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;
using System.Linq;
namespace WebMvc.Areas.Planned.Controllers
{
[Area("Planned")]
public class ToolController : Controller
{
#region postman
public IActionResult Index()
{
return View();
}
[HttpPost]
public string PostMan(HttpItem httpItem)
{
var response = HttpSend(httpItem);
return response;
}
private string HttpSend(HttpItem httpItem)
{
if (string.IsNullOrEmpty(httpItem.URL)) return "{\"error\":\"URL is null\"}";
var method = httpItem.Method;
var item = new HttpItem()
{
URL = httpItem.URL,
Method = method,
Referer = httpItem.Referer
};
if (method.ToUpper() == "POST")
{
if (string.IsNullOrEmpty(httpItem.Postdata)) return "{\"error\":\"The option is post, and the parameter【Postdata】cannot be empty\"}";
item.Postdata = httpItem.Postdata;
item.ContentType = httpItem.ContentType;
}
if (!string.IsNullOrEmpty(httpItem.Referer)) item.Referer = httpItem.Referer;
//设置head信息
if (!string.IsNullOrEmpty(httpItem.HeaderStr))
{
var arr = httpItem.HeaderStr.ToString().Split("&$");
foreach (var value in arr)
{
var temp = value.Split(":");
item.Header.Add(temp[0], temp[1]);
}
}
var http = new HttpHelper();
var result = http.GetHtml(item);
return result.Html;
}
#endregion
#region josn美化
public IActionResult JosnIndex()
{
return View();
}
#endregion
#region 系统监控
public IActionResult Monitor()
{
return View();
}
[HttpGet]
public IActionResult GetSystemInfo()
{
try
{
var allDirves = ComputerHelp.GetDriveInfos();
var driveInfos = allDirves.Select(x => new
{
dirName = x.Name,
sysTypeName = x.DriveFormat,
free = (x.TotalFreeSpace / 1024 / 1024 / 1024).ToString("N1") + "G",
total = (x.TotalSize / 1024 / 1024 / 1024).ToString("N1") + "G",
used = ((x.TotalSize - x.TotalFreeSpace) / 1024 / 1024 / 1024).ToString("N1") + "G",
usage = ((x.TotalSize - x.TotalFreeSpace) * 100 / x.TotalSize).ToString("N1") + "%"
}).ToList();
var memery = ComputerHelp.GetMemery();
var os = ComputerHelp.GetOSInfo();
var cpuInfo = ComputerHelp.GetCPUInfo();
var timeSpan = DateTime.Now - SystemVariable.StartTime;
var result = new
{
cpu = new
{
name = string.Join("|", cpuInfo.Where(x => x.Key.StartsWith("Name")).Select(x => x.Value).ToArray()),
supper = string.Join("|", cpuInfo.Where(x => x.Key.StartsWith("Manufacturer")).Select(x => x.Value).ToArray()),
num = string.Join("|", cpuInfo.Where(x => x.Key.StartsWith("ThreadCount")).Select(x => x.Value).ToArray()),
used = ComputerHelp.GetCpuUsage(),
},
mem = new
{
total = memery.Item1,
free = memery.Item2,
sys = memery.Item3,
used = memery.Item4,
},
sys = new
{
name = ComputerHelp.GetComputerName(),
startTime = SystemVariable.StartTime.ToString(),
runTime = $"{timeSpan.Days}天{timeSpan.Hours}时{timeSpan.Minutes}分{timeSpan.Seconds}秒",
path = Directory.GetCurrentDirectory(),
caption = os["Caption"],
osArchitecture = os["OSArchitecture"],
ip = ComputerHelp.GetAddressIP(),
},
sysFiles = driveInfos
};
return Ok(result);
}
catch (Exception ex)
{
Log4NetHelper.Instance.Error($"获取系统信息失败,{ex}");
return BadRequest(ex);
}
}
#endregion
}
}