neue version für .net framework 4.6.2
unterstützung für app.config
This commit is contained in:
parent
ef7493a09a
commit
6599e17a18
@ -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");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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";
|
||||
|
@ -2,13 +2,16 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Configurations>Debug;Release;PrgmList</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Icons\prm_icon\back-end.ico" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.2" />
|
||||
@ -16,5 +19,29 @@
|
||||
<PackageReference Include="MySql.Data" Version="9.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<SelfContained>true</SelfContained>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<AssemblyName>ProgramList</AssemblyName>
|
||||
<ApplicationIcon>Icons\prm_icon\back-end.ico</ApplicationIcon>
|
||||
<StartupObject>Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
@ -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 + "'");
|
||||
|
@ -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<string, string> 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);
|
||||
|
@ -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<string, string> 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);
|
||||
|
@ -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<string, string> valuesqlCommand);
|
||||
|
||||
internal void InsertOrUpdateData(Dictionary<string, string> value);
|
||||
|
||||
internal void DeleteOldData(string hostname);
|
||||
void InsertData(Dictionary<string, string> valuesqlCommand);
|
||||
|
||||
internal void UpdateData(Dictionary<string, string> value);
|
||||
|
||||
void InsertOrUpdateData(Dictionary<string, string> value);
|
||||
|
||||
void DeleteOldData(string hostname);
|
||||
void UpdateData(Dictionary<string, string> value);
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<string, string> value) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -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<string, string> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user