Skip to content

Commit

Permalink
Merge sql server pull request from perago-cymru/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
glenatron authored Mar 21, 2022
2 parents 6fd3722 + a960c5f commit e9e7a7a
Show file tree
Hide file tree
Showing 51 changed files with 1,992 additions and 556 deletions.
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,20 @@ paket-files/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
/Downloaded

# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*

# Downloaded data files
*/Downloaded

# Secondary installer executables

*.exe
27 changes: 18 additions & 9 deletions MCS-Extractor-Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'
xmlns:ui='http://schemas.microsoft.com/wix/UIExtension'>
<Product Id="755303bf-ad0e-47bd-b32e-51ddb8ff7dad" Name="MCS_Extractor_Installer"
Language="1033" Version="1.0.2.0" Manufacturer="Perago-Wales"
Language="1033" Version="1.0.4.0" Manufacturer="Perago-Wales"
UpgradeCode="759fdfe9-5cc7-46f4-9e59-15805e3f8f64">

<Package
Expand All @@ -15,14 +15,15 @@

<Feature Id="ProductFeature" Title="MCS_Extractor_Installer" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentGroupRef Id="SQLComponents" />
<ComponentGroupRef Id="PGSQLComponents" />
<ComponentGroupRef Id="MSSQLComponents" />
<ComponentGroupRef Id="DownloadFolderGroup" />
</Feature>

<Property Id="POSTGRESUSERNAME" Value="postgres" />
<Property Id="POSTGRESPASSWORD" Secure="yes" Value=" " />
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<Property Id="SQLPATH">$(var.MCS-Extractor.ProjectDir)\Sql\database.sql</Property>
<Property Id="SQLPATH">$(var.MCS-Extractor.ProjectDir)\Sql\postgres\database.sql</Property>
<Property Id="MsiLogging" Value="v" />

<UIRef Id="WixUI_InstallDir" />
Expand All @@ -33,7 +34,10 @@
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MCS Extractor" >
<Directory Id="SQLFolder" Name="Sql" />
<Directory Id="SQLFolder" Name="Sql">
<Directory Id="PostgresFolder" Name="postgres" />
<Directory Id="MSSQLFolder" Name="mssql" />
</Directory>
<Directory Id="DownloadFolder" Name="Downloaded" >
</Directory>
</Directory>
Expand All @@ -47,12 +51,17 @@
<File Id="MCSExtractorExe" Name="MCS_Extractor.exe" DiskId="1" Source="$(var.MCS-Extractor.TargetPath)" KeyPath="yes" />
</Component>
</ComponentGroup>
<ComponentGroup Id="SQLComponents" Directory="SQLFolder" >
<Component Id="TemplateSQLComponent" Guid="666eb58a-018d-4ca2-bf55-24c4dd4edc40" >
<File Id="TemplateSQL" Name="template.sql" DiskId="1" Source="$(var.MCS-Extractor.ProjectDir)\Sql\template.sql" KeyPath="no" />
<ComponentGroup Id="PGSQLComponents" Directory="PostgresFolder" >
<Component Id="PGTemplateSQLComponent" Guid="666eb58a-018d-4ca2-bf55-24c4dd4edc40" >
<File Id="PGTemplateSQL" Name="template.sql" DiskId="1" Source="$(var.MCS-Extractor.ProjectDir)\Sql\postgres\template.sql" KeyPath="no" />
</Component>
<Component Id="DatabaseSQLComponent" Guid="678bd34f-4364-41e4-aa71-0dea0d6e00f1" >
<File Id="DatabaseSQL" Name="database.sql" DiskId="1" Source="$(var.MCS-Extractor.ProjectDir)\Sql\database.sql" KeyPath="no" />
<Component Id="PGDatabaseSQLComponent" Guid="678bd34f-4364-41e4-aa71-0dea0d6e00f1" >
<File Id="PGDatabaseSQL" Name="database.sql" DiskId="1" Source="$(var.MCS-Extractor.ProjectDir)\Sql\postgres\database.sql" KeyPath="no" />
</Component>
</ComponentGroup>
<ComponentGroup Id="MSSQLComponents" Directory="MSSQLFolder" >
<Component Id="MSDatabaseSQLComponent" Guid="4e259e2c-9ecb-11ec-b909-0242ac120002" >
<File Id="MSDatabaseSQL" Name="database.sql" DiskId="1" Source="$(var.MCS-Extractor.ProjectDir)\Sql\mssql\database.sql" KeyPath="no" />
</Component>
</ComponentGroup>
<ComponentGroup Id="DownloadFolderGroup">
Expand Down
11 changes: 10 additions & 1 deletion MCS-Extractor/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<add key="CurrentUserId" value="1" />
<add key="DatabaseName" value="my_council_services_extract" />
<add key="DataDirectory" value="Downloaded" />
<add key="DatabasePlatform" value="" />
<add key="ConnectionString" value="Host=localhost;Port=5432;username=;password=;" />
</appSettings>
<runtime>
Expand All @@ -18,7 +19,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
Expand All @@ -36,6 +37,14 @@
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.1" newVersion="4.0.5.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
23 changes: 18 additions & 5 deletions MCS-Extractor/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Threading.Tasks;
using System.Windows;
using MCS_Extractor.FirstRun;
using MCS_Extractor.FirstRun.Postgres;
using MCS_Extractor.FirstRun.Microsoft;

