From 7b5cf601e61f84b9c8695fab4d6863df4c615bb7 Mon Sep 17 00:00:00 2001 From: Anthony van der Hoorn Date: Tue, 15 Dec 2015 20:32:34 -0800 Subject: [PATCH] More refacotring of types & namespaces --- .../AgentRegisterServices.cs | 1 + src/Glimpse.Agent.Core/Inspectors/Execute.cs | 8 --- src/Glimpse.Agent.Core/Inspectors/Tab.cs | 68 ------------------- .../DefaultMessagePayloadFormatter.cs | 2 +- .../Internal/Tabs/ConnectionTab.cs | 2 +- .../Messaging/HttpMessagePublisher.cs | 1 + src/Glimpse.Agent.Core/Tab.cs | 46 +++++++++++++ src/Glimpse.Agent.Core/TabExecute.cs | 8 +++ .../Razor/ScriptInjector.cs | 1 + .../IResourceOptionsProvider.cs | 4 +- .../OptionsResourceOptionsProvider.cs | 5 +- .../ResourceOptions.cs | 2 +- .../GlimpseCoreServiceCollectionExtensions.cs | 3 +- .../Extensions/JsonSerializerExtensions.cs | 4 +- .../DefaultJsonSerializerProvider.cs | 2 +- .../Internal/Serialization/GuidConverter.cs | 2 +- .../Serialization/IJsonSerializerProvider.cs | 2 +- .../Serialization/StringValuesConverter.cs | 5 +- .../Serialization/TimeSpanConverter.cs | 2 +- .../Internal/TypeNameHelper.cs | 2 - .../Platform/DefaultGlimpseContextAccessor.cs | 1 - .../DefaultResourceOptionsProvider.cs | 1 + .../ServerRegisterServices.cs | 1 + .../Resources/ExportConfigurationResource.cs | 1 + .../Resources/MessageIngressResource.cs | 2 +- 25 files changed, 79 insertions(+), 97 deletions(-) delete mode 100644 src/Glimpse.Agent.Core/Inspectors/Execute.cs delete mode 100644 src/Glimpse.Agent.Core/Inspectors/Tab.cs create mode 100644 src/Glimpse.Agent.Core/Tab.cs create mode 100644 src/Glimpse.Agent.Core/TabExecute.cs rename src/Glimpse.Common.Core/{Initialization => Configuration}/IResourceOptionsProvider.cs (60%) rename src/Glimpse.Common.Core/{Initialization => Configuration}/OptionsResourceOptionsProvider.cs (79%) rename src/Glimpse.Common.Core/{Initialization => Configuration}/ResourceOptions.cs (91%) diff --git a/src/Glimpse.Agent.Core/DependencyInjection/AgentRegisterServices.cs b/src/Glimpse.Agent.Core/DependencyInjection/AgentRegisterServices.cs index 86e90f3c..21af5947 100644 --- a/src/Glimpse.Agent.Core/DependencyInjection/AgentRegisterServices.cs +++ b/src/Glimpse.Agent.Core/DependencyInjection/AgentRegisterServices.cs @@ -9,6 +9,7 @@ using Glimpse.Agent.Inspectors; using Glimpse.Initialization; using System.Linq; +using Glimpse.Configuration; using Glimpse.Platform; namespace Glimpse.DependencyInjection diff --git a/src/Glimpse.Agent.Core/Inspectors/Execute.cs b/src/Glimpse.Agent.Core/Inspectors/Execute.cs deleted file mode 100644 index 6f6d81fa..00000000 --- a/src/Glimpse.Agent.Core/Inspectors/Execute.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Glimpse.Agent.Inspectors -{ - public enum Execute - { - BeforeResponse, - AfterResponse - } -} \ No newline at end of file diff --git a/src/Glimpse.Agent.Core/Inspectors/Tab.cs b/src/Glimpse.Agent.Core/Inspectors/Tab.cs deleted file mode 100644 index 2cc3ff62..00000000 --- a/src/Glimpse.Agent.Core/Inspectors/Tab.cs +++ /dev/null @@ -1,68 +0,0 @@ -//using System; -//using Glimpse.Agent.AspNet.Messages; -//using Microsoft.AspNet.Http; -//#if DNX -//using Microsoft.AspNet.Http.Internal; -//using Microsoft.Extensions.DependencyInjection; -//#endif - -//namespace Glimpse.Agent.Inspectors -//{ -// // TODO: Is this what we want to name this type? -// public abstract class Tab : Inspector -// { -//// TODO: Need to fix this up, there should be a better way -//#if DNX -// private IAgentBroker _broker; -// public IAgentBroker Broker -// { -// get -// { -// if (_broker == null) -// { -// // TODO: this doesn't work -// var httpContextAccessor = new HttpContextAccessor(); -// _broker = httpContextAccessor.HttpContext.RequestServices.GetService(); -// } - -// return _broker; -// } -// set { _broker = value; } -// } -//#endif - -// public override void Before(HttpContext context) -// { -// if (ExecuteWhen == Execute.BeforeResponse) -// Publish(context); -// } - -// public override void After(HttpContext context) -// { -// if (ExecuteWhen == Execute.AfterResponse) -// Publish(context); -// } - -// private void Publish(HttpContext context) -// { -// object data = null; -// try -// { -// data = GetData(context); -// } -// catch (Exception exception) -// { -// data = exception; -// } - -// Broker.SendMessage(new TabMessage(Name, data)); -// } - -// public virtual Execute ExecuteWhen => Execute.AfterResponse; - -// public abstract string Name { get; } - -// // TODO: Is HttpContext the right type to pass in here? -// public abstract object GetData(HttpContext context); -// } -//} \ No newline at end of file diff --git a/src/Glimpse.Agent.Core/Internal/Messaging/DefaultMessagePayloadFormatter.cs b/src/Glimpse.Agent.Core/Internal/Messaging/DefaultMessagePayloadFormatter.cs index 412d7046..0a9472c6 100644 --- a/src/Glimpse.Agent.Core/Internal/Messaging/DefaultMessagePayloadFormatter.cs +++ b/src/Glimpse.Agent.Core/Internal/Messaging/DefaultMessagePayloadFormatter.cs @@ -1,6 +1,6 @@ using System.Linq; -using Glimpse.Common.Internal.Serialization; using Glimpse.Internal.Extensions; +using Glimpse.Internal.Serialization; using Newtonsoft.Json; namespace Glimpse.Agent.Internal.Messaging diff --git a/src/Glimpse.Agent.Core/Internal/Tabs/ConnectionTab.cs b/src/Glimpse.Agent.Core/Internal/Tabs/ConnectionTab.cs index a878c8ae..1083ffdc 100644 --- a/src/Glimpse.Agent.Core/Internal/Tabs/ConnectionTab.cs +++ b/src/Glimpse.Agent.Core/Internal/Tabs/ConnectionTab.cs @@ -22,6 +22,6 @@ // }; // } -// public override Execute ExecuteWhen => Execute.BeforeResponse; +// public override TabExecute TabExecuteWhen => TabExecute.BeforeResponse; // } //} diff --git a/src/Glimpse.Agent.Core/Messaging/HttpMessagePublisher.cs b/src/Glimpse.Agent.Core/Messaging/HttpMessagePublisher.cs index f4a2cb50..e5c5c2d9 100644 --- a/src/Glimpse.Agent.Core/Messaging/HttpMessagePublisher.cs +++ b/src/Glimpse.Agent.Core/Messaging/HttpMessagePublisher.cs @@ -6,6 +6,7 @@ using System.Reactive.Linq; using System.Reactive.Subjects; using System.Threading.Tasks; +using Glimpse.Configuration; using Glimpse.Initialization; namespace Glimpse.Agent diff --git a/src/Glimpse.Agent.Core/Tab.cs b/src/Glimpse.Agent.Core/Tab.cs new file mode 100644 index 00000000..a7f23595 --- /dev/null +++ b/src/Glimpse.Agent.Core/Tab.cs @@ -0,0 +1,46 @@ +using System; +using Glimpse.Agent.AspNet.Messages; +using Glimpse.Agent.Inspectors; +using Microsoft.AspNet.Http; +using Microsoft.Extensions.DependencyInjection; + +namespace Glimpse.Agent +{ + public abstract class Tab : Inspector + { + public override void Before(HttpContext context) + { + if (TabExecuteWhen == TabExecute.BeforeResponse) + Publish(context); + } + + public override void After(HttpContext context) + { + if (TabExecuteWhen == TabExecute.AfterResponse) + Publish(context); + } + + private void Publish(HttpContext context) + { + object data = null; + try + { + data = GetData(context); + } + catch (Exception exception) + { + data = exception; + } + + var broker = context.RequestServices.GetService(); + + broker.SendMessage(new TabMessage(Name, data)); + } + + public virtual TabExecute TabExecuteWhen => TabExecute.AfterResponse; + + public abstract string Name { get; } + + public abstract object GetData(HttpContext context); + } +} \ No newline at end of file diff --git a/src/Glimpse.Agent.Core/TabExecute.cs b/src/Glimpse.Agent.Core/TabExecute.cs new file mode 100644 index 00000000..98ae701b --- /dev/null +++ b/src/Glimpse.Agent.Core/TabExecute.cs @@ -0,0 +1,8 @@ +namespace Glimpse.Agent +{ + public enum TabExecute + { + BeforeResponse, + AfterResponse + } +} \ No newline at end of file diff --git a/src/Glimpse.Agent.Dnx.Mvc/Razor/ScriptInjector.cs b/src/Glimpse.Agent.Dnx.Mvc/Razor/ScriptInjector.cs index 96cec360..1953ab67 100644 --- a/src/Glimpse.Agent.Dnx.Mvc/Razor/ScriptInjector.cs +++ b/src/Glimpse.Agent.Dnx.Mvc/Razor/ScriptInjector.cs @@ -1,5 +1,6 @@ using System; using Glimpse.Common; +using Glimpse.Configuration; using Glimpse.Initialization; using Glimpse.Platform; using Microsoft.AspNet.Razor.TagHelpers; diff --git a/src/Glimpse.Common.Core/Initialization/IResourceOptionsProvider.cs b/src/Glimpse.Common.Core/Configuration/IResourceOptionsProvider.cs similarity index 60% rename from src/Glimpse.Common.Core/Initialization/IResourceOptionsProvider.cs rename to src/Glimpse.Common.Core/Configuration/IResourceOptionsProvider.cs index 1fab60da..a7ce6e4c 100644 --- a/src/Glimpse.Common.Core/Initialization/IResourceOptionsProvider.cs +++ b/src/Glimpse.Common.Core/Configuration/IResourceOptionsProvider.cs @@ -1,4 +1,6 @@ -namespace Glimpse.Initialization +using Glimpse.Initialization; + +namespace Glimpse.Configuration { public interface IResourceOptionsProvider { diff --git a/src/Glimpse.Common.Core/Initialization/OptionsResourceOptionsProvider.cs b/src/Glimpse.Common.Core/Configuration/OptionsResourceOptionsProvider.cs similarity index 79% rename from src/Glimpse.Common.Core/Initialization/OptionsResourceOptionsProvider.cs rename to src/Glimpse.Common.Core/Configuration/OptionsResourceOptionsProvider.cs index 4b026b5a..286d21bc 100644 --- a/src/Glimpse.Common.Core/Initialization/OptionsResourceOptionsProvider.cs +++ b/src/Glimpse.Common.Core/Configuration/OptionsResourceOptionsProvider.cs @@ -1,6 +1,7 @@ -using Microsoft.Extensions.OptionsModel; +using Glimpse.Initialization; +using Microsoft.Extensions.OptionsModel; -namespace Glimpse.Initialization +namespace Glimpse.Configuration { public class OptionsResourceOptionsProvider : IResourceOptionsProvider { diff --git a/src/Glimpse.Common.Core/Initialization/ResourceOptions.cs b/src/Glimpse.Common.Core/Configuration/ResourceOptions.cs similarity index 91% rename from src/Glimpse.Common.Core/Initialization/ResourceOptions.cs rename to src/Glimpse.Common.Core/Configuration/ResourceOptions.cs index 202b471b..8d028918 100644 --- a/src/Glimpse.Common.Core/Initialization/ResourceOptions.cs +++ b/src/Glimpse.Common.Core/Configuration/ResourceOptions.cs @@ -1,4 +1,4 @@ -namespace Glimpse.Initialization +namespace Glimpse.Configuration { public class ResourceOptions { diff --git a/src/Glimpse.Common.Core/DependencyInjection/GlimpseCoreServiceCollectionExtensions.cs b/src/Glimpse.Common.Core/DependencyInjection/GlimpseCoreServiceCollectionExtensions.cs index 934495a6..d3e17f3f 100644 --- a/src/Glimpse.Common.Core/DependencyInjection/GlimpseCoreServiceCollectionExtensions.cs +++ b/src/Glimpse.Common.Core/DependencyInjection/GlimpseCoreServiceCollectionExtensions.cs @@ -1,8 +1,7 @@ using Glimpse; -using Glimpse.Common; -using Glimpse.Common.Internal.Serialization; using Glimpse.Initialization; using Glimpse.Internal; +using Glimpse.Internal.Serialization; using Glimpse.Platform; using Microsoft.Extensions.DependencyInjection.Extensions; using Newtonsoft.Json; diff --git a/src/Glimpse.Common.Core/Internal/Extensions/JsonSerializerExtensions.cs b/src/Glimpse.Common.Core/Internal/Extensions/JsonSerializerExtensions.cs index b4c384a6..b63ad26d 100644 --- a/src/Glimpse.Common.Core/Internal/Extensions/JsonSerializerExtensions.cs +++ b/src/Glimpse.Common.Core/Internal/Extensions/JsonSerializerExtensions.cs @@ -2,9 +2,11 @@ using System.Globalization; using System.IO; using System.Text; +using Glimpse.Internal.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -using GuidConverter = Glimpse.Common.Internal.Serialization.GuidConverter; +using GuidConverter = Glimpse.Internal.Serialization.GuidConverter; +using TimeSpanConverter = Glimpse.Internal.Serialization.TimeSpanConverter; namespace Glimpse.Internal.Extensions { diff --git a/src/Glimpse.Common.Core/Internal/Serialization/DefaultJsonSerializerProvider.cs b/src/Glimpse.Common.Core/Internal/Serialization/DefaultJsonSerializerProvider.cs index 30fa2b5c..6b6ae2f1 100644 --- a/src/Glimpse.Common.Core/Internal/Serialization/DefaultJsonSerializerProvider.cs +++ b/src/Glimpse.Common.Core/Internal/Serialization/DefaultJsonSerializerProvider.cs @@ -1,7 +1,7 @@ using Glimpse.Internal.Extensions; using Newtonsoft.Json; -namespace Glimpse.Common.Internal.Serialization +namespace Glimpse.Internal.Serialization { public class DefaultJsonSerializerProvider : IJsonSerializerProvider { diff --git a/src/Glimpse.Common.Core/Internal/Serialization/GuidConverter.cs b/src/Glimpse.Common.Core/Internal/Serialization/GuidConverter.cs index 90175415..bccc83cd 100644 --- a/src/Glimpse.Common.Core/Internal/Serialization/GuidConverter.cs +++ b/src/Glimpse.Common.Core/Internal/Serialization/GuidConverter.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json; -namespace Glimpse.Common.Internal.Serialization +namespace Glimpse.Internal.Serialization { public class GuidConverter : JsonConverter { diff --git a/src/Glimpse.Common.Core/Internal/Serialization/IJsonSerializerProvider.cs b/src/Glimpse.Common.Core/Internal/Serialization/IJsonSerializerProvider.cs index 430045c4..8841e8ed 100644 --- a/src/Glimpse.Common.Core/Internal/Serialization/IJsonSerializerProvider.cs +++ b/src/Glimpse.Common.Core/Internal/Serialization/IJsonSerializerProvider.cs @@ -1,6 +1,6 @@ using Newtonsoft.Json; -namespace Glimpse.Common.Internal.Serialization +namespace Glimpse.Internal.Serialization { public interface IJsonSerializerProvider { diff --git a/src/Glimpse.Common.Core/Internal/Serialization/StringValuesConverter.cs b/src/Glimpse.Common.Core/Internal/Serialization/StringValuesConverter.cs index 8d8dc4e9..866c6aed 100644 --- a/src/Glimpse.Common.Core/Internal/Serialization/StringValuesConverter.cs +++ b/src/Glimpse.Common.Core/Internal/Serialization/StringValuesConverter.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.Extensions.Primitives; using Newtonsoft.Json; -namespace Glimpse.Internal +namespace Glimpse.Internal.Serialization { public class StringValuesConverter : JsonConverter { diff --git a/src/Glimpse.Common.Core/Internal/Serialization/TimeSpanConverter.cs b/src/Glimpse.Common.Core/Internal/Serialization/TimeSpanConverter.cs index a9bf7288..1ea4f778 100644 --- a/src/Glimpse.Common.Core/Internal/Serialization/TimeSpanConverter.cs +++ b/src/Glimpse.Common.Core/Internal/Serialization/TimeSpanConverter.cs @@ -1,7 +1,7 @@ using System; using Newtonsoft.Json; -namespace Glimpse.Internal +namespace Glimpse.Internal.Serialization { public class TimeSpanConverter : JsonConverter { diff --git a/src/Glimpse.Common.Core/Internal/TypeNameHelper.cs b/src/Glimpse.Common.Core/Internal/TypeNameHelper.cs index 0ed4b1a2..c1b4f404 100644 --- a/src/Glimpse.Common.Core/Internal/TypeNameHelper.cs +++ b/src/Glimpse.Common.Core/Internal/TypeNameHelper.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.Text; -using System.Threading.Tasks; namespace Glimpse.Internal { diff --git a/src/Glimpse.Common.Core/Platform/DefaultGlimpseContextAccessor.cs b/src/Glimpse.Common.Core/Platform/DefaultGlimpseContextAccessor.cs index c960a1bf..2b055eb4 100644 --- a/src/Glimpse.Common.Core/Platform/DefaultGlimpseContextAccessor.cs +++ b/src/Glimpse.Common.Core/Platform/DefaultGlimpseContextAccessor.cs @@ -1,5 +1,4 @@ using System; -using Glimpse.Common; namespace Glimpse.Platform { diff --git a/src/Glimpse.Server.Core/Configuration/DefaultResourceOptionsProvider.cs b/src/Glimpse.Server.Core/Configuration/DefaultResourceOptionsProvider.cs index 2e9a6403..e54cc921 100644 --- a/src/Glimpse.Server.Core/Configuration/DefaultResourceOptionsProvider.cs +++ b/src/Glimpse.Server.Core/Configuration/DefaultResourceOptionsProvider.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Glimpse.Configuration; using Glimpse.Initialization; using Glimpse.Internal.Extensions; using Glimpse.Server.Internal.Extensions; diff --git a/src/Glimpse.Server.Core/DependencyInjection/ServerRegisterServices.cs b/src/Glimpse.Server.Core/DependencyInjection/ServerRegisterServices.cs index 19017a81..78614197 100644 --- a/src/Glimpse.Server.Core/DependencyInjection/ServerRegisterServices.cs +++ b/src/Glimpse.Server.Core/DependencyInjection/ServerRegisterServices.cs @@ -1,4 +1,5 @@ using System.Linq; +using Glimpse.Configuration; using Glimpse.Initialization; using Glimpse.Server; using Glimpse.Server.Configuration; diff --git a/src/Glimpse.Server.Core/Internal/Resources/ExportConfigurationResource.cs b/src/Glimpse.Server.Core/Internal/Resources/ExportConfigurationResource.cs index 521e4ed4..246a316a 100644 --- a/src/Glimpse.Server.Core/Internal/Resources/ExportConfigurationResource.cs +++ b/src/Glimpse.Server.Core/Internal/Resources/ExportConfigurationResource.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using Glimpse.Configuration; using Glimpse.Initialization; using Glimpse.Server.Resources; using Microsoft.AspNet.Http; diff --git a/src/Glimpse.Server.Core/Internal/Resources/MessageIngressResource.cs b/src/Glimpse.Server.Core/Internal/Resources/MessageIngressResource.cs index 3b2c842e..21aad22f 100644 --- a/src/Glimpse.Server.Core/Internal/Resources/MessageIngressResource.cs +++ b/src/Glimpse.Server.Core/Internal/Resources/MessageIngressResource.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Net; using System.Threading.Tasks; -using Glimpse.Common.Internal.Serialization; +using Glimpse.Internal.Serialization; using Glimpse.Server.Resources; using Microsoft.AspNet.Http; using Newtonsoft.Json;