Esempio n. 1
0
        public async Task EchoLoop()
        {
            var buffer = new byte[BufferSize];
            var seg    = new ArraySegment <byte>(buffer);

            while (Socket.State == WebSocketState.Open)
            {
                var incoming = await Socket.ReceiveAsync(seg, CancellationToken.None);

                string receivemsg = Encoding.UTF8.GetString(buffer, 0, incoming.Count);
                if (receivemsg == "getComputerInfo")
                {
                    var hardDiskName = _options.Value.HardDiskPartition;
                    var computerInfo = new ComputerInfoModel
                    {
                        HardDiskSpace       = ComputerInfoHelper.GetHardDiskSpace(hardDiskName),
                        HardDiskUseageSpace = ComputerInfoHelper.GetHardDiskUseSpace(hardDiskName),
                        HardDiskUsageRate   = ComputerInfoHelper.GetHardDiskUsageRate(hardDiskName),
                        CpuUsageRate        = ComputerInfoHelper.GetCpuUsageRate(),
                        MemoryUsageRate     = ComputerInfoHelper.GetMemoryUsageRate(),
                    };
                    var    stringJson = JsonConvert.SerializeObject(computerInfo);
                    string userMsg    = stringJson;
                    byte[] x          = Encoding.UTF8.GetBytes(userMsg);
                    var    outgoing   = new ArraySegment <byte>(x);
                    await this.Socket.SendAsync(outgoing, WebSocketMessageType.Text, true, CancellationToken.None);
                }
            }
        }
Esempio n. 2
0
 public IActionResult HardDIskWarning()
 {
     ViewBag.HardDiskSpace       = ComputerInfoHelper.GetHardDiskSpace("D");
     ViewBag.HardDiskUseageSpace = ComputerInfoHelper.GetHardDiskUseSpace("D");
     ViewBag.HardDiskUsageRate   = ComputerInfoHelper.GetHardDiskUsageRate("D");
     ViewBag.CpuUsageRate        = ComputerInfoHelper.GetCpuUsageRate();
     ViewBag.MemoryUsageRate     = ComputerInfoHelper.GetMemoryUsageRate();
     return(PartialView("_ComputerInfoComponent"));
 }