private static void VerifyPostactionsPath(ValidationTemplateInfo template, List <string> results)
 {
     if (template.PostActions != null && template.PostActions.Any(p => p.Args.Any(a => a.Key == "projectPath" && a.Value.Contains("/"))))
     {
         results.Add("Post-action projectPath should use '\\' instead of '/' to indicate the project file path");
     }
 }
        private static void EnsureVisualBasicTemplatesAreIdentifiedAppropriately(ValidationTemplateInfo template, string filePath, List <string> results, bool isCompositionTemplate)
        {
            var isVbTemplate = filePath.Contains("VB\\");

            if (!isCompositionTemplate && string.IsNullOrWhiteSpace(template.Identity))
            {
                results.Add("The template is missing an identity.");
            }
            else
            {
                if (isVbTemplate)
                {
                    if (isCompositionTemplate && !template.Name.EndsWith("VB", StringComparison.CurrentCulture))
                    {
                        results.Add("The name of templates for VisualBasic should end with 'VB'.");
                    }

                    if (!isCompositionTemplate && !template.Identity.EndsWith("VB", StringComparison.CurrentCulture))
                    {
                        results.Add("The identity of templates for VisualBasic should end with 'VB'.");
                    }
                }
                else
                {
                    if ((isCompositionTemplate && template.Name.EndsWith("VB", StringComparison.CurrentCulture)) || (!isCompositionTemplate && template.Identity.EndsWith("VB", StringComparison.CurrentCulture)))
                    {
                        results.Add("Only VisualBasic templates identities and names should end with 'VB'.");
                    }
                }
            }
        }
        private static void EnsureAllDefinedGuidsAreUsed(ValidationTemplateInfo template, string templateRoot, List <string> results)
        {
            if (template.Guids != null)
            {
                var foundGuids = new List <string>();

                foreach (var file in new DirectoryInfo(templateRoot).GetFiles("*.*", SearchOption.AllDirectories))
                {
                    if (file.Name == "template.json")
                    {
                        continue;
                    }

                    var fileText = File.ReadAllText(file.FullName);

                    foreach (var guid in template.Guids)
                    {
                        if (fileText.Contains(guid))
                        {
                            foundGuids.Add(guid);
                        }
                    }
                }

                foreach (var templateGuid in template.Guids)
                {
                    if (!foundGuids.Contains(templateGuid))
                    {
                        results.Add($"Defined GUID '{templateGuid}' is not used.");
                    }
                }
            }
        }
 private static void EnsureAdequateDescription(ValidationTemplateInfo template, List <string> results)
 {
     if (string.IsNullOrWhiteSpace(template.Description))
     {
         results.Add("Description not provided.");
     }
     else if (template.Description.Trim().Length < 15)
     {
         results.Add("Description is too short.");
     }
 }
 private static void EnsureClassificationAsExpected(ValidationTemplateInfo template, List <string> results)
 {
     if (template.Classifications.Count != 1)
     {
         results.Add("Only a single classification is exected.");
     }
     else if (template.Classifications.First() != "Universal")
     {
         results.Add("Classification of 'Universal' is exected.");
     }
 }
 private static void VerifyWtsCompositionFilterLogic(ValidationTemplateInfo template, KeyValuePair <string, string> tag, List <string> results)
 {
     // Ensure VB templates refer to VB identities
     if (template.TemplateTags["language"] == ProgrammingLanguages.VisualBasic)
     {
         // This can't catch everything but is better than nothing
         if (tag.Value.Contains("identity") && !tag.Value.Contains(".VB"))
         {
             results.Add($" wts.compositionFilter identitiy vlaue does not match the language. ({tag.Value}).");
         }
     }
 }
 private static void EnsureAllDefinedPrimaryOutputsExist(ValidationTemplateInfo template, string templateRoot, List <string> results)
 {
     if (template.PrimaryOutputs != null)
     {
         foreach (var primaryOutput in template.PrimaryOutputs)
         {
             if (!File.Exists(Path.Combine(templateRoot, primaryOutput.Path)))
             {
                 results.Add($"Primary output '{primaryOutput.Path}' does not exist.");
             }
         }
     }
 }
 private static void EnsureValidPrimaryOutputPaths(ValidationTemplateInfo template, List <string> results)
 {
     if (template.PrimaryOutputs != null)
     {
         foreach (var primaryOutput in template.PrimaryOutputs)
         {
             if (primaryOutput.Path.Contains("\\"))
             {
                 results.Add($"Primary output '{primaryOutput.Path}' should use '/' instead of '\\'.");
             }
         }
     }
 }
 private static void VerifyLicensesAndProjPostactions(ValidationTemplateInfo template, List <string> results)
 {
     if (template.TemplateTags.ContainsKey("wts.licenses") && !string.IsNullOrEmpty(template.TemplateTags["wts.licenses"]))
     {
         if (template.PostActions?.Count == 0)
         {
             results.Add($"No postaction found for license defined on template {template.Identity}");
         }
     }
     else
     {
         if (template.PostActions != null && template.PostActions.Any(p => p.ActionId == "0B814718-16A3-4F7F-89F1-69C0F9170EAD"))
         {
             results.Add($"Missing license on template {template.Identity}");
         }
     }
 }
 private static void VerifyLicensesAndProjPostactions(ValidationTemplateInfo template, string templateRoot, List <string> results)
 {
     if (template.TemplateTags.ContainsKey("wts.licenses") && !string.IsNullOrEmpty(template.TemplateTags["wts.licenses"]))
     {
         if (Directory.EnumerateFiles(templateRoot, "_postaction.*", SearchOption.AllDirectories).Count() == 0)
         {
             results.Add($"No projectpostaction found for license defined on template {template.Identity}");
         }
     }
     else
     {
         if (Directory.EnumerateFiles(templateRoot, "_postaction.*", SearchOption.AllDirectories).Count() > 0)
         {
             results.Add($"Missing license on template {template.Identity}");
         }
     }
 }
