Skip to content

Commit a5f4eab

Browse files
authored
Merge pull request #1832 from Hosch250/SCLogging
Add logging to SC.
2 parents 0a56f7e + 270be9c commit a5f4eab

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

RetailCoder.VBE/UI/SourceControl/BranchesViewViewModel.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Windows.Input;
5+
using NLog;
56
using Rubberduck.SourceControl;
67
using Rubberduck.UI.Command;
78
// ReSharper disable ExplicitCallerInfoArgument
@@ -10,6 +11,8 @@ namespace Rubberduck.UI.SourceControl
1011
{
1112
public class BranchesViewViewModel : ViewModelBase, IControlViewModel
1213
{
14+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
15+
1316
public BranchesViewViewModel()
1417
{
1518
_newBranchCommand = new DelegateCommand(_ => CreateBranch(), _ => Provider != null);
@@ -35,13 +38,17 @@ public ISourceControlProvider Provider
3538
get { return _provider; }
3639
set
3740
{
41+
Logger.Trace("Provider changed");
42+
3843
_provider = value;
3944
RefreshView();
4045
}
4146
}
4247

4348
public void RefreshView()
4449
{
50+
Logger.Trace("Refreshing view");
51+
4552
OnPropertyChanged("LocalBranches");
4653
OnPropertyChanged("PublishedBranches");
4754
OnPropertyChanged("UnpublishedBranches");
@@ -192,7 +199,7 @@ public bool IsNotValidBranchName
192199
get { return !IsValidBranchName(NewBranchName); }
193200
}
194201

195-
public bool IsValidBranchName(string name)
202+
private bool IsValidBranchName(string name)
196203
{
197204
// Rules taken from https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
198205
var isValidName = !string.IsNullOrEmpty(name) &&
@@ -285,6 +292,7 @@ private void MergeBranch()
285292

286293
private void CreateBranchOk()
287294
{
295+
Logger.Trace("Creating branch {0}", NewBranchName);
288296
try
289297
{
290298
Provider.CreateBranch(CreateBranchSource, NewBranchName);
@@ -308,6 +316,8 @@ private void CreateBranchCancel()
308316

309317
private void MergeBranchOk()
310318
{
319+
Logger.Trace("Merging branch {0} into branch {1}", SourceBranch, DestinationBranch);
320+
311321
OnLoadingComponentsStarted();
312322

313323
try
@@ -333,6 +343,8 @@ private void MergeBranchCancel()
333343

334344
private void DeleteBranch(bool isBranchPublished)
335345
{
346+
Logger.Trace("Deleting {0}published branch {1}", isBranchPublished ? "" : "un",
347+
isBranchPublished ? CurrentPublishedBranch : CurrentUnpublishedBranch);
336348
try
337349
{
338350
Provider.DeleteBranch(isBranchPublished ? CurrentPublishedBranch : CurrentUnpublishedBranch);
@@ -355,6 +367,7 @@ private bool CanDeleteBranch(bool isBranchPublished)
355367

356368
private void PublishBranch()
357369
{
370+
Logger.Trace("Publishing branch {0}", CurrentUnpublishedBranch);
358371
try
359372
{
360373
Provider.Publish(CurrentUnpublishedBranch);
@@ -369,6 +382,7 @@ private void PublishBranch()
369382

370383
private void UnpublishBranch()
371384
{
385+
Logger.Trace("Unpublishing branch {0}", CurrentPublishedBranch);
372386
try
373387
{
374388
Provider.Unpublish(Provider.Branches.First(b => b.Name == CurrentPublishedBranch).TrackingName);

RetailCoder.VBE/UI/SourceControl/ChangesViewViewModel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.ObjectModel;
33
using System.Linq;
44
using System.Windows.Input;
5+
using NLog;
56
using Rubberduck.SourceControl;
67
using Rubberduck.UI.Command;
78
// ReSharper disable ExplicitCallerInfoArgument
@@ -10,6 +11,8 @@ namespace Rubberduck.UI.SourceControl
1011
{
1112
public class ChangesViewViewModel : ViewModelBase, IControlViewModel
1213
{
14+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
15+
1316
public ChangesViewViewModel()
1417
{
1518
_commitCommand = new DelegateCommand(_ => Commit(), _ => !string.IsNullOrEmpty(CommitMessage) && IncludedChanges != null && IncludedChanges.Any());
@@ -48,6 +51,8 @@ public ISourceControlProvider Provider
4851

4952
public void RefreshView()
5053
{
54+
Logger.Trace("Refreshing view");
55+
5156
OnPropertyChanged("CurrentBranch");
5257

5358
IncludedChanges = Provider == null
@@ -127,6 +132,8 @@ public ObservableCollection<IFileStatusEntry> UntrackedFiles
127132

128133
private void UndoChanges(IFileStatusEntry fileStatusEntry)
129134
{
135+
Logger.Trace("Undoing changes to file {0}", fileStatusEntry.FilePath);
136+
130137
try
131138
{
132139
var localLocation = Provider.CurrentRepository.LocalLocation.EndsWith("\\")
@@ -145,6 +152,8 @@ private void UndoChanges(IFileStatusEntry fileStatusEntry)
145152

146153
private void Commit()
147154
{
155+
Logger.Trace("Committing");
156+
148157
var changes = IncludedChanges.Select(c => c.FilePath).ToList();
149158
if (!changes.Any())
150159
{
@@ -158,12 +167,14 @@ private void Commit()
158167

159168
if (CommitAction == CommitAction.CommitAndSync)
160169
{
170+
Logger.Trace("Commit and sync (pull + push)");
161171
Provider.Pull();
162172
Provider.Push();
163173
}
164174

165175
if (CommitAction == CommitAction.CommitAndPush)
166176
{
177+
Logger.Trace("Commit and push");
167178
Provider.Push();
168179
}
169180

@@ -194,10 +205,12 @@ private void IncludeChanges(IFileStatusEntry fileStatusEntry)
194205
{
195206
if (UntrackedFiles.FirstOrDefault(f => f.FilePath == fileStatusEntry.FilePath) != null)
196207
{
208+
Logger.Trace("Tracking file {0}", fileStatusEntry.FilePath);
197209
Provider.AddFile(fileStatusEntry.FilePath);
198210
}
199211
else
200212
{
213+
Logger.Trace("Removing file {0} from excluded changes", fileStatusEntry.FilePath);
201214
ExcludedChanges.Remove(ExcludedChanges.FirstOrDefault(f => f.FilePath == fileStatusEntry.FilePath));
202215
}
203216

@@ -206,6 +219,7 @@ private void IncludeChanges(IFileStatusEntry fileStatusEntry)
206219

207220
private void ExcludeChanges(IFileStatusEntry fileStatusEntry)
208221
{
222+
Logger.Trace("Adding file {0} to excluded changes", fileStatusEntry.FilePath);
209223
ExcludedChanges.Add(fileStatusEntry);
210224

211225
RefreshView();

RetailCoder.VBE/UI/SourceControl/SettingsViewViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
using System.IO;
44
using System.Windows.Forms;
55
using System.Windows.Input;
6+
using NLog;
67
using Rubberduck.UI.Command;
78
using Rubberduck.SourceControl;
89

910
namespace Rubberduck.UI.SourceControl
1011
{
1112
public class SettingsViewViewModel : ViewModelBase, IControlViewModel, IDisposable
1213
{
14+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
15+
1316
private readonly ISourceControlConfigProvider _configService;
1417
private readonly IFolderBrowserFactory _folderBrowserFactory;
1518
private readonly IOpenFileDialog _openFileDialog;
@@ -125,6 +128,8 @@ private void ShowCommandPromptExePicker()
125128

126129
private void CancelSettingsChanges()
127130
{
131+
Logger.Trace("Settings changes canceled");
132+
128133
UserName = _config.UserName;
129134
EmailAddress = _config.EmailAddress;
130135
DefaultRepositoryLocation = _config.DefaultRepositoryLocation;
@@ -133,6 +138,8 @@ private void CancelSettingsChanges()
133138

134139
private void UpdateSettings()
135140
{
141+
Logger.Trace("Settings changes saved");
142+
136143
_config.UserName = UserName;
137144
_config.EmailAddress = EmailAddress;
138145
_config.DefaultRepositoryLocation = DefaultRepositoryLocation;

RetailCoder.VBE/UI/SourceControl/SourceControlViewViewModel.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public SourceControlViewViewModel(
104104

105105
public void SetTab(SourceControlTab tab)
106106
{
107+
Logger.Trace("Setting active tab to {0}", tab);
107108
SelectedItem = TabItems.First(t => t.ViewModel.Tab == tab);
108109
}
109110

@@ -116,6 +117,7 @@ public void HandleAddedComponent(VBComponent component)
116117
return;
117118
}
118119

120+
Logger.Trace("Component {0} added", component.Name);
119121
var fileStatus = Provider.Status().SingleOrDefault(stat => stat.FilePath.Split('.')[0] == component.Name);
120122
if (fileStatus != null)
121123
{
@@ -132,6 +134,7 @@ public void HandleRemovedComponent(VBComponent component)
132134
return;
133135
}
134136

137+
Logger.Trace("Component {0] removed", component.Name);
135138
var fileStatus = Provider.Status().SingleOrDefault(stat => stat.FilePath.Split('.')[0] == component.Name);
136139
if (fileStatus != null)
137140
{
@@ -148,6 +151,7 @@ public void HandleRenamedComponent(VBComponent component, string oldName)
148151
return;
149152
}
150153

154+
Logger.Trace("Component {0} renamed to {1}", oldName, component.Name);
151155
var fileStatus = Provider.LastKnownStatus().SingleOrDefault(stat => stat.FilePath.Split('.')[0] == oldName);
152156
if (fileStatus != null)
153157
{
@@ -186,6 +190,8 @@ public ISourceControlProvider Provider
186190
get { return _provider; }
187191
set
188192
{
193+
Logger.Trace("Provider changed");
194+
189195
_provider = value;
190196
OnPropertyChanged("RepoDoesNotHaveRemoteLocation");
191197
SetChildPresenterSourceControlProviders(_provider);
@@ -216,7 +222,7 @@ private void _fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
216222
{
217223
return;
218224
}
219-
225+
220226
Logger.Trace("File system watcher detected file changed");
221227
if (_messageBox.Show(RubberduckUI.SourceControl_ExternalModifications, RubberduckUI.SourceControlPanel_Caption,
222228
MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.OK)
@@ -534,10 +540,13 @@ private void ViewModel_ErrorThrown(object sender, ErrorEventArgs e)
534540

535541
if (e.InnerMessage == unauthorizedMessage)
536542
{
543+
Logger.Trace("Requesting login");
537544
DisplayLoginGrid = true;
538545
}
539546
else
540547
{
548+
Logger.Trace("Displaying {0} with title '{1}' and message '{2}'", e.NotificationType, e.Message, e.InnerMessage);
549+
541550
ErrorTitle = e.Message;
542551
ErrorMessage = e.InnerMessage;
543552

@@ -572,6 +581,7 @@ private void InitRepo()
572581
return;
573582
}
574583

584+
Logger.Trace("Initializing repo");
575585
_provider = _providerFactory.CreateProvider(_vbe.ActiveVBProject);
576586
var repo = _provider.InitVBAProject(folderPicker.SelectedPath);
577587
Provider = _providerFactory.CreateProvider(_vbe.ActiveVBProject, repo, _wrapperFactory);
@@ -634,6 +644,7 @@ private void OpenRepo()
634644
return;
635645
}
636646

647+
Logger.Trace("Opening existing repo");
637648
var project = _vbe.ActiveVBProject;
638649
var repo = new Repository(project.HelpFile, folderPicker.SelectedPath, string.Empty);
639650

@@ -660,6 +671,7 @@ private void CloneRepo()
660671
{
661672
OnOpenRepoStarted();
662673

674+
Logger.Trace("Cloning repo");
663675
try
664676
{
665677
_provider = _providerFactory.CreateProvider(_vbe.ActiveVBProject);
@@ -695,6 +707,7 @@ private void PublishRepo()
695707
return;
696708
}
697709

710+
Logger.Trace("Publishing repo to remote");
698711
try
699712
{
700713
Provider.AddOrigin(PublishRemotePath, Provider.CurrentBranch.Name);
@@ -735,6 +748,7 @@ private void ClosePublishRepoGrid()
735748

736749
private void OpenCommandPrompt()
737750
{
751+
Logger.Trace("Opening command prompt");
738752
try
739753
{
740754
Process.Start(_config.CommandPromptLocation);
@@ -754,6 +768,7 @@ private void OpenRepoAssignedToProject()
754768
return;
755769
}
756770

771+
Logger.Trace("Opening repo assigned to project");
757772
try
758773
{
759774
OnOpenRepoStarted();
@@ -775,6 +790,8 @@ private void OpenRepoAssignedToProject()
775790

776791
private void Refresh()
777792
{
793+
Logger.Trace("Refreshing display");
794+
778795
_fileSystemWatcher.EnableRaisingEvents = false;
779796
if (Provider == null)
780797
{

RetailCoder.VBE/UI/SourceControl/UnsyncedCommitsViewViewModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
22
using System.Collections.ObjectModel;
33
using System.Windows.Input;
4+
using NLog;
45
using Rubberduck.SourceControl;
56
using Rubberduck.UI.Command;
67

78
namespace Rubberduck.UI.SourceControl
89
{
910
public class UnsyncedCommitsViewViewModel : ViewModelBase, IControlViewModel
1011
{
12+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
13+
1114
public UnsyncedCommitsViewViewModel()
1215
{
1316
_fetchCommitsCommand = new DelegateCommand(_ => FetchCommits(), _ => Provider != null);
@@ -22,6 +25,8 @@ public ISourceControlProvider Provider
2225
get { return _provider; }
2326
set
2427
{
28+
Logger.Trace("Provider changed");
29+
2530
_provider = value;
2631
_provider.BranchChanged += Provider_BranchChanged;
2732

@@ -31,6 +36,8 @@ public ISourceControlProvider Provider
3136

3237
public void RefreshView()
3338
{
39+
Logger.Trace("Refreshing view");
40+
3441
CurrentBranch = Provider.CurrentBranch.Name;
3542

3643
IncomingCommits = new ObservableCollection<ICommit>(Provider.UnsyncedRemoteCommits);
@@ -90,6 +97,7 @@ private void FetchCommits()
9097
{
9198
try
9299
{
100+
Logger.Trace("Fetching");
93101
Provider.Fetch();
94102

95103
RefreshView();
@@ -104,6 +112,7 @@ private void PullCommits()
104112
{
105113
try
106114
{
115+
Logger.Trace("Pulling");
107116
Provider.Pull();
108117

109118
RefreshView();
@@ -118,6 +127,7 @@ private void PushCommits()
118127
{
119128
try
120129
{
130+
Logger.Trace("Pushing");
121131
Provider.Push();
122132

123133
RefreshView();
@@ -132,6 +142,7 @@ private void SyncCommits()
132142
{
133143
try
134144
{
145+
Logger.Trace("Syncing (pull + push)");
135146
Provider.Pull();
136147
Provider.Push();
137148

0 commit comments

Comments
 (0)