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

首頁 > 開發 > 綜合 > 正文

Online CPU Console using a Web Control Library wit

2024-07-21 02:28:06
字體:
來源:轉載
供稿:網友
國內最大的酷站演示中心!
wroxcontrollib
step one is to set up a web control library. open visual studio .net and choose a web control library project. add three new custom web controls to the project named evenlog.cs, process.cs, and services.cs. add system.serviceprocess as a reference to the project by right-clicking references in the solutions explorer.
eventlog.cs
events are accessed through the system.diagnostics assembly. use this assembly by making a reference at the top of your class.
write to the event log by calling eventlog.writeentry(). the writeentry() method provides many parameters such as the type of event (info, error, etc.), the source of the event (our assembly), and the message of the event.
read from the event log by calling eventlog().entries to obtain the collection of events from the specified machine. this method may be called with parameters such as log type (application, system, security), and machine name.
the code below requests the collection of events and loops through them with a for statement. notice how the collection is called with a machine and log type, that is set by the client application. the collection returns the earliest event first by default; the log must be turned around to view the newest event first. reverse the order by iterating through the collection backwards. print the content out to the client application using the htmltextwriter. htmltextwriter is the default parameter passed into a custom control. let's take a look at the code for eventlog.cs:
using system;
using system.web.ui;
using system.web.ui.webcontrols;
using system.componentmodel;
using system.diagnostics;          //add this reference
public class eventlog : system.web.ui.webcontrols.webcontrol
{
   private string logtype      = "application";
   private string machine      = "";

   //machine is a property that is set by the client
   public string machine
   {
      get
      {
         return machine;
      }

      set
      {
         machine = value;
      }
   }

   protected override void render(htmltextwriter doc)
   {      
      //call the collection of events
      eventlogentrycollection objeventcol = new eventlog(logtype,machine).entries;

      //loop through the collection of events
      for(int icount<objeventcol.count;icount=objeventcol.count; icount>=0; icount++)
      {

         //write to the document
         doc.write(objeventcol.entrytype.tostring() + " - ");
         doc.write(objeventcol[i].source + "<br>");
         doc.write(objeventcol[i].message + "<p>");
      }
   }
}
process.cs
processes may be viewed and stopped using the system.diagnostics assembly. after referencing the assembly at the top of the class file, call process.getprocesses() to retrieve the collection of running processes. specify which machine these processes are viewed from by setting the machine name parameter.
processes can be completely stopped by calling the kill() method. a reference to each thread that a process is running can also be obtained. users can also be allowed to stop specific threads as an alternative to stopping the entire process, but this is an option to use with caution as the user may not be completely familiar with all the internal workings of that application.
the code below requests the collection of processes and loops through them with a foreach statement. notice how the collection is called by a machine that is set by the client application. the contents are then printed out to the client application using the htmltextwriter. let's take a look at the code for process.cs:
using system;
using system.web.ui;
using system.web.ui.webcontrols;
using system.componentmodel;
using system.diagnostics;          //add this reference
public class process : system.web.ui.webcontrols.webcontrol
{
   private string machine      = "";
   private string stopprocess      = "";

   //machine is a property that is set by the client
   public string machine
   {
      get
      {
         return machine;
      }

      set
      {
         machine = value;
      }
   }

   protected override void render(htmltextwriter doc)
   {      
      //loop through the collection of processes
      foreach(process objp in process.getprocesses(machine))
      {
         //write to the document
         doc.write(objp.processname + " - ");
         doc.write(objp.threads.count.tostring() + " - ");
         doc.write(objp.totalprocessortime.tostring() + "<br>");
      }
   }
}
notice in the code that the kill() method is called to completely stop a process while looping through the collection.
foreach(process objp in process.getprocesses(machine))
{
   if(objp.processname.trim() == stopprocess.trim())
   {
      //stops the process
      objp.kill();
   }
}
service.cs
services can be viewed, stopped, started, paused, and resumed using the system.serviceprocess assembly. reference the assembly at the top of the class file and call servicecontroller.getservices() to receive a collection of the services installed on any given machine.
services may be started by calling the start() method, and stopped by calling the stop() method.
in the code below, we request the collection of services, and loop through them with a foreach statement. notice how the collection is called with a machine that is set by the client application. we print the content out to the client application using the htmltextwriter. let's take a look at the code for service.cs:
using system;
using system.web.ui;
using system.web.ui.webcontrols;
using system.componentmodel;
using system.serviceprocess;      //add this reference

public class services : system.web.ui.webcontrols.webcontrol
{
   private string machine      = "";
   private string stopservice      = "";
   private string startservice   = "";

   //machine is a property that is set by the client
   public string machine
   {
      get
      {
         return machine;
      }

      set
      {
         machine = value;
      }
   }

   protected override void render(htmltextwriter doc)
   {      
      //loop through the collection of services
      foreach(servicecontroller objsp in servicecontroller.getservices(machine))
      {
      //write to the document
         doc.write(objsp.displayname + " - ");
         doc.write(objsp.status.tostring() + " - ");
         doc.write(objsp.servicetype.tostring() + "<br>");
      }
   }
}
note that the stop() method is called to stop a service, and the start() method is called to start a service while looping through the collection.
foreach(servicecontroller objsp in servicecontroller.getservices(machine))
{
   if(objsp.displayname.trim() == stopservice.trim())
   {
      //stop a service
      objsp.stop();
   }

   if(objsp.displayname.trim() == startservice.trim())
   {
      /start a service
      objsp.start();
   }
}
wroxcpuconsole
now that our web control library is finished, we continue by building the web interface for this application. open visual studio and choose an [i]asp.net web application
project. add the following three forms: vw_eventlog.aspx, vw_process.aspx, and vw_service.aspx.
note that the .aspx files call a register tag at the top of the document, containing the namespace, assembly name, and tag prefix of the wroxcpucontrol.dll.
vw_eventlo


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 板桥市| 彰武县| 湟源县| 嘉定区| 尼木县| 侯马市| 大关县| 正安县| 成武县| 鄂托克前旗| 肥城市| 常宁市| 迁西县| 榆林市| 峨眉山市| 延庆县| 辛集市| 托克逊县| 息烽县| 乌兰察布市| 大同市| 镇康县| 京山县| 红桥区| 连云港市| 泽普县| 怀宁县| 乌兰县| 塔河县| 肇东市| 临泉县| 出国| 富裕县| 双城市| 广河县| 普宁市| 旬阳县| 璧山县| 中超| 罗城| 辽中县|