Skip to content

Commit 3796552

Browse files
authored
Merge pull request #1931 from Hosch250/SourceControlLogging
Add more logging to Source Control
2 parents fb67486 + bb48e3d commit 3796552

File tree

71 files changed

+505
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+505
-310
lines changed

RetailCoder.VBE/App.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ private void LoadConfig()
494494
_logger.Debug("Loading configuration");
495495
_config = _configService.LoadConfiguration();
496496

497+
_autoSave.ConfigServiceSettingsChanged(this, EventArgs.Empty);
498+
497499
var currentCulture = RubberduckUI.Culture;
498500
try
499501
{

RetailCoder.VBE/AutoSave/AutoSave.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ public AutoSave(VBE vbe, IGeneralConfigService configService)
2222

2323
_configService.SettingsChanged += ConfigServiceSettingsChanged;
2424
_timer.Elapsed += _timer_Elapsed;
25-
26-
ConfigServiceSettingsChanged(null, EventArgs.Empty);
25+
_timer.Enabled = false;
2726
}
2827

29-
private void ConfigServiceSettingsChanged(object sender, EventArgs e)
28+
public void ConfigServiceSettingsChanged(object sender, EventArgs e)
3029
{
3130
var config = _configService.LoadConfiguration();
3231

RetailCoder.VBE/Common/Hotkeys/Hotkey.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace Rubberduck.Common.Hotkeys
1111
public class Hotkey : IHotkey
1212
{
1313
private readonly string _key;
14-
private readonly ICommand _command;
14+
private readonly CommandBase _command;
1515
private readonly IntPtr _hWndVbe;
1616
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
1717

18-
public Hotkey(IntPtr hWndVbe, string key, ICommand command, Keys secondKey = Keys.None)
18+
public Hotkey(IntPtr hWndVbe, string key, CommandBase command, Keys secondKey = Keys.None)
1919
{
2020
_hWndVbe = hWndVbe;
2121

@@ -26,7 +26,7 @@ public Hotkey(IntPtr hWndVbe, string key, ICommand command, Keys secondKey = Key
2626
SecondKey = secondKey;
2727
}
2828

29-
public ICommand Command { get { return _command; } }
29+
public CommandBase Command { get { return _command; } }
3030
public string Key { get { return _key; } }
3131
public HotkeyInfo HotkeyInfo { get; private set; }
3232
public Keys Combo { get; private set; }

RetailCoder.VBE/Common/Hotkeys/IHotkey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System.Windows.Forms;
22
using System.Windows.Input;
3+
using Rubberduck.UI.Command;
34

45
namespace Rubberduck.Common.Hotkeys
56
{
67
public interface IHotkey : IAttachable
78
{
89
string Key { get; }
9-
ICommand Command { get; }
10+
CommandBase Command { get; }
1011
HotkeyInfo HotkeyInfo { get; }
1112
Keys Combo { get; }
1213
Keys SecondKey { get; }

RetailCoder.VBE/Common/RubberduckHooks.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4+
using System.Diagnostics;
45
using System.Linq;
56
using System.Runtime.InteropServices;
67
using System.Windows.Forms;
@@ -26,12 +27,11 @@ public class RubberduckHooks : IRubberduckHooks
2627
private IRawDevice _kb;
2728
private IRawDevice _mouse;
2829
private readonly IGeneralConfigService _config;
29-
private readonly IEnumerable<ICommand> _commands;
30+
private readonly IEnumerable<CommandBase> _commands;
3031
private readonly IList<IAttachable> _hooks = new List<IAttachable>();
31-
private readonly IDictionary<RubberduckHotkey, ICommand> _mappings;
3232
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
3333

34-
public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<ICommand> commands)
34+
public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<CommandBase> commands)
3535
{
3636
_vbe = vbe;
3737
_mainWindowHandle = (IntPtr)vbe.MainWindow.HWnd;
@@ -42,29 +42,11 @@ public RubberduckHooks(VBE vbe, IGeneralConfigService config, IEnumerable<IComma
4242

4343
_commands = commands;
4444
_config = config;
45-
_mappings = GetCommandMappings();
4645
}
4746

48-
private ICommand Command<TCommand>() where TCommand : ICommand
47+
private CommandBase Command(RubberduckHotkey hotkey)
4948
{
50-
return _commands.OfType<TCommand>().SingleOrDefault();
51-
}
52-
53-
private IDictionary<RubberduckHotkey, ICommand> GetCommandMappings()
54-
{
55-
return new Dictionary<RubberduckHotkey, ICommand>
56-
{
57-
{ RubberduckHotkey.ParseAll, Command<ReparseCommand>() },
58-
{ RubberduckHotkey.CodeExplorer, Command<CodeExplorerCommand>() },
59-
{ RubberduckHotkey.IndentModule, Command<IndentCurrentModuleCommand>() },
60-
{ RubberduckHotkey.IndentProcedure, Command<IndentCurrentProcedureCommand>() },
61-
{ RubberduckHotkey.FindSymbol, Command<FindSymbolCommand>() },
62-
{ RubberduckHotkey.RefactorMoveCloserToUsage, Command<RefactorMoveCloserToUsageCommand>() },
63-
{ RubberduckHotkey.InspectionResults, Command<InspectionResultsCommand>() },
64-
{ RubberduckHotkey.RefactorExtractMethod, Command<RefactorExtractMethodCommand>() },
65-
{ RubberduckHotkey.RefactorRename, Command<CodePaneRefactorRenameCommand>() },
66-
{ RubberduckHotkey.TestExplorer, Command<TestExplorerCommand>() }
67-
};
49+
return _commands.SingleOrDefault(s => s.Hotkey == hotkey);
6850
}
6951

7052
public void HookHotkeys()
@@ -92,7 +74,10 @@ public void HookHotkeys()
9274
RubberduckHotkey assigned;
9375
if (Enum.TryParse(hotkey.Name, out assigned))
9476
{
95-
AddHook(new Hotkey(_mainWindowHandle, hotkey.ToString(), _mappings[assigned]));
77+
var command = Command(assigned);
78+
Debug.Assert(command != null);
79+
80+
AddHook(new Hotkey(_mainWindowHandle, hotkey.ToString(), command));
9681
}
9782
}
9883
Attach();

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
2323
private readonly FolderHelper _folderHelper;
2424
private readonly RubberduckParserState _state;
2525

26-
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<ICommand> commands)
26+
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<CommandBase> commands)
2727
{
2828
_folderHelper = folderHelper;
2929
_state = state;
@@ -143,14 +143,14 @@ public bool SortBySelection
143143
}
144144
}
145145

