日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BeetleX进程服务管理组件应用

發布時間:2023/12/4 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BeetleX进程服务管理组件应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

????????有些時候需要在程序中啟動和管理其他應用進程,當碰到這樣的需求的時候可以通過Process對象來完成;為了讓使用和管理更方便在這基礎上封裝 了BeetleX.ServicesProcess組件,通過組件的管理中心讓進程操作更方便,同時還集成了Web套件可直接集成在BeetleX.FastHttpApi中進行Web管理。

??????? BeetleX.ServicesProcess組件提供了ProcessCenter對象來添加,管理,啟動和停止等進程管理功能。具體功能方法如下:

public class ProcessCenter : IDisposable{public ProcessCenter();public?ProcessCenter(ILogHandler?logHandler);public?ServiceManagementConfig?Config?{?get;?}public void Add(string name, string file, string path, string args, bool autoStartup = false);public void Add(ProcessInfo info);public void AutoStartup();public void ChangeUser(string admin, string pwd);public void Delete(string id);public void Dispose();public ServiceProcess GetProcess(string id);public void Modify(string id, ProcessInfo info);public void Start(string id);public void StartAll();public void Stop(string id);public void StopAll();}

以上是組件封裝的方法,使用起來非常簡單。

????????接下來主要介紹如何在BeetleX.FastHttpApi中集成它的web管理功能;創建一個控制臺項目,引用BeetleX.WebFamily組件;引用后編寫以下代碼:

class Program{static void Main(string[] args){WebHost host = new WebHost();host.IsWindowsServices = true;WebHost.Title = "Service Management";WebHost.HeaderModel = "beetlex-process-header";WebHost.HomeModel = "beetlex-process-home";WebHost.TabsEnabled = false;host.RegisterComponent<Program>();host.RegisterComponent<BeetleX.ServicesProcess.ProcessCenter>();host.UseFontawesome();host.UseElement(PageStyle.Element);host.Setting(o =>{o.SetDebug();o.Port = 80;o.LogLevel = LogType.Info;});host.Initialize((http, vue, rec) =>{BeetleX.ServicesProcess.WebController controller = new BeetleX.ServicesProcess.WebController();controller.Init(new logHandler(http));http.ActionFactory.Register(controller, new BeetleX.FastHttpApi.ControllerAttribute { BaseUrl = "process" });rec.AddCss("website.css");vue.Debug();});host.Run();}}class logHandler : BeetleX.ServicesProcess.ILogHandler{public logHandler(BeetleX.FastHttpApi.HttpApiServer sever){mServer = sever;}private BeetleX.FastHttpApi.HttpApiServer mServer;public void Error(string message){mServer.GetLog(LogType.Error)?.Log(LogType.Error, null, message);}public void Info(string message){mServer.GetLog(LogType.Info)?.Log(LogType.Info, null, message);}}

啟動項目后可以查看啟動日志

接下來就可以通過瀏覽器訪問進程管理頁面

如果有需要還可以把當前示例項目發布成windows service

發布后即可以使用sc命令來創建、啟動、停止和刪除服務。

完整示例代碼

https://github.com/beetlex-io/BeetleX-Samples/tree/master/Web.ServiceManagement

總結

以上是生活随笔為你收集整理的BeetleX进程服务管理组件应用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。