-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmachinesping.ashx
55 lines (51 loc) · 1.18 KB
/
machinesping.ashx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<%@ WebHandler Language="C#" Class="machinesping" %>
using System;
using System.Collections.Generic;
using System.Web;
using System.Threading.Tasks;
using System.Net.NetworkInformation;
public class machinesping : IHttpHandler
{
object _lockobject = new object();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/event-stream";
context.Response.CacheControl = "no-cache";
context.Response.Flush();
List<Machine> mls = MachineFactory.Enum();
while (context.Response.IsClientConnected)
{
Parallel.ForEach(mls, (machine) =>
{
Ping ping = new Ping();
IPStatus status = IPStatus.Unknown;
try
{
status = ping.Send(machine.PCNAME).Status;
}
catch (Exception /*e*/)
{
}
lock (_lockobject)
{
try
{
context.Response.Write(string.Format("event: machine\ndata: {0}\n\n", machine.PCNAME + "-" + status.ToString()));
context.Response.Flush();
}
catch (Exception /*e*/) //connection is closed
{
}
}
});
System.Threading.Thread.Sleep(10000);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}