-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sergey Syrovatchenko
committed
May 9, 2019
1 parent
4d3922b
commit f47d4b9
Showing
66 changed files
with
9,261 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.IO; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace SQLIndexManager { | ||
|
||
internal class AES { | ||
private static readonly byte[] Key1 = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; | ||
private static readonly byte[] Key2 = Encoding.UTF8.GetBytes("_SQLIndexManager"); | ||
|
||
internal static string Encrypt(string content) { | ||
using (Rijndael des = Rijndael.Create()) { | ||
var input = Encoding.UTF8.GetBytes(content); | ||
des.Key = Key2; | ||
des.IV = Key1; | ||
using (MemoryStream ms = new MemoryStream()) { | ||
using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)) { | ||
cs.Write(input, 0, input.Length); | ||
cs.FlushFinalBlock(); | ||
var result = ms.ToArray(); | ||
cs.Close(); | ||
ms.Close(); | ||
return Convert.ToBase64String(result); | ||
} | ||
} | ||
} | ||
} | ||
|
||
internal static string Decrypt(string content) { | ||
using (Rijndael des = Rijndael.Create()) { | ||
des.Key = Key2; | ||
des.IV = Key1; | ||
var input = Convert.FromBase64String(content); | ||
var result = new byte[input.Length]; | ||
using (MemoryStream ms = new MemoryStream(input)) { | ||
using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Read)) { | ||
cs.Read(result, 0, result.Length); | ||
cs.Close(); | ||
ms.Close(); | ||
return Encoding.UTF8.GetString(result).TrimEnd('\0'); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
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,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using DevExpress.XtraBars; | ||
using DevExpress.XtraGrid; | ||
using DevExpress.XtraGrid.Views.Grid; | ||
|
||
namespace SQLIndexManager { | ||
|
||
public class OutputEvent { | ||
public DateTime DateTime { get; set; } | ||
public string Message { get; set; } | ||
public DateTime? Duration { get; set; } | ||
} | ||
|
||
public class Output { | ||
private static Output _log; | ||
private List<OutputEvent> _events; | ||
private BarStaticItem _control; | ||
private GridControl _secondaryControl; | ||
|
||
public static Output Current => _log ?? (_log = new Output()); | ||
|
||
private Output() { | ||
_events = new List<OutputEvent>(); | ||
|
||
if (File.Exists(Settings.LogFileName)) { | ||
try { | ||
File.Delete(Settings.LogFileName); | ||
} | ||
catch { } | ||
} | ||
} | ||
|
||
public void SetOutputControl(BarStaticItem control, GridControl secondaryControl) { | ||
_control = control; | ||
_secondaryControl = secondaryControl; | ||
_secondaryControl.DataSource = _events; | ||
} | ||
|
||
public void AddCaption(string message) { | ||
try { | ||
_control.Caption = message; | ||
} | ||
catch { } | ||
} | ||
|
||
public void Add(string message, string message2 = null, long? elapsedMilliseconds = null) { | ||
DateTime now = DateTime.Now; | ||
DateTime? duration = null; | ||
string msg = message; | ||
|
||
if (elapsedMilliseconds >= 0) { | ||
duration = (new DateTime(0)).AddMilliseconds(elapsedMilliseconds ?? 0); | ||
msg = $"Elapsed time: {duration:HH:mm:ss:fff}. {message}"; | ||
} | ||
|
||
OutputEvent ev = new OutputEvent { | ||
DateTime = now, | ||
Message = string.IsNullOrEmpty(message2) ? message : $"{message}\n{message2}", | ||
Duration = duration | ||
}; | ||
|
||
_events.Add(ev); | ||
|
||
try { | ||
_control.Caption = msg; | ||
|
||
GridView grid = (GridView)_secondaryControl.MainView; | ||
grid.RefreshData(); | ||
|
||
using (StreamWriter sw = File.AppendText(Settings.LogFileName)) { | ||
sw.WriteLine($"[ {now:HH:mm:ss.fff} ] {msg}"); | ||
if (!string.IsNullOrEmpty(message2)) | ||
sw.WriteLine(message2); | ||
} | ||
} | ||
catch { } | ||
} | ||
} | ||
|
||
} |
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,29 @@ | ||
using System.ComponentModel; | ||
using System.Threading; | ||
|
||
namespace SQLIndexManager { | ||
|
||
public class ThreadWorker : BackgroundWorker { | ||
private Thread _workerThread; | ||
|
||
protected override void OnDoWork(DoWorkEventArgs e) { | ||
_workerThread = Thread.CurrentThread; | ||
try { | ||
base.OnDoWork(e); | ||
} | ||
catch (ThreadAbortException) { | ||
e.Cancel = true; | ||
Thread.ResetAbort(); | ||
} | ||
} | ||
|
||
public void Abort() { | ||
if (_workerThread != null && _workerThread.IsAlive) { | ||
_workerThread.Abort(); | ||
_workerThread.Join(500); | ||
_workerThread = null; | ||
} | ||
} | ||
} | ||
|
||
} |
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,54 @@ | ||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace SQLIndexManager { | ||
|
||
public static class Utils { | ||
|
||
public static string ToDescription(this Enum value) { | ||
var da = (DescriptionAttribute[])(value.GetType().GetField(value.ToString())).GetCustomAttributes(typeof(DescriptionAttribute), false); | ||
return da.Length > 0 ? da[0].Description : value.ToString(); | ||
} | ||
|
||
public static bool IsBetween(this int value, int minimum, int maximum) { | ||
return value >= minimum && value <= maximum; | ||
} | ||
|
||
public static int PageSize(this int val) { | ||
return val * 1024 / 8; | ||
} | ||
|
||
public static string FormatSize(this decimal val) { | ||
decimal value = val; | ||
string dimension = "KB"; | ||
|
||
if (value > 1024 * 1024 * 1024) { | ||
value = value / 1024 / 1024 / 1024; | ||
dimension = "TB"; | ||
} | ||
else if (value > 1024 * 1024) { | ||
value = value / 1024 / 1024; | ||
dimension = "GB"; | ||
} | ||
else if (value > 1024) { | ||
value = value / 1024; | ||
dimension = "MB"; | ||
} | ||
|
||
return $"{ (value.ToString(value - Math.Truncate(value) == 0 ? "N0" : "N2")) } {dimension}"; | ||
} | ||
|
||
public static string FormatMbSize(this int val) { | ||
decimal value = val; | ||
string dimension = "MB"; | ||
|
||
if (value > 1000) { | ||
value = value / 1024; | ||
dimension = "GB"; | ||
} | ||
|
||
return $"{ (value.ToString(value - Math.Truncate(value) == 0 ? "N0" : "N2")) } {dimension}"; | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.