public static IEnumerable <TemplateLicense> GetAllLicences(UserSelection userSelection) { return(Compose(userSelection) .SelectMany(s => s.Template.GetLicenses()) .Distinct(new TemplateLicenseEqualityComparer()) .ToList()); }
public static IEnumerable <string> GetAllRequiredSdks(UserSelection userSelection) { return(Compose(userSelection) .SelectMany(s => s.Template.GetRequiredSdks()) .Distinct() .ToList()); }
private static void AddProject(UserSelection userSelection, List <GenInfo> genQueue) { var projectTemplates = GenContext.ToolBox.Repo .GetTemplates( TemplateType.Project, userSelection.Platform, userSelection.ProjectType, userSelection.FrontEndFramework, userSelection.BackEndFramework) .OrderBy(projectTemplate => projectTemplate.Identity); foreach (var projectTemplate in projectTemplates) { var genProject = CreateGenInfo(GenContext.Current.ProjectName, projectTemplate, genQueue, false); genProject.Parameters.Add(GenParams.Username, Environment.UserName); genProject.Parameters.Add(GenParams.WizardVersion, string.Concat("v", GenContext.ToolBox.WizardVersion)); genProject.Parameters.Add(GenParams.TemplatesVersion, string.Concat("v", GenContext.ToolBox.TemplatesVersion)); genProject.Parameters.Add(GenParams.ProjectType, userSelection.ProjectType); genProject.Parameters.Add(GenParams.FrontEndFramework, userSelection.FrontEndFramework); genProject.Parameters.Add(GenParams.BackEndFramework, userSelection.BackEndFramework); genProject.Parameters.Add(GenParams.Platform, userSelection.Platform); genProject.Parameters.Add(GenParams.ProjectName, GenContext.Current.ProjectName); genProject.Parameters.Add(GenParams.HomePageName, userSelection.HomeName); AddCasingParams(GenContext.Current.ProjectName, projectTemplate, genProject); } }
private static void AddProjectParams(GenInfo projectGenInfo, UserSelection userSelection) { projectGenInfo?.Parameters.Add(GenParams.Username, Environment.UserName); projectGenInfo?.Parameters.Add(GenParams.WizardVersion, string.Concat("v", GenContext.ToolBox.WizardVersion)); projectGenInfo?.Parameters.Add(GenParams.TemplatesVersion, string.Concat("v", GenContext.ToolBox.TemplatesVersion)); projectGenInfo?.Parameters.Add(GenParams.ProjectType, userSelection.ProjectType); projectGenInfo?.Parameters.Add(GenParams.FrontEndFramework, userSelection.FrontEndFramework); projectGenInfo?.Parameters.Add(GenParams.BackEndFramework, userSelection.BackEndFramework); projectGenInfo?.Parameters.Add(GenParams.Platform, userSelection.Platform); }
public async Task UnsafeGenerateNewItemAsync(TemplateType templateType, UserSelection userSelection) { VerifyGenContextPaths(); var genItems = GenComposer.ComposeNewItem(userSelection).ToList(); var chrono = Stopwatch.StartNew(); var genResults = await GenerateItemsAsync(genItems, true); chrono.Stop(); TrackTelemetry(templateType, genItems, genResults, chrono.Elapsed.TotalSeconds, userSelection.ProjectType, userSelection.Framework, userSelection.Platform); }
private static void AddProject(UserSelection userSelection, List <GenInfo> genQueue) { var projectTemplate = GetProjectTemplate(userSelection.ProjectType, userSelection.Framework, userSelection.Platform); var genProject = CreateGenInfo(GenContext.Current.ProjectName, projectTemplate, genQueue, false); genProject.Parameters.Add(GenParams.Username, Environment.UserName); genProject.Parameters.Add(GenParams.WizardVersion, string.Concat("v", GenContext.ToolBox.WizardVersion)); genProject.Parameters.Add(GenParams.TemplatesVersion, string.Concat("v", GenContext.ToolBox.TemplatesVersion)); genProject.Parameters.Add(GenParams.ProjectType, userSelection.ProjectType); genProject.Parameters.Add(GenParams.Framework, userSelection.Framework); genProject.Parameters.Add(GenParams.Platform, userSelection.Platform); genProject.Parameters.Add(GenParams.ProjectName, GenContext.Current.ProjectName); }
private static void AddProject(UserSelection userSelection, List <GenInfo> genQueue) { var projectTemplates = GenContext.ToolBox.Repo .GetTemplates(TemplateType.Project, userSelection.Context) .OrderBy(projectTemplate => projectTemplate.GetCompositionOrder()); foreach (var projectTemplate in projectTemplates) { var genProject = CreateGenInfo(GenContext.Current.ProjectName, projectTemplate, genQueue, userSelection, false); AddCasingParams(GenContext.Current.ProjectName, projectTemplate, genProject); } }
public async Task UnsafeGenerateProjectAsync(UserSelection userSelection) { VerifyGenContextPaths(); ValidateUserSelection(userSelection, true); var genItems = GenComposer.Compose(userSelection).ToList(); var chrono = Stopwatch.StartNew(); var genResults = await GenerateItemsAsync(genItems); chrono.Stop(); TrackTelemetry(genItems, genResults, chrono.Elapsed.TotalSeconds, userSelection.Context); }
public async Task UnsafeGenerateProjectAsync(UserSelection userSelection) { VerifyGenContextPaths(); ValidateUserSelection(userSelection, true); var genItems = GenComposer.Compose(userSelection).ToList(); var chrono = Stopwatch.StartNew(); var genResults = await GenerateItemsAsync(genItems, false); chrono.Stop(); TrackTelemetry(genItems, genResults, chrono.Elapsed.TotalSeconds, userSelection.ProjectType, userSelection.FrontEndFramework, userSelection.BackEndFramework, userSelection.Platform, userSelection.Language); }
private static void AddProjectParams(GenInfo projectGenInfo, UserSelection userSelection) { projectGenInfo?.Parameters.Add(GenParams.Username, Environment.UserName); projectGenInfo?.Parameters.Add(GenParams.WizardVersion, string.Concat("v", GenContext.ToolBox.WizardVersion)); projectGenInfo?.Parameters.Add(GenParams.TemplatesVersion, string.Concat("v", GenContext.ToolBox.TemplatesVersion)); projectGenInfo?.Parameters.Add(GenParams.ProjectType, userSelection.Context.ProjectType); projectGenInfo?.Parameters.Add(GenParams.FrontEndFramework, userSelection.Context.FrontEndFramework ?? string.Empty); projectGenInfo?.Parameters.Add(GenParams.BackEndFramework, userSelection.Context.BackEndFramework ?? string.Empty); projectGenInfo?.Parameters.Add(GenParams.Platform, userSelection.Context.Platform); foreach (var property in userSelection.Context.PropertyBag) { projectGenInfo?.Parameters.Add($"{GenParams.GenerationPropertiesPrefix}.{property.Key.ToLowerInvariant()}", property.Value); } }
public static IEnumerable <GenInfo> ComposeNewItem(UserSelection userSelection) { var genQueue = new List <GenInfo>(); if (string.IsNullOrEmpty(userSelection.ProjectType) || string.IsNullOrEmpty(userSelection.Framework)) { return(genQueue); } AddTemplates(userSelection.Pages, genQueue, userSelection, true); AddTemplates(userSelection.Features, genQueue, userSelection, true); genQueue = AddInCompositionTemplates(genQueue, userSelection, true); return(genQueue); }
public async Task UnsafeGenerateProjectAsync(UserSelection userSelection) { VerifyGenContextPaths(); var genItems = GenComposer.Compose(userSelection).ToList(); var chrono = Stopwatch.StartNew(); var genResults = await GenerateItemsAsync(genItems, false); chrono.Stop(); // TODO: Adapt telemetry to properly handle backend string appFx = userSelection.FrontEndFramework + (string.IsNullOrEmpty(userSelection.BackEndFramework) ? string.Empty : userSelection.BackEndFramework); TrackTelemetry(genItems, genResults, chrono.Elapsed.TotalSeconds, userSelection.ProjectType, appFx, userSelection.Platform, userSelection.Language); }
public void UnsafeFinishGeneration(UserSelection userSelection) { var compareResult = CompareTempGenerationWithProject(); if (userSelection.ItemGenerationType == ItemGenerationType.GenerateAndMerge) { // BackupProjectFiles compareResult.SyncGeneration = true; ExecuteSyncGenerationPostActions(compareResult); } else { compareResult.SyncGeneration = false; ExecuteOutputGenerationPostActions(compareResult); } }
private static void AddDefaultParams(GenInfo genInfo, UserSelection userSelection, bool newItemGeneration) { var ns = string.Empty; if (newItemGeneration) { ns = GenContext.ToolBox.Shell.GetActiveProjectNamespace(); } if (string.IsNullOrEmpty(ns)) { ns = GenContext.Current.SafeProjectName; } genInfo?.Parameters.Add(GenParams.RootNamespace, ns); genInfo?.Parameters.Add(GenParams.ProjectName, GenContext.Current.ProjectName); genInfo?.Parameters.Add(GenParams.HomePageName, userSelection.HomeName); }
public static IEnumerable <GenInfo> Compose(UserSelection userSelection) { var genQueue = new List <GenInfo>(); if (string.IsNullOrEmpty(userSelection.ProjectType) || string.IsNullOrEmpty(userSelection.FrontEndFramework)) { return(genQueue); } AddProject(userSelection, genQueue); AddTemplates(userSelection.Pages, genQueue, userSelection, false); AddTemplates(userSelection.Features, genQueue, userSelection, false); AddTemplates(userSelection.Services, genQueue, userSelection, false); AddTemplates(userSelection.Testing, genQueue, userSelection, false); genQueue = AddInCompositionTemplates(genQueue, userSelection, false); return(genQueue); }
private static void AddTemplate(GenInfo mainGenInfo, List <GenInfo> queue, ITemplateInfo targetTemplate, UserSelection userSelection, bool newItemGeneration) { if (targetTemplate != null) { foreach (var export in targetTemplate.GetExports()) { mainGenInfo.Parameters.Add(export.Key, export.Value); } var genInfo = CreateGenInfo(mainGenInfo.Name, targetTemplate, queue, newItemGeneration); genInfo?.Parameters.Add(GenParams.HomePageName, userSelection.HomeName); genInfo?.Parameters.Add(GenParams.ProjectName, GenContext.Current.ProjectName); } }
internal static void ValidateUserSelection(UserSelection userSelection, bool isNewProject) { if (isNewProject) { var rootDir = Directory.GetParent(Directory.GetParent(GenContext.Current.DestinationPath).FullName).FullName; var projectNameService = new ProjectNameService(GenContext.ToolBox.Repo.ProjectNameValidationConfig, () => Fs.GetExistingFolderNames(rootDir)); var result = projectNameService.Validate(GenContext.Current.ProjectName); { if (!result.IsValid) { var errors = string.Join(Environment.NewLine, result.Errors.Select(e => $"Error: {e.ErrorType}; Validator: {e.ValidatorName}.")); throw new InvalidDataException(string.Format(StringRes.ErrorProjectNameValidationFailed, GenContext.Current.ProjectName, Environment.NewLine + errors)); } } } foreach (var item in userSelection.Items) { var template = GenContext.ToolBox.Repo.Find(t => t.Identity == item.TemplateId); if (template.GetItemNameEditable()) { Func <IEnumerable <string> > existingNames = () => userSelection.Items.Where(t => t.TemplateId != template.Identity).Select(n => n.Name); var itemNameService = new ItemNameService(GenContext.ToolBox.Repo.ItemNameValidationConfig, existingNames); var validationResult = itemNameService.Validate(item.Name); { if (!validationResult.IsValid) { var errors = string.Join(Environment.NewLine, validationResult.Errors.Select(e => $"Error: {e.ErrorType}; Validator: {e.ValidatorName}.")); throw new InvalidDataException(string.Format(StringRes.ErrorNamingValidationFailed, item.Name, Environment.NewLine + errors)); } } } var dependencies = GenContext.ToolBox.Repo.GetDependencies(template, userSelection.Context, new List <ITemplateInfo>()); foreach (var dependency in dependencies) { if (!userSelection.Items.Any(i => i.TemplateId == dependency.Identity)) { throw new InvalidDataException(string.Format(StringRes.ErrorDependencyMissing, dependency)); } } var requirements = GenContext.ToolBox.Repo.GetRequirements(template, userSelection.Context); if (requirements.Count() > 0 && !userSelection.Items.Any(i => requirements.Select(r => r.Identity).Contains(i.TemplateId))) { throw new InvalidDataException(string.Format(StringRes.ErrorRequirementMissing, requirements.Select(r => r.Name).Aggregate((i, j) => $"{i},{j}"))); } var exclusionTemplates = GenContext.ToolBox.Repo.GetExclusions(template, userSelection.Context); foreach (var exclusion in exclusionTemplates) { if (userSelection.Items.Any(i => i.TemplateId == exclusion.Identity)) { throw new InvalidDataException(string.Format(StringRes.ErrorExcludedTemplatesFound, exclusion.Name)); } } } }
private static void AddRequiredTemplates(ITemplateInfo template, List <GenInfo> genQueue, UserSelection userSelection, bool newItemGeneration) { var requirements = GenContext.ToolBox.Repo.GetRequirements(template, userSelection.Context); if (requirements.Count() > 0) { var requirementTemplate = userSelection.Items.FirstOrDefault(f => requirements.Select(r => r.Identity).Contains(f.TemplateId)); if (requirementTemplate != null) { if (!genQueue.Any(t => t.Name == requirementTemplate.Name && t.Template.Identity == requirementTemplate.TemplateId)) { var requirementTemplateInfo = GenContext.ToolBox.Repo.Find(t => t.Identity == requirementTemplate.TemplateId); var depGenInfo = CreateGenInfo(requirementTemplate.Name, requirementTemplateInfo, genQueue, userSelection, newItemGeneration); AddCasingParams(requirementTemplate.Name, requirementTemplateInfo, depGenInfo); } } } }
private static void AddTemplate(GenInfo mainGenInfo, List <GenInfo> queue, ITemplateInfo targetTemplate, UserSelection userSelection, bool newItemGeneration) { if (targetTemplate != null) { foreach (var export in targetTemplate.GetExports()) { mainGenInfo.Parameters.Add(export.Key, export.Value); } var genInfo = CreateGenInfo(mainGenInfo.Name, targetTemplate, queue, newItemGeneration); foreach (var param in mainGenInfo.Parameters) { if (!genInfo.Parameters.ContainsKey(param.Key)) { genInfo.Parameters.Add(param.Key, param.Value); } } AddCasingParams(mainGenInfo.Name, targetTemplate, genInfo); } }
private static List <GenInfo> AddInCompositionTemplates(List <GenInfo> genQueue, UserSelection userSelection, bool newItemGeneration) { var compositionCatalog = GetCompositionCatalog(userSelection.Platform).ToList(); var context = new QueryablePropertyDictionary { new QueryableProperty("projecttype", userSelection.ProjectType), new QueryableProperty("page", string.Join("|", userSelection.Pages.Select(p => p.TemplateId))), new QueryableProperty("feature", string.Join("|", userSelection.Features.Select(p => p.TemplateId))), new QueryableProperty("service", string.Join("|", userSelection.Services.Select(p => p.TemplateId))), new QueryableProperty("testing", string.Join("|", userSelection.Testing.Select(p => p.TemplateId))), }; if (!string.IsNullOrEmpty(userSelection.FrontEndFramework)) { context.Add(new QueryableProperty("frontendframework", userSelection.FrontEndFramework)); } if (!string.IsNullOrEmpty(userSelection.BackEndFramework)) { context.Add(new QueryableProperty("backendframework", userSelection.BackEndFramework)); } var combinedQueue = new List <GenInfo>(); foreach (var genItem in genQueue) { combinedQueue.Add(genItem); var compositionQueue = new List <GenInfo>(); context.AddOrUpdate(new QueryableProperty("ishomepage", (genItem.Name == userSelection.HomeName).ToString().ToLower())); foreach (var compositionItem in compositionCatalog) { if (compositionItem.Template.GetLanguage() == userSelection.Language && compositionItem.Query.Match(genItem.Template, context)) { AddTemplate(genItem, compositionQueue, compositionItem.Template, userSelection, newItemGeneration); } } combinedQueue.AddRange(compositionQueue.OrderBy(g => g.Template.GetCompositionOrder())); } return(combinedQueue); }
private static void AddRequiredTemplates(ITemplateInfo template, List <GenInfo> genQueue, UserSelection userSelection, bool newItemGeneration) { var requirements = GenContext.ToolBox.Repo.GetRequirements(template, userSelection.Platform, userSelection.ProjectType, userSelection.FrontEndFramework, userSelection.BackEndFramework); if (requirements.Count() > 0) { var requirementTemplate = userSelection.Items.FirstOrDefault(f => requirements.Select(r => r.Identity).Contains(f.TemplateId)); if (requirementTemplate != null) { if (!genQueue.Any(t => t.Name == requirementTemplate.Name && t.Template.Identity == requirementTemplate.TemplateId)) { var requirementTemplateInfo = GenContext.ToolBox.Repo.Find(t => t.Identity == requirementTemplate.TemplateId); var depGenInfo = CreateGenInfo(requirementTemplate.Name, requirementTemplateInfo, genQueue, newItemGeneration); depGenInfo?.Parameters.Add(GenParams.HomePageName, userSelection.HomeName); depGenInfo?.Parameters.Add(GenParams.ProjectName, GenContext.Current.ProjectName); AddCasingParams(requirementTemplate.Name, requirementTemplateInfo, depGenInfo); } } } }
private static void AddDependencyTemplates(ITemplateInfo template, List <GenInfo> genQueue, UserSelection userSelection, bool newItemGeneration) { var dependencies = GenContext.ToolBox.Repo.GetDependencies(template, userSelection.Platform, userSelection.ProjectType, userSelection.FrontEndFramework, userSelection.BackEndFramework, new List <ITemplateInfo>()); foreach (var dependencyItem in dependencies) { var dependencyTemplate = userSelection.Items.FirstOrDefault(f => f.TemplateId == dependencyItem.Identity); if (dependencyTemplate != null) { if (!genQueue.Any(t => t.Name == dependencyTemplate.Name && t.Template.Identity == dependencyTemplate.TemplateId)) { var dependencyTemplateInfo = GenContext.ToolBox.Repo.Find(t => t.Identity == dependencyTemplate.TemplateId); var depGenInfo = CreateGenInfo(dependencyTemplate.Name, dependencyTemplateInfo, genQueue, newItemGeneration); depGenInfo?.Parameters.Add(GenParams.HomePageName, userSelection.HomeName); depGenInfo?.Parameters.Add(GenParams.ProjectName, GenContext.Current.ProjectName); AddCasingParams(dependencyTemplate.Name, dependencyTemplateInfo, depGenInfo); } } else { LogOrAlertException(string.Format(StringRes.ErrorDependencyMissing, dependencyItem.Identity)); } } }
private static void AddTemplates(IEnumerable <UserSelectionItem> selectedTemplates, List <GenInfo> genQueue, UserSelection userSelection, bool newItemGeneration) { foreach (var selectedTemplate in selectedTemplates) { if (!genQueue.Any(t => t.Name == selectedTemplate.Name && t.Template.Identity == selectedTemplate.TemplateId)) { var template = GenContext.ToolBox.Repo.Find(t => t.Identity == selectedTemplate.TemplateId); AddRequiredTemplates(template, genQueue, userSelection, newItemGeneration); AddDependencyTemplates(template, genQueue, userSelection, newItemGeneration); var genInfo = CreateGenInfo(selectedTemplate.Name, template, genQueue, newItemGeneration); genInfo?.Parameters.Add(GenParams.HomePageName, userSelection.HomeName); genInfo?.Parameters.Add(GenParams.ProjectName, GenContext.Current.ProjectName); if (template.GetTemplateOutputType() == TemplateOutputType.Project) { genInfo?.Parameters.Add(GenParams.WizardVersion, string.Concat("v", GenContext.ToolBox.WizardVersion)); genInfo?.Parameters.Add(GenParams.TemplatesVersion, string.Concat("v", GenContext.ToolBox.TemplatesVersion)); genInfo?.Parameters.Add(GenParams.ProjectType, userSelection.ProjectType); genInfo?.Parameters.Add(GenParams.FrontEndFramework, userSelection.FrontEndFramework); genInfo?.Parameters.Add(GenParams.BackEndFramework, userSelection.BackEndFramework); genInfo?.Parameters.Add(GenParams.Platform, userSelection.Platform); genInfo?.Parameters.Add(GenParams.Username, Environment.UserName); } foreach (var dependency in genInfo?.Template.GetDependencyList()) { if (genInfo.Template.Parameters.Any(p => p.Name == dependency)) { var dependencyName = genQueue.FirstOrDefault(t => t.Template.Identity == dependency).Name; genInfo.Parameters.Add(dependency, dependencyName); } } AddCasingParams(selectedTemplate.Name, template, genInfo); } } }
private static void AddTemplates(IEnumerable <UserSelectionItem> selectedTemplates, List <GenInfo> genQueue, UserSelection userSelection, bool newItemGeneration) { foreach (var selectedTemplate in selectedTemplates) { if (!genQueue.Any(t => t.Name == selectedTemplate.Name && t.Template.Identity == selectedTemplate.TemplateId)) { var template = GenContext.ToolBox.Repo.Find(t => t.Identity == selectedTemplate.TemplateId); AddRequiredTemplates(template, genQueue, userSelection, newItemGeneration); AddDependencyTemplates(template, genQueue, userSelection, newItemGeneration); var genInfo = CreateGenInfo(selectedTemplate.Name, template, genQueue, userSelection, newItemGeneration); foreach (var dependency in genInfo?.Template.GetDependencyList()) { if (genInfo.Template.Parameters.Any(p => p.Name == dependency)) { var dependencyName = genQueue.FirstOrDefault(t => t.Template.Identity == dependency).Name; genInfo.Parameters.Add(dependency, dependencyName); } } AddCasingParams(selectedTemplate.Name, template, genInfo); } } }
private static GenInfo CreateGenInfo(string name, ITemplateInfo template, List <GenInfo> queue, UserSelection userSelection, bool newItemGeneration) { var genInfo = new GenInfo(name, template); queue.Add(genInfo); AddDefaultParams(genInfo, userSelection, newItemGeneration); if (template.GetTemplateOutputType() == TemplateOutputType.Project) { AddProjectParams(genInfo, userSelection); } return(genInfo); }