Testing database connection.

This commit is contained in:
Fey 2026-02-01 16:40:44 +01:00
parent c83d69a200
commit 20ee473fda
4 changed files with 427 additions and 307 deletions

View File

@ -8,5 +8,6 @@ namespace Voile.Patchouli.Data
{
public interface IVoileDataStorage
{
bool Ping();
}
}

View File

@ -1,6 +1,7 @@
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -12,7 +13,7 @@ namespace Voile.Storage.Sqlite
{
[VoilePlugin]
[VoilePluginId(3)]
[DisplayName("SQLite")]
[Voile.Patchouli.Reflection.DisplayName("SQLite")]
public class SqliteDataStorageFactory : IVoileDataStorageFactory
{
public IVoileDataStorage CreateDataStorage()
@ -20,6 +21,7 @@ namespace Voile.Storage.Sqlite
throw new NotImplementedException();
}
[Description("The path to the SQLite database file. If it doesn't exist, it will be created")]
public string FilePath { get; set; }
private SqliteConnectionStringBuilder scsb;

View File

@ -48,11 +48,15 @@
tabPagePickDataStorage = new TabPage();
labelDataStorageHint = new Label();
label5 = new Label();
tabPageConfigureDataStorage = new TabPage();
dbSettingsErrorLabel = new Label();
dbTestTrafficLight = new PictureBox();
dbTestButton = new Button();
dbSettingsPropertyGrid = new PropertyGrid();
label6 = new Label();
buttonNext = new Button();
buttonBack = new Button();
openFileDialogCertificate = new OpenFileDialog();
tabPageConfigureDataStorage = new TabPage();
label6 = new Label();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
tabControl1.SuspendLayout();
tabPageWelcome.SuspendLayout();
@ -60,6 +64,7 @@
((System.ComponentModel.ISupportInitialize)pictureBox2).BeginInit();
tabPagePickDataStorage.SuspendLayout();
tabPageConfigureDataStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dbTestTrafficLight).BeginInit();
SuspendLayout();
//
// pictureBox1
@ -265,6 +270,64 @@
label5.TabIndex = 0;
label5.Text = resources.GetString("label5.Text");
//
// tabPageConfigureDataStorage
//
tabPageConfigureDataStorage.Controls.Add(dbSettingsErrorLabel);
tabPageConfigureDataStorage.Controls.Add(dbTestTrafficLight);
tabPageConfigureDataStorage.Controls.Add(dbTestButton);
tabPageConfigureDataStorage.Controls.Add(dbSettingsPropertyGrid);
tabPageConfigureDataStorage.Controls.Add(label6);
tabPageConfigureDataStorage.Location = new Point(4, 24);
tabPageConfigureDataStorage.Name = "tabPageConfigureDataStorage";
tabPageConfigureDataStorage.Size = new Size(348, 384);
tabPageConfigureDataStorage.TabIndex = 3;
tabPageConfigureDataStorage.Text = "Configure Date Storage";
tabPageConfigureDataStorage.UseVisualStyleBackColor = true;
//
// dbSettingsErrorLabel
//
dbSettingsErrorLabel.AutoSize = true;
dbSettingsErrorLabel.Location = new Point(3, 70);
dbSettingsErrorLabel.Name = "dbSettingsErrorLabel";
dbSettingsErrorLabel.Size = new Size(77, 15);
dbSettingsErrorLabel.TabIndex = 9;
dbSettingsErrorLabel.Text = "TEST_RESULT";
//
// dbTestTrafficLight
//
dbTestTrafficLight.Image = Properties.Resources.SETUPAPI_18_1_32x32x4;
dbTestTrafficLight.Location = new Point(214, 70);
dbTestTrafficLight.Name = "dbTestTrafficLight";
dbTestTrafficLight.Size = new Size(32, 32);
dbTestTrafficLight.TabIndex = 8;
dbTestTrafficLight.TabStop = false;
//
// dbTestButton
//
dbTestButton.Location = new Point(252, 70);
dbTestButton.Name = "dbTestButton";
dbTestButton.Size = new Size(93, 32);
dbTestButton.TabIndex = 2;
dbTestButton.Text = "Test Settings";
dbTestButton.UseVisualStyleBackColor = true;
dbTestButton.Click += dbTestButton_Click;
//
// dbSettingsPropertyGrid
//
dbSettingsPropertyGrid.Location = new Point(3, 108);
dbSettingsPropertyGrid.Name = "dbSettingsPropertyGrid";
dbSettingsPropertyGrid.Size = new Size(342, 273);
dbSettingsPropertyGrid.TabIndex = 1;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(3, 0);
label6.Name = "label6";
label6.Size = new Size(38, 15);
label6.TabIndex = 0;
label6.Text = "label6";
//
// buttonNext
//
buttonNext.Enabled = false;
@ -293,25 +356,6 @@
openFileDialogCertificate.Filter = "X.509 Certificate (*.cer)|*.cer";
openFileDialogCertificate.Title = "Open Voile License File";
//
// tabPageConfigureDataStorage
//
tabPageConfigureDataStorage.Controls.Add(label6);
tabPageConfigureDataStorage.Location = new Point(4, 24);
tabPageConfigureDataStorage.Name = "tabPageConfigureDataStorage";
tabPageConfigureDataStorage.Size = new Size(348, 384);
tabPageConfigureDataStorage.TabIndex = 3;
tabPageConfigureDataStorage.Text = "Configure Date Storage";
tabPageConfigureDataStorage.UseVisualStyleBackColor = true;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(3, 0);
label6.Name = "label6";
label6.Size = new Size(38, 15);
label6.TabIndex = 0;
label6.Text = "label6";
//
// FirstRunWizard
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -338,6 +382,7 @@
tabPagePickDataStorage.PerformLayout();
tabPageConfigureDataStorage.ResumeLayout(false);
tabPageConfigureDataStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)dbTestTrafficLight).EndInit();
ResumeLayout(false);
}
@ -367,5 +412,9 @@
private Label labelDataStorageHint;
private TabPage tabPageConfigureDataStorage;
private Label label6;
private PropertyGrid dbSettingsPropertyGrid;
private Button dbTestButton;
private PictureBox dbTestTrafficLight;
private Label dbSettingsErrorLabel;
}
}

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Voile.Patchouli.Data;
using Voile.Patchouli.Reflection;
using Voile.Properties;
@ -34,6 +35,8 @@ namespace Voile
private X509Certificate licenseCertificate;
private bool sharewareMode;
private VoilePluginInfo selectedDataStorage;
private IVoileDataStorageFactory voileDataStorageFactory;
private bool dataStorageConnectionSucessful;
@ -86,7 +89,7 @@ namespace Voile
pictureBox2.Visible = radioButtonHasLicense.Checked;
if (pictureBox2.Visible)
{
switch(licenseState)
switch (licenseState)
{
case 0: //Noch nichts geladen.
pictureBox2.Image = Resources.SETUPAPI_18_1_32x32x4; //Fragezeichen
@ -122,6 +125,13 @@ namespace Voile
//TODO: Hier zusätzlich Lizenzvalidierung einfügen.
buttonNext.Enabled = selectedDataStorage != null;
break;
case 3:
dbSettingsErrorLabel.Text = "";
if (voileDataStorageFactory == null)
{
dbSettingsPropertyGrid.SelectedObject = selectedDataStorage.GetPluginInstance();
}
break;
default:
MessageBox.Show("Could not find handler for the current tab page.");
return;
@ -214,10 +224,13 @@ namespace Voile
{
if (currentTabPage == 0)
{
//Wir sind auf der Willkommensseite, hier wird ausgewählt ob Anfänger oder Experte.
//Es wird nach der Lizenz gefragt
DisplayTabPage(1);
}
else if (currentTabPage == 1)
{
//Hier soll der Nutzer auswählen ob einfach oder schwierig.
if (beginnerMode)
{
//TODO: Automatisch SQLite und Directory Storage auswählen
@ -227,6 +240,11 @@ namespace Voile
DisplayTabPage(2);
}
}
else if (currentTabPage == 2)
{
//Hier soll der Nutzer auswählen, welche DB verwendet werden soll.
DisplayTabPage(3);
}
}
private void buttonLoadLicenseFile_Click(object sender, EventArgs e)
@ -309,5 +327,55 @@ namespace Voile
RefreshView();
return;
}
private void dbTestButton_Click(object sender, EventArgs e)
{
dataStorageConnectionSucessful = false;
if (voileDataStorageFactory == null)
{
IVoileDataStorageFactory newDs = selectedDataStorage.GetPluginInstance() as IVoileDataStorageFactory;
if (newDs == null)
{
dbSettingsErrorLabel.Text = "The selected plugin is not a Data Storage plugin. This is a bug in voile, please report it.";
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
return;
}
voileDataStorageFactory = newDs;
}
IVoileDataStorage dataStorage = null;
try
{
dataStorage = voileDataStorageFactory.CreateDataStorage();
}
catch (Exception ex)
{
dbSettingsErrorLabel.Text = ex.Message;
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
return;
}
try
{
Exception pingResult = dataStorage.Ping();
if (pingResult != null)
{
dbSettingsErrorLabel.Text = pingResult.Message;
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
return;
}
}
catch (Exception ex2)
{
dbSettingsErrorLabel.Text = ex2.Message;
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
return;
}
dbSettingsErrorLabel.Text = "Database connection sucessful!";
pictureBox2.Image = Resources.TRFFC10A_1_32x32x4; //grüne Ampel
dataStorageConnectionSucessful = true;
}
}
}