namespace MCS_Extractor
{
Expand All @@ -17,12 +19,23 @@ public partial class App : Application

private void Application_Startup(object sender, StartupEventArgs e)
{
StartupCheck check = new StartupCheck();
if (check.FirstRun)
FirstRunHandler first = new FirstRunHandler();
if (first.IsFirstRun)
{
var firstRun = new FirstRunWindow();
//firstRun.Owner = this;
firstRun.Show();
switch (first.Platform) {
case "postgres":
var firstRun = new PostgresFirstRunWindow();
//firstRun.Owner = this;
firstRun.Show();
break;
case "mssql":
var msRun = new MicrosoftFirstRunWindow();
msRun.Show();
break;
default: var chooseRun = new SelectDatabaseWindow();
chooseRun.Show();
break;
}
} else
{
var main = new MainWindow();
Expand Down
15 changes: 15 additions & 0 deletions MCS-Extractor/FirstRun/ConfigurationChanged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ public void SetDatabaseCredentials(string username, string password)
UpdateAppSettings("ConnectionString", connectionString);
}

public void SetConnectionString(string newConnect)
{
UpdateAppSettings("ConnectionString", newConnect);
}

public void SetDatabasePlatform(string newPlatform)
{
var viablePlatforms = new string[] { "mssql", "postgres" };
if ( !viablePlatforms.Contains(newPlatform) )
{
throw new Exception(String.Format("\"{0}\" is not a valid database platform.", newPlatform));
}
UpdateAppSettings("DatabasePlatform", newPlatform);
}

private void UpdateAppSettings(string theKey, string theValue)
{
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Expand Down
72 changes: 72 additions & 0 deletions MCS-Extractor/FirstRun/FirstRunHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MCS_Extractor.FirstRun.Interfaces;
using MCS_Extractor.FirstRun.Postgres;
using MCS_Extractor.FirstRun.Microsoft;

namespace MCS_Extractor.FirstRun
{
/// <summary>
/// Class to handle checking for a first run and responding appropriately if there is one.
/// </summary>
class FirstRunHandler
{
private IStartupCheck startup;

public string Platform { get; private set; }

public FirstRunHandler()
{
Platform = ConfigurationManager.AppSettings["DatabasePlatform"].ToLower();
switch (Platform)
{
case "postgres": startup = new PostgresStartupCheck();
break;
case "mssql": startup = new MsStartupCheck();
break;
default:
Debug.WriteLine(String.Format("Could not find startup check for platform {0}", Platform));
break;
}
}

public bool IsFirstRun {
get {
bool isFirst = true;
if (startup != null)
{
isFirst = startup.FirstRun;
}
return isFirst;
}
}

public bool Run()
{
IFirstRunProcess first = null;
bool result = false;
if ( startup != null && startup.FirstRun )
{
switch (Platform)
{
case "postgres": first = new PostgresFirstRunProcess();
break;
case "mssql": first = new MsFirstRunProcess();
break;
default: throw new Exception(String.Format("Could not find first run process for platform {0}", Platform));
break;
}
if ( first != null)
{
result = first.FirstRun();
}
}
return result;
}
}
}
16 changes: 16 additions & 0 deletions MCS-Extractor/FirstRun/Interfaces/IFirstRunProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MCS_Extractor.FirstRun.Interfaces
{
/// <summary>
/// Interface for initial process to create databases etc if they do not already exist.
/// </summary>
interface IFirstRunProcess
{
bool FirstRun();
}
}
13 changes: 13 additions & 0 deletions MCS-Extractor/FirstRun/Interfaces/IStartupCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MCS_Extractor.FirstRun.Interfaces
{
public interface IStartupCheck
{
bool FirstRun { get; }
}
}
17 changes: 17 additions & 0 deletions MCS-Extractor/FirstRun/Microsoft/MicrosoftFirstRunWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window x:Class="MCS_Extractor.FirstRun.Microsoft.MicrosoftFirstRunWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MCS_Extractor.FirstRun.Microsoft"
mc:Ignorable="d"
Title="First Run" Height="300" Width="500">
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="472" Height="35" Cursor="None" TextWrapping="Wrap" >This appears to be your first run of the MCS Extractor so we need to set up your database connection.</TextBlock>
<Label Content="Please paste in your Microsoft SQL Server ConnectionString" HorizontalAlignment="Left" Margin="10,50,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.144,-0.386" Width="457"/>
<Label Content="ConnectionString" HorizontalAlignment="Left" Margin="10,81,0,0" VerticalAlignment="Top" Width="125"/>
<TextBox Name="ConnectionString" HorizontalAlignment="Left" Height="23" Margin="140,84,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="342"/>
<Button Name="ConnectDatabaseButton" Content="Connect To Database" Margin="0,0,10,10" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="125" Click="ConnectDatabaseButton_Click"/>

</Grid>
</Window>
87 changes: 87 additions & 0 deletions MCS-Extractor/FirstRun/Microsoft/MicrosoftFirstRunWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MCS_Extractor.FirstRun;
using MCS_Extractor.ImportedData;

namespace MCS_Extractor.FirstRun.Microsoft
{
/// <summary>
/// The first run window for Microsoft SQL Server deployments.
/// </summary>
public partial class MicrosoftFirstRunWindow : Window
{
public MicrosoftFirstRunWindow()
{
InitializeComponent();
}

private async void ConnectDatabaseButton_Click(object sender, RoutedEventArgs e)
{
ConnectDatabaseButton.IsEnabled = false;
var connectionString = ConnectionString.Text;
if (0 < connectionString.Trim().Length)
{
await Task.Run(() =>
{

var config = new ConfigurationChanged();
config.SetConnectionString(connectionString);
var start = new FirstRunHandler();
var result = !start.IsFirstRun;
if (!result)
{

CheckForDataDirectory();
result = start.Run();

}
if (result)
{
this.Dispatcher.Invoke(() =>
{
var mw = new MainWindow();
mw.Show();
this.Hide();
});
}
else
{
this.Dispatcher.Invoke(() =>
{
MessageBox.Show("There was a problem connecting to the database, please check that the database is enabled and your credentials are correct.");
ConnectDatabaseButton.IsEnabled = true;
});
}
});
} else
{
ConnectDatabaseButton.IsEnabled = true;
}

}

private void CheckForDataDirectory()
{
var datadir = System.IO.Path.Combine(CSVFileHandler.GetInstallFolder(), ConfigurationManager.AppSettings["DataDirectory"]);
if (!Directory.Exists(datadir))
{
Directory.CreateDirectory(datadir);
}
}
}


}
Loading

0 comments on commit e9e7a7a

Please sign in to comment.