diff --git a/src/Microsoft.Framework.DesignTimeHost/ApplicationContext.cs b/src/Microsoft.Framework.DesignTimeHost/ApplicationContext.cs index da63fa2b0..5a2fdceda 100644 --- a/src/Microsoft.Framework.DesignTimeHost/ApplicationContext.cs +++ b/src/Microsoft.Framework.DesignTimeHost/ApplicationContext.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.Versioning; @@ -94,7 +93,7 @@ public void ProcessLoop(object state) } catch (Exception ex) { - Trace.TraceError("[ApplicationContext]: Error occured: {0}", ex); + Logger.TraceError("[ApplicationContext]: Error occured: {0}", ex); // Unhandled errors var error = new ErrorMessage @@ -186,7 +185,7 @@ private bool ProcessMessage() } } - Trace.TraceInformation("[ApplicationContext]: Received {0}", message.MessageType); + Logger.TraceInformation("[ApplicationContext]: Received {0}", message.MessageType); switch (message.MessageType) { @@ -197,13 +196,18 @@ private bool ProcessMessage() { _initializedContext = message.Sender; - var data = message.Payload.ToObject(); + var data = new InitializeMessage + { + Configuration = GetValue(message.Payload, "Configuration"), + ProjectFolder = GetValue(message.Payload, "ProjectFolder") + }; + _appPath.Value = data.ProjectFolder; _configuration.Value = data.Configuration ?? "Debug"; } else { - Trace.TraceInformation("[ApplicationContext]: Received Initialize message more than once for {0}", _appPath.Value); + Logger.TraceInformation("[ApplicationContext]: Received Initialize message more than once for {0}", _appPath.Value); } } break; @@ -214,7 +218,10 @@ private bool ProcessMessage() break; case "ChangeConfiguration": { - var data = message.Payload.ToObject(); + var data = new ChangeConfigurationMessage + { + Configuration = GetValue(message.Payload, "Configuration") + }; _configuration.Value = data.Configuration; } break; @@ -235,7 +242,14 @@ private bool ProcessMessage() break; case "GetCompiledAssembly": { - var libraryKey = message.Payload.ToObject(); + var libraryKey = new RemoteLibraryKey + { + Name = GetValue(message.Payload, "Name"), + TargetFramework = GetValue(message.Payload, "TargetFramework"), + Configuration = GetValue(message.Payload, "Configuration"), + Aspect = GetValue(message.Payload, "Aspect") + }; + var targetFramework = new FrameworkName(libraryKey.TargetFramework); // Only set this the first time for the project @@ -479,7 +493,7 @@ private void Reconcile() { if (IsDifferent(_local.ProjectInformation, _remote.ProjectInformation)) { - Trace.TraceInformation("[ApplicationContext]: OnTransmit(ProjectInformation)"); + Logger.TraceInformation("[ApplicationContext]: OnTransmit(ProjectInformation)"); _initializedContext.Transmit(new Message { @@ -514,7 +528,7 @@ private void Reconcile() if (IsDifferent(localProject.Dependencies, remoteProject.Dependencies)) { - Trace.TraceInformation("[ApplicationContext]: OnTransmit(Dependencies)"); + Logger.TraceInformation("[ApplicationContext]: OnTransmit(Dependencies)"); _initializedContext.Transmit(new Message { @@ -528,7 +542,7 @@ private void Reconcile() if (IsDifferent(localProject.CompilerOptions, remoteProject.CompilerOptions)) { - Trace.TraceInformation("[ApplicationContext]: OnTransmit(CompilerOptions)"); + Logger.TraceInformation("[ApplicationContext]: OnTransmit(CompilerOptions)"); _initializedContext.Transmit(new Message { @@ -542,7 +556,7 @@ private void Reconcile() if (IsDifferent(localProject.References, remoteProject.References)) { - Trace.TraceInformation("[ApplicationContext]: OnTransmit(References)"); + Logger.TraceInformation("[ApplicationContext]: OnTransmit(References)"); _initializedContext.Transmit(new Message { @@ -556,7 +570,7 @@ private void Reconcile() if (IsDifferent(localProject.Sources, remoteProject.Sources)) { - Trace.TraceInformation("[ApplicationContext]: OnTransmit(Sources)"); + Logger.TraceInformation("[ApplicationContext]: OnTransmit(Sources)"); _initializedContext.Transmit(new Message { @@ -615,7 +629,7 @@ private void TriggerProjectOutputsChanged() if (waitingForCompiledAssembly.AssemblySent) { - Trace.TraceInformation("[ApplicationContext]: OnTransmit(ProjectChanged)"); + Logger.TraceInformation("[ApplicationContext]: OnTransmit(ProjectChanged)"); waitingForCompiledAssembly.Connection.Transmit(writer => { @@ -643,7 +657,7 @@ private void SendCompiledAssemblies(ProjectWorld localProject) { if (!waitingForCompiledAssembly.AssemblySent) { - Trace.TraceInformation("[ApplicationContext]: OnTransmit(Assembly)"); + Logger.TraceInformation("[ApplicationContext]: OnTransmit(Assembly)"); waitingForCompiledAssembly.Connection.Transmit(writer => { @@ -989,6 +1003,11 @@ private static DependencyDescription CreateDependencyDescription(LibraryDescript }; } + private static string GetValue(JToken token, string name) + { + return token?[name]?.Value() ?? default(string); + } + private class Trigger { private TValue _value; diff --git a/src/Microsoft.Framework.DesignTimeHost/ConnectionContext.cs b/src/Microsoft.Framework.DesignTimeHost/ConnectionContext.cs index 4488663b3..63e2a5f30 100644 --- a/src/Microsoft.Framework.DesignTimeHost/ConnectionContext.cs +++ b/src/Microsoft.Framework.DesignTimeHost/ConnectionContext.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using Microsoft.Framework.DesignTimeHost.Models; using Microsoft.Framework.Runtime; @@ -57,7 +56,7 @@ public void OnReceive(Message message) ApplicationContext applicationContext; if (!_contexts.TryGetValue(message.ContextId, out applicationContext)) { - Trace.TraceInformation("[ConnectionContext]: Creating new application context for {0}", message.ContextId); + Logger.TraceInformation("[ConnectionContext]: Creating new application context for {0}", message.ContextId); applicationContext = new ApplicationContext(_services, _cache, diff --git a/src/Microsoft.Framework.DesignTimeHost/ProcessingQueue.cs b/src/Microsoft.Framework.DesignTimeHost/ProcessingQueue.cs index dfb33f04f..c3dc47f37 100644 --- a/src/Microsoft.Framework.DesignTimeHost/ProcessingQueue.cs +++ b/src/Microsoft.Framework.DesignTimeHost/ProcessingQueue.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.IO; using System.Threading; using Microsoft.Framework.DesignTimeHost.Models; +using Microsoft.Framework.Runtime; using Newtonsoft.Json; namespace Microsoft.Framework.DesignTimeHost @@ -25,7 +25,7 @@ public ProcessingQueue(Stream stream) public void Start() { - Trace.TraceInformation("[ProcessingQueue]: Start()"); + Logger.TraceInformation("[ProcessingQueue]: Start()"); new Thread(ReceiveMessages).Start(); } @@ -45,7 +45,7 @@ public bool Send(Action write) } catch (Exception ex) { - Trace.TraceInformation("[ProcessingQueue]: Error sending {0}", ex); + Logger.TraceInformation("[ProcessingQueue]: Error sending {0}", ex); } return false; @@ -57,7 +57,7 @@ public bool Send(Message message) { try { - Trace.TraceInformation("[ProcessingQueue]: Send({0})", message); + Logger.TraceInformation("[ProcessingQueue]: Send({0})", message); _writer.Write(JsonConvert.SerializeObject(message)); return true; @@ -68,7 +68,7 @@ public bool Send(Message message) } catch (Exception ex) { - Trace.TraceInformation("[ProcessingQueue]: Error sending {0}", ex); + Logger.TraceInformation("[ProcessingQueue]: Error sending {0}", ex); } } @@ -82,7 +82,7 @@ private void ReceiveMessages() while (true) { var message = JsonConvert.DeserializeObject(_reader.ReadString()); - Trace.TraceInformation("[ProcessingQueue]: OnReceive({0})", message); + Logger.TraceInformation("[ProcessingQueue]: OnReceive({0})", message); OnReceive(message); } } @@ -92,7 +92,7 @@ private void ReceiveMessages() } catch (Exception ex) { - Trace.TraceInformation("[ProcessingQueue]: Error occurred: {0}", ex); + Logger.TraceInformation("[ProcessingQueue]: Error occurred: {0}", ex); } } } diff --git a/src/Microsoft.Framework.Runtime.Common/Impl/Trace.cs b/src/Microsoft.Framework.Runtime.Common/Impl/Logger.cs similarity index 87% rename from src/Microsoft.Framework.Runtime.Common/Impl/Trace.cs rename to src/Microsoft.Framework.Runtime.Common/Impl/Logger.cs index b5142b90e..2634a45fd 100644 --- a/src/Microsoft.Framework.Runtime.Common/Impl/Trace.cs +++ b/src/Microsoft.Framework.Runtime.Common/Impl/Logger.cs @@ -1,14 +1,11 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if ASPNETCORE50 using System; -using System.Reflection; -using Microsoft.Framework.Runtime; -namespace System.Diagnostics +namespace Microsoft.Framework.Runtime { - internal static class Trace + internal static class Logger { public static void TraceError(string message, params object[] args) { @@ -42,5 +39,4 @@ private static bool IsEnabled } } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Microsoft.Framework.Runtime.Roslyn/CompilationContext.cs b/src/Microsoft.Framework.Runtime.Roslyn/CompilationContext.cs index bfd6c4e14..d2e7347e3 100644 --- a/src/Microsoft.Framework.Runtime.Roslyn/CompilationContext.cs +++ b/src/Microsoft.Framework.Runtime.Roslyn/CompilationContext.cs @@ -60,20 +60,20 @@ private static IList GetResources(CompilationContext contex var resourceProvider = new CompositeResourceProvider(new IResourceProvider[] { resxProvider, embeddedResourceProvider }); var sw = Stopwatch.StartNew(); - Trace.TraceInformation("[{0}]: Generating resources for {1}", nameof(CompilationContext), context.Project.Name); + Logger.TraceInformation("[{0}]: Generating resources for {1}", nameof(CompilationContext), context.Project.Name); var resources = resourceProvider.GetResources(context.Project); sw.Stop(); - Trace.TraceInformation("[{0}]: Generated resources for {1} in {2}ms", nameof(CompilationContext), context.Project.Name, sw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Generated resources for {1} in {2}ms", nameof(CompilationContext), context.Project.Name, sw.ElapsedMilliseconds); sw = Stopwatch.StartNew(); - Trace.TraceInformation("[{0}]: Resolving required assembly neutral references for {1}", nameof(CompilationContext), context.Project.Name); + Logger.TraceInformation("[{0}]: Resolving required assembly neutral references for {1}", nameof(CompilationContext), context.Project.Name); var embeddedReferences = EmbeddedReferencesHelper.GetRequiredEmbeddedReferences(context); resources.AddEmbeddedReferences(embeddedReferences); - Trace.TraceInformation("[{0}]: Resolved {1} required assembly neutral references for {2} in {3}ms", + Logger.TraceInformation("[{0}]: Resolved {1} required assembly neutral references for {2} in {3}ms", nameof(CompilationContext), embeddedReferences.Count, context.Project.Name, diff --git a/src/Microsoft.Framework.Runtime.Roslyn/ResxResourceProvider.cs b/src/Microsoft.Framework.Runtime.Roslyn/ResxResourceProvider.cs index efab6cce5..9d7dfba8d 100644 --- a/src/Microsoft.Framework.Runtime.Roslyn/ResxResourceProvider.cs +++ b/src/Microsoft.Framework.Runtime.Roslyn/ResxResourceProvider.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Resources; @@ -25,7 +24,7 @@ public IList GetResources(Project project) private static string GetResourceName(string projectName, string resxFilePath) { - Trace.TraceInformation("[{0}]: Found resource {1}", typeof(ResxResourceProvider).Name, resxFilePath); + Logger.TraceInformation("[{0}]: Found resource {1}", typeof(ResxResourceProvider).Name, resxFilePath); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(resxFilePath); @@ -62,4 +61,4 @@ private static Stream GetResourceStream(string resxFilePath) } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.Framework.Runtime.Roslyn/RoslynCompiler.cs b/src/Microsoft.Framework.Runtime.Roslyn/RoslynCompiler.cs index 22fa5f1f2..e2460b839 100644 --- a/src/Microsoft.Framework.Runtime.Roslyn/RoslynCompiler.cs +++ b/src/Microsoft.Framework.Runtime.Roslyn/RoslynCompiler.cs @@ -80,7 +80,7 @@ public CompilationContext CompileProject( var exportedReferences = incomingReferences.Select(ConvertMetadataReference); - Trace.TraceInformation("[{0}]: Compiling '{1}'", GetType().Name, name); + Logger.TraceInformation("[{0}]: Compiling '{1}'", GetType().Name, name); var sw = Stopwatch.StartNew(); var compilationSettings = project.GetCompilerOptions(target.TargetFramework, target.Configuration) @@ -119,7 +119,7 @@ public CompilationContext CompileProject( compilationSettings.CompilationOptions); var aniSw = Stopwatch.StartNew(); - Trace.TraceInformation("[{0}]: Scanning '{1}' for assembly neutral interfaces", GetType().Name, name); + Logger.TraceInformation("[{0}]: Scanning '{1}' for assembly neutral interfaces", GetType().Name, name); var assemblyNeutralWorker = new AssemblyNeutralWorker(compilation, embeddedReferences); assemblyNeutralWorker.FindTypeCompilations(compilation.Assembly.GlobalNamespace); @@ -130,7 +130,7 @@ public CompilationContext CompileProject( assemblyNeutralWorker.Generate(); aniSw.Stop(); - Trace.TraceInformation("[{0}]: Found {1} assembly neutral interfaces for '{2}' in {3}ms", GetType().Name, assemblyNeutralWorker.TypeCompilations.Count(), name, aniSw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Found {1} assembly neutral interfaces for '{2}' in {3}ms", GetType().Name, assemblyNeutralWorker.TypeCompilations.Count(), name, aniSw.ElapsedMilliseconds); foreach (var t in assemblyNeutralWorker.TypeCompilations) { @@ -166,11 +166,11 @@ public CompilationContext CompileProject( compilationContext.Diagnostics.Add(diag); } - Trace.TraceError("[{0}]: Failed loading meta assembly '{1}'", GetType().Name, name); + Logger.TraceError("[{0}]: Failed loading meta assembly '{1}'", GetType().Name, name); } else { - Trace.TraceError("[{0}]: Failed loading meta assembly '{1}':\n {2}", GetType().Name, name, ex); + Logger.TraceError("[{0}]: Failed loading meta assembly '{1}':\n {2}", GetType().Name, name, ex); } } } @@ -184,11 +184,11 @@ public CompilationContext CompileProject( } precompSw.Stop(); - Trace.TraceInformation("[{0}]: Compile modules ran in in {1}ms", GetType().Name, precompSw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Compile modules ran in in {1}ms", GetType().Name, precompSw.ElapsedMilliseconds); } sw.Stop(); - Trace.TraceInformation("[{0}]: Compiled '{1}' in {2}ms", GetType().Name, name, sw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Compiled '{1}' in {2}ms", GetType().Name, name, sw.ElapsedMilliseconds); return compilationContext; } diff --git a/src/Microsoft.Framework.Runtime.Roslyn/RoslynProjectReference.cs b/src/Microsoft.Framework.Runtime.Roslyn/RoslynProjectReference.cs index 5921d0420..cde70051a 100644 --- a/src/Microsoft.Framework.Runtime.Roslyn/RoslynProjectReference.cs +++ b/src/Microsoft.Framework.Runtime.Roslyn/RoslynProjectReference.cs @@ -72,7 +72,7 @@ public Assembly Load(IAssemblyLoadContext loadContext) { IList resources = CompilationContext.Resources; - Trace.TraceInformation("[{0}]: Emitting assembly for {1}", GetType().Name, Name); + Logger.TraceInformation("[{0}]: Emitting assembly for {1}", GetType().Name, Name); var sw = Stopwatch.StartNew(); @@ -84,13 +84,13 @@ public Assembly Load(IAssemblyLoadContext loadContext) } else { - Trace.TraceWarning("PDB generation is not supported on this platform"); + Logger.TraceWarning("PDB generation is not supported on this platform"); emitResult = CompilationContext.Compilation.Emit(assemblyStream, manifestResources: resources); } sw.Stop(); - Trace.TraceInformation("[{0}]: Emitted {1} in {2}ms", GetType().Name, Name, sw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Emitted {1} in {2}ms", GetType().Name, Name, sw.ElapsedMilliseconds); var diagnostics = CompilationContext.Diagnostics.Concat( emitResult.Diagnostics); @@ -148,7 +148,7 @@ public IDiagnosticResult EmitAssembly(string outputPath) // The default win32resStream extracted from compilation represents a Win32 applicaiton manifest. // It enables the assmebly information to be viewed in Windows Explorer. - Trace.TraceInformation("[{0}]: Emitting assembly for {1}", GetType().Name, Name); + Logger.TraceInformation("[{0}]: Emitting assembly for {1}", GetType().Name, Name); var sw = Stopwatch.StartNew(); @@ -167,7 +167,7 @@ public IDiagnosticResult EmitAssembly(string outputPath) } else { - Trace.TraceWarning("PDB generation is not supported on this platform"); + Logger.TraceWarning("PDB generation is not supported on this platform"); result = CompilationContext.Compilation.Emit( assemblyStream, xmlDocumentationStream: xmlDocStream, @@ -177,7 +177,7 @@ public IDiagnosticResult EmitAssembly(string outputPath) sw.Stop(); - Trace.TraceInformation("[{0}]: Emitted {1} in {2}ms", GetType().Name, Name, sw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Emitted {1} in {2}ms", GetType().Name, Name, sw.ElapsedMilliseconds); var diagnostics = new List(CompilationContext.Diagnostics); diagnostics.AddRange(result.Diagnostics); diff --git a/src/Microsoft.Framework.Runtime/ApplicationShutdown.cs b/src/Microsoft.Framework.Runtime/ApplicationShutdown.cs index bbb4f6666..b1cbdcabc 100644 --- a/src/Microsoft.Framework.Runtime/ApplicationShutdown.cs +++ b/src/Microsoft.Framework.Runtime/ApplicationShutdown.cs @@ -40,7 +40,7 @@ public void RequestShutdownWaitForDebugger() // Schedule the callback after the debugger has been detached if (Interlocked.Exchange(ref _scheduledDetachCallback, 1) == 0) { - Trace.TraceInformation("[{0}]: Scheduling shutdown request for debugger detach.", GetType().Name); + Logger.TraceInformation("[{0}]: Scheduling shutdown request for debugger detach.", GetType().Name); _debuggerDetachWatcher.ScheduleDetachCallback(); } } @@ -54,9 +54,9 @@ public void RequestShutdownWaitForDebugger() public void RequestShutdown() { // Trigger the ShutdownRequested to tell the application to unwind - Trace.TraceInformation("[{0}]: Requesting shutdown.", GetType().Name); + Logger.TraceInformation("[{0}]: Requesting shutdown.", GetType().Name); _cts.Cancel(); - Trace.TraceInformation("[{0}]: Requested shutdown.", GetType().Name); + Logger.TraceInformation("[{0}]: Requested shutdown.", GetType().Name); } } } diff --git a/src/Microsoft.Framework.Runtime/Caching/Cache.cs b/src/Microsoft.Framework.Runtime/Caching/Cache.cs index b657d70a6..283de8c48 100644 --- a/src/Microsoft.Framework.Runtime/Caching/Cache.cs +++ b/src/Microsoft.Framework.Runtime/Caching/Cache.cs @@ -64,7 +64,7 @@ private Lazy UpdateEntry(Lazy currentEntry, object k, Fu } else { - // Trace.TraceInformation("[{0}]: Cache hit for {1}", GetType().Name, k); + // Logger.TraceInformation("[{0}]: Cache hit for {1}", GetType().Name, k); // Already evaluated PropagateCacheDependencies(currentEntry.Value); @@ -108,7 +108,7 @@ private CacheEntry CreateEntry(object k, Func acquire) _accessor.Current = parentContext; } - // Trace.TraceInformation("[{0}]: Cache miss for {1}", GetType().Name, k); + // Logger.TraceInformation("[{0}]: Cache miss for {1}", GetType().Name, k); entry.CompactCacheDependencies(); return entry; diff --git a/src/Microsoft.Framework.Runtime/DefaultHost.cs b/src/Microsoft.Framework.Runtime/DefaultHost.cs index 6f83181e3..9f25a556b 100644 --- a/src/Microsoft.Framework.Runtime/DefaultHost.cs +++ b/src/Microsoft.Framework.Runtime/DefaultHost.cs @@ -119,9 +119,9 @@ private void Initialize(DefaultHostOptions options, IServiceProvider hostService cacheContextAccessor, namedCacheDependencyProvider); - Trace.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory); - Trace.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory); - Trace.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory); + Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory); + Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory); + Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory); _project = _applicationHostContext.Project; diff --git a/src/Microsoft.Framework.Runtime/DependencyManagement/DependencyWalker.cs b/src/Microsoft.Framework.Runtime/DependencyManagement/DependencyWalker.cs index 5e5f16f35..b63f322c4 100644 --- a/src/Microsoft.Framework.Runtime/DependencyManagement/DependencyWalker.cs +++ b/src/Microsoft.Framework.Runtime/DependencyManagement/DependencyWalker.cs @@ -36,7 +36,7 @@ public IEnumerable DependencyProviders public void Walk(string name, SemanticVersion version, FrameworkName targetFramework) { var sw = Stopwatch.StartNew(); - Trace.TraceInformation("[{0}]: Walking dependency graph for '{1} {2}'.", GetType().Name, name, targetFramework); + Logger.TraceInformation("[{0}]: Walking dependency graph for '{1} {2}'.", GetType().Name, name, targetFramework); var context = new WalkContext(); @@ -49,12 +49,12 @@ public void Walk(string name, SemanticVersion version, FrameworkName targetFrame targetFramework); walkSw.Stop(); - Trace.TraceInformation("[{0}]: Graph walk took {1}ms.", GetType().Name, walkSw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Graph walk took {1}ms.", GetType().Name, walkSw.ElapsedMilliseconds); context.Populate(targetFramework, Libraries); sw.Stop(); - Trace.TraceInformation("[{0}]: Resolved dependencies for {1} in {2}ms", GetType().Name, name, sw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Resolved dependencies for {1} in {2}ms", GetType().Name, name, sw.ElapsedMilliseconds); } public string GetMissingDependenciesWarning(FrameworkName targetFramework) diff --git a/src/Microsoft.Framework.Runtime/DependencyManagement/WalkContext.cs b/src/Microsoft.Framework.Runtime/DependencyManagement/WalkContext.cs index ea372b20f..4e4a97f11 100644 --- a/src/Microsoft.Framework.Runtime/DependencyManagement/WalkContext.cs +++ b/src/Microsoft.Framework.Runtime/DependencyManagement/WalkContext.cs @@ -98,7 +98,7 @@ public void Walk( }); buildTreeSw.Stop(); - Trace.TraceInformation("[{0}]: Graph walk stage 1 took in {1}ms", GetType().Name, buildTreeSw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Graph walk stage 1 took in {1}ms", GetType().Name, buildTreeSw.ElapsedMilliseconds); // now we walk the tree as often as it takes to determine // which paths are accepted or rejected, based on conflicts occuring @@ -223,7 +223,7 @@ private void TraceState(Node root) elt.WriteTo(writer); } - Trace.TraceInformation("[{0}] Current State\r\n{1}", GetType().Name, sb); + Logger.TraceInformation("[{0}] Current State\r\n{1}", GetType().Name, sb); } private static void ForEach(Node root, TState state, Func visitor) @@ -320,7 +320,7 @@ public void Populate(FrameworkName frameworkName, IList libr var resolver = groupByResolver.Key; var packageKeys = groupByResolver.Select(x => x.Value.Key).OrderBy(x => x.Name).ToList(); - Trace.TraceInformation("[{0}]: " + string.Join(", ", packageKeys), resolver.GetType().Name); + Logger.TraceInformation("[{0}]: " + string.Join(", ", packageKeys), resolver.GetType().Name); var descriptions = groupByResolver.Select(entry => { @@ -342,7 +342,7 @@ public void Populate(FrameworkName frameworkName, IList libr } sw.Stop(); - Trace.TraceInformation("[{0}]: Populate took {1}ms", GetType().Name, sw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Populate took {1}ms", GetType().Name, sw.ElapsedMilliseconds); } private IEnumerable CorrectDependencyVersion(LibraryDependency dependency) diff --git a/src/Microsoft.Framework.Runtime/DesignTime/ProcessingQueue.cs b/src/Microsoft.Framework.Runtime/DesignTime/ProcessingQueue.cs index e3daf2e7d..c5dc17e31 100644 --- a/src/Microsoft.Framework.Runtime/DesignTime/ProcessingQueue.cs +++ b/src/Microsoft.Framework.Runtime/DesignTime/ProcessingQueue.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Collections.Generic; using System.IO; using System.Threading; @@ -112,7 +111,7 @@ private void ReceiveMessages() } catch (Exception ex) { - Trace.TraceError("[{0}]: Exception occurred: {1}", GetType().Name, ex); + Logger.TraceError("[{0}]: Exception occurred: {1}", GetType().Name, ex); Closed(); return; } diff --git a/src/Microsoft.Framework.Runtime/ExportProviders/ProjectExportProviderHelper.cs b/src/Microsoft.Framework.Runtime/ExportProviders/ProjectExportProviderHelper.cs index 3de91f0bd..e8ba85550 100644 --- a/src/Microsoft.Framework.Runtime/ExportProviders/ProjectExportProviderHelper.cs +++ b/src/Microsoft.Framework.Runtime/ExportProviders/ProjectExportProviderHelper.cs @@ -39,7 +39,7 @@ public static ILibraryExport GetExportsRecursive( Func include) { var dependencyStopWatch = Stopwatch.StartNew(); - Trace.TraceInformation("[{0}]: Resolving references for '{1}' {2}", typeof(ProjectExportProviderHelper).Name, target.Name, target.Aspect); + Logger.TraceInformation("[{0}]: Resolving references for '{1}' {2}", typeof(ProjectExportProviderHelper).Name, target.Name, target.Aspect); var references = new Dictionary(StringComparer.OrdinalIgnoreCase); var sourceReferences = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -74,7 +74,7 @@ public static ILibraryExport GetExportsRecursive( if (libraryExport == null) { // TODO: Failed to resolve dependency so do something useful - Trace.TraceInformation("[{0}]: Failed to resolve dependency '{1}'", typeof(ProjectExportProviderHelper).Name, node.Library.Name); + Logger.TraceInformation("[{0}]: Failed to resolve dependency '{1}'", typeof(ProjectExportProviderHelper).Name, node.Library.Name); } else { @@ -104,7 +104,7 @@ public static ILibraryExport GetExportsRecursive( } dependencyStopWatch.Stop(); - Trace.TraceInformation("[{0}]: Resolved {1} references for '{2}' in {3}ms", + Logger.TraceInformation("[{0}]: Resolved {1} references for '{2}' in {3}ms", typeof(ProjectExportProviderHelper).Name, references.Count, target.Name, diff --git a/src/Microsoft.Framework.Runtime/ExportProviders/ProjectLibraryExportProvider.cs b/src/Microsoft.Framework.Runtime/ExportProviders/ProjectLibraryExportProvider.cs index f3f940cfd..c69f63823 100644 --- a/src/Microsoft.Framework.Runtime/ExportProviders/ProjectLibraryExportProvider.cs +++ b/src/Microsoft.Framework.Runtime/ExportProviders/ProjectLibraryExportProvider.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; namespace Microsoft.Framework.Runtime @@ -38,7 +37,7 @@ public ILibraryExport GetLibraryExport(ILibraryKey target) return null; } - Trace.TraceInformation("[{0}]: GetLibraryExport({1}, {2}, {3}, {4})", GetType().Name, target.Name, target.TargetFramework, target.Configuration, target.Aspect); + Logger.TraceInformation("[{0}]: GetLibraryExport({1}, {2}, {3}, {4})", GetType().Name, target.Name, target.TargetFramework, target.Configuration, target.Aspect); var targetFrameworkInformation = project.GetTargetFramework(target.TargetFramework); @@ -81,7 +80,7 @@ public ILibraryExport GetLibraryExport(ILibraryKey target) return LanguageServices.CreateService(_serviceProvider, _projectLoadContext.Value, typeInfo); }); - Trace.TraceInformation("[{0}]: GetProjectReference({1}, {2}, {3}, {4})", project.LanguageServices.ProjectReferenceProvider.TypeName, target.Name, target.TargetFramework, target.Configuration, target.Aspect); + Logger.TraceInformation("[{0}]: GetProjectReference({1}, {2}, {3}, {4})", project.LanguageServices.ProjectReferenceProvider.TypeName, target.Name, target.TargetFramework, target.Configuration, target.Aspect); // Get the exports for the project dependencies var projectExport = new Lazy(() => ProjectExportProviderHelper.GetExportsRecursive( diff --git a/src/Microsoft.Framework.Runtime/FileSystem/FileWatcher.cs b/src/Microsoft.Framework.Runtime/FileSystem/FileWatcher.cs index 515fa0a31..1cb1d22d5 100644 --- a/src/Microsoft.Framework.Runtime/FileSystem/FileWatcher.cs +++ b/src/Microsoft.Framework.Runtime/FileSystem/FileWatcher.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; namespace Microsoft.Framework.Runtime.FileSystem @@ -101,11 +100,11 @@ public bool ReportChange(string oldPath, string newPath, WatcherChangeTypes chan { if (oldPath != null) { - Trace.TraceInformation("{0} -> {1}", oldPath, newPath); + Logger.TraceInformation("{0} -> {1}", oldPath, newPath); } else { - Trace.TraceInformation("{0} -> {1}", changeType, newPath); + Logger.TraceInformation("{0} -> {1}", changeType, newPath); } if (OnChanged != null) diff --git a/src/Microsoft.Framework.Runtime/GlobalSettings.cs b/src/Microsoft.Framework.Runtime/GlobalSettings.cs index 4f87a7b9e..7628c1daf 100644 --- a/src/Microsoft.Framework.Runtime/GlobalSettings.cs +++ b/src/Microsoft.Framework.Runtime/GlobalSettings.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NuGet; @@ -57,7 +57,9 @@ public static bool TryGetGlobalSettings(string path, out GlobalSettings globalSe var projectSearchPaths = settings["projects"] ?? settings["sources"]; var dependencies = settings["dependencies"] as JObject; - globalSettings.ProjectSearchPaths = projectSearchPaths == null ? new string[] { } : projectSearchPaths.ToObject(); + globalSettings.ProjectSearchPaths = projectSearchPaths == null ? + new string[] { } : + projectSearchPaths.ValueAsArray(); globalSettings.PackagesPath = settings.Value("packages"); globalSettings.PackageHashes = new Dictionary(); globalSettings.FilePath = globalJsonPath; diff --git a/src/Microsoft.Framework.Runtime/JTokenExtensions.cs b/src/Microsoft.Framework.Runtime/JTokenExtensions.cs new file mode 100644 index 000000000..e041acf8e --- /dev/null +++ b/src/Microsoft.Framework.Runtime/JTokenExtensions.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using Newtonsoft.Json.Linq; + +namespace Microsoft.Framework.Runtime +{ + public static class JTokenExtensions + { + public static T[] ValueAsArray(this JToken jToken) + { + return jToken.Select(a => a.Value()).ToArray(); + } + + public static T[] ValueAsArray(this JToken jToken, string name) + { + return jToken?[name]?.ValueAsArray(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.Framework.Runtime/Project.cs b/src/Microsoft.Framework.Runtime/Project.cs index c765b1a03..f693e8f5d 100644 --- a/src/Microsoft.Framework.Runtime/Project.cs +++ b/src/Microsoft.Framework.Runtime/Project.cs @@ -315,13 +315,13 @@ public static Project GetProject(Stream stream, string projectName, string proje } project.Description = GetValue(rawProject, "description"); - project.Authors = authors == null ? new string[] { } : authors.ToObject(); + project.Authors = authors == null ? new string[] { } : authors.ValueAsArray(); project.Dependencies = new List(); project.WebRoot = GetValue(rawProject, "webroot"); project.EntryPoint = GetValue(rawProject, "entryPoint"); project.ProjectUrl = GetValue(rawProject, "projectUrl"); project.RequireLicenseAcceptance = GetValue(rawProject, "requireLicenseAcceptance") ?? false; - project.Tags = tags == null ? new string[] { } : tags.ToObject(); + project.Tags = tags == null ? new string[] { } : tags.ValueAsArray(); project.IsLoadable = GetValue(rawProject, "loadable") ?? true; // TODO: Move this to the dependencies node @@ -359,7 +359,7 @@ public static Project GetProject(Stream stream, string projectName, string proje { foreach (var command in commands) { - project.Commands[command.Key] = command.Value.ToObject(); + project.Commands[command.Key] = command.Value.Value(); } } @@ -371,11 +371,11 @@ public static Project GetProject(Stream stream, string projectName, string proje var value = script.Value; if (value.Type == JTokenType.String) { - project.Scripts[script.Key] = new string[] { value.ToObject() }; + project.Scripts[script.Key] = new string[] { value.Value() }; } else if (value.Type == JTokenType.Array) { - project.Scripts[script.Key] = script.Value.ToObject(); + project.Scripts[script.Key] = script.Value.ValueAsArray(); } else { @@ -443,7 +443,7 @@ private static IEnumerable GetSourcePatternCore(JObject rawProject, stri } // Assume it's an array (it should explode if it's not) - return token.ToObject().SelectMany(GetSourcesSplit); + return token.ValueAsArray().SelectMany(GetSourcesSplit); } private static string FolderToPattern(string candidate, string projectDir) @@ -824,8 +824,8 @@ private CompilerOptions GetCompilationOptions(JToken topLevelOrConfiguration) var options = new CompilerOptions { - Defines = ConvertValue(rawOptions, "define"), - LanguageVersion = ConvertValue(rawOptions, "languageVersion"), + Defines = rawOptions.ValueAsArray("define"), + LanguageVersion = GetValue(rawOptions, "languageVersion"), AllowUnsafe = GetValue(rawOptions, "allowUnsafe"), Platform = GetValue(rawOptions, "platform"), WarningsAsErrors = GetValue(rawOptions, "warningsAsErrors"), @@ -852,27 +852,10 @@ private static T GetValue(JToken token, string name) return obj.Value(); } - private static T ConvertValue(JToken token, string name) - { - if (token == null) - { - return default(T); - } - - var obj = token[name]; - - if (obj == null) - { - return default(T); - } - - return obj.ToObject(); - } - private static string GetDirectoryName(string path) { path = path.TrimEnd(Path.DirectorySeparatorChar); return path.Substring(Path.GetDirectoryName(path).Length).Trim(Path.DirectorySeparatorChar); } } -} +} \ No newline at end of file diff --git a/src/Microsoft.Framework.Runtime/Servicing/Breadcrumbs.cs b/src/Microsoft.Framework.Runtime/Servicing/Breadcrumbs.cs index 0d8c9b1ee..84aba54ce 100644 --- a/src/Microsoft.Framework.Runtime/Servicing/Breadcrumbs.cs +++ b/src/Microsoft.Framework.Runtime/Servicing/Breadcrumbs.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics; using System.IO; using System.Reflection; using NuGet; @@ -28,7 +27,7 @@ public Breadcrumbs(string breadcrumbsFolder) } else { - Trace.TraceInformation("Breadcrumbs for servicing will not be written because the breadcrumbs folder ({0}) does not exist.", breadcrumbsFolder); + Logger.TraceInformation("Breadcrumbs for servicing will not be written because the breadcrumbs folder ({0}) does not exist.", breadcrumbsFolder); } } @@ -96,7 +95,7 @@ private void CreateBreadcrumbFile(string fileName) if (!File.Exists(fullFilePath)) { File.Create(fullFilePath).Dispose(); - Trace.TraceInformation("Wrote servicing breadcrumb for {0}", fileName); + Logger.TraceInformation("Wrote servicing breadcrumb for {0}", fileName); } } catch (UnauthorizedAccessException exception) @@ -111,7 +110,7 @@ private void CreateBreadcrumbFile(string fileName) private static void LogBreadcrumbsCreationFailure(string fileName, Exception exception) { - Trace.TraceInformation("Failed to write servicing breadcrumb for {0} because an exception was thrown: {1}", fileName, exception); + Logger.TraceInformation("Failed to write servicing breadcrumb for {0} because an exception was thrown: {1}", fileName, exception); } } } \ No newline at end of file diff --git a/src/Microsoft.Framework.Runtime/Servicing/ServicingIndex.cs b/src/Microsoft.Framework.Runtime/Servicing/ServicingIndex.cs index a0dedc549..fd788ccea 100644 --- a/src/Microsoft.Framework.Runtime/Servicing/ServicingIndex.cs +++ b/src/Microsoft.Framework.Runtime/Servicing/ServicingIndex.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.IO; using NuGet; -using System.Diagnostics; namespace Microsoft.Framework.Runtime.Servicing { @@ -20,12 +19,12 @@ public void Initialize(string folderPath) var indexFilePath = Path.Combine(folderPath, "index.txt"); if (!File.Exists(indexFilePath)) { - Trace.TraceInformation("[{0}]: Servicing index not found at {1}", GetType().Name, indexFilePath); + Logger.TraceInformation("[{0}]: Servicing index not found at {1}", GetType().Name, indexFilePath); return; } else { - Trace.TraceInformation("[{0}]: Servicing index loaded from {1}", GetType().Name, indexFilePath); + Logger.TraceInformation("[{0}]: Servicing index loaded from {1}", GetType().Name, indexFilePath); } using (var stream = new FileStream(indexFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { @@ -43,14 +42,14 @@ public void Initialize(string folderPath) var parts = line.Split(new[] { '=' }, 2); if (parts.Length != 2) { - Trace.TraceInformation("[{0}]: {1}({2}): malformed servicing file", GetType().Name, indexFilePath, lineNumber); + Logger.TraceInformation("[{0}]: {1}({2}): malformed servicing file", GetType().Name, indexFilePath, lineNumber); continue; } parts[0] = parts[0].Trim(); parts[1] = parts[1].Trim(); if (parts[0].Length == 0 || parts[1].Length == 0) { - Trace.TraceInformation("[{0}]: {1}({2}): malformed servicing file", GetType().Name, indexFilePath, lineNumber); + Logger.TraceInformation("[{0}]: {1}({2}): malformed servicing file", GetType().Name, indexFilePath, lineNumber); continue; } var fields = parts[0].Split(new[] { '|' }); @@ -58,20 +57,20 @@ public void Initialize(string folderPath) { if (fields.Length != 4) { - Trace.TraceInformation("[{0}]: {1}({2}): malformed servicing key", GetType().Name, indexFilePath, lineNumber); + Logger.TraceInformation("[{0}]: {1}({2}): malformed servicing key", GetType().Name, indexFilePath, lineNumber); continue; } SemanticVersion version; if (!SemanticVersion.TryParseStrict(fields[2], out version)) { - Trace.TraceInformation("[{0}]: {1}({2}): malformed servicing version ", GetType().Name, indexFilePath, lineNumber); + Logger.TraceInformation("[{0}]: {1}({2}): malformed servicing version ", GetType().Name, indexFilePath, lineNumber); continue; } var key = new EntryKey(fields[1], version); Entry entry; if (!_entries.TryGetValue(key, out entry)) { - Trace.TraceInformation("[{0}]: Adding entry for {1} {2}", GetType().Name, key.Id, key.Version); + Logger.TraceInformation("[{0}]: Adding entry for {1} {2}", GetType().Name, key.Id, key.Version); entry = new Entry(); _entries.Add(key, entry); } @@ -93,7 +92,7 @@ public bool TryGetReplacement(string packageId, SemanticVersion packageVersion, if (string.Equals(normalizedAssetPath, mapping.AssetPath, StringComparison.OrdinalIgnoreCase)) { replacementPath = Path.Combine(_folderPath, mapping.ReplacementPath); - Trace.TraceInformation("[{0}]: Using replacement {4} for {1} {2} {3}", GetType().Name, packageId, packageVersion, assetPath, replacementPath); + Logger.TraceInformation("[{0}]: Using replacement {4} for {1} {2} {3}", GetType().Name, packageId, packageVersion, assetPath, replacementPath); return true; } } diff --git a/src/kre.host/LoaderContainer.cs b/src/kre.host/LoaderContainer.cs index 628cffd8d..7dd21f230 100644 --- a/src/kre.host/LoaderContainer.cs +++ b/src/kre.host/LoaderContainer.cs @@ -30,7 +30,7 @@ public IDisposable AddLoader(IAssemblyLoader loader) public Assembly Load(string name) { - Trace.TraceInformation("[{0}]: Load name={1}", GetType().Name, name); + Logger.TraceInformation("[{0}]: Load name={1}", GetType().Name, name); var sw = Stopwatch.StartNew(); foreach (var loader in _loaders.Reverse()) @@ -38,7 +38,7 @@ public Assembly Load(string name) var assembly = loader.Load(name); if (assembly != null) { - Trace.TraceInformation("[{0}]: Loaded name={1} in {2}ms", loader.GetType().Name, name, sw.ElapsedMilliseconds); + Logger.TraceInformation("[{0}]: Loaded name={1} in {2}ms", loader.GetType().Name, name, sw.ElapsedMilliseconds); return assembly; } } diff --git a/src/kre.hosting.shared/RuntimeBootstrapper.cs b/src/kre.hosting.shared/RuntimeBootstrapper.cs index d6df6e752..d52f26553 100644 --- a/src/kre.hosting.shared/RuntimeBootstrapper.cs +++ b/src/kre.hosting.shared/RuntimeBootstrapper.cs @@ -73,16 +73,6 @@ private static void PrintErrors(Exception ex) public static Task ExecuteAsync(string[] args) { - var enableTrace = Environment.GetEnvironmentVariable(EnvironmentNames.Trace) == "1"; -#if ASPNET50 - // TODO: Make this pluggable and not limited to the console logger - if (enableTrace) - { - var listener = new ConsoleTraceListener(); - Trace.Listeners.Add(listener); - Trace.AutoFlush = true; - } -#endif var app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = Constants.BootstrapperExeName; diff --git a/test/Microsoft.Framework.Runtime.Tests/DependencyWalkerFacts.cs b/test/Microsoft.Framework.Runtime.Tests/DependencyWalkerFacts.cs index f7184cbbb..9277e2281 100644 --- a/test/Microsoft.Framework.Runtime.Tests/DependencyWalkerFacts.cs +++ b/test/Microsoft.Framework.Runtime.Tests/DependencyWalkerFacts.cs @@ -193,7 +193,7 @@ public IEnumerable GetAttemptedPaths(FrameworkName targetFramework) public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkName frameworkName) { - Trace.WriteLine(string.Format("StubAssemblyLoader.GetDependencies {0} {1} {2}", libraryRange.Name, libraryRange.VersionRange, frameworkName)); + Logger.TraceInformation("StubAssemblyLoader.GetDependencies {0} {1} {2}", libraryRange.Name, libraryRange.VersionRange, frameworkName); Entry entry; if (!_entries.TryGetValue(libraryRange, out entry)) { @@ -201,7 +201,7 @@ public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkNam } var d = entry.Dependencies as LibraryDependency[] ?? entry.Dependencies.ToArray(); - Trace.WriteLine(string.Format("StubAssemblyLoader.GetDependencies {0} {1}", d.Aggregate("", (a, b) => a + " " + b), frameworkName)); + Logger.TraceInformation("StubAssemblyLoader.GetDependencies {0} {1}", d.Aggregate("", (a, b) => a + " " + b), frameworkName); return new LibraryDescription { @@ -214,7 +214,7 @@ public void Initialize(IEnumerable packages, FrameworkName f { var d = packages.Select(CreateDependency).ToArray(); - Trace.WriteLine(string.Format("StubAssemblyLoader.Initialize {0} {1}", d.Aggregate("", (a, b) => a + " " + b), frameworkName)); + Logger.TraceInformation("StubAssemblyLoader.Initialize {0} {1}", d.Aggregate("", (a, b) => a + " " + b), frameworkName); Dependencies = d; FrameworkName = frameworkName;