Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
581016f20e | |||
a88528e929 | |||
53a493d167 | |||
d7363b5028 | |||
42d51fe90c | |||
5770a58145 | |||
1c61fc198d | |||
a076294858 | |||
21220f2018 | |||
00176a2d83 | |||
19b63d6c27 | |||
1af8b3af4a | |||
2595fc54a5 |
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.12.35527.113 d17.12
|
||||
VisualStudioVersion = 17.12.35527.113
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgrammList", "ProgrammList\ProgrammList.csproj", "{06D431CD-A938-4DFD-8D77-4C612FDAD914}"
|
||||
EndProject
|
||||
@ -15,8 +15,8 @@ Global
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.Build.0 = Release|Any CPU
|
||||
{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|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
|
||||
|
@ -1,17 +1,34 @@
|
||||
using System.Configuration;
|
||||
|
||||
namespace ProgrammList.ConfigManager {
|
||||
public class ConfigManager {
|
||||
public static class PrmListConfigManager {
|
||||
|
||||
public static string GetSetting(string key) {
|
||||
return ConfigurationManager.AppSettings[key];
|
||||
try {
|
||||
if (!File.Exists(Directory.GetCurrentDirectory() + "\\app.conf")) {
|
||||
return "";
|
||||
}
|
||||
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
||||
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);
|
||||
}
|
||||
return "13";
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
try {
|
||||
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
||||
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
|
||||
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
||||
config.AppSettings.Settings["key"].Value = value;
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Exception
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,16 +4,13 @@ using ProgrammList.ListPrograms;
|
||||
class Program {
|
||||
public static void Main(string[] args) {
|
||||
|
||||
string dbType = ConfigManager.GetSetting("DB_Type");
|
||||
string dbType = PrmListConfigManager.GetSetting("DB_Type");
|
||||
ListPrograms list = new ListPrograms(dbType);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<Configurations>Debug;Release;PrgmList</Configurations>
|
||||
<ApplicationIcon>icons\back-end.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="icons\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 +21,11 @@
|
||||
<PackageReference Include="MySql.Data" Version="9.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Data.Sqlite">
|
||||
<HintPath>bin\Release\net6.0\Microsoft.Data.Sqlite.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
63
ProgrammList/Properties/Resources.Designer.cs
generated
Normal file
63
ProgrammList/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
101
ProgrammList/Properties/Resources.resx
Normal file
101
ProgrammList/Properties/Resources.resx
Normal file
@ -0,0 +1,101 @@
|
||||
<?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>
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.Win32;
|
||||
using ProgrammList.ConfigManager;
|
||||
using ProgrammList.sql;
|
||||
using System.Net;
|
||||
|
||||
@ -9,24 +10,33 @@ namespace ProgrammList.ListPrograms {
|
||||
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
|
||||
private SqlBase sql = null;
|
||||
|
||||
internal ListPrograms(string sqlType) {
|
||||
|
||||
internal ListPrograms(string sqlType, params string[] filename) {
|
||||
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)) {
|
||||
sql = new Mysql();
|
||||
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);
|
||||
}
|
||||
else if (sqlType.Equals("MSSQL", StringComparison.OrdinalIgnoreCase)) {
|
||||
sql = new Mssql();
|
||||
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);
|
||||
}
|
||||
else if (sqlType.Equals("SQLITE", StringComparison.OrdinalIgnoreCase)) {
|
||||
sql = new Sqlite(prgm_path);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,24 +3,44 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
|
||||
namespace ProgrammList.sql {
|
||||
public class Mssql : SqlBaseAbstract {
|
||||
public class Mssql : SqlBase {
|
||||
|
||||
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
|
||||
|
||||
SqlConnection mssqlcon = null;
|
||||
SqlConnectionStringBuilder builder;
|
||||
|
||||
|
||||
//private static Dbconnection instance;
|
||||
public Mssql() {
|
||||
var builder = new SqlConnectionStringBuilder {
|
||||
DataSource = "localhost",
|
||||
UserID = "sa",
|
||||
Password = "2677890E23",
|
||||
InitialCatalog = "prgmlist",
|
||||
public Mssql(String server, string user, string pw, string db) {
|
||||
builder = new SqlConnectionStringBuilder {
|
||||
DataSource = server,
|
||||
UserID = user,
|
||||
Password = pw,
|
||||
InitialCatalog = db,
|
||||
TrustServerCertificate = true
|
||||
};
|
||||
}
|
||||
|
||||
connstring = builder.ToString();
|
||||
|
||||
|
||||
public void Open() {
|
||||
try {
|
||||
mssqlcon = new SqlConnection(builder.ConnectionString);
|
||||
mssqlcon.Open();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
System.Environment.Exit(13);
|
||||
}
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
mssqlcon.Close();
|
||||
}
|
||||
|
||||
public void GetAllData() {
|
||||
Open(DB.MSSQL);
|
||||
var command = sqlcon.CreateCommand();
|
||||
Open();
|
||||
var command = mssqlcon.CreateCommand();
|
||||
command.CommandText = @"SELECT * FROM list";
|
||||
|
||||
using (var reader = command.ExecuteReader()) {
|
||||
@ -31,8 +51,8 @@ namespace ProgrammList.sql {
|
||||
Close();
|
||||
}
|
||||
public bool GetSingleLine(string pcid, string program, string version) {
|
||||
Open(DB.MSSQL);
|
||||
var command = sqlcon.CreateCommand();
|
||||
Open();
|
||||
var command = mssqlcon.CreateCommand();
|
||||
command.CommandText = @"SELECT * FROM list where PCID like "
|
||||
+ pcid + " and DisplayName like "
|
||||
+ program + " and DisplayVersion like " + version + ";";
|
||||
@ -43,8 +63,8 @@ namespace ProgrammList.sql {
|
||||
}
|
||||
|
||||
public void CheckTableExists() {
|
||||
Open(DB.MSSQL);
|
||||
var command = sqlcon.CreateCommand();
|
||||
Open();
|
||||
var command = mssqlcon.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";
|
||||
var returncode = command.ExecuteScalar();
|
||||
if (returncode != null) {
|
||||
@ -55,12 +75,7 @@ namespace ProgrammList.sql {
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
if (rc > 0) {
|
||||
Console.WriteLine("Creating table...");
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
var cols = string.Join(" VARCHAR(255),", valuenames);
|
||||
cols = cols + " Varchar(255)";
|
||||
@ -71,8 +86,8 @@ namespace ProgrammList.sql {
|
||||
|
||||
|
||||
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
||||
Open(DB.MSSQL);
|
||||
var transaction = sqlcon.BeginTransaction();
|
||||
Open();
|
||||
var transaction = mssqlcon.BeginTransaction();
|
||||
|
||||
string result = "";
|
||||
for (int i = 0; i < valuenames.Length; i++) {
|
||||
@ -88,10 +103,9 @@ namespace ProgrammList.sql {
|
||||
|
||||
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
|
||||
|
||||
var command = new SqlCommand(sqlCommand, sqlcon, transaction);
|
||||
var command = new SqlCommand(sqlCommand, mssqlcon, transaction);
|
||||
command.ExecuteNonQuery();
|
||||
transaction.Commit();
|
||||
Console.WriteLine(sqlCommand);
|
||||
Close();
|
||||
}
|
||||
|
||||
@ -105,8 +119,8 @@ namespace ProgrammList.sql {
|
||||
}
|
||||
|
||||
public void DeleteOldData(string hostname) {
|
||||
Open(DB.MSSQL);
|
||||
var command = sqlcon.CreateCommand();
|
||||
Open();
|
||||
var command = mssqlcon.CreateCommand();
|
||||
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
||||
command.CommandText = sqlCommand;
|
||||
command.ExecuteReader();
|
||||
@ -114,8 +128,8 @@ namespace ProgrammList.sql {
|
||||
}
|
||||
|
||||
public void UpdateData(Dictionary<string, string> value) {
|
||||
Open(DB.MSSQL);
|
||||
var transaction = sqlcon.BeginTransaction();
|
||||
Open();
|
||||
var transaction = mssqlcon.BeginTransaction();
|
||||
string sqlCommand = @"Update list ";
|
||||
|
||||
string result = "set ";
|
||||
@ -133,13 +147,12 @@ namespace ProgrammList.sql {
|
||||
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
|
||||
|
||||
|
||||
var command = new SqlCommand(sqlCommand, sqlcon, transaction);
|
||||
var command = new SqlCommand(sqlCommand, mssqlcon, transaction);
|
||||
for (int i = 0; i < valuenames.Length; i++) {
|
||||
if (valuenames[i] != "PCID") {
|
||||
command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
|
||||
}
|
||||
}
|
||||
Console.WriteLine(sqlCommand);
|
||||
command.ExecuteNonQuery();
|
||||
transaction.Commit();
|
||||
Close();
|
||||
|
@ -3,11 +3,19 @@
|
||||
namespace ProgrammList.sql {
|
||||
|
||||
|
||||
internal class Mysql : SqlBaseAbstract {
|
||||
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 Boolean GetSingleLine(string pcid, string program, string version) {
|
||||
Open(DB.MYSQL);
|
||||
Open();
|
||||
var command = mysqlcon.CreateCommand();
|
||||
command.CommandText = @"SELECT * FROM list where PCID like "
|
||||
+ pcid + " and DisplayName like "
|
||||
@ -18,10 +26,20 @@ namespace ProgrammList.sql {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void Open() {
|
||||
mysqlcon = new MySqlConnection(connstring);
|
||||
mysqlcon.Open();
|
||||
}
|
||||
|
||||
public void Close() {
|
||||
mysqlcon.Close();
|
||||
}
|
||||
|
||||
public void CheckTableExists() {
|
||||
Open(DB.MYSQL);
|
||||
Open();
|
||||
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;
|
||||
@ -35,7 +53,7 @@ namespace ProgrammList.sql {
|
||||
|
||||
|
||||
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
||||
Open(DB.MYSQL);
|
||||
Open();
|
||||
var transaction = mysqlcon.BeginTransaction();
|
||||
|
||||
string result = "";
|
||||
@ -55,7 +73,6 @@ namespace ProgrammList.sql {
|
||||
var command = new MySqlCommand(sqlCommand, mysqlcon, transaction);
|
||||
command.ExecuteNonQuery();
|
||||
transaction.Commit();
|
||||
Console.WriteLine(sqlCommand);
|
||||
Close();
|
||||
}
|
||||
|
||||
@ -69,7 +86,7 @@ namespace ProgrammList.sql {
|
||||
}
|
||||
|
||||
public void UpdateData(Dictionary<string, string> value) {
|
||||
Open(DB.MYSQL);
|
||||
Open();
|
||||
var transaction = mysqlcon.BeginTransaction();
|
||||
string sqlCommand = @"Update list ";
|
||||
|
||||
@ -94,7 +111,7 @@ namespace ProgrammList.sql {
|
||||
command.Parameters.AddWithValue("$" + valuenames[i], value.GetValueOrDefault(valuenames[i]));
|
||||
}
|
||||
}
|
||||
Console.WriteLine(sqlCommand);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
transaction.Commit();
|
||||
Close();
|
||||
@ -102,7 +119,7 @@ namespace ProgrammList.sql {
|
||||
|
||||
|
||||
public void DeleteOldData(string hostname) {
|
||||
Open(DB.MYSQL);
|
||||
Open();
|
||||
var command = mysqlcon.CreateCommand();
|
||||
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
||||
command.CommandText = sqlCommand;
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
interface SqlBase {
|
||||
|
||||
|
||||
internal void Open();
|
||||
internal void Close();
|
||||
internal bool GetSingleLine(string pcid, string program, string version);
|
||||
|
||||
internal void CheckTableExists();
|
||||
|
@ -1,86 +0,0 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using MySql.Data.MySqlClient;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
bool SqlBase.GetSingleLine(string pcid, string program, string version) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void SqlBase.CheckTableExists() {
|
||||
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.DeleteOldData(string hostname) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void SqlBase.UpdateData(Dictionary<string, string> value) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,45 @@
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System.Configuration;
|
||||
|
||||
namespace ProgrammList.sql {
|
||||
public class Sqlite : SqlBaseAbstract {
|
||||
public class Sqlite : SqlBase {
|
||||
|
||||
string filename;
|
||||
SqliteConnection sqlitecon;
|
||||
|
||||
public Sqlite(string prm_path) {
|
||||
sqlitecon = new SqliteConnection("Data Source=" + prm_path + ConfigurationManager.AppSettings["filename"]);
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
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 "
|
||||
@ -19,11 +47,12 @@ 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();
|
||||
@ -34,10 +63,12 @@ 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 = "";
|
||||
@ -55,32 +86,32 @@ 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"))) {
|
||||
|
||||
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 ";
|
||||
|
||||
@ -106,12 +137,13 @@ namespace ProgrammList.sql {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@ -121,6 +153,7 @@ namespace ProgrammList.sql {
|
||||
var name = reader.GetString(0);
|
||||
}
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
}
|
||||
|
32
README.md
32
README.md
@ -1 +1,31 @@
|
||||
# ProgrammList
|
||||
# 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.
|
||||
|
||||
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.
|
||||
|
||||
In later versions this should be made configurable through the app.conf file.
|
||||
|
||||
Plan for the future:
|
||||
- UI To configure the program through parameter, default will be cli auto run. there may be branches for winform vs wpf
|
||||
- Additional Database support and eventuall csv support. (
|
||||
- Depending on .net version (see branches) a portable version or installer.
|
||||
|
||||
# ProgrammList (GER)
|
||||
|
||||
Ein Programm zum erstellen einer Liste installierter Programme auf einem Rechner. Man kann das Programmm in einen Netzwerkordner legen um von mehreren Systemen die Information zu bekommen und diese Zentral zu Speichern.
|
||||
|
||||
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.
|
||||
|
||||
In Späteren Versionen sollte dies auch über das Config file editierbar sein.
|
||||
|
||||
Zukunftsplan:
|
||||
- Oberfläche zur Einrichtung der Konfigurationsdatei. Eventuell in eigenen Branches (WinForm vs WPF)
|
||||
- Zusätzliche Datenbanken und eventuell auch ein CSV report.
|
||||
- Je nach .net version, Portable single exe oder ein installer
|
||||
|
Loading…
x
Reference in New Issue
Block a user