Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor solution a bit to make add crossplatform support #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
/.vs/
/Bin/
/obj/
*.sln.DotSettings.user
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/

# Visual Studio Code
.vscode

# Rider
.idea

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# Visual Studio 2015
.vs/
8 changes: 5 additions & 3 deletions Common/GridMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using SQLIndexManager.Core;
using SQLIndexManager.Core.Server;
using SQLIndexManager.Properties;

namespace SQLIndexManager {
namespace SQLIndexManager.Common {

public class GridMethod: Control {
public static class GridMethod {

public static void GridRowCellStyle(object sender, RowCellStyleEventArgs e) {
if (e.RowHandle == ((GridView)sender).FocusedRowHandle) {
Expand All @@ -18,7 +20,7 @@ public static void GridRowCellStyle(object sender, RowCellStyleEventArgs e) {

public static void GridDoubleClick(object sender, EventArgs e) {
GridView obj = (GridView)sender;
Point pt = obj.GridControl.PointToClient(MousePosition);
Point pt = obj.GridControl.PointToClient(Control.MousePosition);

GridHitInfo info = obj.CalcHitInfo(pt);
if (info.Column == null || info.Column.Caption == Resources.Fix || info.Column.Caption == Resources.Selection)
Expand Down
19 changes: 19 additions & 0 deletions Common/OutputHandlerWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using DevExpress.XtraBars;
using SQLIndexManager.Core;

namespace SQLIndexManager.Common {
public class OutputHandlerWindow : IOutputHandler {

private readonly BarStaticItem _control;

public OutputHandlerWindow(BarStaticItem control) {

_control = control;
}

public void AddCaption(string message) {

_control.Caption = message;
}
}
}
2 changes: 1 addition & 1 deletion Common/ThreadWorker.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel;
using System.Threading;

namespace SQLIndexManager {
namespace SQLIndexManager.Common {

public class ThreadWorker : BackgroundWorker {

Expand Down
16 changes: 16 additions & 0 deletions Common/UIUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using SQLIndexManager.Core;
using SQLIndexManager.Forms;

namespace SQLIndexManager.Common {

public static class UIUtils {

public static void ShowErrorFrom(Exception e, string message = "Error") {
Output.Current.Add($"{message}: {e.Source}", e.Message);
using (ErrorBox errorBox = new ErrorBox(e)) {
errorBox.ShowDialog();
}
}
}
}
2 changes: 1 addition & 1 deletion Console/NativeMethods.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.InteropServices;

namespace SQLIndexManager {
namespace SQLIndexManager.Console {

public static class NativeMethods {

Expand Down
2 changes: 1 addition & 1 deletion Forms/AboutBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Forms/AboutBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using SQLIndexManager.Common;
using SQLIndexManager.Core;
using SQLIndexManager.Properties;

namespace SQLIndexManager {
namespace SQLIndexManager.Forms {

public partial class AboutBox : XtraForm {

Expand All @@ -23,7 +25,7 @@ private void GitHub_HyperlinkClick(object sender, HyperlinkClickEventArgs e) {
Process.Start(Resources.GitHubLink);
}
catch (Exception ex) {
Utils.ShowErrorFrom(ex);
UIUtils.ShowErrorFrom(ex);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Forms/ConnectionBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions Forms/ConnectionBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
using System.Data.SqlClient;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SQLIndexManager.Properties;
using SQLIndexManager.Common;
using SQLIndexManager.Core;
using SQLIndexManager.Core.Server;
using SQLIndexManager.Core.Settings;

namespace SQLIndexManager {
namespace SQLIndexManager.Forms {

public partial class ConnectionBox : XtraForm {

Expand Down Expand Up @@ -56,7 +59,7 @@ private void CancelConnection() {
}

private void OpenConnection(object sender, DoWorkEventArgs e) {
SqlConnection connection = Connection.Create(GetHost());
SqlConnection connection = ConnectionUtils.Create(GetHost());
connection.Open();
e.Result = connection;
}
Expand Down Expand Up @@ -88,7 +91,7 @@ private void CheckConnection(object sender, RunWorkerCompletedEventArgs e) {
}

if (_serverInfo.MajorVersion < ServerVersion.Sql2008) {
XtraMessageBox.Show(Resources.MinVersionMessage, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
XtraMessageBox.Show(MessageConstants.MinVersionMessage, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
boxServer.Focus();
}
else {
Expand Down
2 changes: 1 addition & 1 deletion Forms/DatabaseBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions Forms/DatabaseBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using SQLIndexManager.Common;
using SQLIndexManager.Core;
using SQLIndexManager.Core.Server;
using SQLIndexManager.Core.Settings;
using SQLIndexManager.Properties;

namespace SQLIndexManager {
namespace SQLIndexManager.Forms {

public partial class DatabaseBox : XtraForm {

Expand Down Expand Up @@ -56,24 +60,24 @@ public List<string> GetDatabases() {
private Stopwatch _ts = new Stopwatch();

private void ScanDatabases(object sender, DoWorkEventArgs e) {
using (SqlConnection connection = Connection.Create(Settings.ActiveHost)) {
using (SqlConnection connection = ConnectionUtils.Create(Settings.ActiveHost)) {
try {
connection.Open();

try { _disks = QueryEngine.GetDiskInfo(connection); }
catch (Exception ex) { Utils.ShowErrorFrom(ex, "Refresh disk info failed"); }
catch (Exception ex) { UIUtils.ShowErrorFrom(ex, "Refresh disk info failed"); }

try { _databases = QueryEngine.GetDatabases(connection); }
catch (Exception ex) { Utils.ShowErrorFrom(ex, "Refresh databases failed"); }
catch (Exception ex) { UIUtils.ShowErrorFrom(ex, "Refresh databases failed"); }

if (_databases.Count > 0 && !Settings.ServerInfo.IsAzure) {
try { QueryEngine.RefreshDatabaseSize(connection, _databases); }
catch (Exception ex) { Utils.ShowErrorFrom(ex, "Refresh database sizes failed"); }
catch (Exception ex) { UIUtils.ShowErrorFrom(ex, "Refresh database sizes failed"); }
}

}
catch (Exception ex) {
Utils.ShowErrorFrom(ex, "Refresh failed");
UIUtils.ShowErrorFrom(ex, "Refresh failed");
}
finally {
connection.Close();
Expand Down
2 changes: 1 addition & 1 deletion Forms/ErrorBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Forms/ErrorBox.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SQLIndexManager.Core;
using SQLIndexManager.Core.Server;
using SQLIndexManager.Core.Settings;
using SQLIndexManager.Properties;

namespace SQLIndexManager {
namespace SQLIndexManager.Forms {

public partial class ErrorBox : XtraForm {

Expand Down
2 changes: 1 addition & 1 deletion Forms/MainBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions Forms/MainBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@
using DevExpress.XtraGrid.Localization;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using SQLIndexManager.Common;
using SQLIndexManager.Core;
using SQLIndexManager.Core.Server;
using SQLIndexManager.Core.Settings;
using SQLIndexManager.Properties;
using SQLIndexManager.Server;

namespace SQLIndexManager {
namespace SQLIndexManager.Forms {

public partial class MainBox : RibbonForm {

public MainBox() {
InitializeComponent();

Output.Current.SetOutputControl(labelInfo);
var outputHandler = new OutputHandlerWindow(labelInfo);
Output.Current.AddOutputHandler(outputHandler);
Output.Current.Add($"Log folder: {Environment.CurrentDirectory}");

view.CustomColumnDisplayText += GridMethod.GridColumnDisplayText;
Expand Down Expand Up @@ -129,7 +135,7 @@ private void ScanIndexes(object sender, DoWorkEventArgs e) {
}

if (!ex.Message.Contains("timeout")) {
Utils.ShowErrorFrom(ex);
UIUtils.ShowErrorFrom(ex);
return;
}

Expand Down Expand Up @@ -927,7 +933,7 @@ private void ButtonLog(object sender, ItemClickEventArgs e) {
Process.Start(AppInfo.LogFileName);
}
catch (Exception ex) {
Utils.ShowErrorFrom(ex);
UIUtils.ShowErrorFrom(ex);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Forms/SettingsBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Forms/SettingsBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using SQLIndexManager.Core;
using SQLIndexManager.Core.Server;
using SQLIndexManager.Core.Settings;

namespace SQLIndexManager {
namespace SQLIndexManager.Forms {

public partial class SettingsBox : XtraForm {

Expand Down
2 changes: 1 addition & 1 deletion Forms/SplashScreenBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Forms/SplashScreenBox.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DevExpress.XtraSplashScreen;
using SQLIndexManager.Core;

namespace SQLIndexManager {
namespace SQLIndexManager.Forms {

public partial class SplashScreenBox : SplashScreen {

Expand Down
11 changes: 8 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
using System.Windows.Forms;
using DevExpress.LookAndFeel;
using DevExpress.XtraSplashScreen;
using SQLIndexManager.Common;
using SQLIndexManager.Console;
using SQLIndexManager.Core;
using SQLIndexManager.Core.CommandLine;
using SQLIndexManager.Core.Settings;
using SQLIndexManager.Forms;

namespace SQLIndexManager {

Expand Down Expand Up @@ -48,7 +54,7 @@ static void Main(string[] args) {
}

private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) {
Utils.ShowErrorFrom(e.Exception);
UIUtils.ShowErrorFrom(e.Exception);
}

private static void AttachConsole() {
Expand All @@ -66,9 +72,8 @@ private static void AttachConsole() {
if (!consoleAttached && !NativeMethods.AllocConsole())
Environment.Exit(1);
else
Console.OutputEncoding = (Encoding)Console.OutputEncoding.Clone();
System.Console.OutputEncoding = (Encoding)System.Console.OutputEncoding.Clone();
}

}

}
Loading