Skip to content

Commit b4ffb25

Browse files
authored
Merge pull request #1006 from Particular/plugin-check
Improvements in plugin loading and error handling
2 parents 71706b6 + 95f4229 commit b4ffb25

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

src/ServiceInsight.Tests/ShellViewModelTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public void TestInitialize()
8787
app,
8888
windowManager,
8989
Substitute.For<IApplicationVersionService>(),
90+
logWindow,
9091
endpointExplorer,
9192
messageList,
9293
() => Substitute.For<ServiceControlConnectionViewModel>(),
@@ -97,14 +98,13 @@ public void TestInitialize()
9798
licenseManager,
9899
messageFlow,
99100
sagaWindow,
100-
messageBodyView,
101101
headerView,
102102
sequenceDiagramView,
103103
settingsProvider,
104104
versionUpdateChecker,
105105
messageProperties,
106-
logWindow,
107-
commandLineArgParser);
106+
commandLineArgParser,
107+
messageBodyView);
108108

109109
((IViewAware)shell).AttachView(view);
110110
}

src/ServiceInsight/AssemblyScanning/AssemblyScanner.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ IEnumerable<string> ReservedAssemblyNames
5858
yield return "DevExpress";
5959
yield return "Serilog";
6060
yield return "Mindscape";
61-
yield return "System";
62-
yield return "Microsoft";
6361
yield return "RestSharp";
6462
yield return "GongSolutions";
6563
yield return "ICSharpCode";

src/ServiceInsight/Framework/Logging/LoggingConfig.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
{
33
using System;
44
using System.IO;
5+
using System.Linq;
56
using System.Reactive.Concurrency;
67
using System.Reactive.Linq;
78
using Caliburn.Micro;
89
using LogWindow;
10+
using MessageViewers.CustomMessageViewer;
911
using Serilog;
12+
using Serilog.Core;
1013
using Serilog.Events;
1114
using Serilog.Filters;
1215
using ServiceControl;
@@ -19,9 +22,7 @@ public static void SetupLogging()
1922

2023
Log.Logger = new LoggerConfiguration()
2124
.MinimumLevel.Verbose()
22-
23-
// Turn off some of Caliburn.Micro's chattiness
24-
.Filter.ByExcluding(le => Matching.FromSource(typeof(Screen).FullName)(le) && le.Level <= LogEventLevel.Information)
25+
.Filter.ByExcluding(le => Matching.FromSource(typeof(Screen).FullName)(le) && le.Level <= LogEventLevel.Information) // Turn off some of Caliburn.Micro's chattiness
2526
.Filter.ByExcluding(le => Matching.FromSource(typeof(Caliburn.Micro.Action).FullName)(le) && le.Level <= LogEventLevel.Information)
2627
.Filter.ByExcluding(le => Matching.FromSource(typeof(ActionMessage).FullName)(le) && le.Level <= LogEventLevel.Information)
2728
.Filter.ByExcluding(le => Matching.FromSource(typeof(ViewModelBinder).FullName)(le) && le.Level <= LogEventLevel.Information)
@@ -30,7 +31,7 @@ public static void SetupLogging()
3031
.WriteTo.Trace(outputTemplate: "[{Level}] ({SourceContext}) {Message}{NewLine}{Exception}")
3132
.WriteTo.Logger(lc => lc
3233
.MinimumLevel.Verbose()
33-
.Filter.ByIncludingOnly(Matching.FromSource<DefaultServiceControl>())
34+
.Filter.ByIncludingOnly(MatchingTypes(typeof(DefaultServiceControl), typeof(CustomMessageViewerResolver)))
3435
.WriteTo.Observers(logEvents => logEvents
3536
.ObserveOn(TaskPoolScheduler.Default)
3637
.Do(LogWindowViewModel.LogObserver)
@@ -42,5 +43,15 @@ public static void SetupCaliburnMicroLogging()
4243
{
4344
LogManager.GetLog = type => new CaliburnMicroLogAdapter(Log.ForContext(type));
4445
}
46+
47+
static Func<LogEvent, bool> MatchingTypes(params Type[] type)
48+
{
49+
var scalars = type.Select(t => new ScalarValue(t.FullName));
50+
51+
return e =>
52+
{
53+
return scalars.Any(s => e.Properties.TryGetValue(Constants.SourceContextPropertyName, out var propertyValue) && s.Equals(propertyValue));
54+
};
55+
}
4556
}
4657
}

src/ServiceInsight/MessageViewers/CustomMessageViewer/CustomMessageViewerResolver.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace ServiceInsight.MessageViewers.CustomMessageViewer
22
{
3+
using System;
4+
using Anotar.Serilog;
35
using Autofac;
46

57
sealed class CustomMessageViewerResolver : ICustomMessageViewerResolver
@@ -13,7 +15,22 @@ public CustomMessageViewerResolver(ILifetimeScope autofacContainer)
1315

1416
public ICustomMessageBodyViewer GetCustomMessageBodyViewer()
1517
{
16-
return autofacContainer.ResolveOptional<ICustomMessageBodyViewer>() ?? new NopViewer();
18+
try
19+
{
20+
var viewer = autofacContainer.ResolveOptional<ICustomMessageBodyViewer>();
21+
22+
if (viewer != null)
23+
{
24+
LogTo.Information("Loaded {0} custom message viewer from the plugin.", viewer.GetType());
25+
}
26+
27+
return viewer ?? new NopViewer();
28+
}
29+
catch (Exception ex)
30+
{
31+
LogTo.Fatal(ex, "Failed to load the custom viewer plugin.");
32+
return new NopViewer();
33+
}
1734
}
1835
}
1936
}

