// Private Methods (2) private static void addAllFiles(string rootDir, string path, VSTemplateTemplateContentProject contentProject, OptionsGui data) { var files = Directory.GetFiles(path); foreach (var filePath in files) { var shouldReplace = ModifyFactory.IsCodeFile(filePath) || ModifyFactory.IsProjectFile(filePath); var projectItem = new ProjectItem { ReplaceParameters = shouldReplace, ReplaceParametersSpecified = shouldReplace, TargetFileName = filePath.GetFileName().replaceNamespace(data), Value = filePath.Replace(rootDir, string.Empty).replaceNamespace(data) }; contentProject.Items.Add(projectItem); } var folders = Directory.GetDirectories(path); foreach (var folder in folders) { if (folder.EndsWith("bin", StringComparison.InvariantCultureIgnoreCase) || folder.EndsWith("obj", StringComparison.InvariantCultureIgnoreCase)) { continue; } addAllFiles(rootDir, folder, contentProject, data); } }
// Public Methods (1) public static string GetProjectVSTemplate(OptionsGui data, string projectFilePath) { var regex = new Regex(@"[^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Nl}\p{Mn}\p{Mc}\p{Cf}\p{Pc}\p{Lm}]"); var template = new VSTemplate { Type = "Project", Version = "3.0.0" }; template.TemplateData.Name.Value = data.ProductName; template.TemplateData.Description.Value = data.ProductDescription; template.TemplateData.ProjectType = data.ProjectType; template.TemplateData.ProjectSubType = data.ProjectSubType; template.TemplateData.SortOrder = "1000"; template.TemplateData.CreateNewFolderSpecified = true; template.TemplateData.CreateNewFolder = true; template.TemplateData.DefaultName = regex.Replace(data.ProductName, ""); template.TemplateData.ProvideDefaultNameSpecified = true; template.TemplateData.ProvideDefaultName = true; template.TemplateData.LocationFieldSpecified = true; template.TemplateData.LocationField = VSTemplateTemplateDataLocationField.Enabled; template.TemplateData.EnableLocationBrowseButtonSpecified = true; template.TemplateData.EnableLocationBrowseButton = true; template.TemplateData.Icon.Value = "__Template_small.png"; template.TemplateData.PreviewImage.Value = "__Template_large.png"; var contentProject = new VSTemplateTemplateContentProject { File = projectFilePath.GetFileName().replaceNamespace(data), ReplaceParameters = true, ReplaceParametersSpecified = true, TargetFileName = projectFilePath.GetFileName().replaceNamespace(data) }; var rootDir = projectFilePath.GetDirectoryName() + "\\"; addAllFiles(rootDir, rootDir, contentProject, data); template.TemplateContent.Items.Add(contentProject); template.WizardExtension = new List <VSTemplateWizardExtension> { new VSTemplateWizardExtension { Assembly = new List <object> { typeof(SafeRootProjectWizard.ChildWizard).Assembly.FullName }, FullClassName = new List <object> { typeof(SafeRootProjectWizard.ChildWizard).FullName } } }; return(Serializer.Serialize(template)); }
private bool ValidateProjectOrSampleTemplate(string vsTemplatePath, Microsoft.Expression.Project.Templates.VSTemplate vsTemplate) { bool flag; object[] objArray; CultureInfo currentCulture; string invalidTemplateElement; if (vsTemplate.TemplateData != null && vsTemplate.TemplateData.ExpressionBlendPrototypingEnabled && (!this.IsPrototypingEnabled || vsTemplate.TemplateData.ProjectSubType == "Silverlight" && !BlendSdkHelper.IsSdkInstalled(BlendSdkHelper.CurrentSilverlightVersion) || vsTemplate.TemplateData.ProjectSubType == "WPF" && !BlendSdkHelper.IsSdkInstalled(BlendSdkHelper.CurrentWpfVersion))) { return(false); } if (!this.ValidateTemplateType(vsTemplatePath, vsTemplate, "Project")) { return(false); } if (!this.ValidateAnyTemplate(vsTemplatePath, vsTemplate)) { return(false); } bool flag1 = false; if (vsTemplate.TemplateContent.Items != null) { object[] items = vsTemplate.TemplateContent.Items; int num = 0; while (true) { if (num >= (int)items.Length) { if (flag1) { return(true); } currentCulture = CultureInfo.CurrentCulture; invalidTemplateElement = StringTable.InvalidTemplateElement; objArray = new object[] { "TemplateContent" }; this.LogTemplateLoadError(vsTemplatePath, string.Format(currentCulture, invalidTemplateElement, objArray)); return(false); } object obj = items[num]; VSTemplateTemplateContentProject vSTemplateTemplateContentProject = obj as VSTemplateTemplateContentProject; if (vSTemplateTemplateContentProject != null) { if (vSTemplateTemplateContentProject.File == null) { CultureInfo cultureInfo = CultureInfo.CurrentCulture; string missingTemplateAttribute = StringTable.MissingTemplateAttribute; object[] objArray1 = new object[] { "Project", "File" }; this.LogTemplateLoadError(vsTemplatePath, string.Format(cultureInfo, missingTemplateAttribute, objArray1)); flag = false; break; } else if (Microsoft.Expression.Framework.Documents.PathHelper.ValidatePath(vSTemplateTemplateContentProject.File) == null) { flag1 = true; } else { CultureInfo currentCulture1 = CultureInfo.CurrentCulture; string invalidTemplateValue = StringTable.InvalidTemplateValue; object[] file = new object[] { "File", vSTemplateTemplateContentProject.File }; this.LogTemplateLoadError(vsTemplatePath, string.Format(currentCulture1, invalidTemplateValue, file)); flag = false; break; } } if (obj is VSTemplateTemplateContentProjectItem) { CultureInfo cultureInfo1 = CultureInfo.CurrentCulture; string unsupportedTemplateElement = StringTable.UnsupportedTemplateElement; object[] objArray2 = new object[] { "ProjectItem" }; this.LogTemplateLoadError(vsTemplatePath, string.Format(cultureInfo1, unsupportedTemplateElement, objArray2)); flag = false; break; } else if (!(obj is VSTemplateTemplateContentReferences)) { num++; } else { CultureInfo currentCulture2 = CultureInfo.CurrentCulture; string str = StringTable.UnsupportedTemplateElement; object[] objArray3 = new object[] { "References" }; this.LogTemplateLoadError(vsTemplatePath, string.Format(currentCulture2, str, objArray3)); flag = false; break; } } return(flag); } if (flag1) { return(true); } currentCulture = CultureInfo.CurrentCulture; invalidTemplateElement = StringTable.InvalidTemplateElement; objArray = new object[] { "TemplateContent" }; this.LogTemplateLoadError(vsTemplatePath, string.Format(currentCulture, invalidTemplateElement, objArray)); return(false); }