diff --git a/ProgrammList/ConfigManager/ConfigManager.cs b/ProgrammList/ConfigManager/ConfigManager.cs
deleted file mode 100644
index f8a9fa4..0000000
--- a/ProgrammList/ConfigManager/ConfigManager.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System.Configuration;
-
-namespace ProgrammList.ConfigManager {
- public class ConfigManager {
- public static string GetSetting(string key) {
- return ConfigurationManager.AppSettings[key];
- }
-
- public static void SetSetting(string key, string value) {
- Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- configuration.AppSettings.Settings[key].Value = value;
- configuration.Save(ConfigurationSaveMode.Full, true);
- ConfigurationManager.RefreshSection("appSettings");
-
- }
- }
-}
\ No newline at end of file
diff --git a/ProgrammList/Program.cs b/ProgrammList/Program.cs
index e936474..8cac316 100644
--- a/ProgrammList/Program.cs
+++ b/ProgrammList/Program.cs
@@ -1,12 +1,13 @@
using ProgrammList.ConfigManager;
using ProgrammList.ListPrograms;
+using System;
class Program {
public static void Main(string[] args) {
- string dbType = ConfigManager.GetSetting("DB_Type");
- ListPrograms list = new ListPrograms(dbType);
-
+ string dbType = PrmListConfigManager.GetSetting("DB_Type");
+ ListPrograms list = new ListPrograms();
+ list.init();
Console.WriteLine("Deleting old data");
list.DeleteOldData();
string keyname1 = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstal";
diff --git a/ProgrammList/ProgrammList.csproj b/ProgrammList/ProgrammList.csproj
index d57e020..dad93f4 100644
--- a/ProgrammList/ProgrammList.csproj
+++ b/ProgrammList/ProgrammList.csproj
@@ -2,13 +2,16 @@
Exe
- net8.0
- enable
- enable
+ disable
+ disable
AnyCPU;x64
Debug;Release;PrgmList
+
+
+
+
@@ -16,5 +19,29 @@
+
+
+ True
+ True
+ Resources.resx
+
+
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
+
+ Exe
+ net462
+ true
+ true
+ win-x64
+ ProgramList
+ Icons\prm_icon\back-end.ico
+ Program
+
diff --git a/ProgrammList/list_creation/ListPrograms.cs b/ProgrammList/list_creation/ListPrograms.cs
index b17d861..fdf2e9d 100644
--- a/ProgrammList/list_creation/ListPrograms.cs
+++ b/ProgrammList/list_creation/ListPrograms.cs
@@ -1,15 +1,20 @@
using Microsoft.Win32;
+using ProgrammList.ConfigManager;
using ProgrammList.sql;
+using System;
+using System.Collections.Generic;
+using System.IO;
using System.Net;
namespace ProgrammList.ListPrograms {
- internal class ListPrograms {
+ public class ListPrograms {
string prgm_path = Directory.GetCurrentDirectory() + "\\";
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
private SqlBase sql = null;
- internal ListPrograms(string sqlType) {
+ public void init() {
+ string sqlType = PrmListConfigManager.GetSetting("DB_Type");
if (sqlType == null) {
Console.WriteLine("SQL Database not defined in app.conf, allowed types:");
Console.WriteLine("MYSQL");
@@ -30,12 +35,12 @@ namespace ProgrammList.ListPrograms {
}
}
- internal void DeleteOldData() {
+ public void DeleteOldData() {
sql.CheckTableExists();
sql.DeleteOldData(Dns.GetHostName());
}
- internal void createList(string hkey, string bit) {
+ public void createList(string hkey, string bit) {
RegistryKey key = Registry.LocalMachine.OpenSubKey(hkey);
try {
if (key == null) {
@@ -56,11 +61,11 @@ namespace ProgrammList.ListPrograms {
count++;
}
- result = String.Join("", value.ToArray());
-
- if (result.EndsWith(",")) {
- result = result.Remove(result.Length - 1);
- }
+ // result = String.Join("", value.ToArray());
+ //
+ // if (result.EndsWith(",")) {
+ // result = result.Remove(result.Length - 1);
+ // }
value.Add("PCID", "'" + Dns.GetHostName() + "'");
value.Add("update_date", "'" + DateTime.Now + "'");
diff --git a/ProgrammList/sql/Mssql.cs b/ProgrammList/sql/Mssql.cs
index 72e5a0d..7077735 100644
--- a/ProgrammList/sql/Mssql.cs
+++ b/ProgrammList/sql/Mssql.cs
@@ -1,6 +1,8 @@
using Microsoft.Data.SqlClient;
+using System;
+using System.Collections.Generic;
namespace ProgrammList.sql {
public class Mssql : SqlBaseAbstract {
@@ -46,6 +48,8 @@ namespace ProgrammList.sql {
Open(DB.MSSQL);
var command = sqlcon.CreateCommand();
command.CommandText = "select case when exists (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'prgmlist' AND TABLE_NAME = 'list') then 1 else 0 end";
+
+ Console.WriteLine("Executing: " + command.CommandText);
var returncode = command.ExecuteScalar();
if (returncode != null) {
int rc;
@@ -76,7 +80,9 @@ namespace ProgrammList.sql {
string result = "";
for (int i = 0; i < valuenames.Length; i++) {
- result += valuesqlCommand.GetValueOrDefault(valuenames[i]);
+ string val = "";
+ valuesqlCommand.TryGetValue(valuenames[i], out val);
+ result += val;
if (i < valuenames.Length - 1) {
result += ",";
@@ -96,7 +102,13 @@ namespace ProgrammList.sql {
}
public void InsertOrUpdateData(Dictionary value) {
- if (GetSingleLine(value.GetValueOrDefault("PCID"), value.GetValueOrDefault("DisplayName"), value.GetValueOrDefault("DisplayVersion"))) {
+ string pcid = "";
+ value.TryGetValue("PCID", out pcid);
+ string displayName = "";
+ value.TryGetValue("DisplayName", out displayName);
+ string displayVersion = "";
+ value.TryGetValue("DisplayVersion", out displayVersion);
+ if (GetSingleLine(pcid, displayName, displayVersion)) {
UpdateData(value);
}
else {
@@ -120,7 +132,9 @@ namespace ProgrammList.sql {
string result = "set ";
for (int i = 0; i < valuenames.Length; i++) {
- result += valuenames[i] + " = " + value.GetValueOrDefault(valuenames[i]);
+ string val = "";
+ value.TryGetValue(valuenames[i], out val);
+ result += valuenames[i] + " = " + val;
if (i < valuenames.Length - 1) {
result += " ,";
@@ -128,15 +142,23 @@ namespace ProgrammList.sql {
}
sqlCommand = sqlCommand + result;
- sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
- " and DisplayName like " + value.GetValueOrDefault("DisplayName") +
- " and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
+ string pcid = "";
+ value.TryGetValue("PCID", out pcid);
+ string displayName = "";
+ value.TryGetValue("DisplayName", out displayName);
+ string displayVersion = "";
+ value.TryGetValue("DisplayVersion", out displayVersion);
+ sqlCommand = sqlCommand + " WHERE PCID = " + pcid +
+ " and DisplayName like " + displayName +
+ " and DisplayVersion like " + displayVersion;
var command = new SqlCommand(sqlCommand, sqlcon, transaction);
for (int i = 0; i < valuenames.Length; i++) {
if (valuenames[i] != "PCID") {
- command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
+ string itemValue = "";
+ value.TryGetValue(valuenames[i], out itemValue);
+ command.Parameters.AddWithValue("$" + valuenames[i], itemValue);
}
}
Console.WriteLine(sqlCommand);
diff --git a/ProgrammList/sql/MySql.cs b/ProgrammList/sql/MySql.cs
index 2cc5a57..4b5e7fd 100644
--- a/ProgrammList/sql/MySql.cs
+++ b/ProgrammList/sql/MySql.cs
@@ -1,9 +1,11 @@
using MySql.Data.MySqlClient;
+using System;
+using System.Collections.Generic;
namespace ProgrammList.sql {
- internal class Mysql : SqlBaseAbstract {
+ public class Mysql : SqlBaseAbstract {
public Boolean GetSingleLine(string pcid, string program, string version) {
@@ -40,7 +42,9 @@ namespace ProgrammList.sql {
string result = "";
for (int i = 0; i < valuenames.Length; i++) {
- result += valuesqlCommand.GetValueOrDefault(valuenames[i]);
+ string val = "";
+ valuesqlCommand.TryGetValue(valuenames[i], out val);
+ result += val;
if (i < valuenames.Length - 1) {
result += ",";
@@ -48,7 +52,7 @@ namespace ProgrammList.sql {
}
- var cols = String.Join(",", valuenames);
+ var cols = string.Join(",", valuenames);
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
@@ -60,7 +64,13 @@ namespace ProgrammList.sql {
}
public void InsertOrUpdateData(Dictionary value) {
- if (GetSingleLine(value.GetValueOrDefault("PCID"), value.GetValueOrDefault("DisplayName"), value.GetValueOrDefault("DisplayVersion"))) {
+ string pcid = "";
+ value.TryGetValue("PCID", out pcid);
+ string displayName = "";
+ value.TryGetValue("DisplayName", out displayName);
+ string displayVersion = "";
+ value.TryGetValue("DisplayVersion", out displayVersion);
+ if (GetSingleLine(pcid, displayName, displayVersion)) {
UpdateData(value);
}
else {
@@ -75,7 +85,9 @@ namespace ProgrammList.sql {
string result = "set ";
for (int i = 0; i < valuenames.Length; i++) {
- result += valuenames[i] + " = " + value.GetValueOrDefault(valuenames[i]);
+ string val = "";
+ value.TryGetValue(valuenames[i], out val);
+ result += valuenames[i] + " = " + val;
if (i < valuenames.Length - 1) {
result += " ,";
@@ -83,15 +95,23 @@ namespace ProgrammList.sql {
}
sqlCommand = sqlCommand + result;
- sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
- " and DisplayName like " + value.GetValueOrDefault("DisplayName") +
- " and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
+ string pcid = "";
+ value.TryGetValue("PCID", out pcid);
+ string displayName = "";
+ value.TryGetValue("DisplayName", out displayName);
+ string displayVersion = "";
+ value.TryGetValue("DisplayVersion", out displayVersion);
+ sqlCommand = sqlCommand + " WHERE PCID = " + pcid +
+ " and DisplayName like " + displayName +
+ " and DisplayVersion like " + displayVersion;
var command = new MySqlCommand(sqlCommand, mysqlcon, transaction);
for (int i = 0; i < valuenames.Length; i++) {
if (valuenames[i] != "PCID") {
- command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
+ string itemValue = "";
+ value.TryGetValue(valuenames[i], out itemValue);
+ command.Parameters.AddWithValue("$" + valuenames[i], itemValue);
}
}
Console.WriteLine(sqlCommand);
diff --git a/ProgrammList/sql/SqlBase.cs b/ProgrammList/sql/SqlBase.cs
index 296bae4..46b64b5 100644
--- a/ProgrammList/sql/SqlBase.cs
+++ b/ProgrammList/sql/SqlBase.cs
@@ -1,19 +1,23 @@
-namespace ProgrammList.sql {
+using System.Collections.Generic;
+
+namespace ProgrammList.sql {
interface SqlBase {
- internal bool GetSingleLine(string pcid, string program, string version);
+ bool GetSingleLine(string pcid, string program, string version);
- internal void CheckTableExists();
+ void CheckTableExists();
- internal void InsertData(Dictionary valuesqlCommand);
- internal void InsertOrUpdateData(Dictionary value);
- internal void DeleteOldData(string hostname);
+ void InsertData(Dictionary valuesqlCommand);
- internal void UpdateData(Dictionary value);
+
+ void InsertOrUpdateData(Dictionary value);
+
+ void DeleteOldData(string hostname);
+ void UpdateData(Dictionary value);
}
diff --git a/ProgrammList/sql/SqlBaseAbstract.cs b/ProgrammList/sql/SqlBaseAbstract.cs
index 1c5b570..4f7d128 100644
--- a/ProgrammList/sql/SqlBaseAbstract.cs
+++ b/ProgrammList/sql/SqlBaseAbstract.cs
@@ -1,6 +1,8 @@
using Microsoft.Data.SqlClient;
using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
+using System;
+using System.Collections.Generic;
namespace ProgrammList.sql {
@@ -59,11 +61,15 @@ namespace ProgrammList.sql {
}
}
- bool SqlBase.GetSingleLine(string pcid, string program, string version) {
+ void SqlBase.CheckTableExists() {
throw new NotImplementedException();
}
- void SqlBase.CheckTableExists() {
+ void SqlBase.DeleteOldData(string hostname) {
+ throw new NotImplementedException();
+ }
+
+ bool SqlBase.GetSingleLine(string pcid, string program, string version) {
throw new NotImplementedException();
}
@@ -75,10 +81,6 @@ namespace ProgrammList.sql {
throw new NotImplementedException();
}
- void SqlBase.DeleteOldData(string hostname) {
- throw new NotImplementedException();
- }
-
void SqlBase.UpdateData(Dictionary value) {
throw new NotImplementedException();
}
diff --git a/ProgrammList/sql/Sqlite.cs b/ProgrammList/sql/Sqlite.cs
index 539d24f..dbee1db 100644
--- a/ProgrammList/sql/Sqlite.cs
+++ b/ProgrammList/sql/Sqlite.cs
@@ -1,4 +1,6 @@
using Microsoft.Data.Sqlite;
+using System;
+using System.Collections.Generic;
using System.Configuration;
namespace ProgrammList.sql {
@@ -42,7 +44,8 @@ namespace ProgrammList.sql {
string result = "";
for (int i = 0; i < valuenames.Length; i++) {
- result += valuesqlCommand.GetValueOrDefault(valuenames[i]);
+ string value = "";
+ result += valuesqlCommand.TryGetValue(valuenames[i], out value);
if (i < valuenames.Length - 1) {
result += ",";
@@ -61,7 +64,13 @@ namespace ProgrammList.sql {
}
public void InsertOrUpdateData(Dictionary value) {
- if (GetSingleLine(value.GetValueOrDefault("PCID"), value.GetValueOrDefault("DisplayName"), value.GetValueOrDefault("DisplayVersion"))) {
+ string pcid = "";
+ string displayName = "";
+ string displayVersion = "";
+ value.TryGetValue("PCID", out pcid);
+ value.TryGetValue("DisplayName", out displayName);
+ value.TryGetValue("DisplayVersion", out displayVersion);
+ if (GetSingleLine(pcid, displayName, displayVersion)) {
Console.WriteLine("Update");
UpdateData(value);
@@ -86,7 +95,9 @@ namespace ProgrammList.sql {
string result = "set ";
for (int i = 0; i < valuenames.Length; i++) {
- result += valuenames[i] + " = " + value.GetValueOrDefault(valuenames[i]);
+ string res = "";
+ value.TryGetValue(valuenames[i], out res);
+ result += valuenames[i] + " = " + res;
if (i < valuenames.Length - 1) {
result += " ,";
@@ -94,15 +105,23 @@ namespace ProgrammList.sql {
}
sqlCommand = sqlCommand + result;
- sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
- " and DisplayName like " + value.GetValueOrDefault("DisplayName") +
- " and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
+ string pcid = "";
+ value.TryGetValue("PCID", out pcid);
+ string displayName = "";
+ value.TryGetValue("DisplayName", out displayName);
+ string displayVersion = "";
+ value.TryGetValue("DisplayVersion", out displayVersion);
+ sqlCommand = sqlCommand + " WHERE PCID = " + pcid +
+ " and DisplayName like " + displayName +
+ " and DisplayVersion like " + displayVersion;
var command = new SqliteCommand(sqlCommand, sqlitecon, transaction);
for (int i = 0; i < valuenames.Length; i++) {
if (valuenames[i] != "PCID") {
- command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
+ string itemValue = "";
+ value.TryGetValue(valuenames[i], out itemValue);
+ command.Parameters.AddWithValue("$" + valuenames[i], itemValue);
}
}