src/ServiceInsight/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,4 @@
55

66
[assembly: ThemeInfo(
77
ResourceDictionaryLocation.None,
8-
//where theme specific resource dictionaries are located
9-
//(used if a resource is not found in the page,
10-
// or application resource dictionaries)
11-
ResourceDictionaryLocation.SourceAssembly)]
12-
//where the generic resource dictionary is located
13-
//(used if a resource is not found in the page,
14-
// app, or any theme specific resource dictionaries)
8+
ResourceDictionaryLocation.SourceAssembly)]

src/ServiceInsight/Shell/ShellViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public ShellViewModel(
5959
IAppCommands appCommander,
6060
IWindowManagerEx windowManager,
6161
IApplicationVersionService applicationVersionService,
62+
LogWindowViewModel logWindow,
6263
EndpointExplorerViewModel endpointExplorer,
6364
MessageListViewModel messages,
6465
Func<ServiceControlConnectionViewModel> serviceControlConnection,
@@ -69,14 +70,13 @@ public ShellViewModel(
6970
AppLicenseManager licenseManager,
7071
MessageFlowViewModel messageFlow,
7172
SagaWindowViewModel sagaWindow,
72-
MessageBodyViewModel messageBodyViewer,
7373
MessageHeadersViewModel messageHeadersViewer,
7474
SequenceDiagramViewModel sequenceDiagramViewer,
7575
ISettingsProvider settingsProvider,
7676
IVersionUpdateChecker versionUpdateChecker,
7777
MessagePropertiesViewModel messageProperties,
78-
LogWindowViewModel logWindow,
79-
CommandLineArgParser commandLineArgParser)
78+
CommandLineArgParser commandLineArgParser,
79+
MessageBodyViewModel messageBodyViewer)
8080
{
8181
this.appCommander = appCommander;
8282
this.windowManager = windowManager;

src/ServiceInsight/Startup/CommandLineArgParser.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@
22
{
33
using System;
44
using System.IO.Pipes;
5-
using System.ServiceProcess;
6-
using Serilog;
75
using System.Collections.Generic;
86
using System.IO;
9-
using System.Net;
10-
using System.Net.Sockets;
117
using Anotar.Serilog;
128
using ServiceInsight.Models;
13-
using ServiceInsight.Framework.Settings;
149

1510
public class CommandLineArgParser
1611
{

0 commit comments

Comments
 (0)