Added a page to configure the database.
This commit is contained in:
parent
20ee473fda
commit
eed28664a6
1
.gitignore
vendored
1
.gitignore
vendored
@ -38,3 +38,4 @@
|
||||
/Voile.Storage.SqlServer/bin/Debug/net8.0
|
||||
/Voile.Storage.Sqlite/obj
|
||||
/Voile.Storage.Sqlite/bin/Debug/net8.0
|
||||
/.vs/Voile/CopilotIndices/17.14.1577.30250
|
||||
|
||||
@ -8,6 +8,6 @@ namespace Voile.Patchouli.Data
|
||||
{
|
||||
public interface IVoileDataStorage
|
||||
{
|
||||
bool Ping();
|
||||
Exception Ping();
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,5 +8,6 @@ namespace Voile.Patchouli.Data
|
||||
{
|
||||
public interface IVoileObjectStorage
|
||||
{
|
||||
Exception Ping();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Voile.Patchouli.Reflection
|
||||
{
|
||||
|
||||
[System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class VoilePluginCanSaveFileAttribute : Attribute
|
||||
{
|
||||
public VoilePluginCanSaveFileAttribute(bool enable, string filter, CanSaveFileMode mode = CanSaveFileMode.SaveFile, bool fileMustExist = false)
|
||||
{
|
||||
Enable = enable;
|
||||
Filter = filter;
|
||||
Mode = mode;
|
||||
FileMustExist = fileMustExist;
|
||||
}
|
||||
|
||||
public bool Enable { get; }
|
||||
public string Filter { get; }
|
||||
public CanSaveFileMode Mode { get; }
|
||||
public bool FileMustExist { get; }
|
||||
}
|
||||
|
||||
public enum CanSaveFileMode
|
||||
{
|
||||
OpenFile = 0,
|
||||
SaveFile = 1,
|
||||
Directory = 2
|
||||
}
|
||||
}
|
||||
@ -131,5 +131,26 @@ namespace Voile.Patchouli.Reflection
|
||||
return Description;
|
||||
}
|
||||
}
|
||||
|
||||
private VoilePluginCanSaveFileAttribute _canSaveFile;
|
||||
public VoilePluginCanSaveFileAttribute CanSaveFile
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_canSaveFile == null)
|
||||
{
|
||||
VoilePluginCanSaveFileAttribute child = Type.GetCustomAttribute<VoilePluginCanSaveFileAttribute>();
|
||||
if (child != null)
|
||||
{
|
||||
_canSaveFile = child;
|
||||
}
|
||||
else
|
||||
{
|
||||
_canSaveFile = new VoilePluginCanSaveFileAttribute(false, null);
|
||||
}
|
||||
}
|
||||
return _canSaveFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ namespace Voile.Storage.Sqlite
|
||||
[VoilePlugin]
|
||||
[VoilePluginId(3)]
|
||||
[Voile.Patchouli.Reflection.DisplayName("SQLite")]
|
||||
[VoilePluginCanSaveFile(true,"SQLite3 Database (*.db)|*.db",CanSaveFileMode.SaveFile,false)]
|
||||
public class SqliteDataStorageFactory : IVoileDataStorageFactory
|
||||
{
|
||||
public IVoileDataStorage CreateDataStorage()
|
||||
|
||||
31
Voile/FirstRunWizard.Designer.cs
generated
31
Voile/FirstRunWizard.Designer.cs
generated
@ -57,6 +57,7 @@
|
||||
buttonNext = new Button();
|
||||
buttonBack = new Button();
|
||||
openFileDialogCertificate = new OpenFileDialog();
|
||||
loadFileButton = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||
tabControl1.SuspendLayout();
|
||||
tabPageWelcome.SuspendLayout();
|
||||
@ -108,7 +109,7 @@
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(6, 3);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(329, 240);
|
||||
label2.Size = new Size(328, 240);
|
||||
label2.TabIndex = 3;
|
||||
label2.Text = resources.GetString("label2.Text");
|
||||
//
|
||||
@ -126,7 +127,7 @@
|
||||
radioButtonAmExpert.AutoSize = true;
|
||||
radioButtonAmExpert.Location = new Point(6, 271);
|
||||
radioButtonAmExpert.Name = "radioButtonAmExpert";
|
||||
radioButtonAmExpert.Size = new Size(298, 34);
|
||||
radioButtonAmExpert.Size = new Size(299, 34);
|
||||
radioButtonAmExpert.TabIndex = 1;
|
||||
radioButtonAmExpert.Text = "I’m an expert. Let me choose my own database and \r\nstorage options.";
|
||||
radioButtonAmExpert.UseVisualStyleBackColor = true;
|
||||
@ -257,7 +258,7 @@
|
||||
labelDataStorageHint.AutoSize = true;
|
||||
labelDataStorageHint.Location = new Point(3, 165);
|
||||
labelDataStorageHint.Name = "labelDataStorageHint";
|
||||
labelDataStorageHint.Size = new Size(124, 15);
|
||||
labelDataStorageHint.Size = new Size(121, 15);
|
||||
labelDataStorageHint.TabIndex = 1;
|
||||
labelDataStorageHint.Text = "DATA_STORAGE_HINT";
|
||||
//
|
||||
@ -287,20 +288,21 @@
|
||||
// dbSettingsErrorLabel
|
||||
//
|
||||
dbSettingsErrorLabel.AutoSize = true;
|
||||
dbSettingsErrorLabel.Location = new Point(3, 70);
|
||||
dbSettingsErrorLabel.Location = new Point(3, 87);
|
||||
dbSettingsErrorLabel.Name = "dbSettingsErrorLabel";
|
||||
dbSettingsErrorLabel.Size = new Size(77, 15);
|
||||
dbSettingsErrorLabel.Size = new Size(74, 15);
|
||||
dbSettingsErrorLabel.TabIndex = 9;
|
||||
dbSettingsErrorLabel.Text = "TEST_RESULT";
|
||||
//
|
||||
// dbTestTrafficLight
|
||||
//
|
||||
dbTestTrafficLight.Image = Properties.Resources.SETUPAPI_18_1_32x32x4;
|
||||
dbTestTrafficLight.Location = new Point(214, 70);
|
||||
dbTestTrafficLight.Location = new Point(313, 34);
|
||||
dbTestTrafficLight.Name = "dbTestTrafficLight";
|
||||
dbTestTrafficLight.Size = new Size(32, 32);
|
||||
dbTestTrafficLight.TabIndex = 8;
|
||||
dbTestTrafficLight.TabStop = false;
|
||||
dbTestTrafficLight.Click += dbTestTrafficLight_Click;
|
||||
//
|
||||
// dbTestButton
|
||||
//
|
||||
@ -324,9 +326,9 @@
|
||||
label6.AutoSize = true;
|
||||
label6.Location = new Point(3, 0);
|
||||
label6.Name = "label6";
|
||||
label6.Size = new Size(38, 15);
|
||||
label6.Size = new Size(394, 75);
|
||||
label6.TabIndex = 0;
|
||||
label6.Text = "label6";
|
||||
label6.Text = "Here are the configuration options for the database engine you selected. \r\n\r\nAdjust the settings as needed, and when you're ready, \r\nclick \"Test Settings\" to verify the connection before \r\nmoving on.";
|
||||
//
|
||||
// buttonNext
|
||||
//
|
||||
@ -348,6 +350,7 @@
|
||||
buttonBack.TabIndex = 3;
|
||||
buttonBack.Text = "< Back";
|
||||
buttonBack.UseVisualStyleBackColor = true;
|
||||
buttonBack.Click += buttonBack_Click;
|
||||
//
|
||||
// openFileDialogCertificate
|
||||
//
|
||||
@ -356,11 +359,22 @@
|
||||
openFileDialogCertificate.Filter = "X.509 Certificate (*.cer)|*.cer";
|
||||
openFileDialogCertificate.Title = "Open Voile License File";
|
||||
//
|
||||
// loadFileButton
|
||||
//
|
||||
loadFileButton.Location = new Point(257, 430);
|
||||
loadFileButton.Name = "loadFileButton";
|
||||
loadFileButton.Size = new Size(75, 23);
|
||||
loadFileButton.TabIndex = 4;
|
||||
loadFileButton.Text = "Load File";
|
||||
loadFileButton.UseVisualStyleBackColor = true;
|
||||
loadFileButton.Click += loadFileButton_Click;
|
||||
//
|
||||
// FirstRunWizard
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(502, 465);
|
||||
Controls.Add(loadFileButton);
|
||||
Controls.Add(buttonBack);
|
||||
Controls.Add(buttonNext);
|
||||
Controls.Add(tabControl1);
|
||||
@ -416,5 +430,6 @@
|
||||
private Button dbTestButton;
|
||||
private PictureBox dbTestTrafficLight;
|
||||
private Label dbSettingsErrorLabel;
|
||||
private Button loadFileButton;
|
||||
}
|
||||
}
|
||||
@ -41,12 +41,12 @@ namespace Voile
|
||||
|
||||
|
||||
|
||||
public void DisplayTabPage(int target, bool isGoingBack = false)
|
||||
public void DisplayTabPage(int target)
|
||||
{
|
||||
if (pastPages == null)
|
||||
pastPages = new Stack<int>();
|
||||
else
|
||||
pastPages.Push(target);
|
||||
pastPages.Push(currentTabPage);
|
||||
|
||||
if (allPages == null)
|
||||
{
|
||||
@ -65,6 +65,7 @@ namespace Voile
|
||||
|
||||
void RefreshView()
|
||||
{
|
||||
loadFileButton.Visible = false;
|
||||
buttonBack.Enabled = false;
|
||||
buttonNext.Enabled = false;
|
||||
|
||||
@ -126,6 +127,7 @@ namespace Voile
|
||||
buttonNext.Enabled = selectedDataStorage != null;
|
||||
break;
|
||||
case 3:
|
||||
loadFileButton.Visible = selectedDataStorage.CanSaveFile.Enable;
|
||||
dbSettingsErrorLabel.Text = "";
|
||||
if (voileDataStorageFactory == null)
|
||||
{
|
||||
@ -377,5 +379,74 @@ namespace Voile
|
||||
pictureBox2.Image = Resources.TRFFC10A_1_32x32x4; //grüne Ampel
|
||||
dataStorageConnectionSucessful = true;
|
||||
}
|
||||
|
||||
private void buttonBack_Click(object sender, EventArgs e)
|
||||
{
|
||||
int previousTabPageId = pastPages.Pop();
|
||||
|
||||
tabControl1.TabPages.Clear();
|
||||
tabControl1.TabPages.Add(allPages[previousTabPageId]);
|
||||
currentTabPage = previousTabPageId;
|
||||
RefreshView();
|
||||
}
|
||||
|
||||
private void loadFileButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
switch (currentTabPage)
|
||||
{
|
||||
case 3:
|
||||
VoilePluginCanSaveFileAttribute canSaveFile = selectedDataStorage.CanSaveFile;
|
||||
switch (canSaveFile.Mode)
|
||||
{
|
||||
case CanSaveFileMode.SaveFile:
|
||||
SaveFileDialog sfd = new SaveFileDialog();
|
||||
sfd.Filter = canSaveFile.Filter;
|
||||
sfd.OverwritePrompt = canSaveFile.FileMustExist;
|
||||
DialogResult dialogResult = sfd.ShowDialog(this);
|
||||
if (dialogResult == DialogResult.OK)
|
||||
{
|
||||
if (voileDataStorageFactory == null)
|
||||
{
|
||||
voileDataStorageFactory = selectedDataStorage.GetPluginInstance() as IVoileDataStorageFactory;
|
||||
}
|
||||
SetFileNameProperty(voileDataStorageFactory, sfd.FileName);
|
||||
dbSettingsPropertyGrid.Refresh();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
MessageBox.Show(this, String.Format("Don't know what to do with a {1} dialog on page {0}.", currentTabPage, canSaveFile.Mode), allPages[currentTabPage].Text, MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
MessageBox.Show(this, String.Format("Don't know what to do on page {0}", currentTabPage), allPages[currentTabPage].Text, MessageBoxButtons.OK, MessageBoxIcon.Hand);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetFileNameProperty(object voilePlugin, string targetFileName)
|
||||
{
|
||||
Type type = voilePlugin.GetType();
|
||||
|
||||
System.Reflection.PropertyInfo[] propertyInfos = type.GetProperties();
|
||||
foreach (System.Reflection.PropertyInfo propertyInfo in propertyInfos)
|
||||
{
|
||||
if (!propertyInfo.CanWrite)
|
||||
continue;
|
||||
|
||||
string name = propertyInfo.Name.ToLower();
|
||||
switch (name)
|
||||
{
|
||||
case "filepath":
|
||||
propertyInfo.SetValue(voilePlugin, targetFileName, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dbTestTrafficLight_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("Adjust the settings as needed, and when you're ready, click \"Test Settings\" to verify the connection before moving on.", string.Format("Configuring {0}", selectedDataStorage.DisplayName),MessageBoxButtons.OK,MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,5 +15,10 @@ namespace Voile.Persistence
|
||||
}
|
||||
|
||||
public DirectoryInfo Directory { get; }
|
||||
|
||||
public Exception Ping()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user