国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

NancyFx框架檢測(cè)任務(wù)管理器詳解

2020-01-24 00:26:34
字體:
供稿:網(wǎng)友

本文為大家分享了NancyFx框架檢測(cè)任務(wù)管理器的具體方法,供大家參考,具體內(nèi)容如下

先建一個(gè)空的項(xiàng)目和之前的NancyFx系列一樣的步驟

然后建三個(gè)文件夾Models,Module,Views

然后分別安裝一下組件

jQuery

Microsoft.AspNet.SignalR

Microsoft.Owin

Nancy

Nancy.Owin

然后往Model類里面添加CPUHub類,Broadcaster類

CPUHub類

public class CPUHub:Hub  {    private readonly Broadcaster broadcaster;    public CPUHub():this(Broadcaster.broadcaster)    {    }    public CPUHub(Broadcaster broadcaster)    {      this.broadcaster = broadcaster;    }  }

Broadcaster類

public class Broadcaster  {    private readonly static Lazy<Broadcaster> lazy = new Lazy<Broadcaster>(()=>new Broadcaster(GlobalHost.ConnectionManager.GetHubContext<CPUHub>().Clients));    private readonly TimeSpan timeSpan = TimeSpan.FromMilliseconds(1000);    private readonly Timer timer;    public static Broadcaster broadcaster    {      get { return lazy.Value; }    }    private IHubConnectionContext hubConnectionContext    {      get;      set;    }    private Broadcaster(IHubConnectionContext hubConnectionContexts)    {      hubConnectionContext = hubConnectionContexts;      timer = new Timer(BroadcastCpuUsage,null,timeSpan,timeSpan);    }    private void BroadcastCpuUsage(object o)    {      string cpu = GetCurrentCpu();    }    private string GetCurrentCpu()    {      string currentCpu = "";      HttpClient httpClient = new HttpClient();      httpClient.BaseAddress = new Uri("http://localhost:3039");      var response = httpClient.GetAsync("api/cpu").Result;      if (response.IsSuccessStatusCode)      {        currentCpu = response.Content.ReadAsStringAsync().Result;      }      return currentCpu;    }  }

然后在往Module里面添加CPUModule類

public class CPUModule:NancyModule  {    PerformanceCounter performanceCounter;    public CPUModule():base("api/cpu")    {      InitializePerformanceCounter();      Get("/",Lexan=>       {        int cpu = (int)Math.Ceiling(performanceCounter.NextValue());        return Response.AsText(cpu.ToString());      });    }    private void InitializePerformanceCounter()    {      performanceCounter = new PerformanceCounter();      performanceCounter.CategoryName = "";      performanceCounter.CounterName = "";      performanceCounter.InstanceName = "";      performanceCounter.NextValue();      Thread.Sleep(1000);    }  }

然后添加index.html頁面在根目錄下

<!DOCTYPE html><html><head>  <title>NancyTaskManager</title></head><body>  <label id="lblVal"></label>  <br />  <canvas id="cvPercentage"></canvas>  <br />  <br />  <canvas id="cvGraph" height="450" width="600"></canvas>  <script src="Scripts/jquery-2.1.0.js"></script>  <script src="Scripts/jquery.signalR-2.0.2.js"></script>  <script src="Scripts/Chart.js"></script>  <script src="/signalr/hubs"></script>  <script src="Scripts/taskManager.js"></script></body></html>

繼續(xù)往根目錄里面添加Startup類

[assembly:OwinStartup(typeof( NancyFxTaskManager.Startup))]namespace NancyFxTaskManager{  public class Startup  {    public void Configuration(IAppBuilder app)    {      app.MapSignalR().UseNancy();          }  }}

好了我們準(zhǔn)備就緒,看看運(yùn)行效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大英县| 宜宾县| 潼南县| 越西县| 喀喇| 富蕴县| 高淳县| 成安县| 六枝特区| 寿宁县| 玛纳斯县| 兴安县| 固原市| 洛川县| 芦山县| 衢州市| 永年县| 高唐县| 灵石县| 朝阳区| 米易县| 张家港市| 景谷| 祁连县| 镇江市| 桃江县| 西安市| 石柱| 翼城县| 综艺| 敖汉旗| 盈江县| 岳池县| 武定县| 河南省| 吉木萨尔县| 莱阳市| 岑巩县| 肃北| 南木林县| 咸阳市|