-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathAPI.cs
More file actions
137 lines (114 loc) · 4.92 KB
/
API.cs
File metadata and controls
137 lines (114 loc) · 4.92 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using StackifyLib.Utils;
namespace StackifyLib
{
public class API
{
private static Utils.HttpClient client;
static API()
{
client = new HttpClient(null, null);
}
public static Models.Device[] GetDeviceList()
{
var response = client.SendJsonAndGetResponse((client.BaseAPIUrl) +
"API/Device/GetAll",
null);
if (response.StatusCode == HttpStatusCode.OK)
{
return JsonConvert.DeserializeObject<Models.Device[]>(response.ResponseText);
}
else
{
return null;
}
}
public static bool SetServerEnvironmentForThisDevice(string environmentName)
{
var deviceid = Logger.Identity()?.DeviceID;
if(deviceid == null)
throw new Exception("Unable to evaluate current device id");
return SetServerEnvironmentByID(deviceid.Value, environmentName);
}
public static bool SetServerEnvironmentByID(int id, string environmentName)
{
var response = client.POSTAndGetResponse((client.BaseAPIUrl) +
"API/Device/SetServerEnvironmentByID/?id=" + id + "&environmentName=" + environmentName, null);
return response.StatusCode == HttpStatusCode.OK;
}
public static bool RemoveServerByID(int id, bool uninstallAgent = false)
{
var response = client.POSTAndGetResponse((client.BaseAPIUrl) +
"API/Device/RemoveServerByID/?id=" + id + "&uninstallAgent=" + uninstallAgent, null);
return response.StatusCode == HttpStatusCode.OK;
}
public static bool RemoveServerByName(string name, bool uninstallAgent = false)
{
var response = client.POSTAndGetResponse((client.BaseAPIUrl) +
"API/Device/RemoveServerByName/?name=" + name + "&uninstallAgent=" + uninstallAgent,
null);
return response.StatusCode == HttpStatusCode.OK;
}
public static bool UninstallAgentByID(int id)
{
var response = client.POSTAndGetResponse((client.BaseAPIUrl) +
"API/Device/UninstallAgentByID/?id=" + id,
null);
return response.StatusCode == HttpStatusCode.OK;
}
public static bool UninstallAgentByName(string name)
{
var response = client.POSTAndGetResponse((client.BaseAPIUrl) +
"API/Device/UninstallAgentByName/?name=" + name,
null);
return response.StatusCode == HttpStatusCode.OK;
}
public static bool? ConfigureAlerts(Dictionary<int, string> devices)
{
var response = client.SendJsonAndGetResponse((client.BaseAPIUrl) +
"API/Device/ConfigureAlerts",
JsonConvert.SerializeObject(devices));
if (response.StatusCode == HttpStatusCode.OK)
{
return JsonConvert.DeserializeObject<bool>(response.ResponseText);
}
else
{
return null;
}
}
public static Models.Monitor[] GetDeviceMonitors(int clientDeviceId)
{
var response = client.SendJsonAndGetResponse((client.BaseAPIUrl) +
"API/Device/Monitors/" + clientDeviceId.ToString(),
null);
if (response.StatusCode == HttpStatusCode.OK)
{
return JsonConvert.DeserializeObject<Models.Monitor[]>(response.ResponseText);
}
else
{
return null;
}
}
public static Models.MonitorMetric GetMetrics(int monitorID, DateTimeOffset startDateUtc, DateTimeOffset endDateUtc, short pointSizeInMinutes = 5)
{
var response = client.SendJsonAndGetResponse((client.BaseAPIUrl) +
"API/Device/MonitorMetrics/" + string.Format("?monitorID={0}&startDateUtc={1}&endDateUtc={2}&pointSizeInMinutes={3}", monitorID, startDateUtc.UtcDateTime.ToString("o"), endDateUtc.UtcDateTime.ToString("o"), pointSizeInMinutes),
null);
if (response.StatusCode == HttpStatusCode.OK)
{
return JsonConvert.DeserializeObject<Models.MonitorMetric>(response.ResponseText);
}
else
{
return null;
}
}
}
}