-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProcessControl.cs
72 lines (65 loc) · 2.21 KB
/
ProcessControl.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
namespace pctesting
{
class ProcessControl
{
List<Process> processLastIteration=new List<Process>();
List<DateTime> startTime=new List<DateTime>();
DBService.DataServiceClient client = new DBService.DataServiceClient();
string comp;
string user;
public ProcessControl(string user, string comp)
{
this.comp = comp;
this.user = user;
processLastIteration = Process.GetProcesses().ToList();
for (int i = 0; i < processLastIteration.Count; i++)
{
try
{
startTime.Add(processLastIteration[i].StartTime);
}
catch (Exception e)
{
processLastIteration.Remove(processLastIteration[i]);
i--;
}
}
}
public void UpdateProcess()
{
Process[] proc = Process.GetProcesses();
for (int i = 0; i < processLastIteration.Count;i++ )
{
if (!processLastIteration.Exists(lp => lp.Id == processLastIteration[i].Id))
{
client.SaveProcessesToDB(processLastIteration[i].ProcessName, startTime[i], DateTime.Now, DateTime.Now - processLastIteration[i].StartTime, comp, user);
}
}
startTime.Clear();
processLastIteration = proc.ToList();
for(int i=0;i<processLastIteration.Count;i++)
{
try
{
startTime.Add(processLastIteration[i].StartTime);
}
catch(Exception e)
{
processLastIteration.Remove(processLastIteration[i]);
i--;
}
}
}
public void SaveToDatabase()
{
for (int i = 0; i < processLastIteration.Count; i++)
{
client.SaveProcessesToDB(processLastIteration[i].ProcessName, startTime[i], DateTime.Now, DateTime.Now - startTime[i], comp, user);
}
}
}
}