diff --git a/Dapper.Crud.Tests/Dapper.Crud.Tests.csproj b/Dapper.Crud.Tests/Dapper.Crud.Tests.csproj index 010ac71..c2b0a33 100644 --- a/Dapper.Crud.Tests/Dapper.Crud.Tests.csproj +++ b/Dapper.Crud.Tests/Dapper.Crud.Tests.csproj @@ -39,7 +39,7 @@ - + 2.4.1 diff --git a/Dapper.Crud.VSExtension.sln b/Dapper.Crud.VSExtension.sln index c47eadc..b673731 100644 --- a/Dapper.Crud.VSExtension.sln +++ b/Dapper.Crud.VSExtension.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27428.2037 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30804.86 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapper.Crud.VSExtension", "Dapper.Crud.VSExtension\Dapper.Crud.VSExtension.csproj", "{E1F9280B-5191-4741-A4A9-C78DE32FFF7E}" EndProject diff --git a/Dapper.Crud.VSExtension/Dapper.Crud.VSExtension.csproj b/Dapper.Crud.VSExtension/Dapper.Crud.VSExtension.csproj index f4d9ffb..059e4dc 100644 --- a/Dapper.Crud.VSExtension/Dapper.Crud.VSExtension.csproj +++ b/Dapper.Crud.VSExtension/Dapper.Crud.VSExtension.csproj @@ -172,6 +172,48 @@ Always true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Always true @@ -204,7 +246,25 @@ Always true - + + + + + + + + + + + + + + + + + + + Always true @@ -212,35 +272,11 @@ Always true - + Always true - - Always - true - - - Always - true - - - Always - true - - - Always - true - - - Always - true - - - Always - true - - + Always true @@ -248,31 +284,7 @@ Always true - - Always - true - - - Always - true - - - Always - true - - - Always - true - - - Always - true - - - Always - true - - + Always true @@ -280,26 +292,16 @@ Always true - - Always - true - - - Always - true - - - Always - true - - - Always - true - - + Always true + + + + + + Always true @@ -308,11 +310,23 @@ Always true + + + + + + + + + + + + - 2.0.30 + 2.0.78 1.0.7 @@ -323,29 +337,39 @@ 2.2.0 + + 3.6.0 + + + 3.8.0 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + - 3.4.0 + 3.8.0 runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - - - - - - - - - - - - - + + + + + + 16.7.30329.88 + + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers all @@ -413,6 +437,7 @@ VSPackage.Designer.cs + diff --git a/Dapper.Crud.VSExtension/Helpers/AssemblyHelper.cs b/Dapper.Crud.VSExtension/Helpers/AssemblyHelper.cs index 606dd62..c004a71 100644 --- a/Dapper.Crud.VSExtension/Helpers/AssemblyHelper.cs +++ b/Dapper.Crud.VSExtension/Helpers/AssemblyHelper.cs @@ -8,6 +8,8 @@ namespace Dapper.Crud.VSExtension.Helpers { public static class AssemblyHelper { + public static string codeGlobal; + private static Assembly BuildAssembly(string code) { using (var compiler = new Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider()) @@ -19,7 +21,7 @@ private static Assembly BuildAssembly(string code) { GenerateExecutable = false, GenerateInMemory = true, - CompilerOptions = "/unsafe /optimize /langversion:7.1" + CompilerOptions = "/unsafe /optimize /langversion:8.0" }; var assemblies = AppDomain.CurrentDomain @@ -55,6 +57,7 @@ private static Assembly BuildAssembly(string code) public static object ExecuteCode(string code, string namespacename, string classname, bool isstatic) { + codeGlobal = code; Assembly asm = BuildAssembly(code); classname = FixClassName(classname); diff --git a/Dapper.Crud.VSExtension/Helpers/FileHelper.cs b/Dapper.Crud.VSExtension/Helpers/FileHelper.cs index 9e34e06..68ff28b 100644 --- a/Dapper.Crud.VSExtension/Helpers/FileHelper.cs +++ b/Dapper.Crud.VSExtension/Helpers/FileHelper.cs @@ -56,8 +56,10 @@ public static string GenerateRawStringAllFiles(IEnumerable fileList) var strContent = File.ReadAllLines(file); foreach (var line in strContent) { - if (line.Contains("using")) + if (line.StartsWith("using") && line.EndsWith(";")) + { lstUsings.Add(line); + } else lstContent.Add(line); } diff --git a/Dapper.Crud.VSExtension/Logger/Logger.cs b/Dapper.Crud.VSExtension/Logger/Logger.cs index 981ae26..5fd9f5d 100644 --- a/Dapper.Crud.VSExtension/Logger/Logger.cs +++ b/Dapper.Crud.VSExtension/Logger/Logger.cs @@ -1,6 +1,4 @@ -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.Threading; +using Microsoft.VisualStudio.Shell.Interop; using System; namespace Dapper.Crud.VSExtension @@ -23,7 +21,7 @@ public static void Log(object message) { if (EnsurePane()) { - ThreadHelper.Generic.BeginInvoke(() => + Microsoft.VisualStudio.Shell.ThreadHelper.Generic.BeginInvoke(() => { _pane.OutputStringThreadSafe(DateTime.Now + ": " + message + Environment.NewLine); }); @@ -39,7 +37,7 @@ private static bool EnsurePane() { if (_pane == null) { - ThreadHelper.JoinableTaskFactory.Run(async () => + Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.Run(async () => { IVsOutputWindow output = (IVsOutputWindow)_provider.GetService(typeof(SVsOutputWindow)); if (_pane == null) diff --git a/Dapper.Crud.VSExtension/frmExtension.Designer.cs b/Dapper.Crud.VSExtension/frmExtension.Designer.cs index 49e7064..7855716 100644 --- a/Dapper.Crud.VSExtension/frmExtension.Designer.cs +++ b/Dapper.Crud.VSExtension/frmExtension.Designer.cs @@ -364,7 +364,7 @@ private void InitializeComponent() this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "frmExtension"; - this.Text = "Dapper Extension 3.0.8"; + this.Text = "Dapper Extension 3.0.9"; this.gBox.ResumeLayout(false); this.gBox.PerformLayout(); this.groupBox1.ResumeLayout(false); diff --git a/Dapper.Crud.VSExtension/frmExtension.cs b/Dapper.Crud.VSExtension/frmExtension.cs index 6172cde..d7f3baa 100644 --- a/Dapper.Crud.VSExtension/frmExtension.cs +++ b/Dapper.Crud.VSExtension/frmExtension.cs @@ -1,407 +1,407 @@ -using Dapper.Crud.VSExtension.Helpers; -using ScintillaNET; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Threading; -using System.Windows.Forms; - -namespace Dapper.Crud.VSExtension -{ - public partial class frmExtension : Form - { - public string Projectpath; - public string RawContent; - public bool _darkMode = false; - - public frmExtension() - { - InitializeComponent(); - SetTxtStyles(); - LoadFiles(); - picLoader.Visible = false; - } - - private static string GetAssemblyLocalPathFrom(Type type) - { - string codebase = type.Assembly.CodeBase; - var uri = new Uri(codebase, UriKind.Absolute); - return uri.LocalPath; - } - - private void SetLoading(bool displayLoader) - { - if (displayLoader) - { - this.Invoke((MethodInvoker)delegate - { - picLoader.Visible = true; - this.Cursor = Cursors.WaitCursor; - }); - } - else - { - this.Invoke((MethodInvoker)delegate - { - picLoader.Visible = false; - this.Cursor = Cursors.Default; - }); - } - } - - private void btnGenerate_Click(object sender, EventArgs e) +using Dapper.Crud.VSExtension.Helpers; +using ScintillaNET; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Threading; +using System.Windows.Forms; + +namespace Dapper.Crud.VSExtension +{ + public partial class frmExtension : Form + { + public string Projectpath; + public string RawContent; + public bool _darkMode = false; + + public frmExtension() + { + InitializeComponent(); + SetTxtStyles(); + LoadFiles(); + picLoader.Visible = false; + } + + private static string GetAssemblyLocalPathFrom(Type type) + { + string codebase = type.Assembly.CodeBase; + var uri = new Uri(codebase, UriKind.Absolute); + return uri.LocalPath; + } + + private void SetLoading(bool displayLoader) + { + if (displayLoader) + { + this.Invoke((MethodInvoker)delegate + { + picLoader.Visible = true; + this.Cursor = Cursors.WaitCursor; + }); + } + else + { + this.Invoke((MethodInvoker)delegate + { + picLoader.Visible = false; + this.Cursor = Cursors.Default; + }); + } + } + + private void btnGenerate_Click(object sender, EventArgs e) { var threadInput = new Thread(GenerateCrud); threadInput.Start(); - } - - private void GenerateCrud() - { - try - { - Logger.Log("Initializing generation process..."); - SetLoading(true); - - txtOutput.Text = string.Empty; - foreach (var item in lstFiles.CheckedItems) - { - var model = item.ToString(); - IList properties = GetPropertyInfos(model); - IList propertiesUpdate = GetPropertyInfos(model); - IList propertiesDelete = GetPropertyInfos(model); - - string output = string.Empty; - - if (chkClass.Checked) - { - output += ClassGenerator.GenerateClassBody(model, chkInterface.Checked); - - if (chkSelect.Checked) - output += MethodGenerator.GenerateSelect( - DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), - model, chkClass.Checked, chkAsync.Checked); - - if (chkInsert.Checked) - output += MethodGenerator.GenerateInsert( - DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked), - model, chkClass.Checked, chkAsync.Checked, chkReturnIdentity.Checked); - - if (chkUpdate.Checked) - output += MethodGenerator.GenerateUpdate( - DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked), - model, chkClass.Checked, chkAsync.Checked); - - if (chkDelete.Checked) - output += MethodGenerator.GenerateDelete( - DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), - model, chkClass.Checked, chkAsync.Checked); - - output += "}"; - - txtOutput.Text += output; - - if (chkGenerateFiles.Checked) - FileHelper.GenerateClass(output, model, Projectpath); - } - else - { - if (chkGenerateMethod.Checked) - { - if (chkSelect.Checked) - txtOutput.Text += - MethodGenerator.GenerateSelect(DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); - - if (chkInsert.Checked) - txtOutput.Text += - MethodGenerator.GenerateInsert(DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked), model, chkClass.Checked, chkAsync.Checked, chkReturnIdentity.Checked); - - if (chkUpdate.Checked) - txtOutput.Text += - MethodGenerator.GenerateUpdate(DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); - - if (chkDelete.Checked) - txtOutput.Text += - MethodGenerator.GenerateDelete(DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); - } - else - { - if (chkSelect.Checked) - txtOutput.Text += DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked); - - if (chkInsert.Checked) - txtOutput.Text += DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked); - - if (chkUpdate.Checked) - txtOutput.Text += DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked); - - if (chkDelete.Checked) - txtOutput.Text += DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked); - } - } - - if (chkInterface.Checked) - { - output = InterfaceGenerator.GenerateInterfaceBody(model); - - if (chkSelect.Checked) - output += InterfaceGenerator.GenerateSelect(model, chkAsync.Checked); - - if (chkInsert.Checked) - output += InterfaceGenerator.GenerateInsert(model, chkAsync.Checked, chkReturnIdentity.Checked); - - if (chkUpdate.Checked) - output += InterfaceGenerator.GenerateUpdate(model, chkAsync.Checked); - - if (chkDelete.Checked) - output += InterfaceGenerator.GenerateDelete(model, chkAsync.Checked); - - output += "}"; - - txtOutput.Text += output; - - if (chkGenerateFiles.Checked) - FileHelper.GenerateInterface(output, model, Projectpath); - } - } - SetLoading(false); - Logger.Log($"Process Completed Successfully!"); - } - catch (Exception ex) - { - SetLoading(false); - Logger.Log($"Error during the operation: {ex.Message} InnerException {ex.InnerException} StackTrace {ex.StackTrace}"); - txtOutputLog.ForeColor = Color.Red; - txtOutputLog.Text = $"Error during the operation: {ex.Message} InnerException {ex.InnerException} StackTrace {ex.StackTrace}"; - } - } - - private void SetTxtStyles() - { - txtOutput.StyleResetDefault(); - txtOutput.Styles[Style.Default].Font = "Consolas"; - txtOutput.Styles[Style.Default].Size = 10; - txtOutput.StyleClearAll(); - - if (_darkMode) - { - // Configure the CPP (C#) lexer styles - txtOutput.Styles[Style.Cpp.Default].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.Default].ForeColor = Color.Pink; - txtOutput.Styles[Style.Cpp.Comment].ForeColor = Color.FromArgb(0, 128, 0); // Green - txtOutput.Styles[Style.Cpp.CommentLine].ForeColor = Color.FromArgb(0, 128, 0); // Green - txtOutput.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray - txtOutput.Styles[Style.Cpp.Number].ForeColor = Color.Olive; - txtOutput.Styles[Style.Cpp.Word].ForeColor = Color.Blue; - txtOutput.Styles[Style.Cpp.Word2].ForeColor = Color.Blue; - txtOutput.Styles[Style.Cpp.String].ForeColor = Color.FromArgb(163, 21, 21); // Red - txtOutput.Styles[Style.Cpp.Character].ForeColor = Color.FromArgb(163, 21, 21); // Red - txtOutput.Styles[Style.Cpp.Verbatim].ForeColor = Color.FromArgb(163, 21, 21); // Red - txtOutput.Styles[Style.Cpp.StringEol].BackColor = Color.Pink; - txtOutput.Styles[Style.Cpp.Operator].ForeColor = Color.Purple; - txtOutput.Styles[Style.Cpp.Preprocessor].ForeColor = Color.Maroon; - - txtOutput.Styles[Style.Cpp.Comment].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.CommentLine].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.CommentLineDoc].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.Number].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.Word].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.Word2].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.String].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.Character].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.Verbatim].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.StringEol].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.Operator].BackColor = Color.FromArgb(41, 41, 41); - txtOutput.Styles[Style.Cpp.Preprocessor].BackColor = Color.FromArgb(41, 41, 41); + } + + private void GenerateCrud() + { + try + { + Logger.Log("Initializing generation process..."); + SetLoading(true); + + txtOutput.Text = string.Empty; + foreach (var item in lstFiles.CheckedItems) + { + var model = item.ToString(); + IList properties = GetPropertyInfos(model); + IList propertiesUpdate = GetPropertyInfos(model); + IList propertiesDelete = GetPropertyInfos(model); + + string output = string.Empty; + + if (chkClass.Checked) + { + output += ClassGenerator.GenerateClassBody(model, chkInterface.Checked); + + if (chkSelect.Checked) + output += MethodGenerator.GenerateSelect( + DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), + model, chkClass.Checked, chkAsync.Checked); + + if (chkInsert.Checked) + output += MethodGenerator.GenerateInsert( + DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked), + model, chkClass.Checked, chkAsync.Checked, chkReturnIdentity.Checked); + + if (chkUpdate.Checked) + output += MethodGenerator.GenerateUpdate( + DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked), + model, chkClass.Checked, chkAsync.Checked); + + if (chkDelete.Checked) + output += MethodGenerator.GenerateDelete( + DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), + model, chkClass.Checked, chkAsync.Checked); + + output += "}"; + + txtOutput.Text += output; + + if (chkGenerateFiles.Checked) + FileHelper.GenerateClass(output, model, Projectpath); + } + else + { + if (chkGenerateMethod.Checked) + { + if (chkSelect.Checked) + txtOutput.Text += + MethodGenerator.GenerateSelect(DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); + + if (chkInsert.Checked) + txtOutput.Text += + MethodGenerator.GenerateInsert(DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked), model, chkClass.Checked, chkAsync.Checked, chkReturnIdentity.Checked); + + if (chkUpdate.Checked) + txtOutput.Text += + MethodGenerator.GenerateUpdate(DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); + + if (chkDelete.Checked) + txtOutput.Text += + MethodGenerator.GenerateDelete(DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked), model, chkClass.Checked, chkAsync.Checked); + } + else + { + if (chkSelect.Checked) + txtOutput.Text += DapperGenerator.Select(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked); + + if (chkInsert.Checked) + txtOutput.Text += DapperGenerator.Insert(model, properties, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked, chkReturnIdentity.Checked); + + if (chkUpdate.Checked) + txtOutput.Text += DapperGenerator.Update(model, propertiesUpdate, chkGenerateMethod.Checked, chkClass.Checked, chkAutoIncrement.Checked, chkAsync.Checked); + + if (chkDelete.Checked) + txtOutput.Text += DapperGenerator.Delete(model, propertiesDelete, chkGenerateMethod.Checked, chkClass.Checked, chkAsync.Checked); + } + } + + if (chkInterface.Checked) + { + output = InterfaceGenerator.GenerateInterfaceBody(model); + + if (chkSelect.Checked) + output += InterfaceGenerator.GenerateSelect(model, chkAsync.Checked); + + if (chkInsert.Checked) + output += InterfaceGenerator.GenerateInsert(model, chkAsync.Checked, chkReturnIdentity.Checked); + + if (chkUpdate.Checked) + output += InterfaceGenerator.GenerateUpdate(model, chkAsync.Checked); + + if (chkDelete.Checked) + output += InterfaceGenerator.GenerateDelete(model, chkAsync.Checked); + + output += "}"; + + txtOutput.Text += output; + + if (chkGenerateFiles.Checked) + FileHelper.GenerateInterface(output, model, Projectpath); + } + } + SetLoading(false); + Logger.Log($"Process Completed Successfully!"); + } + catch (Exception ex) + { + SetLoading(false); + Logger.Log($"Error during the operation: {ex.Message} InnerException {ex.InnerException} StackTrace {ex.StackTrace} Code {AssemblyHelper.codeGlobal}"); + txtOutputLog.ForeColor = Color.Red; + txtOutputLog.Text = $"Error during the operation: {ex.Message} InnerException {ex.InnerException} StackTrace {ex.StackTrace} Code {AssemblyHelper.codeGlobal}"; + } + } + + private void SetTxtStyles() + { + txtOutput.StyleResetDefault(); + txtOutput.Styles[Style.Default].Font = "Consolas"; + txtOutput.Styles[Style.Default].Size = 10; + txtOutput.StyleClearAll(); + + if (_darkMode) + { + // Configure the CPP (C#) lexer styles + txtOutput.Styles[Style.Cpp.Default].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.Default].ForeColor = Color.Pink; + txtOutput.Styles[Style.Cpp.Comment].ForeColor = Color.FromArgb(0, 128, 0); // Green + txtOutput.Styles[Style.Cpp.CommentLine].ForeColor = Color.FromArgb(0, 128, 0); // Green + txtOutput.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray + txtOutput.Styles[Style.Cpp.Number].ForeColor = Color.Olive; + txtOutput.Styles[Style.Cpp.Word].ForeColor = Color.Blue; + txtOutput.Styles[Style.Cpp.Word2].ForeColor = Color.Blue; + txtOutput.Styles[Style.Cpp.String].ForeColor = Color.FromArgb(163, 21, 21); // Red + txtOutput.Styles[Style.Cpp.Character].ForeColor = Color.FromArgb(163, 21, 21); // Red + txtOutput.Styles[Style.Cpp.Verbatim].ForeColor = Color.FromArgb(163, 21, 21); // Red + txtOutput.Styles[Style.Cpp.StringEol].BackColor = Color.Pink; + txtOutput.Styles[Style.Cpp.Operator].ForeColor = Color.Purple; + txtOutput.Styles[Style.Cpp.Preprocessor].ForeColor = Color.Maroon; + + txtOutput.Styles[Style.Cpp.Comment].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.CommentLine].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.CommentLineDoc].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.Number].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.Word].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.Word2].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.String].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.Character].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.Verbatim].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.StringEol].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.Operator].BackColor = Color.FromArgb(41, 41, 41); + txtOutput.Styles[Style.Cpp.Preprocessor].BackColor = Color.FromArgb(41, 41, 41); } else - { - // Configure the CPP (C#) lexer styles - txtOutput.Styles[Style.Cpp.Default].ForeColor = Color.Silver; - txtOutput.Styles[Style.Cpp.Comment].ForeColor = Color.FromArgb(0, 128, 0); // Green - txtOutput.Styles[Style.Cpp.CommentLine].ForeColor = Color.FromArgb(0, 128, 0); // Green - txtOutput.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray - txtOutput.Styles[Style.Cpp.Number].ForeColor = Color.Olive; - txtOutput.Styles[Style.Cpp.Word].ForeColor = Color.Blue; - txtOutput.Styles[Style.Cpp.Word2].ForeColor = Color.Blue; - txtOutput.Styles[Style.Cpp.String].ForeColor = Color.FromArgb(163, 21, 21); // Red - txtOutput.Styles[Style.Cpp.Character].ForeColor = Color.FromArgb(163, 21, 21); // Red - txtOutput.Styles[Style.Cpp.Verbatim].ForeColor = Color.FromArgb(163, 21, 21); // Red - txtOutput.Styles[Style.Cpp.StringEol].BackColor = Color.Pink; - txtOutput.Styles[Style.Cpp.Operator].ForeColor = Color.Purple; - txtOutput.Styles[Style.Cpp.Preprocessor].ForeColor = Color.Maroon; - } - } - - private void btnLoad_Click(object sender, EventArgs e) - { - LoadFiles(); - } - - private void LoadFiles() - { - lstFiles.Items.Clear(); - var project = ProjectHelpers.GetActiveProject(); - - Projectpath = project.GetFullPath(); - - var files = Directory.GetFiles(Projectpath, "*.cs", SearchOption.AllDirectories).ToList(); - var filteredList = FileHelper.FilterFileList(files); - - var fileList = filteredList.ToList(); - foreach (var file in fileList) - { - var model = file.Replace(Projectpath, "").Replace(".cs", ""); - lstFiles.Items.Add(model); - } - - RawContent = FileHelper.GenerateRawStringAllFiles(fileList); - } - - private IList GetPropertyInfos(string model) - { - var installationPath = GetAssemblyLocalPathFrom(typeof(CreateCrudPackage)); - installationPath = installationPath.Replace("Dapper.Crud.VSExtension.dll", ""); - - Environment.SetEnvironmentVariable("ROSLYN_COMPILER_LOCATION", installationPath + "\\roslyn", EnvironmentVariableTarget.Process); - - Assembly.LoadFrom(installationPath + "System.Web.Optimization.dll"); - Assembly.LoadFrom(installationPath + "System.Web.Mvc.dll"); - Assembly.LoadFrom(installationPath + "Dapper.Contrib.dll"); - Assembly.LoadFrom(installationPath + "Microsoft.AspNetCore.Mvc.dll"); - - var file = Projectpath + model + ".cs"; - var objectModel = ModelHelper.Generate(CleanupAttributes(File.ReadAllLines(file)), CleanupAttributes(RawContent), model); - var props = new List(objectModel.GetType().GetProperties()); - - var types = ModelHelper.Types(); - - foreach (var prop in props.ToList()) - { - if (!types.Contains(prop.PropertyType.Name.ToLower())) - { - props.Remove(prop); - } - } - - var sortedProps = SortProperties(props); - - return sortedProps; - } - - private string[] CleanupAttributes(string[] content) - { - for (int i = 0; i < content.Length; i++) - { - content[i] = content[i].Trim().Replace("[HiddenInput", "//[HiddenInput"); - content[i] = content[i].Trim().Replace("[DisplayValue", "//[DisplayValue"); - content[i] = content[i].Trim().Replace("[ErrorMessage", "//[ErrorMessage"); - content[i] = content[i].Trim().Replace("[Required", "//[Required"); - } - - return content; - } - - private string CleanupAttributes(string content) - { + { + // Configure the CPP (C#) lexer styles + txtOutput.Styles[Style.Cpp.Default].ForeColor = Color.Silver; + txtOutput.Styles[Style.Cpp.Comment].ForeColor = Color.FromArgb(0, 128, 0); // Green + txtOutput.Styles[Style.Cpp.CommentLine].ForeColor = Color.FromArgb(0, 128, 0); // Green + txtOutput.Styles[Style.Cpp.CommentLineDoc].ForeColor = Color.FromArgb(128, 128, 128); // Gray + txtOutput.Styles[Style.Cpp.Number].ForeColor = Color.Olive; + txtOutput.Styles[Style.Cpp.Word].ForeColor = Color.Blue; + txtOutput.Styles[Style.Cpp.Word2].ForeColor = Color.Blue; + txtOutput.Styles[Style.Cpp.String].ForeColor = Color.FromArgb(163, 21, 21); // Red + txtOutput.Styles[Style.Cpp.Character].ForeColor = Color.FromArgb(163, 21, 21); // Red + txtOutput.Styles[Style.Cpp.Verbatim].ForeColor = Color.FromArgb(163, 21, 21); // Red + txtOutput.Styles[Style.Cpp.StringEol].BackColor = Color.Pink; + txtOutput.Styles[Style.Cpp.Operator].ForeColor = Color.Purple; + txtOutput.Styles[Style.Cpp.Preprocessor].ForeColor = Color.Maroon; + } + } + + private void btnLoad_Click(object sender, EventArgs e) + { + LoadFiles(); + } + + private void LoadFiles() + { + lstFiles.Items.Clear(); + var project = ProjectHelpers.GetActiveProject(); + + Projectpath = project.GetFullPath(); + + var files = Directory.GetFiles(Projectpath, "*.cs", SearchOption.AllDirectories).ToList(); + var filteredList = FileHelper.FilterFileList(files); + + var fileList = filteredList.ToList(); + foreach (var file in fileList) + { + var model = file.Replace(Projectpath, "").Replace(".cs", ""); + lstFiles.Items.Add(model); + } + + RawContent = FileHelper.GenerateRawStringAllFiles(fileList); + } + + private IList GetPropertyInfos(string model) + { + var installationPath = GetAssemblyLocalPathFrom(typeof(CreateCrudPackage)); + installationPath = installationPath.Replace("Dapper.Crud.VSExtension.dll", ""); + + Environment.SetEnvironmentVariable("ROSLYN_COMPILER_LOCATION", installationPath + "\\roslyn", EnvironmentVariableTarget.Process); + + Assembly.LoadFrom(installationPath + "System.Web.Optimization.dll"); + Assembly.LoadFrom(installationPath + "System.Web.Mvc.dll"); + Assembly.LoadFrom(installationPath + "Dapper.Contrib.dll"); + Assembly.LoadFrom(installationPath + "Microsoft.AspNetCore.Mvc.dll"); + + var file = Projectpath + model + ".cs"; + var objectModel = ModelHelper.Generate(CleanupAttributes(File.ReadAllLines(file)), CleanupAttributes(RawContent), model); + var props = new List(objectModel.GetType().GetProperties()); + + var types = ModelHelper.Types(); + + foreach (var prop in props.ToList()) + { + if (!types.Contains(prop.PropertyType.Name.ToLower())) + { + props.Remove(prop); + } + } + + var sortedProps = SortProperties(props); + + return sortedProps; + } + + private string[] CleanupAttributes(string[] content) + { + for (int i = 0; i < content.Length; i++) + { + content[i] = content[i].Trim().Replace("[HiddenInput", "//[HiddenInput"); + content[i] = content[i].Trim().Replace("[DisplayValue", "//[DisplayValue"); + content[i] = content[i].Trim().Replace("[ErrorMessage", "//[ErrorMessage"); + content[i] = content[i].Trim().Replace("[Required", "//[Required"); + } + + return content; + } + + private string CleanupAttributes(string content) + { content = content.Replace("[HiddenInput", "//[HiddenInput"); content = content.Replace("[DisplayValue", "//[DisplayValue"); content = content.Replace("[ErrorMessage", "//[ErrorMessage"); - content = content.Replace("[Required", "//[Required"); - - return content; - } - - private IList SortProperties(IList prop) - { - List sortedProp = new List(); - - foreach (var p in prop) - { - if (p.Name == "Id") - { - sortedProp.Add(p); - break; - } - } - foreach (var p in prop) - { - if (p.Name != "Id") - { - sortedProp.Add(p); - } - } - - return sortedProp; - } - - private void btnClear_Click(object sender, EventArgs e) - { - txtOutput.Text = string.Empty; - } - - private void btnSelectAll_Click(object sender, EventArgs e) - { - chkSelect.Checked = true; - chkInsert.Checked = true; - chkUpdate.Checked = true; - chkDelete.Checked = true; - } - - private void chkClass_CheckedChanged(object sender, EventArgs e) - { - chkGenerateMethod.Checked = chkClass.Checked; - } - - private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) - { - Process.Start("https://www.buymeacoffee.com/Obk4RIZ"); + content = content.Replace("[Required", "//[Required"); + + return content; + } + + private IList SortProperties(IList prop) + { + List sortedProp = new List(); + + foreach (var p in prop) + { + if (p.Name == "Id") + { + sortedProp.Add(p); + break; + } + } + foreach (var p in prop) + { + if (p.Name != "Id") + { + sortedProp.Add(p); + } + } + + return sortedProp; + } + + private void btnClear_Click(object sender, EventArgs e) + { + txtOutput.Text = string.Empty; } - private void btnChangeMode_Click(object sender, EventArgs e) - { - SetTxtStyles(); - if (!_darkMode) - { - this.BackColor = SystemColors.Control; - - foreach (Control child in this.Controls) - { - child.ForeColor = Color.Black; - txtOutput.BackColor = SystemColors.Control; - txtOutputLog.BackColor = SystemColors.Control; - lstFiles.BackColor = SystemColors.Control; - } - - foreach (var button in this.Controls.OfType