-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAPIWrapper.cs
More file actions
121 lines (104 loc) · 3.76 KB
/
APIWrapper.cs
File metadata and controls
121 lines (104 loc) · 3.76 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
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using Altiris.Common;
using Altiris.Database;
using Altiris.NS;
using Altiris.NS.ItemManagement;
using Altiris.NS.Logging;
using Altiris.NS.ContextManagement;
using Altiris.NS.Security;
using Symantec.CWoC.PatchTrending;
namespace Symantec.CWoC.APIWrappers
{
class SecurityAPI
{
public static bool is_user_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);
}
}
++Counters.SqlQueries;
Counters.SqlRows += t.Rows.Count;
Altiris.NS.Logging.EventLog.ReportVerbose(sqlStatement);
Altiris.NS.Logging.EventLog.ReportVerbose(String.Format("SQL result set contained {0} rows.", t.Rows.Count.ToString()));
return t;
} catch {
throw new Exception("Failed to execute SQL command \n'" + sqlStatement + "'.");
}
}
public static int ExecuteNonQuery(string sqlStatement) {
using (DatabaseContext context = DatabaseContext.GetContext()) {
SqlCommand sql_cmd = context.CreateCommand() as SqlCommand;
sql_cmd.CommandText = sqlStatement;
Altiris.NS.Logging.EventLog.ReportVerbose(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();
Altiris.NS.Logging.EventLog.ReportVerbose(String.Format("SQL Query = \n{0}\nResults = {1}.", sqlStatement, Convert.ToInt32(result).ToString()));
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();
}
}
}