Connection test working.
This commit is contained in:
parent
eed28664a6
commit
19f617780d
21
Voile.Patchouli/Data/VoileDataException.cs
Normal file
21
Voile.Patchouli/Data/VoileDataException.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Voile.Common;
|
||||||
|
|
||||||
|
namespace Voile.Patchouli.Data
|
||||||
|
{
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class VoileDataException : VoileException
|
||||||
|
{
|
||||||
|
public VoileDataException() { }
|
||||||
|
public VoileDataException(string message) : base(message) { }
|
||||||
|
public VoileDataException(string message, Exception inner) : base(message, inner) { }
|
||||||
|
protected VoileDataException(
|
||||||
|
System.Runtime.Serialization.SerializationInfo info,
|
||||||
|
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
63
Voile.Storage.Sqlite/SqliteDataStorage.cs
Normal file
63
Voile.Storage.Sqlite/SqliteDataStorage.cs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Voile.Patchouli.Data;
|
||||||
|
|
||||||
|
namespace Voile.Storage.Sqlite
|
||||||
|
{
|
||||||
|
internal class SqliteDataStorage : IVoileDataStorage
|
||||||
|
{
|
||||||
|
private readonly SqliteConnectionStringBuilder connectionStringBuilder;
|
||||||
|
|
||||||
|
public SqliteDataStorage(SqliteConnectionStringBuilder connectionStringBuilder)
|
||||||
|
{
|
||||||
|
this.connectionStringBuilder = connectionStringBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Exception Ping()
|
||||||
|
{
|
||||||
|
SqliteConnection conn = new SqliteConnection(connectionStringBuilder.ConnectionString);
|
||||||
|
conn.Open();
|
||||||
|
|
||||||
|
bool tableAlreadyExists = false;
|
||||||
|
|
||||||
|
using (SqliteCommand selectMaster = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
selectMaster.CommandText = "SELECT rootpage FROM sqlite_master WHERE name = 'a_connection_test'";
|
||||||
|
SqliteDataReader sqliteDataReader = selectMaster.ExecuteReader();
|
||||||
|
tableAlreadyExists = sqliteDataReader.Read();
|
||||||
|
sqliteDataReader.Close();
|
||||||
|
selectMaster.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tableAlreadyExists)
|
||||||
|
{
|
||||||
|
using (SqliteCommand createTableCommand = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
createTableCommand.CommandText = "create table a_connection_test\r\n(\r\n serial integer not null\r\n constraint a_connection_test_pk\r\n primary key autoincrement,\r\n dateadded TEXT default CURRENT_TIMESTAMP not null,\r\n hostname TEXT not null\r\n);\r\n\r\n";
|
||||||
|
int v = createTableCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using (SqliteCommand insertCommand = conn.CreateCommand())
|
||||||
|
{
|
||||||
|
insertCommand.CommandText = "INSERT INTO a_connection_test (hostname) VALUES (@hostname)";
|
||||||
|
insertCommand.Parameters.AddWithValue("@hostname", Environment.MachineName);
|
||||||
|
int v = insertCommand.ExecuteNonQuery();
|
||||||
|
if (v != 1)
|
||||||
|
{
|
||||||
|
insertCommand.Dispose();
|
||||||
|
conn.Dispose();
|
||||||
|
return new VoileDataException("Failed to do a test INSERT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.Close();
|
||||||
|
conn.Dispose();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,7 +19,18 @@ namespace Voile.Storage.Sqlite
|
|||||||
{
|
{
|
||||||
public IVoileDataStorage CreateDataStorage()
|
public IVoileDataStorage CreateDataStorage()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
if (string.IsNullOrEmpty(FilePath) || string.IsNullOrWhiteSpace(FilePath))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(String.Format("{0} should not be empty.", nameof(FilePath)));
|
||||||
|
}
|
||||||
|
if (scsb == null)
|
||||||
|
{
|
||||||
|
scsb = new SqliteConnectionStringBuilder();
|
||||||
|
scsb.DataSource = FilePath;
|
||||||
|
scsb.Mode = SqliteOpenMode.ReadWriteCreate;
|
||||||
|
scsb.Pooling = true;
|
||||||
|
}
|
||||||
|
return new SqliteDataStorage(scsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Description("The path to the SQLite database file. If it doesn't exist, it will be created")]
|
[Description("The path to the SQLite database file. If it doesn't exist, it will be created")]
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="10.0.2" />
|
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="10.0.2" />
|
||||||
|
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="3.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
8
Voile/FirstRunWizard.Designer.cs
generated
8
Voile/FirstRunWizard.Designer.cs
generated
@ -288,7 +288,7 @@
|
|||||||
// dbSettingsErrorLabel
|
// dbSettingsErrorLabel
|
||||||
//
|
//
|
||||||
dbSettingsErrorLabel.AutoSize = true;
|
dbSettingsErrorLabel.AutoSize = true;
|
||||||
dbSettingsErrorLabel.Location = new Point(3, 87);
|
dbSettingsErrorLabel.Location = new Point(3, 79);
|
||||||
dbSettingsErrorLabel.Name = "dbSettingsErrorLabel";
|
dbSettingsErrorLabel.Name = "dbSettingsErrorLabel";
|
||||||
dbSettingsErrorLabel.Size = new Size(74, 15);
|
dbSettingsErrorLabel.Size = new Size(74, 15);
|
||||||
dbSettingsErrorLabel.TabIndex = 9;
|
dbSettingsErrorLabel.TabIndex = 9;
|
||||||
@ -306,7 +306,7 @@
|
|||||||
//
|
//
|
||||||
// dbTestButton
|
// dbTestButton
|
||||||
//
|
//
|
||||||
dbTestButton.Location = new Point(252, 70);
|
dbTestButton.Location = new Point(3, 97);
|
||||||
dbTestButton.Name = "dbTestButton";
|
dbTestButton.Name = "dbTestButton";
|
||||||
dbTestButton.Size = new Size(93, 32);
|
dbTestButton.Size = new Size(93, 32);
|
||||||
dbTestButton.TabIndex = 2;
|
dbTestButton.TabIndex = 2;
|
||||||
@ -316,9 +316,9 @@
|
|||||||
//
|
//
|
||||||
// dbSettingsPropertyGrid
|
// dbSettingsPropertyGrid
|
||||||
//
|
//
|
||||||
dbSettingsPropertyGrid.Location = new Point(3, 108);
|
dbSettingsPropertyGrid.Location = new Point(3, 135);
|
||||||
dbSettingsPropertyGrid.Name = "dbSettingsPropertyGrid";
|
dbSettingsPropertyGrid.Name = "dbSettingsPropertyGrid";
|
||||||
dbSettingsPropertyGrid.Size = new Size(342, 273);
|
dbSettingsPropertyGrid.Size = new Size(342, 246);
|
||||||
dbSettingsPropertyGrid.TabIndex = 1;
|
dbSettingsPropertyGrid.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// label6
|
// label6
|
||||||
|
|||||||
@ -129,6 +129,7 @@ namespace Voile
|
|||||||
case 3:
|
case 3:
|
||||||
loadFileButton.Visible = selectedDataStorage.CanSaveFile.Enable;
|
loadFileButton.Visible = selectedDataStorage.CanSaveFile.Enable;
|
||||||
dbSettingsErrorLabel.Text = "";
|
dbSettingsErrorLabel.Text = "";
|
||||||
|
buttonNext.Enabled = dataStorageConnectionSucessful;
|
||||||
if (voileDataStorageFactory == null)
|
if (voileDataStorageFactory == null)
|
||||||
{
|
{
|
||||||
dbSettingsPropertyGrid.SelectedObject = selectedDataStorage.GetPluginInstance();
|
dbSettingsPropertyGrid.SelectedObject = selectedDataStorage.GetPluginInstance();
|
||||||
@ -224,28 +225,31 @@ namespace Voile
|
|||||||
|
|
||||||
private void buttonNext_Click(object sender, EventArgs e)
|
private void buttonNext_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (currentTabPage == 0)
|
switch (currentTabPage)
|
||||||
{
|
{
|
||||||
//Wir sind auf der Willkommensseite, hier wird ausgewählt ob Anfänger oder Experte.
|
case 0:
|
||||||
//Es wird nach der Lizenz gefragt
|
//Wir sind auf der Willkommensseite, hier wird ausgewählt ob Anfänger oder Experte.
|
||||||
DisplayTabPage(1);
|
//Es wird nach der Lizenz gefragt
|
||||||
}
|
DisplayTabPage(1);
|
||||||
else if (currentTabPage == 1)
|
break;
|
||||||
{
|
case 1:
|
||||||
//Hier soll der Nutzer auswählen ob einfach oder schwierig.
|
//Hier soll der Nutzer auswählen ob einfach oder schwierig.
|
||||||
if (beginnerMode)
|
if (beginnerMode)
|
||||||
{
|
{
|
||||||
//TODO: Automatisch SQLite und Directory Storage auswählen
|
//TODO: Automatisch SQLite und Directory Storage auswählen
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DisplayTabPage(2);
|
DisplayTabPage(2);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
else if (currentTabPage == 2)
|
case 2:
|
||||||
{
|
//Hier soll der Nutzer auswählen, welche DB verwendet werden soll.
|
||||||
//Hier soll der Nutzer auswählen, welche DB verwendet werden soll.
|
DisplayTabPage(3);
|
||||||
DisplayTabPage(3);
|
break;
|
||||||
|
default:
|
||||||
|
MessageBox.Show(String.Format("Don't know how to proceed from page {0}. This is a bug in Voile, please report it.", currentTabPage), "Voile onboarding", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +345,7 @@ namespace Voile
|
|||||||
{
|
{
|
||||||
dbSettingsErrorLabel.Text = "The selected plugin is not a Data Storage plugin. This is a bug in voile, please report it.";
|
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;
|
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
|
||||||
|
RefreshView();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
voileDataStorageFactory = newDs;
|
voileDataStorageFactory = newDs;
|
||||||
@ -355,6 +360,7 @@ namespace Voile
|
|||||||
{
|
{
|
||||||
dbSettingsErrorLabel.Text = ex.Message;
|
dbSettingsErrorLabel.Text = ex.Message;
|
||||||
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
|
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
|
||||||
|
RefreshView();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,6 +371,7 @@ namespace Voile
|
|||||||
{
|
{
|
||||||
dbSettingsErrorLabel.Text = pingResult.Message;
|
dbSettingsErrorLabel.Text = pingResult.Message;
|
||||||
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
|
dbTestTrafficLight.Image = Resources.TRFFC10C_1_32x32x4;
|
||||||
|
RefreshView();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,8 +383,9 @@ namespace Voile
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbSettingsErrorLabel.Text = "Database connection sucessful!";
|
dbSettingsErrorLabel.Text = "Database connection sucessful!";
|
||||||
pictureBox2.Image = Resources.TRFFC10A_1_32x32x4; //grüne Ampel
|
dbTestTrafficLight.Image = Resources.TRFFC10A_1_32x32x4; //grüne Ampel
|
||||||
dataStorageConnectionSucessful = true;
|
dataStorageConnectionSucessful = true;
|
||||||
|
RefreshView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonBack_Click(object sender, EventArgs e)
|
private void buttonBack_Click(object sender, EventArgs e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user