Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 52 additions & 9 deletions src/CodingWithCalvin.SuperClean/Commands/SuperCleanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,24 @@ private static async Task OpenPathAsync(object sender, EventArgs e)
case SolutionItemType.Solution:
try
{
var (success, errors) = await SuperCleanSolution();
var (success, errors, skippedWebsites) = await SuperCleanSolution();

if (!success)
{
throw new ApplicationException(errors);
}

VsixTelemetry.LogInformation("Solution super cleaned successfully");

if (skippedWebsites.Count > 0)
{
MessageBox.Show(
$"Super Clean skipped the following Web Site project(s) because their bin folder is required at runtime:{Environment.NewLine}{Environment.NewLine} • {string.Join($"{Environment.NewLine} • ", skippedWebsites)}",
"Super Clean",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);
}
}
catch (Exception ex)
{
Expand All @@ -116,8 +126,23 @@ Unable to Super Clean solution
case SolutionItemType.Project:
try
{
SuperCleanProject(activeItem);
VsixTelemetry.LogInformation("Project super cleaned successfully");
var cleaned = await SuperCleanProjectAsync(activeItem);

if (cleaned)
{
VsixTelemetry.LogInformation("Project super cleaned successfully");
}
else
{
VsixTelemetry.LogInformation($"Project skipped: {activeItem.Name}");

MessageBox.Show(
$"Super Clean skipped \"{activeItem.Name}\" because Web Site projects rely on their bin folder at runtime.",
"Super Clean",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information
);
}
}
catch (Exception ex)
{
Expand All @@ -139,20 +164,27 @@ Unable to Super Clean project ${activeItem.Name}
break;
}

async Task<(bool, string)> SuperCleanSolution()
async Task<(bool, string, List<string>)> SuperCleanSolution()
{
using var solutionActivity = VsixTelemetry.StartCommandActivity("SuperClean.SuperCleanSolution");

var success = true;
var errors = new StringBuilder();
var projectCount = 0;
var skippedWebsites = new List<string>();

foreach (var project in await VS.Solutions.GetAllProjectsAsync())
{
try
{
SuperCleanProject(project);
projectCount++;
if (await SuperCleanProjectAsync(project))
{
projectCount++;
}
else
{
skippedWebsites.Add(project.Name);
}
}
catch (Exception ex)
{
Expand All @@ -163,16 +195,25 @@ Unable to Super Clean project ${activeItem.Name}
}

solutionActivity?.SetTag("projects.cleaned", projectCount);
solutionActivity?.SetTag("projects.skipped", skippedWebsites.Count);
solutionActivity?.SetTag("success", success);

return (success, errors.ToString());
return (success, errors.ToString(), skippedWebsites);
}

void SuperCleanProject(SolutionItem project)
async Task<bool> SuperCleanProjectAsync(SolutionItem project)
{
using var projectActivity = VsixTelemetry.StartCommandActivity("SuperClean.SuperCleanProject");

var projectPath =
if (project is Project typedProject && await typedProject.IsKindAsync(ProjectTypes.WEBSITE))
{
projectActivity?.SetTag("skipped", true);
projectActivity?.SetTag("skip.reason", "website-project");
VsixTelemetry.LogInformation($"Skipped Web Site project: {project.Name}");
return false;
}

var projectPath =
Path.GetDirectoryName(project.FullPath)
?? throw new InvalidOperationException();

Expand All @@ -190,6 +231,8 @@ void SuperCleanProject(SolutionItem project)
Directory.Delete(objPath, true);
projectActivity?.SetTag("obj.deleted", true);
}

return true;
}
}
}
Expand Down
Loading