-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge sql server pull request from perago-cymru/development
Development
- Loading branch information
Showing
51 changed files
with
1,992 additions
and
556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
MCS-Extractor/FirstRun/Microsoft/MicrosoftFirstRunWindow.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
87
MCS-Extractor/FirstRun/Microsoft/MicrosoftFirstRunWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.