-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ILogFileOutlinePlugin's content is displayed in the outline side panel …
- Loading branch information
1 parent
e77a900
commit 70ef480
Showing
7 changed files
with
228 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
98 changes: 98 additions & 0 deletions
98
src/Tailviewer/Ui/Controls/SidePanel/Outline/LogFileOutlineViewModelProxy.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Reflection; | ||
using System.Windows; | ||
using log4net; | ||
using Tailviewer.BusinessLogic.LogFiles; | ||
using Tailviewer.Ui.Outline; | ||
|
||
namespace Tailviewer.Ui.Controls.SidePanel.Outline | ||
{ | ||
/// <summary> | ||
/// Responsible for wrapping a <see cref="ILogFileOutlineViewModel" /> and catching all of its unhandled | ||
/// exceptions, if necessary. | ||
/// </summary> | ||
internal sealed class LogFileOutlineViewModelProxy | ||
: ILogFileOutlineViewModel | ||
{ | ||
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
private readonly ILogFileOutlineViewModel _innerViewModel; | ||
|
||
private readonly ILogFileOutlinePlugin _plugin; | ||
private readonly IServiceContainer _services; | ||
|
||
public LogFileOutlineViewModelProxy(ILogFileOutlinePlugin plugin, IServiceContainer services, ILogFile logFile) | ||
{ | ||
_plugin = plugin; | ||
_services = services; | ||
_innerViewModel = TryCreateViewModel(services, plugin, logFile); | ||
} | ||
|
||
#region Implementation of INotifyPropertyChanged | ||
|
||
#pragma warning disable 67 | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
#pragma warning restore 67 | ||
|
||
#endregion | ||
|
||
private static ILogFileOutlineViewModel TryCreateViewModel(IServiceContainer services, | ||
ILogFileOutlinePlugin plugin, | ||
ILogFile logFile) | ||
{ | ||
try | ||
{ | ||
return plugin.CreateViewModel(services, logFile); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.ErrorFormat("Caught unexpected exception: {0}", e); | ||
return null; | ||
} | ||
} | ||
|
||
public FrameworkElement TryCreateContent() | ||
{ | ||
if (_innerViewModel == null) | ||
return null; | ||
|
||
try | ||
{ | ||
return _plugin.CreateContentPresenterFor(_services, _innerViewModel); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.ErrorFormat("Caught unexpected exception: {0}", e); | ||
return null; | ||
} | ||
} | ||
|
||
#region Implementation of IDisposable | ||
|
||
public void Dispose() | ||
{ | ||
try | ||
{ | ||
_innerViewModel?.Dispose(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.ErrorFormat("Caught unexpected exception: {0}", e); | ||
} | ||
} | ||
|
||
public void Update() | ||
{ | ||
try | ||
{ | ||
_innerViewModel?.Update(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.ErrorFormat("Caught unexpected exception: {0}", e); | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains 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
Oops, something went wrong.