-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPIWrapper.cs
More file actions
106 lines (93 loc) · 3.13 KB
/
APIWrapper.cs
File metadata and controls
106 lines (93 loc) · 3.13 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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using Altiris.Database;
using Altiris.NS.ContextManagement;
using Altiris.NS.Security;
namespace Symantec.CWoC.APIWrappers
{
class SecurityAPI
{
public static bool user_is_admin()
{
bool is_altiris_admin = false;
string identity = string.Empty;
try
{
SecurityContextManager.SetContextData();
Role role = SecurityRoleManager.Get(new Guid("{2E1F478A-4986-4223-9D1E-B5920A63AB41}"));
if (role != null)
identity = role.Trustee.Identity;
if (identity != string.Empty)
{
foreach (string admin in SecurityTrusteeManager.GetCurrentUserMemberships())
{
if (admin == identity)
{
is_altiris_admin = true;
break;
}
}
}
}
catch
{
}
return is_altiris_admin;
}
}
class DatabaseAPI {
public static DataTable GetTable(string sqlStatement) {
DataTable t = new DataTable();
try {
using (DatabaseContext context = DatabaseContext.GetContext()) {
SqlCommand cmdAllResources = context.CreateCommand() as SqlCommand;
cmdAllResources.CommandText = sqlStatement;
using (SqlDataReader r = cmdAllResources.ExecuteReader()) {
t.Load(r);
}
}
return t;
} catch {
throw new Exception("Failed to execute SQL command...");
}
}
public static int ExecuteNonQuery(string sqlStatement) {
using (DatabaseContext context = DatabaseContext.GetContext()) {
SqlCommand sql_cmd = context.CreateCommand() as SqlCommand;
sql_cmd.CommandText = sqlStatement;
return sql_cmd.ExecuteNonQuery();
}
}
public static int ExecuteScalar(string sqlStatement) {
using (DatabaseContext context = DatabaseContext.GetContext()) {
SqlCommand cmd = context.CreateCommand() as SqlCommand;
cmd.CommandText = sqlStatement;
Object result = cmd.ExecuteScalar();
return Convert.ToInt32(result);
}
}
}
class Timer {
private static Stopwatch chrono;
public static void Init() {
chrono = new Stopwatch();
chrono.Start();
}
public static void Start() {
chrono.Start();
}
public static void Stop() {
chrono.Stop();
}
public static string tickCount() {
return chrono.ElapsedTicks.ToString();
}
public static string duration() {
return chrono.ElapsedMilliseconds.ToString();
}
}
}