Ejemplo n.º 11
0
        private static void VerifySymbols(ValidationTemplateInfo template, List <string> results)
        {
            if (template.Symbols == null)
            {
                return;
            }

            var type        = typeof(GenParams);
            var paramValues = type.GetFields(BindingFlags.Static | BindingFlags.Public)
                              .Where(f => f.IsLiteral)
                              .Select(f => f.GetValue(null).ToString())
                              .ToList();

            // The explicit values here are the ones that are currently in use.
            // In theory any string could be exported and used as a symbol but currently it's only these
            // If lots of templates start exporting new symbols it might be necessary to change how symbol keys are verified
            var allValidSymbolKeys = new List <string>(paramValues)
            {
                "baseclass", "setter",
                "wts.Page.Settings", "wts.Page.Settings.CodeBehind", "wts.Page.Settings.Prism", "wts.Page.Settings.CaliburnMicro", "wts.Page.Settings.VB", "wts.Page.Settings.CodeBehind.VB",
                "copyrightYear",
                "wts.safeprojectName",
                "commandclass",
                "onNavigatedToParams", "onNavigatedFromParams",
                "configtype", "configvalue",
                "pagetype",
                "canExecuteChangedMethodName",
                "wts.generation.appmodel",
            };

            foreach (var symbol in template.Symbols)
            {
                if (!allValidSymbolKeys.Contains(symbol.Key))
                {
                    results.Add($"Invalid Symbol key '{symbol.Key}' specified.");
                }
            }
        }
        private static void VerifySymbols(ValidationTemplateInfo template, List <string> results)
        {
            var type        = typeof(GenParams);
            var paramValues = type.GetFields(BindingFlags.Static | BindingFlags.Public)
                              .Where(f => f.IsLiteral)
                              .Select(f => f.GetValue(null).ToString())
                              .ToList();

            // The explicit values here are the ones that are currently in use.
            // In theory any string could be exported and used as a symbol but currently it's only these
            // If lots of tempaltes start exporting new symbols it might be necessary to change how symbol keys are verified
            var allValidSymbolKeys = new List <string>(paramValues)
            {
                "baseclass", "setter"
            };

            foreach (var symbol in template.Symbols)
            {
                if (!allValidSymbolKeys.Contains(symbol.Key))
                {
                    results.Add($"Invalid Symbol key '{symbol.Key}' specified.");
                }
            }
        }
 private static void VerifyWtsTypeFeatureMultipleInstancesRule(KeyValuePair <string, string> tag, ValidationTemplateInfo template, List <string> results)
 {
     if ("feature".Equals(tag.Value))
     {
         if (template.TemplateTags.Keys.Contains("wts.multipleInstance"))
         {
             bool.TryParse(template.TemplateTags["wts.multipleInstance"], out var allowMultipleInstances);
             if (!allowMultipleInstances)
             {
                 if (!template.TemplateTags.Keys.Contains("wts.defaultInstance") || string.IsNullOrWhiteSpace(template.TemplateTags["wts.defaultInstance"]))
                 {
                     results.Add($"Template must define a valid value for wts.defaultInstance tag as wts.Type is '{tag.Value}' and wts.multipleInstance is 'false'.");
                 }
             }
         }
     }
 }
        private static void VerifyTagUsage(ValidationTemplateInfo template, List <string> results)
        {
            foreach (var tag in template.TemplateTags)
            {
                switch (tag.Key)
                {
                case "language":
                    VerifyLanguageTagValue(tag, results);
                    break;

                case "type":
                    VerifyTypeTagValue(tag, results);
                    break;

                case "wts.type":
                    VerifyWtsTypeTagValue(tag, results);
                    VerifyWtsTypeFeatureMultipleInstancesRule(tag, template, results);
                    break;

                case "wts.order":
                    VerifyWtsOrderTagValue(results);
                    break;

                case "wts.displayOrder":
                    VerifyWtsDisplayOrderTagValue(tag, results);
                    break;

                case "wts.compositionOrder":
                    VerifyWtsCompositionOrderTagValue(tag, results);
                    break;

                case "wts.frontendframework":
                case "wts.backendframework":
                    VerifyWtsFrameworkTagValue(tag, results);
                    break;

                case "wts.projecttype":
                    VerifyWtsProjecttypeTagValue(tag, results);
                    break;

                case "wts.platform":
                    VerifyPlatformTagValue(tag, results);
                    break;

                case "wts.version":
                    VerifyWtsVersionTagValue(tag, results);
                    break;

                case "wts.genGroup":
                    VerifyWtsGengroupTagValue(tag, results);
                    break;

                case "wts.rightClickEnabled":
                    VerifyWtsRightclickenabledTagValue(tag, results);
                    break;

                case "wts.compositionFilter":
                    VerifyWtsCompositionFilterTagValue(tag, results);
                    VerifyWtsCompositionFilterLogic(template, tag, results);
                    break;

                case "wts.licenses":
                    VerifyWtsLicensesTagValue(tag, results);
                    break;

                case "wts.group":
                    VerifyWtsGroupTagValue(tag, results);
                    break;

                case "wts.multipleInstance":
                    VerifyWtsMultipleinstanceTagValue(tag, results);
                    break;

                case "wts.dependencies":
                    // This value is checked with the TemplateFolderVerifier
                    break;

                case "wts.requirements":
                    // This value is checked with the TemplateFolderVerifier
                    break;

                case "wts.exclusions":
                // This value is checked with the TemplateFolderVerifier
                case "wts.defaultInstance":
                    VerifyWtsDefaultinstanceTagValue(tag, results);
                    break;

                case "wts.isHidden":
                    VerifyWtsIshiddenTagValue(tag, results);
                    break;

                case "wts.isGroupExclusiveSelection":
                    VerifyWtsWtsIsGroupExclusiveSelectionTagValue(tag, results);
                    break;

                case "wts.telemName":
                    VerifyWtsTelemNameTagValue(tag, results);
                    break;

                case "wts.outputToParent":
                    VerifyWtsOutputToParentTagValue(tag, results);
                    break;

                case "wts.requiredVsWorkload":
                    VerifyRequiredVsWorkloadTagValue(tag, results);
                    break;

                case "wts.requiredSdks":
                    VerifyRequiredSdkTagValue(results);
                    break;

                case "wts.requiredVersions":
                    VerifyRequiredVersionsTagValue(tag, results);
                    break;

                case "wts.export.baseclass":
                    VerifyWtsExportBaseclassTagValue(tag, results);
                    break;

                case "wts.export.setter":
                    VerifyWtsExportSetterTagValue(tag, results);
                    break;

                case "wts.export.configtype":
                    VerifyWtsExportConfigTypeTagValue(tag, results);
                    break;

                case "wts.export.configvalue":
                    VerifyWtsExportConfigValueTagValue(tag, results);
                    break;

                case "wts.export.commandclass":
                    VerifyWtsExportCommandClassTagValue(tag, results);
                    break;

                case "wts.export.pagetype":
                    VerifyWtsExportPageTypeTagValue(tag, results);
                    break;

                case "wts.export.canExecuteChangedMethodName":
                    VerifyWtsExportCanExecuteChangedMethodNameTagValue(tag, results);
                    break;

                case "wts.export.onNavigatedToParams":
                    VerifyWtsExportOnNavigatedToParamsTagValue(tag, results);
                    break;

                case "wts.export.onNavigatedFromParams":
                    VerifyWtsExportOnNavigatedFromParamsTagValue(tag, results);
                    break;

                default:
                    results.Add($"Unknown tag '{tag.Key}' specified in the file.");
                    break;
                }
            }

            if (template.TemplateTags.ContainsKey("language") && template.TemplateTags.ContainsKey("wts.frontendframework"))
            {
                VerifyFrameworksAreAppropriateForLanguage(template.TemplateTags["language"], template.TemplateTags["wts.frontendframework"], results);
            }
        }
