Last active
November 2, 2016 22:33
-
-
Save scionwest/fedfaf9fe7f0f8eb6108b209fcf22a11 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| { | |
| "EnableProfiling": "false", | |
| "IsProfilerWhitelisting": "true", | |
| "ProfilerProvider": "ADOT.Core.Profiling.SingletonProfilerProvider", | |
| "IncludedTypes": [ | |
| "ADOT.Core.Profiling.StopwatchFactory", | |
| "ADOT.Core.Profiling.SingletoneProfilerProvider" | |
| ], | |
| "IncludedNamespaces": [ | |
| "ADOT.DataAccess", | |
| "ADOT.Logging" | |
| ] | |
| } |
This file contains hidden or 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
| public class ProfilerFactoryConverter : CustomCreationConverter<IAppProfilerFactory> | |
| { | |
| public override IAppProfilerFactory Create(Type objectType) | |
| { | |
| // We don't use this - ReadJson below is used instead. | |
| // Inheriting from CustomCreationConverter requires that we expose this method though. | |
| throw new NotSupportedException(); | |
| } | |
| public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | |
| { | |
| JToken jsonObject = JObject.ReadFrom(reader); | |
| string providerTypeToActivate = jsonObject.Value<string>(); | |
| Type typeToActivate = Type.GetType(providerTypeToActivate); | |
| object instancedObject = Activator.CreateInstance(typeToActivate); | |
| return instancedObject as IAppProfilerFactory; | |
| } | |
| } |
This file contains hidden or 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
| public partial class ProfileRuntimeSettings | |
| { | |
| public static ProfileRuntimeSettings Load() | |
| { | |
| string json = File.ReadAllText("AppProfiling.json"); | |
| var settings = JsonConvert.DeserializeObject<ProfileRuntimeSettings>(json); | |
| return settings; | |
| } | |
| [JsonConverter(typeof(ProfilerFactoryConverter))] | |
| public IAppProfilerFactory ProfilerProvider { get; set; } | |
| public bool EnableProfiling { get; set; } | |
| public bool IsProfilerWhitelisting { get; set; } = true; | |
| public string[] IncludedTypes { get; set; } | |
| public string[] IncludedNamespaces { get; set; } | |
| } |
This file contains hidden or 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
| [TestMethod] | |
| public void ProfilerSettings_IsLoadedFromJson() | |
| { | |
| // Arrange | |
| AppProfiler.LoadSettings(); | |
| // Act | |
| IAppProfiler profiler = AppProfiler.GlobalSettings.ProfilerProvider.Create(); | |
| // Act | |
| Assert.IsNotNull(profiler); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment