Skip to content

Commit ad88489

Browse files
Merge pull request #395 from nvisionative/develop
Merged `develop` into `main` for `2.4.0` release
2 parents 40ac358 + 25865ab commit ad88489

17 files changed

+411
-347
lines changed

nvQuickSite/Controllers/DatabaseController.cs

+12-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace nvQuickSite.Controllers
1919
{
2020
using System;
2121
using System.Data;
22-
using System.Data.SqlClient;
2322

23+
using Microsoft.Data.SqlClient;
2424
using nvQuickSite.Controllers.Exceptions;
2525
using Serilog;
2626

@@ -77,6 +77,7 @@ public void DropDatabase()
7777
{
7878
Log.Logger.Information("Dropping database {dbName}", this.dbName);
7979
string myDBServerName = this.dbServerName;
80+
string connectionStringTrustServerCertificate = "TrustServerCertificate=True;";
8081
string connectionStringAuthSection = string.Empty;
8182
if (this.usesWindowsAuthentication)
8283
{
@@ -87,11 +88,14 @@ public void DropDatabase()
8788
connectionStringAuthSection = "User ID=" + this.dbUserName + ";Password=" + this.dbPassword + ";";
8889
}
8990

90-
using (SqlConnection myConn = new SqlConnection("Server=" + myDBServerName + "; Initial Catalog=master;" + connectionStringAuthSection))
91+
using (SqlConnection myConn = new SqlConnection($"Server={myDBServerName}; Initial Catalog=master; {connectionStringTrustServerCertificate} {connectionStringAuthSection}"))
9192
{
9293
string useMaster = @"USE master";
9394
string dropDatabase = $@"IF EXISTS(SELECT name FROM sys.databases WHERE name = '{this.dbName}') " +
94-
$"DROP DATABASE [{this.dbName}]";
95+
$"BEGIN " +
96+
$"ALTER DATABASE [{this.dbName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; " +
97+
$"DROP DATABASE [{this.dbName}]; " +
98+
$"END";
9599

96100
SqlCommand useMasterCommand = new SqlCommand(useMaster, myConn);
97101
SqlCommand dropDatabaseCommand = new SqlCommand(dropDatabase, myConn);
@@ -128,6 +132,7 @@ public void DropDatabase()
128132
public void CreateDatabase()
129133
{
130134
Log.Logger.Information("Creating database {dbName}", this.dbName);
135+
string connectionStringTrustServerCertificate = "TrustServerCertificate=True;";
131136
string connectionStringAuthSection = string.Empty;
132137
string connectionTimeout = "Connection Timeout=5;";
133138
if (this.usesWindowsAuthentication)
@@ -139,7 +144,7 @@ public void CreateDatabase()
139144
connectionStringAuthSection = $"User ID={this.dbUserName};Password={this.dbPassword};";
140145
}
141146

142-
using (SqlConnection myConn = new SqlConnection($"Server={this.dbServerName}; Initial Catalog=master;{connectionStringAuthSection}{connectionTimeout}"))
147+
using (SqlConnection myConn = new SqlConnection($"Server={this.dbServerName}; Initial Catalog=master; {connectionStringTrustServerCertificate} {connectionStringAuthSection} {connectionTimeout}"))
143148
{
144149
string str = $"CREATE DATABASE [{this.dbName}] ON PRIMARY " +
145150
$"(NAME = [{this.dbName}_Data], " +
@@ -183,6 +188,7 @@ public void CreateDatabase()
183188
internal void SetDatabasePermissions()
184189
{
185190
Log.Logger.Information("Setting permissions on database {dbName}", this.dbName);
191+
string connectionStringTrustServerCertificate = "TrustServerCertificate=True;";
186192
string connectionStringAuthSection = string.Empty;
187193
if (this.usesWindowsAuthentication)
188194
{
@@ -193,7 +199,7 @@ internal void SetDatabasePermissions()
193199
connectionStringAuthSection = $"User ID={this.dbUserName};Password={this.dbPassword};";
194200
}
195201

196-
using (SqlConnection myConn = new SqlConnection($"Server={this.dbServerName}; Initial Catalog=master;{connectionStringAuthSection}"))
202+
using (SqlConnection myConn = new SqlConnection($"Server={this.dbServerName}; Initial Catalog=master; {connectionStringTrustServerCertificate} {connectionStringAuthSection}"))
197203
{
198204
var appPoolNameFull = @"IIS APPPOOL\DefaultAppPool";
199205
var appPoolName = "DefaultAppPool";
@@ -208,7 +214,7 @@ internal void SetDatabasePermissions()
208214
SqlCommand grantLogin = new SqlCommand($"sp_grantlogin '{appPoolNameFull}'", myConn);
209215
SqlCommand useDb = new SqlCommand($"USE [{this.dbName}]", myConn);
210216
SqlCommand grantDbAccess = new SqlCommand($"sp_grantdbaccess '{appPoolNameFull}', '{appPoolName}'", myConn);
211-
SqlCommand addRoleMember = new SqlCommand($"sp_addrolemember 'db_owner', '{appPoolName}'", myConn);
217+
SqlCommand addRoleMember = new SqlCommand($"ALTER ROLE [db_owner] ADD MEMBER [{appPoolName}] ", myConn);
212218

213219
try
214220
{

nvQuickSite/Controllers/DialogController.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ internal enum DialogButtons
6161
/// <param name="icon">Icon for the bitmap image (e.g., SystemIcons.Error, SystemIcons.Warning, SystemIcons.Information).</param>
6262
/// <param name="dialogButtons">Type of buttons to use for the custom message box.</param>
6363
/// <param name="doNotWarnAgain">User preference for not warning again with a dialog (i.e., no longer show the dialog).</param>
64+
/// <param name="exception">A value indicating whether the dialog is for an exception.</param>
6465
/// <returns>DialogResult.</returns>
65-
internal static DialogResult ShowMessage(string title, string message, Icon icon, DialogButtons dialogButtons, bool doNotWarnAgain = false)
66+
internal static DialogResult ShowMessage(string title, string message, Icon icon, DialogButtons dialogButtons, bool exception = false, bool doNotWarnAgain = false)
6667
{
6768
var dialogTitle = title;
6869
var dialogMessage = message;
@@ -71,7 +72,7 @@ internal static DialogResult ShowMessage(string title, string message, Icon icon
7172
switch (dialogButtons)
7273
{
7374
case DialogButtons.OK:
74-
using (var messageBox = new MsgBoxOk(dialogTitle, dialogMessage, dialogIcon))
75+
using (var messageBox = new MsgBoxOk(dialogTitle, dialogMessage, dialogIcon, exception))
7576
{
7677
result = messageBox.ShowDialog();
7778
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (c) 2016-2020 nvisionative, Inc.
2+
//
3+
// This file is part of nvQuickSite.
4+
//
5+
// nvQuickSite is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// nvQuickSite is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with nvQuickSite. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using System;
19+
using System.IO;
20+
using System.IO.Compression;
21+
using System.Linq;
22+
23+
using nvQuickSite.Exceptions;
24+
using Serilog;
25+
26+
/// <summary>
27+
/// Controller for extracting a package.
28+
/// </summary>
29+
public class PackageExtractorController
30+
{
31+
/// <summary>
32+
/// Action to be executed when the progress is updated.
33+
/// </summary>
34+
public event Action<string> ProgressUpdated;
35+
36+
/// <summary>
37+
/// Action to be executed when the progress value is updated.
38+
/// </summary>
39+
public event Action<int> ProgressValueUpdated;
40+
41+
/// <summary>
42+
/// Extracts a package.
43+
/// </summary>
44+
/// <param name="openPath">Open Path.</param>
45+
/// <param name="savePath">Save Path.</param>
46+
/// <exception cref="ReadAndExtractException">Read and Extract Exception.</exception>
47+
public void ExtractPackage(string openPath, string savePath)
48+
{
49+
try
50+
{
51+
Log.Logger.Information("Extracting package");
52+
53+
using (var zip = ZipFile.OpenRead(openPath))
54+
{
55+
long totalSize = zip.Entries.Sum(entry => entry.Length);
56+
57+
long progressSize = 0;
58+
59+
foreach (var entry in zip.Entries)
60+
{
61+
var entryPath = Path.Combine(savePath, entry.FullName);
62+
63+
if (string.IsNullOrEmpty(entry.Name)) // Directory
64+
{
65+
Directory.CreateDirectory(entryPath);
66+
}
67+
else // File
68+
{
69+
var directoryPath = Path.GetDirectoryName(entryPath);
70+
if (!Directory.Exists(directoryPath))
71+
{
72+
Directory.CreateDirectory(directoryPath);
73+
}
74+
75+
this.ExtractEntryWithProgress(entry, entryPath, ref progressSize, totalSize);
76+
}
77+
}
78+
}
79+
80+
this.ProgressUpdated?.Invoke("Congratulations! Your new site is now ready to visit!");
81+
}
82+
catch (Exception ex)
83+
{
84+
var message = "Error attempting to read and extract the package";
85+
Log.Error(ex, message);
86+
throw new ReadAndExtractException(message, ex) { Source = "Read And Extract Package" };
87+
}
88+
89+
Log.Logger.Information("Extracted package from {openPath} to {savePath}", openPath, savePath);
90+
}
91+
92+
private void ExtractEntryWithProgress(ZipArchiveEntry entry, string destinationPath, ref long progressSize, long totalSize)
93+
{
94+
this.ProgressUpdated?.Invoke("Copying: " + entry.FullName);
95+
96+
using (var inputStream = entry.Open())
97+
using (var outputStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write))
98+
{
99+
var buffer = new byte[81920];
100+
int bytesRead;
101+
while ((bytesRead = inputStream.Read(buffer, 0, buffer.Length)) > 0)
102+
{
103+
outputStream.Write(buffer, 0, bytesRead);
104+
progressSize += bytesRead;
105+
106+
int progressPercentage = (int)((progressSize * 100) / totalSize);
107+
this.ProgressValueUpdated?.Invoke(progressPercentage);
108+
}
109+
}
110+
}
111+
}

nvQuickSite/Controls/Dialogs/MsgBoxOk.Designer.cs

+47-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nvQuickSite/Controls/Dialogs/MsgBoxOk.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace nvQuickSite.Controls.Dialogs
1919
{
20+
using System;
2021
using System.Drawing;
2122

2223
using MetroFramework.Forms;
@@ -32,12 +33,23 @@ public partial class MsgBoxOk : MetroForm
3233
/// <param name="dialogTitle">The title to show in the dialog.</param>
3334
/// <param name="dialogMessage">The message to show in the dialog.</param>
3435
/// <param name="dialogIconImage">The image to use as the dialog icon.</param>
35-
public MsgBoxOk(string dialogTitle, string dialogMessage, Image dialogIconImage)
36+
/// <param name="exception">Whether or not the dialog is an exception.</param>
37+
public MsgBoxOk(string dialogTitle, string dialogMessage, Image dialogIconImage, bool exception = false)
3638
{
3739
this.InitializeComponent();
3840
this.lblTitle.Text = dialogTitle;
3941
this.lblMessage.Text = dialogMessage;
4042
this.dialogIcon.Image = dialogIconImage;
43+
this.btnGetHelp.Visible = exception;
44+
this.btnGetHelp.Click += (sender, e) =>
45+
{
46+
this.linkLabelReportIssue.Visible = true;
47+
System.Diagnostics.Process.Start($"https://github.com/nvisionative/nvQuickSite/issues?q=is%3Aissue+{dialogTitle}+{dialogMessage}");
48+
};
49+
this.linkLabelReportIssue.Click += (sender, e) =>
50+
{
51+
System.Diagnostics.Process.Start($"https://github.com/nvisionative/nvQuickSite/issues/new?title=[In-App%20Issue]{dialogTitle}&body={dialogMessage}");
52+
};
4153
}
4254
}
4355
}

0 commit comments

Comments
 (0)