146-
private readonly ICommand _copyResultsCommand;
147-
public ICommand CopyResultsCommand { get { return _copyResultsCommand; } }
146+
private readonly CommandBase _copyResultsCommand;
147+
public CommandBase CopyResultsCommand { get { return _copyResultsCommand; } }
148148

149-
private readonly ICommand _setNameSortCommand;
150-
public ICommand SetNameSortCommand { get { return _setNameSortCommand; } }
149+
private readonly CommandBase _setNameSortCommand;
150+
public CommandBase SetNameSortCommand { get { return _setNameSortCommand; } }
151151

152-
private readonly ICommand _setSelectionSortCommand;
153-
public ICommand SetSelectionSortCommand { get { return _setSelectionSortCommand; } }
152+
private readonly CommandBase _setSelectionSortCommand;
153+
public CommandBase SetSelectionSortCommand { get { return _setSelectionSortCommand; } }
154154

155155
private bool _sortByType = true;
156156
public bool SortByType
@@ -419,64 +419,64 @@ private void SetErrorState(CodeExplorerItemViewModel itemNode, VBComponent compo
419419
}
420420
}
421421

422-
private readonly ICommand _refreshCommand;
423-
public ICommand RefreshCommand { get { return _refreshCommand; } }
422+
private readonly CommandBase _refreshCommand;
423+
public CommandBase RefreshCommand { get { return _refreshCommand; } }
424424

425-
private readonly ICommand _refreshComponentCommand;
426-
public ICommand RefreshComponentCommand { get { return _refreshComponentCommand; } }
425+
private readonly CommandBase _refreshComponentCommand;
426+
public CommandBase RefreshComponentCommand { get { return _refreshComponentCommand; } }
427427

