Compare commits

..

4 Commits

Author SHA1 Message Date
0a81086722
Update README.md 2025-03-07 21:55:42 +01:00
299e807e8a
Update README.md 2025-03-07 21:54:13 +01:00
bdb9f412a1 README updates 2025-03-07 21:40:22 +01:00
6599e17a18 neue version für .net framework 4.6.2
unterstützung für app.config
2025-03-07 21:05:03 +01:00
14 changed files with 298 additions and 354 deletions

View File

@ -15,8 +15,8 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Release|x64
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.Build.0 = Release|x64
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.ActiveCfg = Debug|x64
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.Build.0 = Debug|x64
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.PrgmList|Any CPU.ActiveCfg = PrgmList|Any CPU

View File

@ -1,20 +1,21 @@
using System.Configuration;
using System;
using System.Configuration;
using System.IO;
namespace ProgrammList.ConfigManager {
public static class PrmListConfigManager {
public static string GetSetting(string key) {
try {
if (!File.Exists(Directory.GetCurrentDirectory() + "\\app.conf")) {
return "";
}
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
Console.WriteLine("Loading " + Directory.GetCurrentDirectory() + "\\app.conf");
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
return config.AppSettings.Settings[key].Value;
}
catch (Exception e) {
System.Environment.Exit(13);
Console.WriteLine("Error on Key " + key + ": " + e.ToString());
Console.WriteLine(e.ToString());
}
return "13";
}
@ -22,12 +23,14 @@ namespace ProgrammList.ConfigManager {
public static void SetSetting(string key, string value) {
try {
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
Console.WriteLine("Loading " + Directory.GetCurrentDirectory() + "\\app.conf");
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
config.AppSettings.Settings["key"].Value = value;
}
catch (Exception e) {
// Exception
Console.WriteLine("Error on Key " + key + ": " + e.ToString());
Console.WriteLine(e.ToString());
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -1,16 +1,20 @@
using ProgrammList.ConfigManager;
using ProgrammList.ListPrograms;
using System;
class Program {
public static void Main(string[] args) {
string dbType = PrmListConfigManager.GetSetting("DB_Type");
ListPrograms list = new ListPrograms(dbType);
ListPrograms list = new ListPrograms();
list.init();
Console.WriteLine("Deleting old data");
list.DeleteOldData();
string keyname1 = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstal";
Console.WriteLine("Searching for 32 bit");
list.createList(keyname1, "x86");
string keyname2 = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
Console.WriteLine("Searching for 64 bit");
list.createList(keyname2, "x64");
}

View File

@ -2,16 +2,14 @@
<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>
<ApplicationIcon>icons\back-end.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Content Include="icons\back-end.ico" />
<Content Include="Icons\prm_icon\back-end.ico" />
</ItemGroup>
<ItemGroup>
@ -22,10 +20,28 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Data.Sqlite">
<HintPath>bin\Release\net6.0\Microsoft.Data.Sqlite.dll</HintPath>
</Reference>
<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>

View File

@ -1,63 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProgrammList.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProgrammList.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@ -1,101 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,51 +1,46 @@
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, params string[] filename) {
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");
Console.WriteLine("MARIADB");
Console.WriteLine("MSSQL");
Console.WriteLine("SQLITE");
throw new ArgumentNullException();
}
string sqlname = "";
if (sqlType.Equals("MYSQL", StringComparison.OrdinalIgnoreCase) || sqlType.Equals("MARIADB", StringComparison.OrdinalIgnoreCase)) {
string server = PrmListConfigManager.GetSetting("server");
string database = PrmListConfigManager.GetSetting("DB");
string user = PrmListConfigManager.GetSetting("user");
string pw = PrmListConfigManager.GetSetting("pw");
sql = new Mysql(server, database, user, pw);
sql = new Mysql();
}
else if (sqlType.Equals("MSSQL", StringComparison.OrdinalIgnoreCase)) {
string server = PrmListConfigManager.GetSetting("server");
string database = PrmListConfigManager.GetSetting("DB");
string user = PrmListConfigManager.GetSetting("user");
string pw = PrmListConfigManager.GetSetting("pw");
sql = new Mssql(server, user, pw, database);
sql = new Mssql();
}
else if (sqlType.Equals("SQLITE", StringComparison.OrdinalIgnoreCase) && filename != null) {
sql = new Sqlite(prgm_path, filename[0]);
}
else {
// Default sqlite im gleichen ordner
sql = new Sqlite(Directory.GetCurrentDirectory() + "\\sqllite.db");
else if (sqlType.Equals("SQLITE", StringComparison.OrdinalIgnoreCase)) {
sql = new Sqlite(prgm_path);
}
}
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) {
@ -66,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 + "'");

View File

@ -1,46 +1,28 @@

using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
namespace ProgrammList.sql {
public class Mssql : SqlBase {
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
SqlConnection mssqlcon = null;
SqlConnectionStringBuilder builder;
public class Mssql : SqlBaseAbstract {
//private static Dbconnection instance;
public Mssql(String server, string user, string pw, string db) {
builder = new SqlConnectionStringBuilder {
DataSource = server,
UserID = user,
Password = pw,
InitialCatalog = db,
public Mssql() {
var builder = new SqlConnectionStringBuilder {
DataSource = "localhost",
UserID = "sa",
Password = "2677890E23",
InitialCatalog = "prgmlist",
TrustServerCertificate = true
};
}
public void Open() {
try {
mssqlcon = new SqlConnection(builder.ConnectionString);
mssqlcon.Open();
}
catch (Exception ex) {
System.Environment.Exit(13);
}
}
public void Close() {
mssqlcon.Close();
connstring = builder.ToString();
}
public void GetAllData() {
Open();
var command = mssqlcon.CreateCommand();
Open(DB.MSSQL);
var command = sqlcon.CreateCommand();
command.CommandText = @"SELECT * FROM list";
using (var reader = command.ExecuteReader()) {
@ -51,8 +33,8 @@ namespace ProgrammList.sql {
Close();
}
public bool GetSingleLine(string pcid, string program, string version) {
Open();
var command = mssqlcon.CreateCommand();
Open(DB.MSSQL);
var command = sqlcon.CreateCommand();
command.CommandText = @"SELECT * FROM list where PCID like "
+ pcid + " and DisplayName like "
+ program + " and DisplayVersion like " + version + ";";
@ -63,9 +45,11 @@ namespace ProgrammList.sql {
}
public void CheckTableExists() {
Open();
var command = mssqlcon.CreateCommand();
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;
@ -75,7 +59,12 @@ namespace ProgrammList.sql {
throw new FormatException();
}
return;
if (rc > 0) {
Console.WriteLine("Creating table...");
}
else {
return;
}
}
var cols = string.Join(" VARCHAR(255),", valuenames);
cols = cols + " Varchar(255)";
@ -86,12 +75,14 @@ namespace ProgrammList.sql {
public void InsertData(Dictionary<string, string> valuesqlCommand) {
Open();
var transaction = mssqlcon.BeginTransaction();
Open(DB.MSSQL);
var transaction = sqlcon.BeginTransaction();
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 += ",";
@ -103,14 +94,21 @@ namespace ProgrammList.sql {
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
var command = new SqlCommand(sqlCommand, mssqlcon, transaction);
var command = new SqlCommand(sqlCommand, sqlcon, transaction);
command.ExecuteNonQuery();
transaction.Commit();
Console.WriteLine(sqlCommand);
Close();
}
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 {
@ -119,8 +117,8 @@ namespace ProgrammList.sql {
}
public void DeleteOldData(string hostname) {
Open();
var command = mssqlcon.CreateCommand();
Open(DB.MSSQL);
var command = sqlcon.CreateCommand();
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
command.CommandText = sqlCommand;
command.ExecuteReader();
@ -128,13 +126,15 @@ namespace ProgrammList.sql {
}
public void UpdateData(Dictionary<string, string> value) {
Open();
var transaction = mssqlcon.BeginTransaction();
Open(DB.MSSQL);
var transaction = sqlcon.BeginTransaction();
string sqlCommand = @"Update list ";
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 += " ,";
@ -142,17 +142,26 @@ 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, mssqlcon, transaction);
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);
command.ExecuteNonQuery();
transaction.Commit();
Close();

View File

@ -1,21 +1,15 @@
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
namespace ProgrammList.sql {
internal class Mysql : SqlBase {
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
public string connstring = null;
public MySqlConnection mysqlcon = null;
public Mysql(String server, String db, String user, String pw) {
connstring = string.Format("Server={0}; database={1}; UID={2}; password={3}", server, db, user, pw);
}
public class Mysql : SqlBaseAbstract {
public Boolean GetSingleLine(string pcid, string program, string version) {
Open();
Open(DB.MYSQL);
var command = mysqlcon.CreateCommand();
command.CommandText = @"SELECT * FROM list where PCID like "
+ pcid + " and DisplayName like "
@ -26,20 +20,10 @@ namespace ProgrammList.sql {
return result;
}
public void Open() {
mysqlcon = new MySqlConnection(connstring);
mysqlcon.Open();
}
public void Close() {
mysqlcon.Close();
}
public void CheckTableExists() {
Open();
Open(DB.MYSQL);
var command = mysqlcon.CreateCommand();
command.CommandText = "SHOW TABLES LIKE 'list';";
command.CommandText = @"SHOW TABLES LIKE 'list';";
var name = command.ExecuteScalar();
if (name != null && name.ToString() == "list") {
return;
@ -53,12 +37,14 @@ namespace ProgrammList.sql {
public void InsertData(Dictionary<string, string> valuesqlCommand) {
Open();
Open(DB.MYSQL);
var transaction = mysqlcon.BeginTransaction();
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 += ",";
@ -66,18 +52,25 @@ namespace ProgrammList.sql {
}
var cols = String.Join(",", valuenames);
var cols = string.Join(",", valuenames);
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
var command = new MySqlCommand(sqlCommand, mysqlcon, transaction);
command.ExecuteNonQuery();
transaction.Commit();
Console.WriteLine(sqlCommand);
Close();
}
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 {
@ -86,13 +79,15 @@ namespace ProgrammList.sql {
}
public void UpdateData(Dictionary<string, string> value) {
Open();
Open(DB.MYSQL);
var transaction = mysqlcon.BeginTransaction();
string sqlCommand = @"Update list ";
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 += " ,";
@ -100,18 +95,26 @@ 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);
command.ExecuteNonQuery();
transaction.Commit();
Close();
@ -119,7 +122,7 @@ namespace ProgrammList.sql {
public void DeleteOldData(string hostname) {
Open();
Open(DB.MYSQL);
var command = mysqlcon.CreateCommand();
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
command.CommandText = sqlCommand;

View File

@ -1,20 +1,23 @@
namespace ProgrammList.sql {
using System.Collections.Generic;
namespace ProgrammList.sql {
interface SqlBase {
internal void Open();
internal void Close();
internal bool GetSingleLine(string pcid, string program, string version);
internal void CheckTableExists();
bool GetSingleLine(string pcid, string program, string version);
internal void InsertData(Dictionary<string, string> valuesqlCommand);
void CheckTableExists();
internal void InsertOrUpdateData(Dictionary<string, string> value);
internal void DeleteOldData(string hostname);
internal void UpdateData(Dictionary<string, string> value);
void InsertData(Dictionary<string, string> valuesqlCommand);
void InsertOrUpdateData(Dictionary<string, string> value);
void DeleteOldData(string hostname);
void UpdateData(Dictionary<string, string> value);
}

View File

@ -0,0 +1,88 @@
using Microsoft.Data.SqlClient;
using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
namespace ProgrammList.sql {
public abstract class SqlBaseAbstract : SqlBase {
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
public string connstring = null;
public MySqlConnection mysqlcon = null;
public SqlConnection sqlcon = null;
public SqliteConnection sqlitecon = null;
public void Close() {
if (mysqlcon != null) {
mysqlcon.Close();
}
else if (sqlcon != null) {
sqlcon.Close();
}
else if (sqlitecon != null) {
sqlitecon.Close();
}
}
public void Open(DB type) {
switch (type) {
case DB.MYSQL:
case DB.MARIADB:
mysqlcon = new MySqlConnection(connstring);
try {
mysqlcon.Open();
}
catch (Exception ex) {
Console.Write(ex.ToString());
}
break;
case DB.MSSQL:
sqlcon = new SqlConnection(connstring);
try {
mysqlcon.Open();
}
catch (Exception ex) {
Console.Write(ex.ToString());
}
break;
case DB.SQLITE:
sqlitecon = new SqliteConnection(connstring);
try {
mysqlcon.Open();
}
catch (Exception ex) {
Console.Write(ex.ToString());
}
break;
}
}
void SqlBase.CheckTableExists() {
throw new NotImplementedException();
}
void SqlBase.DeleteOldData(string hostname) {
throw new NotImplementedException();
}
bool SqlBase.GetSingleLine(string pcid, string program, string version) {
throw new NotImplementedException();
}
void SqlBase.InsertData(Dictionary<string, string> valuesqlCommand) {
throw new NotImplementedException();
}
void SqlBase.InsertOrUpdateData(Dictionary<string, string> value) {
throw new NotImplementedException();
}
void SqlBase.UpdateData(Dictionary<string, string> value) {
throw new NotImplementedException();
}
}
}

View File

@ -1,45 +1,19 @@
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.Configuration;
namespace ProgrammList.sql {
public class Sqlite : SqlBase {
public class Sqlite : SqlBaseAbstract {
string filename;
SqliteConnection sqlitecon;
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
public string connstring = null;
public Sqlite(string prm_path, string filename) {
sqlitecon = new SqliteConnection("Data Source=" + prm_path + filename);
}
public void Open() {
sqlitecon.Open();
}
public void Close() {
sqlitecon.Close();
}
public void Open(DB type) {
sqlitecon = new SqliteConnection(connstring);
sqlitecon.Open();
}
public Sqlite(string prm_path) {
string setting = ConfigManager.PrmListConfigManager.GetSetting("filename");
if (setting != null && setting != "") {
sqlitecon = new SqliteConnection("Data Source=" + prm_path + setting);
}
else {
sqlitecon = new SqliteConnection("Data Source=" + prm_path + "sqlite.db");
}
sqlitecon = new SqliteConnection("Data Source=" + prm_path + ConfigurationManager.AppSettings["filename"]);
sqlitecon.Open();
}
public bool GetSingleLine(string pcid, string program, string version) {
Open();
var command = sqlitecon.CreateCommand();
command.CommandText = @"SELECT * FROM list where PCID like "
+ pcid + " and DisplayName like "
@ -47,12 +21,11 @@ namespace ProgrammList.sql {
bool result = command.ExecuteReader().Read();
Close();
return result;
}
public void CheckTableExists() {
Open();
var command = sqlitecon.CreateCommand();
command.CommandText = @"SELECT name FROM sqlite_master WHERE type='table' AND name='list';";
var name = command.ExecuteScalar();
@ -63,17 +36,16 @@ namespace ProgrammList.sql {
cols = cols + " Varchar";
command.CommandText = "CREATE TABLE list (" + cols + ")";
command.ExecuteNonQuery();
Close();
}
public void InsertData(Dictionary<string, string> valuesqlCommand) {
Open();
var transaction = sqlitecon.BeginTransaction();
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 += ",";
@ -86,38 +58,46 @@ namespace ProgrammList.sql {
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
SqliteConnection con;
var command = new SqliteCommand(sqlCommand, sqlitecon, transaction);
Console.WriteLine(sqlCommand);
command.ExecuteNonQuery();
transaction.Commit();
Close();
}
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);
}
else {
Console.WriteLine("Insert");
InsertData(value);
}
}
public void DeleteOldData(string hostname) {
Open();
var command = sqlitecon.CreateCommand();
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
command.CommandText = sqlCommand;
command.ExecuteReader();
Close();
}
public void UpdateData(Dictionary<string, string> value) {
Open();
var transaction = sqlitecon.BeginTransaction();
string sqlCommand = @"Update list ";
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 += " ,";
@ -125,25 +105,32 @@ 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);
}
}
Console.WriteLine(command.CommandText);
command.ExecuteNonQuery();
transaction.Commit();
Close();
}
public void DeleteData(string id) {
Open();
var command = sqlitecon.CreateCommand();
command.CommandText = @"SELECT name FROM user WHERE id = $id";
command.Parameters.AddWithValue("$id", id);
@ -153,7 +140,6 @@ namespace ProgrammList.sql {
var name = reader.GetString(0);
}
}
Close();
}
}

View File

@ -1,3 +1,4 @@
# ProgrammList (EN)
A Program to create a list of programs installled on a system. You may add this program on a networkfolder to get more information from single clients that execute a script to invoke it and save the data to a centralized database.
@ -5,7 +6,7 @@ A Program to create a list of programs installled on a system. You may add this
Supported databases are MSSQL, Sqlite and MySql.
For Sqlite a database file will be created as long as the parameter for it is in the coresponding app.conf file. The app.conf file has to be in the same folder as the .exe file.
For MSSQL and MySql additional Parameters are needed in the app.conf.
For MSSQL and MySql standard parameters are used currently such as IP (localhost) and Port.
In later versions this should be made configurable through the app.conf file.
@ -21,7 +22,7 @@ Ein Programm zum erstellen einer Liste installierter Programme auf einem Rechner
Untersützt werden bisher Speichermethoden in MSSQL, Sqlite und MySql.
Für Sqlite wird eine Dantenbankdatei über eine app.conf date erstellt. Die app.conf Datei muss sich dazu im gleichen Ordner wie die exe befinden.
Für MSSQL und MySql werden zusätzliche parameter in der app.config benötigt.
Für MSSQL und MySql werden bisher Standard Parameter für IP (Localhost) und Port verwendet.
In Späteren Versionen sollte dies auch über das Config file editierbar sein.