public static void SetOptOut(bool OptOut) { TelemetryConfiguration.Active.DisableTelemetry = OptOut; using (var cmd = new SqliteCommand(UPDATE_TELEMETRY, DatabaseManager.Connection, DatabaseManager.Transaction)) { cmd.Parameters.AddWithValue("@TelemetryOptOut", OptOut.ToString()); cmd.ExecuteNonQuery(); DatabaseManager.Commit(); } }
public static void DeleteRun(string runid) { using (var cmd = new SqliteCommand(SQL_GET_RESULT_TYPES_SINGLE, DatabaseManager.Connection, DatabaseManager.Transaction)) { cmd.Parameters.AddWithValue("@run_id", runid); using (var reader = cmd.ExecuteReader()) { if (!reader.HasRows) { Log.Warning("That Run ID wasn't found in the database"); return; } while (reader.Read()) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_RUN, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } if (reader["type"].ToString() == "monitor") { if ((int.Parse(reader["file_system"].ToString()) != 0)) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_FILES_MONITORED, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } } else { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_RESULTS, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_COLLECT, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } } } cmd.CommandText = "VACUUM"; cmd.ExecuteNonQuery(); } DatabaseManager.Commit(); }
public static void SetOptOut(bool optOut) { OptOut = optOut; using var config = TelemetryConfiguration.CreateDefault(); config.InstrumentationKey = INSTRUMENTATION_KEY; config.DisableTelemetry = OptOut; Client = new TelemetryClient(config); Client.Context.Component.Version = AsaHelpers.GetVersionString(); // Force some values to static values to prevent gathering unneeded data Client.Context.Cloud.RoleInstance = "Asa"; Client.Context.Cloud.RoleName = "Asa"; Client.Context.Location.Ip = "1.1.1.1"; using (var cmd = new SqliteCommand(UPDATE_TELEMETRY, DatabaseManager.Connection, DatabaseManager.Transaction)) { cmd.Parameters.AddWithValue("@TelemetryOptOut", OptOut.ToString(CultureInfo.InvariantCulture)); cmd.ExecuteNonQuery(); DatabaseManager.Commit(); } }
public static void DeleteRun(string runid) { using (var cmd = new SqliteCommand(SQL_GET_RESULT_TYPES_SINGLE, DatabaseManager.Connection, DatabaseManager.Transaction)) { cmd.Parameters.AddWithValue("@run_id", runid); using (var reader = cmd.ExecuteReader()) { if (!reader.HasRows) { Log.Warning("That Run ID wasn't found in the database"); return; } while (reader.Read()) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_RUN, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } if (reader["type"].ToString() == "monitor") { if ((int.Parse(reader["file_system"].ToString()) != 0)) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_FILES_MONITORED, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } } else { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_RESULTS, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } if ((int.Parse(reader["file_system"].ToString()) != 0)) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_FILES, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } if ((int.Parse(reader["ports"].ToString()) != 0)) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_PORTS, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } if ((int.Parse(reader["users"].ToString()) != 0)) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_USERS, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } if ((int.Parse(reader["services"].ToString()) != 0)) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_SERVICES, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } if ((int.Parse(reader["registry"].ToString()) != 0)) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_REGISTRY, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } if ((int.Parse(reader["certificates"].ToString()) != 0)) { using (var inner_cmd = new SqliteCommand(SQL_TRUNCATE_CERTIFICATES, DatabaseManager.Connection, DatabaseManager.Transaction)) { inner_cmd.Parameters.AddWithValue("@run_id", runid); inner_cmd.ExecuteNonQuery(); } } } } } } DatabaseManager.Commit(); }