diff --git a/NetBash.Sample/Commands/GridCommand.cs b/NetBash.Sample/Commands/GridCommand.cs index 9433651..8a17b71 100644 --- a/NetBash.Sample/Commands/GridCommand.cs +++ b/NetBash.Sample/Commands/GridCommand.cs @@ -2,15 +2,12 @@ using System.Collections.Generic; using System.Linq; using System.Web; -using NDesk.Options; using System.Text; using System.IO; using NetBash.Formatting; namespace NetBash.Sample.Commands { - //implemented example from http://tirania.org/blog/archive/2008/Oct-14.html using NDesk.Options - [WebCommand("grid", "Usage: grid")] public class GridCommand : IWebCommand { diff --git a/NetBash.Sample/NetBash.Sample.csproj b/NetBash.Sample/NetBash.Sample.csproj index 41a958c..64855c8 100644 --- a/NetBash.Sample/NetBash.Sample.csproj +++ b/NetBash.Sample/NetBash.Sample.csproj @@ -119,7 +119,9 @@ - + + Designer + Web.config diff --git a/NetBash.Sample/Views/Shared/_Layout.cshtml b/NetBash.Sample/Views/Shared/_Layout.cshtml index 38afc48..2facc0f 100644 --- a/NetBash.Sample/Views/Shared/_Layout.cshtml +++ b/NetBash.Sample/Views/Shared/_Layout.cshtml @@ -3,6 +3,7 @@ @ViewBag.Title + @NetBash.NetBash.RenderIncludes() diff --git a/NetBash.nupkg b/NetBash.nupkg index abf5b94..699f455 100644 Binary files a/NetBash.nupkg and b/NetBash.nupkg differ diff --git a/NetBash/Formatting/TableExtensions.cs b/NetBash/Formatting/TableExtensions.cs index 7316170..e0c79eb 100644 --- a/NetBash/Formatting/TableExtensions.cs +++ b/NetBash/Formatting/TableExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Data; namespace NetBash.Formatting { @@ -9,31 +10,39 @@ public static class TableExtensions { public static string ToConsoleTable(this IEnumerable data) { + var type = typeof(T); + var isEmpty = data == null || !data.Any(); + //Lets start with a string builder var sb = new StringBuilder(); //If its a list of primatives just output them straight up, yo - if (typeof(T).IsPrimitive || typeof(String) == typeof(T) || typeof(Decimal) == typeof(T)) + if (type.IsPrimitive || typeof(String) == type || typeof(Decimal) == type) { foreach (var row in data) { sb.Append(row.ToString()); } + return sb.ToString(); } //Headers - //TODO - Something that reads the class directly instead of the first item (So empty lists dont crash) - var properties = data.First().GetType().GetProperties(); + var properties = type.GetProperties(); //get the column widths var columnWidths = new Dictionary(); foreach (var prop in properties) { - var max = data.Max(row => prop.GetValue(row, null).ToString().Length); + var max = prop.Name.Length; + + if (!isEmpty) + { + max = data.Max(row => prop.GetValue(row, null).ToString().Length); - if (prop.Name.Length > max) - max = prop.Name.Length; + if (prop.Name.Length > max) + max = prop.Name.Length; + } //Add some space columnWidths.Add(prop.Name, max + 3); @@ -54,15 +63,22 @@ public static string ToConsoleTable(this IEnumerable data) } sb.AppendLine(); - - foreach (var row in data) + + if (!isEmpty) { - foreach (var prop in properties) + foreach (var row in data) { - sb.AppendFormat("{0,-" + columnWidths[prop.Name] + "}", prop.GetValue(row, null)); - } + foreach (var prop in properties) + { + sb.AppendFormat("{0,-" + columnWidths[prop.Name] + "}", prop.GetValue(row, null)); + } - sb.AppendLine(); + sb.AppendLine(); + } + } + else + { + sb.AppendLine("NO RESULTS"); } //Another dashed linebreak diff --git a/NetBash/NetBash.cs b/NetBash/NetBash.cs index 0e7789e..ecd538b 100644 --- a/NetBash/NetBash.cs +++ b/NetBash/NetBash.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -22,25 +22,29 @@ public static void Init() NetBashHandler.RegisterRoutes(); } + private static Type[] TryGetTypes(Assembly assembly) + { + try + { + return assembly.GetTypes(); + } + catch (ReflectionTypeLoadException) + { + return Type.EmptyTypes; + } + } + internal void LoadCommands() { - try - { - _interfaceType = typeof(IWebCommand); - var assemblies = AssemblyLocator.GetAssemblies(); + _interfaceType = typeof(IWebCommand); + var assemblies = AssemblyLocator.GetAssemblies(); - var results = from a in assemblies - from t in a.GetTypes() - where _interfaceType.IsAssignableFrom(t) - select t; + var results = from a in assemblies + from t in TryGetTypes(a) + where _interfaceType.IsAssignableFrom(t) + select t; - _commandTypes = results.ToList(); - } - catch (ReflectionTypeLoadException ex) - { - var text = string.Join(", ", ex.LoaderExceptions.Select(e => e.Message)); - throw new ApplicationException(text); - } + _commandTypes = results.ToList(); //if we still cant find any throw exception if (_commandTypes == null || !_commandTypes.Any()) diff --git a/NetBash/Properties/AssemblyInfo.cs b/NetBash/Properties/AssemblyInfo.cs index d9e9763..8fe1f3c 100644 --- a/NetBash/Properties/AssemblyInfo.cs +++ b/NetBash/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.2.3")] +[assembly: AssemblyVersion("0.3.0")] //[assembly: AssemblyFileVersion("0.2")] diff --git a/NetBash/UI/script-js.js b/NetBash/UI/script-js.js index 0255e06..ef0063f 100644 --- a/NetBash/UI/script-js.js +++ b/NetBash/UI/script-js.js @@ -54,7 +54,7 @@ function NetBash($, window, opt) { clearTimeout(showLoader); $("#console-input").removeClass("loading"); - $("#console-result").scrollTop($("#console-result").attr("scrollHeight")); + $("#console-result").scrollTop($("#console-result")[0].scrollHeight); }; this.openConsole = function () { @@ -69,6 +69,7 @@ function NetBash($, window, opt) { }, 100, function () { isOpen = true; }); + self.scrollBottom(); }; this.closeConsole = function () { @@ -116,7 +117,7 @@ function NetBash($, window, opt) { $('
').html(data.Content).appendTo('#console-result'); } else { //pre that shit - $('
').html(data.Content).appendTo('#console-result');
+                            $('
' + data.Content + '
').appendTo('#console-result'); } } else { self.setError(data.Content); diff --git a/NetBash/UI/style-css.css b/NetBash/UI/style-css.css index b3a0515..de163be 100644 --- a/NetBash/UI/style-css.css +++ b/NetBash/UI/style-css.css @@ -1 +1 @@ -#netbash-wrap{position:fixed;bottom:0;left:50%;width:45%;height:25px;background:rgba(0, 0, 0, 0.6);color:#00ff00;font-family:'Consolas','Lucida Console','Courier New',monospace !important;}#netbash-wrap #console-input{overflow:hidden;position:absolute;bottom:0;width:100%;background:rgba(0, 0, 0, 0.2);}#netbash-wrap #console-input.loading{background-repeat:no-repeat;background-image:url(data:image/gif;base64,R0lGODlhKwALAMIAAP///3ysLL7Vl3ysLP///////////////yH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJDwADACwAAAAAKwALAAADNDiyzPNQtRbhpHfWTCP/mgduYEl+Z8mlGauG1ii+7bzadBejeL64sIfvAtQJR7yioHJsJQAAIfkECQ8AAQAsAAAAACsACwAAAz8Ys8zxMIhJaYQ1q8bHzeAHVh0njtOJlo06uiDrRKhF14K8wNpd6x4fikfSEW0YHPCYEo6WzlBUI7s8albJMAEAIfkECQ8AAQAsAAAAACsACwAAAz8YsszxMIxJaYQtq6xj/dPFjaRwgZ9YrsuJWhHLuu+gyiT93jino7xe4wcKCluemi127ECUS8xqM7o8alaqLwEAIfkEAQ8AAQAsAAAAACsACwAAA0IYsszxULUW4bgYy0kjn1UmXl8HlU40iuhStUK4YvDbyvNQe7ea671T8PEDomxHX24nTFp+zEc0UNxwKtISljoLJAAAOw==);background-size:13px 7px;background-position:3px center;}#netbash-wrap #console-input.loading span{visibility:hidden;}#netbash-wrap #console-input span{float:left;font-weight:bold;padding:0 3px 0 5px;line-height:23px;color:#fff;}#netbash-wrap #console-input input{width:94%;background-color:transparent;border:0;height:100%;color:#00ff00 !important;font-size:15px;outline:none;font-family:'Consolas','Lucida Console','Courier New',monospace !important;}#netbash-wrap #console-result{display:none;padding:10px;font-size:13px;height:455px;overflow:auto;}#netbash-wrap #console-result .console-message{color:#999;padding-bottom:5px;}#netbash-wrap #console-result .console-request{padding-bottom:2px;color:#fff;}#netbash-wrap #console-result .console-response{padding-bottom:5px;margin:0;}#netbash-wrap #console-result .console-error{color:Red;padding-bottom:5px;margin:0;}#netbash-wrap #console-result::-webkit-scrollbar{height:1ex;-webkit-border-radius:1ex;}#netbash-wrap #console-result::-webkit-scrollbar-thumb{background:rgba(255, 255, 255, 0.2);}#netbash-wrap a{color:Blue;text-decoration:underline;}#netbash-wrap a:hover{color:Aqua;}#netbash-wrap a:visited{color:Blue;} \ No newline at end of file +#netbash-wrap{position:fixed;bottom:0;left:50%;width:45%;height:25px;background:rgba(0, 0, 0, 0.6);color:#00ff00;font-family:'Consolas','Lucida Console','Courier New',monospace !important;}#netbash-wrap #console-input{overflow:hidden;position:absolute;bottom:0;width:100%;background:#000;background:rgba(0, 0, 0, 0.2);}#netbash-wrap #console-input.loading{background-repeat:no-repeat;background-image:url(data:image/gif;base64,R0lGODlhKwALAMIAAP///3ysLL7Vl3ysLP///////////////yH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJDwADACwAAAAAKwALAAADNDiyzPNQtRbhpHfWTCP/mgduYEl+Z8mlGauG1ii+7bzadBejeL64sIfvAtQJR7yioHJsJQAAIfkECQ8AAQAsAAAAACsACwAAAz8Ys8zxMIhJaYQ1q8bHzeAHVh0njtOJlo06uiDrRKhF14K8wNpd6x4fikfSEW0YHPCYEo6WzlBUI7s8albJMAEAIfkECQ8AAQAsAAAAACsACwAAAz8YsszxMIxJaYQtq6xj/dPFjaRwgZ9YrsuJWhHLuu+gyiT93jino7xe4wcKCluemi127ECUS8xqM7o8alaqLwEAIfkEAQ8AAQAsAAAAACsACwAAA0IYsszxULUW4bgYy0kjn1UmXl8HlU40iuhStUK4YvDbyvNQe7ea671T8PEDomxHX24nTFp+zEc0UNxwKtISljoLJAAAOw==);background-size:13px 7px;background-position:3px center;}#netbash-wrap #console-input.loading span{visibility:hidden;}#netbash-wrap #console-input span{float:left;font-weight:bold;padding:0 3px 0 5px;line-height:23px;color:#fff;}#netbash-wrap #console-input input{width:94%;background-color:transparent;border:0;height:100%;color:#00ff00 !important;font-size:15px;outline:none;font-family:'Consolas','Lucida Console','Courier New',monospace !important;}#netbash-wrap #console-result{display:none;padding:10px;font-size:13px;height:455px;overflow:auto;background:#000\9;}#netbash-wrap #console-result .console-message{color:#999;padding-bottom:5px;}#netbash-wrap #console-result .console-request{padding-bottom:2px;color:#fff;}#netbash-wrap #console-result .console-response{padding-bottom:5px;margin:0;}#netbash-wrap #console-result .console-error{color:Red;padding-bottom:5px;margin:0;}#netbash-wrap #console-result::-webkit-scrollbar{height:1ex;-webkit-border-radius:1ex;}#netbash-wrap #console-result::-webkit-scrollbar-thumb{background:rgba(255, 255, 255, 0.2);}#netbash-wrap a{color:Blue;text-decoration:underline;}#netbash-wrap a:hover{color:Aqua;}#netbash-wrap a:visited{color:Blue;} \ No newline at end of file diff --git a/NetBash/UI/style.less b/NetBash/UI/style.less index 3a4b749..bb658ab 100644 --- a/NetBash/UI/style.less +++ b/NetBash/UI/style.less @@ -16,6 +16,7 @@ position:absolute; bottom:0; width:100%; + background:rgb(0, 0, 0); /* The Fallback */ background:rgba(0,0,0, 0.2); &.loading @@ -56,7 +57,9 @@ padding:10px; font-size:13px; height:455px; - overflow:auto; + overflow:auto; + + background: #000\9; /* ie Fallback */ .console-message { diff --git a/README.md b/README.md index a64ecd8..49a8c2c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ NetBash is a drop in (think mvc mini profiler) command line for your web app. +Download from NuGet - **PM> Install-Package NetBash** + #### Set up On application start call NetBash.Init() to initilize the routes. You can optionally set the Authorize action, this action is run to determine whether to show the console.