Implemented database backups and restores into the AdvertisingProfitControlData DLL and added a form, DatabaseRecovery, to manage the backups and restores. Updated the installer to include the data DLL file into the install bundle.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using System.Windows.Forms;
|
||||
using AdvertisingProfitControlData;
|
||||
using Microsoft.Win32;
|
||||
@@ -13,6 +16,19 @@ namespace AdvertsingProfitControl
|
||||
public FrmLoginForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
//Check to see if the backup folder exists.
|
||||
if (!Directory.Exists(Backup.DefaultBackupLocation))
|
||||
{
|
||||
Directory.CreateDirectory(Backup.DefaultBackupLocation);
|
||||
//Create it and set its permissions so SQL can write to it.
|
||||
//Reference: https://stackoverflow.com/questions/5298905/add-everyone-privilege-to-folder-using-c-net
|
||||
var sec = Directory.GetAccessControl(Backup.DefaultBackupLocation);
|
||||
// Using this instead of the "Everyone" string means we work on non-English systems.
|
||||
var everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
|
||||
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
|
||||
Directory.SetAccessControl(Backup.DefaultBackupLocation, sec);
|
||||
}
|
||||
//Scan the registry for SQL server instances (not the recommended way).
|
||||
var registryView = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32;
|
||||
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
|
||||
{
|
||||
@@ -57,7 +73,7 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
ConnectionSuccessful = true;
|
||||
//Try to initialize the database.
|
||||
var db = new AdvertisingProfitControlModel(connectionString);
|
||||
var db = new AdvertisingProfitControlDbContext(connectionString);
|
||||
//Force the UI thread to draw the label's text so the user can see it.
|
||||
informationLabel.Text = @"Connection successful! Preparing main form...";
|
||||
informationLabel.Invalidate();
|
||||
|
||||
Reference in New Issue
Block a user