428-
private readonly ICommand _navigateCommand;
429-
public ICommand NavigateCommand { get { return _navigateCommand; } }
428+
private readonly CommandBase _navigateCommand;
429+
public CommandBase NavigateCommand { get { return _navigateCommand; } }
430430

431-
private readonly ICommand _addTestModuleCommand;
432-
public ICommand AddTestModuleCommand { get { return _addTestModuleCommand; } }
431+
private readonly CommandBase _addTestModuleCommand;
432+
public CommandBase AddTestModuleCommand { get { return _addTestModuleCommand; } }
433433

434-
private readonly ICommand _addStdModuleCommand;
435-
public ICommand AddStdModuleCommand { get { return _addStdModuleCommand; } }
434+
private readonly CommandBase _addStdModuleCommand;
435+
public CommandBase AddStdModuleCommand { get { return _addStdModuleCommand; } }
436436

437-
private readonly ICommand _addClassModuleCommand;
438-
public ICommand AddClassModuleCommand { get { return _addClassModuleCommand; } }
437+
private readonly CommandBase _addClassModuleCommand;
438+
public CommandBase AddClassModuleCommand { get { return _addClassModuleCommand; } }
439439

440-
private readonly ICommand _addUserFormCommand;
441-
public ICommand AddUserFormCommand { get { return _addUserFormCommand; } }
440+
private readonly CommandBase _addUserFormCommand;
441+
public CommandBase AddUserFormCommand { get { return _addUserFormCommand; } }
442442

443-
private readonly ICommand _openDesignerCommand;
444-
public ICommand OpenDesignerCommand { get { return _openDesignerCommand; } }
443+
private readonly CommandBase _openDesignerCommand;
444+
public CommandBase OpenDesignerCommand { get { return _openDesignerCommand; } }
445445

446-
private readonly ICommand _openProjectPropertiesCommand;
447-
public ICommand OpenProjectPropertiesCommand { get { return _openProjectPropertiesCommand; } }
446+
private readonly CommandBase _openProjectPropertiesCommand;
447+
public CommandBase OpenProjectPropertiesCommand { get { return _openProjectPropertiesCommand; } }
448448

449-
private readonly ICommand _renameCommand;
450-
public ICommand RenameCommand { get { return _renameCommand; } }
449+
private readonly CommandBase _renameCommand;
450+
public CommandBase RenameCommand { get { return _renameCommand; } }
451451

452-
private readonly ICommand _indenterCommand;
453-
public ICommand IndenterCommand { get { return _indenterCommand; } }
452+
private readonly CommandBase _indenterCommand;
453+
public CommandBase IndenterCommand { get { return _indenterCommand; } }
454454

455-
private readonly ICommand _findAllReferencesCommand;
456-
public ICommand FindAllReferencesCommand { get { return _findAllReferencesCommand; } }
455+
private readonly CommandBase _findAllReferencesCommand;
456+
public CommandBase FindAllReferencesCommand { get { return _findAllReferencesCommand; } }
457457

458-
private readonly ICommand _findAllImplementationsCommand;
459-
public ICommand FindAllImplementationsCommand { get { return _findAllImplementationsCommand; } }
458+
private readonly CommandBase _findAllImplementationsCommand;
459+
public CommandBase FindAllImplementationsCommand { get { return _findAllImplementationsCommand; } }
460460

461-
private readonly ICommand _importCommand;
462-
public ICommand ImportCommand { get { return _importCommand; } }
461+
private readonly CommandBase _importCommand;
462+
public CommandBase ImportCommand { get { return _importCommand; } }
463463

464-
private readonly ICommand _exportCommand;
465-
public ICommand ExportCommand { get { return _exportCommand; } }
464+
private readonly CommandBase _exportCommand;
465+
public CommandBase ExportCommand { get { return _exportCommand; } }
466466

467-
private readonly ICommand _removeCommand;
468-
public ICommand RemoveCommand { get { return _removeCommand; } }
467+
private readonly CommandBase _removeCommand;
468+
public CommandBase RemoveCommand { get { return _removeCommand; } }
469469

470-
private readonly ICommand _printCommand;
471-
public ICommand PrintCommand { get { return _printCommand; } }
470+
private readonly CommandBase _printCommand;
471+
public CommandBase PrintCommand { get { return _printCommand; } }
472472

