Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
0a81086722 | |||
299e807e8a | |||
bdb9f412a1 | |||
6599e17a18 |
@ -15,8 +15,8 @@ Global
|
|||||||
Release|x64 = Release|x64
|
Release|x64 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Release|x64
|
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|Any CPU.Build.0 = Release|x64
|
{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.ActiveCfg = Debug|x64
|
||||||
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.Debug|x64.Build.0 = 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
|
{06D431CD-A938-4DFD-8D77-4C612FDAD914}.PrgmList|Any CPU.ActiveCfg = PrgmList|Any CPU
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
using System.Configuration;
|
using System;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace ProgrammList.ConfigManager {
|
namespace ProgrammList.ConfigManager {
|
||||||
public static class PrmListConfigManager {
|
public static class PrmListConfigManager {
|
||||||
|
|
||||||
public static string GetSetting(string key) {
|
public static string GetSetting(string key) {
|
||||||
try {
|
try {
|
||||||
if (!File.Exists(Directory.GetCurrentDirectory() + "\\app.conf")) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
||||||
|
Console.WriteLine("Loading " + Directory.GetCurrentDirectory() + "\\app.conf");
|
||||||
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
|
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
|
||||||
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
||||||
return config.AppSettings.Settings[key].Value;
|
return config.AppSettings.Settings[key].Value;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
System.Environment.Exit(13);
|
Console.WriteLine("Error on Key " + key + ": " + e.ToString());
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
return "13";
|
return "13";
|
||||||
}
|
}
|
||||||
@ -22,12 +23,14 @@ namespace ProgrammList.ConfigManager {
|
|||||||
public static void SetSetting(string key, string value) {
|
public static void SetSetting(string key, string value) {
|
||||||
try {
|
try {
|
||||||
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
||||||
|
Console.WriteLine("Loading " + Directory.GetCurrentDirectory() + "\\app.conf");
|
||||||
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
|
configMap.ExeConfigFilename = Directory.GetCurrentDirectory() + "\\app.conf";
|
||||||
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
||||||
config.AppSettings.Settings["key"].Value = value;
|
config.AppSettings.Settings["key"].Value = value;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
// Exception
|
Console.WriteLine("Error on Key " + key + ": " + e.ToString());
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
ProgrammList/Icons/prm_icon/back-end.ico
Normal file
BIN
ProgrammList/Icons/prm_icon/back-end.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
@ -1,16 +1,20 @@
|
|||||||
using ProgrammList.ConfigManager;
|
using ProgrammList.ConfigManager;
|
||||||
using ProgrammList.ListPrograms;
|
using ProgrammList.ListPrograms;
|
||||||
|
using System;
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
public static void Main(string[] args) {
|
public static void Main(string[] args) {
|
||||||
|
|
||||||
string dbType = PrmListConfigManager.GetSetting("DB_Type");
|
string dbType = PrmListConfigManager.GetSetting("DB_Type");
|
||||||
ListPrograms list = new ListPrograms(dbType);
|
ListPrograms list = new ListPrograms();
|
||||||
|
list.init();
|
||||||
|
Console.WriteLine("Deleting old data");
|
||||||
list.DeleteOldData();
|
list.DeleteOldData();
|
||||||
string keyname1 = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstal";
|
string keyname1 = "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstal";
|
||||||
|
Console.WriteLine("Searching for 32 bit");
|
||||||
list.createList(keyname1, "x86");
|
list.createList(keyname1, "x86");
|
||||||
string keyname2 = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
|
string keyname2 = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
|
||||||
|
Console.WriteLine("Searching for 64 bit");
|
||||||
list.createList(keyname2, "x64");
|
list.createList(keyname2, "x64");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,14 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<Nullable>disable</Nullable>
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<Platforms>AnyCPU;x64</Platforms>
|
<Platforms>AnyCPU;x64</Platforms>
|
||||||
<Configurations>Debug;Release;PrgmList</Configurations>
|
<Configurations>Debug;Release;PrgmList</Configurations>
|
||||||
<ApplicationIcon>icons\back-end.ico</ApplicationIcon>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="icons\back-end.ico" />
|
<Content Include="Icons\prm_icon\back-end.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -22,10 +20,28 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Microsoft.Data.Sqlite">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<HintPath>bin\Release\net6.0\Microsoft.Data.Sqlite.dll</HintPath>
|
<DesignTime>True</DesignTime>
|
||||||
</Reference>
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
</ItemGroup>
|
</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>
|
</Project>
|
||||||
|
63
ProgrammList/Properties/Resources.Designer.cs
generated
63
ProgrammList/Properties/Resources.Designer.cs
generated
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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>
|
|
@ -1,51 +1,46 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using ProgrammList.ConfigManager;
|
using ProgrammList.ConfigManager;
|
||||||
using ProgrammList.sql;
|
using ProgrammList.sql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace ProgrammList.ListPrograms {
|
namespace ProgrammList.ListPrograms {
|
||||||
internal class ListPrograms {
|
public class ListPrograms {
|
||||||
|
|
||||||
string prgm_path = Directory.GetCurrentDirectory() + "\\";
|
string prgm_path = Directory.GetCurrentDirectory() + "\\";
|
||||||
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
|
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
|
||||||
private SqlBase sql = null;
|
private SqlBase sql = null;
|
||||||
|
|
||||||
|
public void init() {
|
||||||
internal ListPrograms(string sqlType, params string[] filename) {
|
string sqlType = PrmListConfigManager.GetSetting("DB_Type");
|
||||||
if (sqlType == null) {
|
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();
|
throw new ArgumentNullException();
|
||||||
}
|
}
|
||||||
|
|
||||||
string sqlname = "";
|
|
||||||
if (sqlType.Equals("MYSQL", StringComparison.OrdinalIgnoreCase) || sqlType.Equals("MARIADB", StringComparison.OrdinalIgnoreCase)) {
|
if (sqlType.Equals("MYSQL", StringComparison.OrdinalIgnoreCase) || sqlType.Equals("MARIADB", StringComparison.OrdinalIgnoreCase)) {
|
||||||
string server = PrmListConfigManager.GetSetting("server");
|
sql = new Mysql();
|
||||||
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)) {
|
else if (sqlType.Equals("MSSQL", StringComparison.OrdinalIgnoreCase)) {
|
||||||
string server = PrmListConfigManager.GetSetting("server");
|
sql = new Mssql();
|
||||||
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) && filename != null) {
|
else if (sqlType.Equals("SQLITE", StringComparison.OrdinalIgnoreCase)) {
|
||||||
sql = new Sqlite(prgm_path, filename[0]);
|
sql = new Sqlite(prgm_path);
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Default sqlite im gleichen ordner
|
|
||||||
sql = new Sqlite(Directory.GetCurrentDirectory() + "\\sqllite.db");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void DeleteOldData() {
|
public void DeleteOldData() {
|
||||||
sql.CheckTableExists();
|
sql.CheckTableExists();
|
||||||
sql.DeleteOldData(Dns.GetHostName());
|
sql.DeleteOldData(Dns.GetHostName());
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void createList(string hkey, string bit) {
|
public void createList(string hkey, string bit) {
|
||||||
RegistryKey key = Registry.LocalMachine.OpenSubKey(hkey);
|
RegistryKey key = Registry.LocalMachine.OpenSubKey(hkey);
|
||||||
try {
|
try {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
@ -66,11 +61,11 @@ namespace ProgrammList.ListPrograms {
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = String.Join("", value.ToArray());
|
// result = String.Join("", value.ToArray());
|
||||||
|
//
|
||||||
if (result.EndsWith(",")) {
|
// if (result.EndsWith(",")) {
|
||||||
result = result.Remove(result.Length - 1);
|
// result = result.Remove(result.Length - 1);
|
||||||
}
|
// }
|
||||||
|
|
||||||
value.Add("PCID", "'" + Dns.GetHostName() + "'");
|
value.Add("PCID", "'" + Dns.GetHostName() + "'");
|
||||||
value.Add("update_date", "'" + DateTime.Now + "'");
|
value.Add("update_date", "'" + DateTime.Now + "'");
|
||||||
|
@ -1,46 +1,28 @@
|
|||||||
|
|
||||||
|
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace ProgrammList.sql {
|
namespace ProgrammList.sql {
|
||||||
public class Mssql : SqlBase {
|
public class Mssql : SqlBaseAbstract {
|
||||||
|
|
||||||
public string[] valuenames = { "PCID", "DisplayName", "DisplayVersion", "InstallDate", "update_date", "APP_Architecture" };
|
|
||||||
|
|
||||||
SqlConnection mssqlcon = null;
|
|
||||||
SqlConnectionStringBuilder builder;
|
|
||||||
|
|
||||||
|
|
||||||
//private static Dbconnection instance;
|
//private static Dbconnection instance;
|
||||||
public Mssql(String server, string user, string pw, string db) {
|
public Mssql() {
|
||||||
builder = new SqlConnectionStringBuilder {
|
var builder = new SqlConnectionStringBuilder {
|
||||||
DataSource = server,
|
DataSource = "localhost",
|
||||||
UserID = user,
|
UserID = "sa",
|
||||||
Password = pw,
|
Password = "2677890E23",
|
||||||
InitialCatalog = db,
|
InitialCatalog = "prgmlist",
|
||||||
TrustServerCertificate = true
|
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() {
|
public void GetAllData() {
|
||||||
Open();
|
Open(DB.MSSQL);
|
||||||
var command = mssqlcon.CreateCommand();
|
var command = sqlcon.CreateCommand();
|
||||||
command.CommandText = @"SELECT * FROM list";
|
command.CommandText = @"SELECT * FROM list";
|
||||||
|
|
||||||
using (var reader = command.ExecuteReader()) {
|
using (var reader = command.ExecuteReader()) {
|
||||||
@ -51,8 +33,8 @@ namespace ProgrammList.sql {
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
public bool GetSingleLine(string pcid, string program, string version) {
|
public bool GetSingleLine(string pcid, string program, string version) {
|
||||||
Open();
|
Open(DB.MSSQL);
|
||||||
var command = mssqlcon.CreateCommand();
|
var command = sqlcon.CreateCommand();
|
||||||
command.CommandText = @"SELECT * FROM list where PCID like "
|
command.CommandText = @"SELECT * FROM list where PCID like "
|
||||||
+ pcid + " and DisplayName like "
|
+ pcid + " and DisplayName like "
|
||||||
+ program + " and DisplayVersion like " + version + ";";
|
+ program + " and DisplayVersion like " + version + ";";
|
||||||
@ -63,9 +45,11 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void CheckTableExists() {
|
public void CheckTableExists() {
|
||||||
Open();
|
Open(DB.MSSQL);
|
||||||
var command = mssqlcon.CreateCommand();
|
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";
|
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();
|
var returncode = command.ExecuteScalar();
|
||||||
if (returncode != null) {
|
if (returncode != null) {
|
||||||
int rc;
|
int rc;
|
||||||
@ -75,8 +59,13 @@ namespace ProgrammList.sql {
|
|||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rc > 0) {
|
||||||
|
Console.WriteLine("Creating table...");
|
||||||
|
}
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
var cols = string.Join(" VARCHAR(255),", valuenames);
|
var cols = string.Join(" VARCHAR(255),", valuenames);
|
||||||
cols = cols + " Varchar(255)";
|
cols = cols + " Varchar(255)";
|
||||||
command.CommandText = "CREATE TABLE list (" + cols + ")";
|
command.CommandText = "CREATE TABLE list (" + cols + ")";
|
||||||
@ -86,12 +75,14 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
|
|
||||||
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
||||||
Open();
|
Open(DB.MSSQL);
|
||||||
var transaction = mssqlcon.BeginTransaction();
|
var transaction = sqlcon.BeginTransaction();
|
||||||
|
|
||||||
string result = "";
|
string result = "";
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
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) {
|
if (i < valuenames.Length - 1) {
|
||||||
result += ",";
|
result += ",";
|
||||||
@ -103,14 +94,21 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
|
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
|
||||||
|
|
||||||
var command = new SqlCommand(sqlCommand, mssqlcon, transaction);
|
var command = new SqlCommand(sqlCommand, sqlcon, transaction);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
|
Console.WriteLine(sqlCommand);
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertOrUpdateData(Dictionary<string, string> value) {
|
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);
|
UpdateData(value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -119,8 +117,8 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteOldData(string hostname) {
|
public void DeleteOldData(string hostname) {
|
||||||
Open();
|
Open(DB.MSSQL);
|
||||||
var command = mssqlcon.CreateCommand();
|
var command = sqlcon.CreateCommand();
|
||||||
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
||||||
command.CommandText = sqlCommand;
|
command.CommandText = sqlCommand;
|
||||||
command.ExecuteReader();
|
command.ExecuteReader();
|
||||||
@ -128,13 +126,15 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateData(Dictionary<string, string> value) {
|
public void UpdateData(Dictionary<string, string> value) {
|
||||||
Open();
|
Open(DB.MSSQL);
|
||||||
var transaction = mssqlcon.BeginTransaction();
|
var transaction = sqlcon.BeginTransaction();
|
||||||
string sqlCommand = @"Update list ";
|
string sqlCommand = @"Update list ";
|
||||||
|
|
||||||
string result = "set ";
|
string result = "set ";
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
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) {
|
if (i < valuenames.Length - 1) {
|
||||||
result += " ,";
|
result += " ,";
|
||||||
@ -142,17 +142,26 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sqlCommand = sqlCommand + result;
|
sqlCommand = sqlCommand + result;
|
||||||
sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
|
string pcid = "";
|
||||||
" and DisplayName like " + value.GetValueOrDefault("DisplayName") +
|
value.TryGetValue("PCID", out pcid);
|
||||||
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
|
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++) {
|
for (int i = 0; i < valuenames.Length; i++) {
|
||||||
if (valuenames[i] != "PCID") {
|
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();
|
command.ExecuteNonQuery();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
Close();
|
Close();
|
||||||
|
@ -1,21 +1,15 @@
|
|||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace ProgrammList.sql {
|
namespace ProgrammList.sql {
|
||||||
|
|
||||||
|
|
||||||
internal class Mysql : SqlBase {
|
public class Mysql : SqlBaseAbstract {
|
||||||
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) {
|
public Boolean GetSingleLine(string pcid, string program, string version) {
|
||||||
Open();
|
Open(DB.MYSQL);
|
||||||
var command = mysqlcon.CreateCommand();
|
var command = mysqlcon.CreateCommand();
|
||||||
command.CommandText = @"SELECT * FROM list where PCID like "
|
command.CommandText = @"SELECT * FROM list where PCID like "
|
||||||
+ pcid + " and DisplayName like "
|
+ pcid + " and DisplayName like "
|
||||||
@ -26,20 +20,10 @@ namespace ProgrammList.sql {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Open() {
|
|
||||||
mysqlcon = new MySqlConnection(connstring);
|
|
||||||
mysqlcon.Open();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Close() {
|
|
||||||
mysqlcon.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CheckTableExists() {
|
public void CheckTableExists() {
|
||||||
Open();
|
Open(DB.MYSQL);
|
||||||
var command = mysqlcon.CreateCommand();
|
var command = mysqlcon.CreateCommand();
|
||||||
command.CommandText = "SHOW TABLES LIKE 'list';";
|
command.CommandText = @"SHOW TABLES LIKE 'list';";
|
||||||
var name = command.ExecuteScalar();
|
var name = command.ExecuteScalar();
|
||||||
if (name != null && name.ToString() == "list") {
|
if (name != null && name.ToString() == "list") {
|
||||||
return;
|
return;
|
||||||
@ -53,12 +37,14 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
|
|
||||||
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
||||||
Open();
|
Open(DB.MYSQL);
|
||||||
var transaction = mysqlcon.BeginTransaction();
|
var transaction = mysqlcon.BeginTransaction();
|
||||||
|
|
||||||
string result = "";
|
string result = "";
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
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) {
|
if (i < valuenames.Length - 1) {
|
||||||
result += ",";
|
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 + ")";
|
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
|
||||||
|
|
||||||
var command = new MySqlCommand(sqlCommand, mysqlcon, transaction);
|
var command = new MySqlCommand(sqlCommand, mysqlcon, transaction);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
|
Console.WriteLine(sqlCommand);
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertOrUpdateData(Dictionary<string, string> value) {
|
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);
|
UpdateData(value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -86,13 +79,15 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateData(Dictionary<string, string> value) {
|
public void UpdateData(Dictionary<string, string> value) {
|
||||||
Open();
|
Open(DB.MYSQL);
|
||||||
var transaction = mysqlcon.BeginTransaction();
|
var transaction = mysqlcon.BeginTransaction();
|
||||||
string sqlCommand = @"Update list ";
|
string sqlCommand = @"Update list ";
|
||||||
|
|
||||||
string result = "set ";
|
string result = "set ";
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
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) {
|
if (i < valuenames.Length - 1) {
|
||||||
result += " ,";
|
result += " ,";
|
||||||
@ -100,18 +95,26 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sqlCommand = sqlCommand + result;
|
sqlCommand = sqlCommand + result;
|
||||||
sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
|
string pcid = "";
|
||||||
" and DisplayName like " + value.GetValueOrDefault("DisplayName") +
|
value.TryGetValue("PCID", out pcid);
|
||||||
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
|
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);
|
var command = new MySqlCommand(sqlCommand, mysqlcon, transaction);
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
for (int i = 0; i < valuenames.Length; i++) {
|
||||||
if (valuenames[i] != "PCID") {
|
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();
|
command.ExecuteNonQuery();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
Close();
|
Close();
|
||||||
@ -119,7 +122,7 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
|
|
||||||
public void DeleteOldData(string hostname) {
|
public void DeleteOldData(string hostname) {
|
||||||
Open();
|
Open(DB.MYSQL);
|
||||||
var command = mysqlcon.CreateCommand();
|
var command = mysqlcon.CreateCommand();
|
||||||
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
||||||
command.CommandText = sqlCommand;
|
command.CommandText = sqlCommand;
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
namespace ProgrammList.sql {
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ProgrammList.sql {
|
||||||
|
|
||||||
interface SqlBase {
|
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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
88
ProgrammList/sql/SqlBaseAbstract.cs
Normal file
88
ProgrammList/sql/SqlBaseAbstract.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,45 +1,19 @@
|
|||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
|
||||||
namespace ProgrammList.sql {
|
namespace ProgrammList.sql {
|
||||||
public class Sqlite : SqlBase {
|
public class Sqlite : SqlBaseAbstract {
|
||||||
|
|
||||||
string filename;
|
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) {
|
public Sqlite(string prm_path) {
|
||||||
string setting = ConfigManager.PrmListConfigManager.GetSetting("filename");
|
sqlitecon = new SqliteConnection("Data Source=" + prm_path + ConfigurationManager.AppSettings["filename"]);
|
||||||
if (setting != null && setting != "") {
|
sqlitecon.Open();
|
||||||
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) {
|
public bool GetSingleLine(string pcid, string program, string version) {
|
||||||
Open();
|
|
||||||
var command = sqlitecon.CreateCommand();
|
var command = sqlitecon.CreateCommand();
|
||||||
command.CommandText = @"SELECT * FROM list where PCID like "
|
command.CommandText = @"SELECT * FROM list where PCID like "
|
||||||
+ pcid + " and DisplayName like "
|
+ pcid + " and DisplayName like "
|
||||||
@ -47,12 +21,11 @@ namespace ProgrammList.sql {
|
|||||||
|
|
||||||
|
|
||||||
bool result = command.ExecuteReader().Read();
|
bool result = command.ExecuteReader().Read();
|
||||||
Close();
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckTableExists() {
|
public void CheckTableExists() {
|
||||||
Open();
|
|
||||||
var command = sqlitecon.CreateCommand();
|
var command = sqlitecon.CreateCommand();
|
||||||
command.CommandText = @"SELECT name FROM sqlite_master WHERE type='table' AND name='list';";
|
command.CommandText = @"SELECT name FROM sqlite_master WHERE type='table' AND name='list';";
|
||||||
var name = command.ExecuteScalar();
|
var name = command.ExecuteScalar();
|
||||||
@ -63,17 +36,16 @@ namespace ProgrammList.sql {
|
|||||||
cols = cols + " Varchar";
|
cols = cols + " Varchar";
|
||||||
command.CommandText = "CREATE TABLE list (" + cols + ")";
|
command.CommandText = "CREATE TABLE list (" + cols + ")";
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
public void InsertData(Dictionary<string, string> valuesqlCommand) {
|
||||||
Open();
|
|
||||||
var transaction = sqlitecon.BeginTransaction();
|
var transaction = sqlitecon.BeginTransaction();
|
||||||
|
|
||||||
string result = "";
|
string result = "";
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
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) {
|
if (i < valuenames.Length - 1) {
|
||||||
result += ",";
|
result += ",";
|
||||||
@ -86,38 +58,46 @@ namespace ProgrammList.sql {
|
|||||||
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
|
string sqlCommand = "INSERT INTO list(" + cols + ")" + "VALUES(" + result + ")";
|
||||||
SqliteConnection con;
|
SqliteConnection con;
|
||||||
var command = new SqliteCommand(sqlCommand, sqlitecon, transaction);
|
var command = new SqliteCommand(sqlCommand, sqlitecon, transaction);
|
||||||
|
Console.WriteLine(sqlCommand);
|
||||||
command.ExecuteNonQuery();
|
command.ExecuteNonQuery();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertOrUpdateData(Dictionary<string, string> value) {
|
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);
|
UpdateData(value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
Console.WriteLine("Insert");
|
||||||
InsertData(value);
|
InsertData(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteOldData(string hostname) {
|
public void DeleteOldData(string hostname) {
|
||||||
Open();
|
|
||||||
var command = sqlitecon.CreateCommand();
|
var command = sqlitecon.CreateCommand();
|
||||||
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
string sqlCommand = @"delete from list where PCID = '" + hostname + "';";
|
||||||
command.CommandText = sqlCommand;
|
command.CommandText = sqlCommand;
|
||||||
command.ExecuteReader();
|
command.ExecuteReader();
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateData(Dictionary<string, string> value) {
|
public void UpdateData(Dictionary<string, string> value) {
|
||||||
Open();
|
|
||||||
var transaction = sqlitecon.BeginTransaction();
|
var transaction = sqlitecon.BeginTransaction();
|
||||||
string sqlCommand = @"Update list ";
|
string sqlCommand = @"Update list ";
|
||||||
|
|
||||||
string result = "set ";
|
string result = "set ";
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
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) {
|
if (i < valuenames.Length - 1) {
|
||||||
result += " ,";
|
result += " ,";
|
||||||
@ -125,25 +105,32 @@ namespace ProgrammList.sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sqlCommand = sqlCommand + result;
|
sqlCommand = sqlCommand + result;
|
||||||
sqlCommand = sqlCommand + " WHERE PCID = " + value.GetValueOrDefault("PCID") +
|
string pcid = "";
|
||||||
" and DisplayName like " + value.GetValueOrDefault("DisplayName") +
|
value.TryGetValue("PCID", out pcid);
|
||||||
" and DisplayVersion like " + value.GetValueOrDefault("DisplayVersion");
|
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);
|
var command = new SqliteCommand(sqlCommand, sqlitecon, transaction);
|
||||||
for (int i = 0; i < valuenames.Length; i++) {
|
for (int i = 0; i < valuenames.Length; i++) {
|
||||||
if (valuenames[i] != "PCID") {
|
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();
|
command.ExecuteNonQuery();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteData(string id) {
|
public void DeleteData(string id) {
|
||||||
Open();
|
|
||||||
var command = sqlitecon.CreateCommand();
|
var command = sqlitecon.CreateCommand();
|
||||||
command.CommandText = @"SELECT name FROM user WHERE id = $id";
|
command.CommandText = @"SELECT name FROM user WHERE id = $id";
|
||||||
command.Parameters.AddWithValue("$id", id);
|
command.Parameters.AddWithValue("$id", id);
|
||||||
@ -153,7 +140,6 @@ namespace ProgrammList.sql {
|
|||||||
var name = reader.GetString(0);
|
var name = reader.GetString(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
# ProgrammList (EN)
|
# 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.
|
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.
|
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 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.
|
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.
|
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 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.
|
In Späteren Versionen sollte dies auch über das Config file editierbar sein.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user