Ejemplo n.º 15
0
        private static void VerifyTagUsage(ValidationTemplateInfo template, List <string> results)
        {
            foreach (var tag in template.TemplateTags)
            {
                switch (tag.Key)
                {
                case "language":
                    VerifyLanguageTagValue(tag, results);
                    break;

                case "type":
                    VerifyTypeTagValue(tag, results);
                    break;

                case "wts.type":
                    VerifyWtsTypeTagValue(tag, results);
                    VerifyWtsTypeFeatureMultipleInstancesRule(tag, template, results);
                    break;

                case "wts.order":
                    VerifyWtsOrderTagValue(tag, results);
                    break;

                case "wts.displayOrder":
                    VerifyWtsDisplayOrderTagValue(tag, results);
                    break;

                case "wts.compositionOrder":
                    VerifyWtsCompositionOrderTagValue(tag, results);
                    break;

                case "wts.framework":
                    VerifyWtsFrameworkTagValue(tag, results);
                    break;

                case "wts.projecttype":
                    VerifyWtsProjecttypeTagValue(tag, results);
                    break;

                case "wts.platform":
                    VerifyPlatformTagValue(tag, results);
                    break;

                case "wts.version":
                    VerifyWtsVersionTagValue(tag, results);
                    break;

                case "wts.genGroup":
                    VerifyWtsGengroupTagValue(tag, results);
                    break;

                case "wts.rightClickEnabled":
                    VerifyWtsRightclickenabledTagValue(tag, results);
                    break;

                case "wts.compositionFilter":
                    VerifyWtsCompositionFilterTagValue(tag, results);
                    VerifyWtsCompositionFilterLogic(template, tag, results);
                    break;

                case "wts.licenses":
                    VerifyWtsLicensesTagValue(tag, results);
                    break;

                case "wts.group":
                    VerifyWtsGroupTagValue(tag, results);
                    break;

                case "wts.multipleInstance":
                    VerifyWtsMultipleinstanceTagValue(tag, results);
                    break;

                case "wts.dependencies":
                    // This value is checked with the TemplateFolderVerifier
                    break;

                case "wts.defaultInstance":
                    VerifyWtsDefaultinstanceTagValue(tag, results);
                    break;

                case "wts.export.baseclass":
                    VerifyWtsExportBaseclassTagValue(tag, results);
                    break;

                case "wts.export.setter":
                    VerifyWtsExportSetterTagValue(tag, results);
                    break;

                case "wts.isHidden":
                    VerifyWtsIshiddenTagValue(tag, results);
                    break;

                case "wts.telemName":
                    VerifyWtsTelemNameTagValue(tag, results);
                    break;

                default:
                    results.Add($"Unknown tag '{tag.Value}' specified in the file.");
                    break;
                }
            }
        }