473-
private readonly ICommand _commitCommand;
474-
public ICommand CommitCommand { get { return _commitCommand; } }
473+
private readonly CommandBase _commitCommand;
474+
public CommandBase CommitCommand { get { return _commitCommand; } }
475475

476-
private readonly ICommand _undoCommand;
477-
public ICommand UndoCommand { get { return _undoCommand; } }
476+
private readonly CommandBase _undoCommand;
477+
public CommandBase UndoCommand { get { return _undoCommand; } }
478478

479-
private readonly ICommand _externalRemoveCommand;
479+
private readonly CommandBase _externalRemoveCommand;
480480

481481
// this is a special case--we have to reset SelectedItem to prevent a crash
482482
private void ExecuteRemoveComand(object param)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using Ninject.Extensions.Interception;
3+
using NLog;
4+
5+
namespace Rubberduck.Root
6+
{
7+
/// <summary>
8+
/// An interceptor that logs an unhandled exception.
9+
/// </summary>
10+
public class FatalExceptionInterceptor : InterceptorBase
11+
{
12+
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
13+
14+
protected override void OnError(IInvocation invocation, Exception exception)
15+
{
16+
_logger.Fatal(exception);
17+
throw new InterceptedException(exception);
18+
}
19+
}
20+
}

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ private void BindCommandsToMenuItems()
311311
.Where(type => type.IsClass && type.Namespace != null && type.Namespace.StartsWith(typeof(CommandBase).Namespace ?? String.Empty))
312312
.ToList();
313313

314-
// note: ICommand naming convention: [Foo]Command
314+
// note: CommandBase naming convention: [Foo]Command
315315
var baseCommandTypes = new[] { typeof(CommandBase), typeof(RefactorCommandBase) };
316316
var commands = types.Where(type => type.IsClass && baseCommandTypes.Contains(type.BaseType) && type.Name.EndsWith("Command"));
317317
foreach (var command in commands)
@@ -323,17 +323,16 @@ private void BindCommandsToMenuItems()
323323
var item = types.SingleOrDefault(type => type.Name == commandName + "CommandMenuItem");
324324
if (item != null)
325325
{
326-
var binding = Bind<ICommand>().To(command);
326+
var binding = Bind<CommandBase>().To(command);
327327
var whenCommandMenuItemCondition =
328328
binding.WhenInjectedInto(item).BindingConfiguration.Condition;
329329
var whenHooksCondition =
330330
binding.WhenInjectedInto<RubberduckHooks>().BindingConfiguration.Condition;
331331

332332
binding.When(request => whenCommandMenuItemCondition(request) || whenHooksCondition(request))
333-
.InSingletonScope();
333+
.InSingletonScope();
334334

335-
//Bind<ICommand>().To(command).WhenInjectedExactlyInto(item);
336-
//Bind<ICommand>().To(command);
335+
binding.Intercept().With<FatalExceptionInterceptor>();
337336
}
338337
}
339338
catch (InvalidOperationException)
@@ -353,7 +352,7 @@ private void BindCommandsToCodeExplorer()
353352

354353
foreach (var command in commands)
355354
{
356-
Bind<ICommand>().To(command).InSingletonScope();
355+
Bind<CommandBase>().To(command).InSingletonScope();
357356
}
358357
}
359358

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@
391391
<Compile Include="Refactorings\ExtractMethod\IExtractMethodProc.cs" />
392392
<Compile Include="Refactorings\ExtractMethod\IExtractMethodRule.cs" />
393393
<Compile Include="Refactorings\ExtractMethod\IExtractMethodSelectionValidation.cs" />
394+
<Compile Include="Root\FatalExceptionInterceptor.cs" />
394395
<Compile Include="Root\EnumerableCounterInterceptor.cs" />
395396
<Compile Include="Root\InterceptedException.cs" />
396397
<Compile Include="Root\InterceptorBase.cs" />

RetailCoder.VBE/Settings/RubberduckHotkey.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Rubberduck.Settings
22
{
33
public enum RubberduckHotkey
44
{
5+
None,
56
ParseAll,
67
IndentProcedure,
78
IndentModule,

0 commit comments

Comments
 (0)