in src/Microsoft.VisualStudio.SlowCheetah.VS/Package/PreviewTransformCommand.cs [118:170]
protected override void OnInvoke(object sender, EventArgs e)
{
uint itemId = VSConstants.VSITEMID_NIL;
// Verify only one item is selected
if (!ProjectUtilities.IsSingleProjectItemSelection(out IVsHierarchy hierarchy, out itemId))
{
return;
}
// Make sure that the project supports transformations
IVsProject project = (IVsProject)hierarchy;
if (!this.ScPackage.ProjectSupportsTransforms(project))
{
return;
}
// Get the full path of the selected file
if (ErrorHandler.Failed(project.GetMkDocument(itemId, out string transformPath)))
{
return;
}
// Checks the SlowCheetah NuGet package installation
this.ScPackage.JoinableTaskFactory.Run(() => this.NuGetManager.CheckSlowCheetahInstallation(hierarchy));
// Get the parent of the file to start searching for the source file
ErrorHandler.ThrowOnFailure(hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_Parent, out object parentIdObj));
uint parentId = (uint)(int)parentIdObj;
if (parentId == (uint)VSConstants.VSITEMID.Nil)
{
return;
}
if (!this.TryGetFileToTransform(hierarchy, parentId, Path.GetFileName(transformPath), out uint docId, out string documentPath))
{
throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.Error_FileToTransformNotFound, transformPath));
}
try
{
// Save the source and transform files before previewing
PackageUtilities.GetAutomationFromHierarchy<ProjectItem>(hierarchy, docId).Save();
PackageUtilities.GetAutomationFromHierarchy<ProjectItem>(hierarchy, itemId).Save();
}
catch
{
// If the item is not open, an exception is thrown,
// but that is not a problem as it is not dirty
}
this.PreviewTransform(hierarchy, documentPath, transformPath);
}