Skip to content

Commit

Permalink
Fix Add new feature file wizard (Issue #46)
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Aug 1, 2019
1 parent 6a4dc75 commit 6e54d18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Deveroom.VisualStudio.Annotations;
using Deveroom.VisualStudio.Diagonostics;
using Deveroom.VisualStudio.Monitoring;
using Deveroom.VisualStudio.ProjectSystem;
Expand All @@ -16,8 +17,8 @@ public abstract class VsProjectScopeWizard<TWizard> : IWizard where TWizard : cl
protected TWizard _wizard;
protected Project _project;

protected IDeveroomLogger Logger => _wizardRunParameters?.ProjectScope.IdeScope.Logger;
protected IMonitoringService MonitoringService => _wizardRunParameters?.ProjectScope.IdeScope.MonitoringService;
[CanBeNull] protected IDeveroomLogger Logger => _wizardRunParameters?.ProjectScope.IdeScope.Logger;
[CanBeNull] protected IMonitoringService MonitoringService => _wizardRunParameters?.ProjectScope.IdeScope.MonitoringService;

public virtual void RunStarted(object automationObjectDte, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
Expand Down Expand Up @@ -135,13 +136,13 @@ public virtual void ProjectItemFinishedGenerating(ProjectItem projectItem)

if (_wizardRunParameters.ReplacementsDictionary.TryGetValue(WizardRunParameters.CustomToolSettingKey, out var customToolSetting))
{
Logger.LogVerbose($"Set CustomTool to '{customToolSetting}' for {projectItem.Name}");
Logger?.LogVerbose($"Set CustomTool to '{customToolSetting}' for {projectItem.Name}");
projectItem.Properties.Item("CustomTool").Value = customToolSetting;
}

if (_wizardRunParameters.ReplacementsDictionary.TryGetValue(WizardRunParameters.BuildActionKey, out var buildActionSetting))
{
Logger.LogVerbose($"Set build action to '{buildActionSetting}' for {projectItem.Name}");
Logger?.LogVerbose($"Set build action to '{buildActionSetting}' for {projectItem.Name}");
projectItem.Properties.Item("ItemType").Value = buildActionSetting;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ private void CopyWithTemplateParamResolution(string sourceFile, string targetFil
var updatedFileContent = Regex.Replace(fileContent, @"\$[^\$\s]+\$",
match => replacementsDictionary.TryGetValue(match.Value, out var value) ? value : match.Value);
fileSystem.File.WriteAllText(targetFile, updatedFileContent, Encoding.UTF8);
Logger.LogVerbose($"New file created: {targetFile}");
Logger?.LogVerbose($"New file created: {targetFile}");
}
catch (Exception ex)
{
Logger.LogException(MonitoringService, ex);
Logger?.LogException(MonitoringService, ex);
}
}

Expand All @@ -84,12 +84,13 @@ private void ScheduleOpenFile(string targetFile)
var logger = Logger;
_openFileTimer = SafeDispatcherTimer.CreateOneTime(1, Logger, MonitoringService, () =>
{
OpenFile(targetFile, project);
OpenFile(targetFile, project, logger);
});
_openFileTimer.Start();
}

private void OpenFile(string targetFile, Project project)
// this method needs to be static as it is called from the timer, when the core wizard has been disposed already.
private static void OpenFile(string targetFile, Project project, IDeveroomLogger logger)
{
try
{
Expand All @@ -98,12 +99,12 @@ private void OpenFile(string targetFile, Project project)
{
//projectItem.Open();
project.DTE.ExecuteCommand("File.OpenFile", targetFile);
Logger.LogVerbose($"File opened: {targetFile}");
logger.LogVerbose($"File opened: {targetFile}");
}
}
catch (Exception ex)
{
Logger.LogException(MonitoringService, ex);
logger.LogDebugException(ex);
}
}
}
Expand Down

0 comments on commit 6e54d18

Please sign in to comment.