初始化
This commit is contained in:
205
Face.Web/Areas/App/Controllers/HomeController.cs
Normal file
205
Face.Web/Areas/App/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
using AUTS.Services.Manager;
|
||||
using Face.Domain.Entities;
|
||||
using Face.Domain.ViewModels;
|
||||
using Face.Services.Cache;
|
||||
using Face.Services.DBUtility.Common;
|
||||
using Face.Web.Areas.App.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.Remoting.Lifetime;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Face.Web.Areas.App.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
// GET: App/Home
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.errorcout = GetErrorcount();
|
||||
|
||||
return View();
|
||||
}
|
||||
public ActionResult SetCustomerID(int customerID)
|
||||
{
|
||||
//返回实体
|
||||
ReturnResult result = new ReturnResult();
|
||||
|
||||
#region 变更缓存
|
||||
//System.Web.HttpContext.Current.Session[onUserOperationSessionName] = customerID;
|
||||
|
||||
//CacheHelp.GetUserOperation(Umodel.UserName, customerID);
|
||||
|
||||
#endregion
|
||||
|
||||
result.Status = 200;
|
||||
result.Message = "变更数据库成功";
|
||||
return Json(result);
|
||||
}
|
||||
|
||||
public int GetErrorcount()
|
||||
{
|
||||
List<errormessagehandling> pmsinfo = SqlSugarBase.Db.Queryable<errormessagehandling>().ToList();
|
||||
|
||||
return pmsinfo.Count();
|
||||
}
|
||||
[HttpPost]
|
||||
public ActionResult closeProcess(Condition data)
|
||||
{
|
||||
//LogHelp.WriteExceptionLog("");
|
||||
Logs.WriteLog("重启服务");
|
||||
string art = process.GetProcessKill();
|
||||
return Json("closeProcess");
|
||||
}
|
||||
[HttpPost]
|
||||
public ActionResult openProcess(Condition data)
|
||||
{
|
||||
process.GetProcess();
|
||||
return Json("openProcess");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
public static class process
|
||||
{
|
||||
//开启进程方法
|
||||
public static string GetProcess()
|
||||
{
|
||||
//找到所有进程
|
||||
Process[] ps = Process.GetProcesses();
|
||||
DataTable ProcessTable = new DataTable();
|
||||
ProcessTable.Columns.Add("Name", typeof(string));
|
||||
ProcessTable.Columns.Add("Start Time", typeof(DateTime));
|
||||
ProcessTable.Columns.Add("CPU %", typeof(TimeSpan));
|
||||
ProcessTable.Columns.Add("Threads", typeof(string));
|
||||
ProcessTable.Columns.Add("Session ID", typeof(int));
|
||||
ProcessTable.Columns.Add("Unique ID", typeof(int));
|
||||
ProcessTable.Columns.Add("RAM", typeof(float));
|
||||
ProcessTable.Columns.Add("Machine", typeof(string));
|
||||
ProcessTable.Columns.Add("Priority", typeof(int));
|
||||
foreach (Process Process in ps)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
//找到具有指定名称的进程
|
||||
// 换成你的exe名字 去掉exe
|
||||
if (!Process.ProcessName.ToUpper().Contains("TESTWEBSOCKET"))
|
||||
continue;
|
||||
string pName = Process.ProcessName;
|
||||
DateTime pStartTime = Process.StartTime;
|
||||
TimeSpan pProcTime = Process.TotalProcessorTime;
|
||||
string pThreads = Process.Threads.ToString();
|
||||
int pSessionId = Process.SessionId;
|
||||
int pId = Process.Id;
|
||||
long pRam = Process.VirtualMemorySize64;
|
||||
string pMachineName = Process.MachineName;
|
||||
int pPriority = Process.BasePriority;
|
||||
//杀死进程
|
||||
Process.Kill();
|
||||
ProcessTable.Rows.Add(pName
|
||||
, pStartTime
|
||||
, pProcTime
|
||||
, pThreads
|
||||
, pSessionId
|
||||
, pId
|
||||
, pRam
|
||||
, pMachineName
|
||||
, pPriority);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
// 换成你的exe路径
|
||||
//Process.Start(@"C:\FaceConsole\bin6\Release\TestWebSocket.exe");
|
||||
Process.Start(@"D:\NewGitRepos\TestWebSocket\TestWebSocket\bin\Release\TestWebSocket.exe");
|
||||
return JsonConvert.SerializeObject(ProcessTable);
|
||||
}
|
||||
/// <summary>
|
||||
/// 关闭进程
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetProcessKill()
|
||||
{
|
||||
try
|
||||
{
|
||||
//找到所有进程
|
||||
Process[] ps = Process.GetProcesses();
|
||||
DataTable ProcessTable = new DataTable();
|
||||
ProcessTable.Columns.Add("Name", typeof(string));
|
||||
ProcessTable.Columns.Add("Start Time", typeof(DateTime));
|
||||
ProcessTable.Columns.Add("CPU %", typeof(TimeSpan));
|
||||
ProcessTable.Columns.Add("Threads", typeof(string));
|
||||
ProcessTable.Columns.Add("Session ID", typeof(int));
|
||||
ProcessTable.Columns.Add("Unique ID", typeof(int));
|
||||
ProcessTable.Columns.Add("RAM", typeof(float));
|
||||
ProcessTable.Columns.Add("Machine", typeof(string));
|
||||
ProcessTable.Columns.Add("Priority", typeof(int));
|
||||
foreach (Process Process in ps)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
//找到具有指定名称的进程
|
||||
// 换成你的exe名字 去掉exe
|
||||
if (!Process.ProcessName.ToUpper().Contains("FACESTEST"))
|
||||
continue;
|
||||
string pName = Process.ProcessName;
|
||||
DateTime pStartTime = Process.StartTime;
|
||||
TimeSpan pProcTime = Process.TotalProcessorTime;
|
||||
string pThreads = Process.Threads.ToString();
|
||||
int pSessionId = Process.SessionId;
|
||||
int pId = Process.Id;
|
||||
long pRam = Process.VirtualMemorySize64;
|
||||
string pMachineName = Process.MachineName;
|
||||
int pPriority = Process.BasePriority;
|
||||
//杀死进程
|
||||
Process.Kill();
|
||||
ProcessTable.Rows.Add(pName
|
||||
, pStartTime
|
||||
, pProcTime
|
||||
, pThreads
|
||||
, pSessionId
|
||||
, pId
|
||||
, pRam
|
||||
, pMachineName
|
||||
, pPriority);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logs.WriteLog("重启服务错误" + e);
|
||||
}
|
||||
}
|
||||
// 换成你的exe路径
|
||||
|
||||
Process.Start(@"C:\FaceTest\bin\Release\FacesTest.exe");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logs.WriteLog(e.ToString());
|
||||
}
|
||||
|
||||
|
||||
return JsonConvert.SerializeObject("ok");
|
||||
}
|
||||
|
||||
//Process.Start(@"D:\NewGitRepos\TestWebSocket\TestWebSocket\bin\Release\TestWebSocket.exe");
|
||||
}
|
||||
Reference in New Issue
Block a user