private IItemContainer GetUnfoldParent(IProductElement element, VsTemplateType templateType) { var parentWithArtifactLink = element.Traverse( x => x.GetParent(), x => x.TryGetReference(ReferenceKindConstants.SolutionItem) != null); if (parentWithArtifactLink != null) { var referencedItems = SolutionArtifactLinkReference.GetResolvedReferences(parentWithArtifactLink, this.uriService); if (templateType == VsTemplateType.Project || templateType == VsTemplateType.ProjectGroup) { var parentItem = referencedItems.FirstOrDefault(item => item.Kind == ItemKind.Solution || item.Kind == ItemKind.SolutionFolder); if (parentItem != null) return parentItem; } else if (templateType == VsTemplateType.Item) { var parentItem = referencedItems.FirstOrDefault(item => item.Kind == ItemKind.Project || item.Kind == ItemKind.Folder); if (parentItem != null) return parentItem; } // Why not continue up??? For extension points it makes perfect sense! if (!(parentWithArtifactLink is IProduct)) { // The Traverse at the top first checks the stop condition on the source element itself, // meaning in our case that we would enter an infinite loop if were to get here again // and pass ourselves up. So we travel one element up for the traversal. return GetUnfoldParent(parentWithArtifactLink.GetParent(), templateType); } } return GetUnfoldParent(this.solution, templateType); }
private static IItemContainer GetUnfoldParent(ISolution solution, VsTemplateType templateType) { var selectedItem = solution.GetSelectedItems().FirstOrDefault() ?? solution; if (templateType == VsTemplateType.Project || templateType == VsTemplateType.ProjectGroup) { return(selectedItem.Traverse(item => item.Parent, item => item is ISolution || (item is ISolutionFolder && !item.IsSolutionItemsFolder()))); } if (templateType == VsTemplateType.Item) { var parentItem = (selectedItem.Kind == ItemKind.Folder || selectedItem.Kind == ItemKind.Project) ? selectedItem : selectedItem.Traverse(item => item.Parent, item => item is IFolder || item is IProject || item is ISolution); if (parentItem is ISolution) { var item = parentItem.Find(SolutionExtensions.SolutionItemsFolderName).FirstOrDefault(); if (item != null) { return(item); } return(parentItem.AddDirectory(SolutionExtensions.SolutionItemsFolderName)); } return(parentItem); } throw new NotSupportedException( string.Format(CultureInfo.CurrentCulture, Resources.UnfoldParentResolver_UnsupportedTemplate, templateType)); }
/// <summary> /// Resolves the instance. /// </summary> /// <param name="templateType">Type of the template.</param> /// <param name="templatePath">The template path.</param> protected override ITemplate ResolveInstance(VsTemplateType templateType, string templatePath) { if (templateType == VsTemplateType.Project || templateType == VsTemplateType.ProjectGroup) { return(new VsProjectTemplate(templatePath)); } if (templateType == VsTemplateType.Item) { return(new VsItemTemplate(templatePath)); } return(null); }
public static string GetUriBase(VsTemplateType templateType) { if (templateType == VsTemplateType.Item || templateType == VsTemplateType.Project || templateType == VsTemplateType.ProjectGroup) { return(HostFormat.NamedFormat(new { TemplateType = templateType.ToString().ToLower(CultureInfo.InvariantCulture), })); } else { throw new NotSupportedException(); } }
public static string GetUriBase(VsTemplateType templateType) { if (templateType == VsTemplateType.Item || templateType == VsTemplateType.Project || templateType == VsTemplateType.ProjectGroup) { return HostFormat.NamedFormat(new { TemplateType = templateType.ToString().ToLower(CultureInfo.InvariantCulture), }); } else { throw new NotSupportedException(); } }
private IItemContainer GetUnfoldParent(IProductElement element, VsTemplateType templateType) { var parentWithArtifactLink = element.Traverse( x => x.GetParent(), x => x.TryGetReference(ReferenceKindConstants.SolutionItem) != null); if (parentWithArtifactLink != null) { var referencedItems = SolutionArtifactLinkReference.GetResolvedReferences(parentWithArtifactLink, this.uriService); if (templateType == VsTemplateType.Project || templateType == VsTemplateType.ProjectGroup) { var parentItem = referencedItems.FirstOrDefault(item => item.Kind == ItemKind.Solution || item.Kind == ItemKind.SolutionFolder); if (parentItem != null) { return(parentItem); } } else if (templateType == VsTemplateType.Item) { var parentItem = referencedItems.FirstOrDefault(item => item.Kind == ItemKind.Project || item.Kind == ItemKind.Folder); if (parentItem != null) { return(parentItem); } } // Why not continue up??? For extension points it makes perfect sense! if (!(parentWithArtifactLink is IProduct)) { // The Traverse at the top first checks the stop condition on the source element itself, // meaning in our case that we would enter an infinite loop if were to get here again // and pass ourselves up. So we travel one element up for the traversal. return(GetUnfoldParent(parentWithArtifactLink.GetParent(), templateType)); } } return(GetUnfoldParent(this.solution, templateType)); }
/// <summary> /// Resolves the instance. /// </summary> /// <param name="templateType">The type of the template.</param> /// <param name="templatePath">The template path.</param> protected abstract T ResolveInstance(VsTemplateType templateType, string templatePath);
/// <summary> /// Resolves the instance. /// </summary> /// <param name="templateType">The type of the template.</param> /// <param name="templatePath">The template path.</param> protected override IVsTemplate ResolveInstance(VsTemplateType templateType, string templatePath) { return(VsTemplateFile.Read(templatePath)); }
private static IItemContainer GetUnfoldParent(ISolution solution, VsTemplateType templateType) { var selectedItem = solution.GetSelectedItems().FirstOrDefault() ?? solution; if (templateType == VsTemplateType.Project || templateType == VsTemplateType.ProjectGroup) { return selectedItem.Traverse(item => item.Parent, item => item is ISolution || (item is ISolutionFolder && !item.IsSolutionItemsFolder())); } if (templateType == VsTemplateType.Item) { var parentItem = (selectedItem.Kind == ItemKind.Folder || selectedItem.Kind == ItemKind.Project) ? selectedItem : selectedItem.Traverse(item => item.Parent, item => item is IFolder || item is IProject || item is ISolution); if (parentItem is ISolution) { var item = parentItem.Find(SolutionExtensions.SolutionItemsFolderName).FirstOrDefault(); if (item != null) { return item; } return parentItem.AddDirectory(SolutionExtensions.SolutionItemsFolderName); } return parentItem; } throw new NotSupportedException( string.Format(CultureInfo.CurrentCulture, Resources.UnfoldParentResolver_UnsupportedTemplate, templateType)); }