public void AddRange(IGeneratorConfiguration generatorConfiguration, IModuleAssembly moduleAssembly, List <IModuleOrAssembly> modulesOrAssemblies, ModuleAddType moduleAddType, Func <IModuleOrAssembly, bool> filter) { var generatorModules = (IEnumerable <ESModule>)generatorConfiguration.KeyValuePairs["Providers"]; var addModules = generatorModules.Where(m => m is Validator && filter(m)); modulesOrAssemblies.AddRange(addModules); }
private static async Task GenerateClass(KernelInvocationContext context, IFileReader fileReader, IGeneratorConfiguration config) { var classGenerator = new ClassGenerator(); var className = Path.GetFileNameWithoutExtension(fileReader.FileName); className = char.ToUpper(className[0]) + className.Substring(1); context.Display($"Generating class {className}", new[] { "text/html" }); var source = classGenerator.GenerateFile(fileReader.FileMetaData, config); var result = await context.HandlingKernel.SubmitCodeAsync(source); result.KernelEvents.Subscribe((ev) => { }, (ex) => { context.Display(ex.Message, new[] { "text/plain" }); }); result.KernelEvents.Subscribe((ev) => { if (ev is ErrorProduced error) { context.Fail(context.Command, null, error.Message); } if (ev is CommandFailed failure) { context.Fail(context.Command, null, failure.Message); } }); }
public void Create(IOutput output, IGeneratorConfiguration generatorConfiguration) { if (output is ISolution solution) { if (solution.Directory != null && !System.IO.Path.IsPathRooted(solution.Directory)) { solution.Directory = System.IO.Path.Combine(generatorConfiguration.OutputPath, solution.Directory); } foreach (var project in solution.Projects) { var path = System.IO.Path.IsPathRooted(project.Path) ? project.Path : System.IO.Path.Combine(generatorConfiguration.OutputPath, project.Path); foreach (var fg in project.FileGroups) { var groupPath = string.IsNullOrWhiteSpace(fg.Name) ? path : System.IO.Path.Combine(path, fg.Name); foreach (var file in fg.Files.Where(f => f.Name.EndsWith(".csproj"))) { file.Path = (string.IsNullOrWhiteSpace(file.Path) || groupPath.Contains(file.Path)) ? groupPath : System.IO.Path.Combine(groupPath, file.Path); if (!System.IO.Path.IsPathRooted(file.Path)) { file.Path = System.IO.Path.Combine(generatorConfiguration.OutputPath, file.Path); } _projectFiles.Add(file.FullName); } } } } }
public static void GenerateJson(IBase baseObject, string configPath, IGeneratorConfiguration generatorConfiguration) { var host = new TemplateEngineHost(); var container = (RestEntityContainer)baseObject; var rootObject = (object)container.JsonRootObject; Dictionary <string, object> sessionVariables; Dictionary <string, string> nameValueDictionary; FileInfo fileInfo; string fileLocation; string filePath; string output; try { // WebAPI Rest config json sessionVariables = new Dictionary <string, object>(); nameValueDictionary = rootObject.GetDynamicMemberNameValueDictionary().Where(p => !p.Key.IsOneOf("$schema", "title", "type", "clientControllerRouteBase") && p.Value is string).ToDictionary(p => p.Key, p => (string)p.Value); sessionVariables.Add("NameValues", nameValueDictionary); fileLocation = configPath; filePath = PathCombine(fileLocation, "Config.json"); fileInfo = new FileInfo(filePath); output = host.Generate <WebAPIRestConfigJsonTemplate>(sessionVariables, false); generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "Config.json")); } catch (Exception e) { generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString()); } }
public Settings(ILogger <Settings> logger, ILoader <ISettings> settingsLoader, IGeneratorConfiguration configuration, IPackageService packageService) { _logger = logger; _settingsLoader = settingsLoader; _configuration = configuration; _packageService = packageService; }
public string[] GenerateSource(string fileName, IGeneratorConfiguration config) { IList <string> sourceFiles = new List <string>(); using (var archive = new ArchiveReader(fileName)) { var outputPath = config.Output; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } string sourceFileName = CreateSourceFileName(archive.CoreFile.FileName, outputPath, config); sourceFiles.Add(sourceFileName); var metaData = archive.CoreFile.FileMetaData; var coreSource = roslynClassGenerator.GenerateFile(metaData, config); File.WriteAllText(sourceFileName, coreSource, Encoding.UTF8); foreach (var extension in archive.Extensions.GetFileReaders()) { var extensionFileName = CreateSourceFileName(extension.FileName, outputPath, config); sourceFiles.Add(extensionFileName); var meta = extension.FileMetaData; var extensionSource = roslynClassGenerator.GenerateFile(meta, config); File.WriteAllText(extensionFileName, extensionSource, Encoding.UTF8); } } return(sourceFiles.ToArray()); }
public PropertyDefinition(IGeneratorConfiguration configuration) { field2PropertyTypeMapping.Add(FieldType.Text, "string"); field2PropertyTypeMapping.Add(FieldType.MultiLineText, "string"); field2PropertyTypeMapping.Add(FieldType.Xhtml, "System.Web.Mvc.MvcHtmlString"); field2PropertyTypeMapping.Add(FieldType.Date, "DateTime"); field2PropertyTypeMapping.Add(FieldType.Number, "double"); field2PropertyTypeMapping.Add(FieldType.ExternalLink, "string"); field2PropertyTypeMapping.Add(FieldType.Keyword, "string"); field2PropertyTypeMapping.Add(FieldType.ComponentLink, configuration.BaseClasses.Any() ? configuration.BaseClasses.FirstOrDefault() : "EntityModel"); field2PropertyTypeMapping.Add(FieldType.MultiMediaLink, configuration.BaseClassesForMultimedia.Any() ? configuration.BaseClassesForMultimedia.FirstOrDefault() : "EntityModel"); field2PropertyTypeMapping.Add(FieldType.Entities, "IEntityModel"); field2PropertyTypeMapping.Add(FieldType.Regions, "IRegionModel"); field2PropertyTypeMapping.Add(FieldType.PageTitle, "string"); field2PropertyTypeMapping.Add(FieldType.PageId, "TcmUri"); field2PropertyAttributeMapping.Add(FieldType.Text, "TextField"); field2PropertyAttributeMapping.Add(FieldType.MultiLineText, "TextField"); field2PropertyAttributeMapping.Add(FieldType.Xhtml, "RichTextField"); field2PropertyAttributeMapping.Add(FieldType.Date, "DateField"); field2PropertyAttributeMapping.Add(FieldType.Number, "NumberField"); field2PropertyAttributeMapping.Add(FieldType.ExternalLink, "TextField"); field2PropertyAttributeMapping.Add(FieldType.Keyword, "KeywordTitleField"); field2PropertyAttributeMapping.Add(FieldType.ComponentLink, "LinkedComponentField"); field2PropertyAttributeMapping.Add(FieldType.MultiMediaLink, "LinkedComponentField"); field2PropertyAttributeMapping.Add(FieldType.Embedded, "EmbeddedSchemaField"); field2PropertyAttributeMapping.Add(FieldType.Entities, "ComponentPresentations"); field2PropertyAttributeMapping.Add(FieldType.Regions, "Regions"); field2PropertyAttributeMapping.Add(FieldType.PageTitle, "PageTitle"); field2PropertyAttributeMapping.Add(FieldType.PageId, "PageId"); }
public bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var uiAttribute = (UIAttribute)facet.Attribute; var name = baseObject.GetNavigationName(); var parentObject = (IParentBase)baseObject; var pagesPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.Pages]; var pagesFolder = (Folder)generatorConfiguration.FileSystem[pagesPath]; var imports = generatorConfiguration.CreateImports(this, baseObject, pagesFolder); var module = new AngularModule(name + "Module"); var formFields = new List <FormField>(); generatorConfiguration.ModuleAssemblies.Push(module); foreach (var childObject in parentObject.GetFormFields(generatorConfiguration.PartsAliasResolver)) { if (childObject is IAttribute) { formFields.Add(new FormField((IAttribute)childObject, generatorConfiguration)); } else { } } $basename$PageGenerator.GeneratePage(baseObject, pagesPath, name, generatorConfiguration, module, imports, module, formFields); return(true); }
public override bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var uiAttribute = (UIAttribute)facet.Attribute; var name = baseObject.GetNavigationName(UIKind.BlankPage); var parentObject = (IParentBase)baseObject; var pagesPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.Pages]; var pagesFolder = (Folder)generatorConfiguration.FileSystem[pagesPath]; var loadKind = uiAttribute.UILoadKind; IModuleAssembly module; IEnumerable <ModuleImportDeclaration> imports; if (uiAttribute.UILoadKind == UILoadKind.RootPage) { this.Raise <ApplicationFacetHandler>(); } imports = generatorConfiguration.CreateImports(this, baseObject, pagesFolder, false, 1); module = generatorConfiguration.PushModuleAssembly <AngularModule>(name); module.UILoadKind = uiAttribute.UILoadKind; BlankPageGenerator.GeneratePage(baseObject, pagesPath, name, generatorConfiguration, module, imports, loadKind); return(true); }
private static dynamic AddUsings(IGeneratorConfiguration config) { return(tr( td("Usings"), td(config.Usings.Select(u => ul(u))) )); }
public void AddRange(IBase baseObject, IGeneratorConfiguration generatorConfiguration, List <Module> modules, ModuleAddType moduleAddType, Func <Module, bool> filter) { var generatorModules = (IEnumerable <ESModule>)generatorConfiguration.KeyValuePairs["Modules"]; var addModules = generatorModules.Where(m => filter(m)); modules.AddRange(addModules); }
private AttributeListSyntax GenerateTermAttribute(FieldType metaData, IGeneratorConfiguration config) { LiteralExpressionSyntax literalExpression = null; switch (config.TermAttribute) { case TermAttributeType.name: literalExpression = SyntaxFactory.LiteralExpression( SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(metaData.Term)); break; case TermAttributeType.index: literalExpression = SyntaxFactory.LiteralExpression( SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(metaData.Index)); break; default: throw new Exception("Invalid term attribute configuration"); } ; return(SyntaxFactory.AttributeList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.Attribute( SyntaxFactory.IdentifierName("Term")) .WithArgumentList( SyntaxFactory.AttributeArgumentList( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.AttributeArgument(literalExpression))))))); }
public string GenerateFile(IFileMetaData fileMetaData, IGeneratorConfiguration config) { var classDeclaration = GeneratClassSyntax(fileMetaData, config); if (config.MapMethod) { var staticMethodSyntax = config.TermAttribute == TermAttributeType.none ? MapMethodGenerator.MapStaticInstanceMethodSyntax(fileMetaData, config) : MapMethodGenerator.MapStaticInstanceMethodSyntax(classDeclaration); classDeclaration = classDeclaration.AddMembers(staticMethodSyntax); } if (string.IsNullOrEmpty(config.Namespace)) { var usings = new SyntaxList <UsingDirectiveSyntax>(); foreach (var usingNamespace in config.Usings) { usings = usings.Add(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(usingNamespace))); } var node = SyntaxFactory.CompilationUnit() .WithUsings(usings) .WithMembers(SyntaxFactory.SingletonList <MemberDeclarationSyntax>(classDeclaration)); return(FormatDeclarationSyntax(node)); } var @namespace = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName(config.Namespace)); foreach (var usingNamespace in config.Usings) { @namespace = @namespace.AddUsings(SyntaxFactory.UsingDirective(SyntaxFactory.ParseName(usingNamespace))); } @namespace = @namespace.AddMembers(classDeclaration); return(FormatDeclarationSyntax(@namespace)); }
public ValidationSet(IGeneratorConfiguration generatorConfiguration) { validationEntries = new List <ValidationEntry>(); validationMasks = new List <ValidationMask>(); validationElements = new List <ValidationElement>(); this.generatorConfiguration = generatorConfiguration; }
public override bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var uiAttribute = (UIAttribute)facet.Attribute; var name = baseObject.GetNavigationName(); var parentObject = (IParentBase)baseObject; var pagesPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.Pages]; var pagesFolder = (Folder)generatorConfiguration.FileSystem[pagesPath]; var imports = generatorConfiguration.CreateImports(this, baseObject, pagesFolder, false, 1); var inputObjects = new List <object>(); // TODO - change, preferably to a typed List, to match your needs IModuleAssembly module; foreach (var childObject in parentObject.GetFollowingChildren(generatorConfiguration.PartsAliasResolver)) { // TODO - add code to capture children elements inputObjects.Add(new object()); } module = generatorConfiguration.PushModuleAssembly <AngularModule>(name); module.UILoadKind = uiAttribute.UILoadKind; $basename$PageGenerator.GeneratePage(baseObject, pagesPath, name, generatorConfiguration, module, imports, module /* , .. TODO - add additional parameters */); return(true); }
public void Create(IGeneratorConfiguration configuration) { _logger.LogInformation("Generation started: {Started}", DateTime.Now.ToShortTimeString()); var result = Context.ValidateConfiguration(configuration); if (!result.IsValid) { _logger.LogInformation("Generation failed: {Failed}", DateTime.Now.ToShortTimeString()); return; } var output = _codeGenerator.Create(Context); try { var outputPath = Context.Settings?.OutputPath ?? Directory.GetCurrentDirectory(); var supportRegen = Context.Settings?.SupportRegen ?? true; _outputStrategy.Create(output, outputPath, supportRegen); _logger.LogInformation("Generation complete: {Complete}", DateTime.Now.ToShortTimeString()); } catch (InvalidOperationException ex) { _logger.LogError(ex, "Generation skipped for Module '{Module}' as there was no defined output strategy", Context.Module?.Name + string.Empty); } }
public bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var container = (IEntityContainer)baseObject; var servicesPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.WebAPIServicesRoot]; var graphQLPath = FileSystemObject.PathCombine(servicesPath, "GraphQL"); string name; string dataContext; string dataContextNamespace; if (container is RestEntityContainer) { var entityWithPathPrefix = baseObject.CastTo <IEntityWithPrefix>(); name = (string)((RestEntityContainer)container).Variables["title"]; dataContext = "I" + name + "DataContext"; dataContextNamespace = ((RestEntityContainer)container).Namespace + ".Models." + entityWithPathPrefix.PathPrefix; } else { name = baseObject.Name.RemoveEndIfMatches("Entities", "Context"); dataContext = "I" + baseObject.Name; dataContextNamespace = ((Entity_Container)container).Namespace; } WebAPIGraphQLSchemaGenerator.GenerateSchema(baseObject, graphQLPath, name, dataContext, dataContextNamespace, generatorConfiguration); return(true); }
public TemplateCollector(IGeneratorConfiguration config) { log = LogManager.GetLogger(this.GetType()); Logger.Setup(config); log.Debug("started SchemaCollector"); Client = CoreserviceClientFactory.GetClient(); }
public override bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var uiAttribute = (UIAttribute)facet.Attribute; var name = baseObject.Name; var parentObject = (IElement)baseObject; var modelsPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.Models]; var modelsFolder = (Folder)generatorConfiguration.FileSystem[modelsPath]; var imports = generatorConfiguration.CreateImports(this, baseObject, modelsFolder); var formFields = new List <FormField>(); foreach (var childObject in parentObject.GetFormFields(generatorConfiguration.PartsAliasResolver)) { if (childObject is IAttribute) { formFields.Add(new FormField((IAttribute)childObject, generatorConfiguration)); } else { } } ClientModelGenerator.GenerateModel(baseObject, modelsPath, name, generatorConfiguration, imports, formFields); return(true); }
public override bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration) { var uiAttribute = (UIAttribute)facet.Attribute; var name = baseObject.GetNavigationName(); var parentObject = (IParentBase)baseObject; var pagesPath = generatorConfiguration.ApplicationFolderHierarchy[IonicFileSystemType.Pages]; var pagesFolder = (Folder)generatorConfiguration.FileSystem[pagesPath]; var imports = generatorConfiguration.CreateImports(this, baseObject, pagesFolder, false, 1); var slidingTabs = new List <SlidingTab>(); var featureKind = uiAttribute.GetFeatureKind(); var isComponent = featureKind.IsComponent(); IModuleAssembly module; foreach (var childObject in parentObject.GetFollowingChildren(generatorConfiguration.PartsAliasResolver, baseObject.Kind != DefinitionKind.StaticContainer)) { slidingTabs.Add(new SlidingTab(childObject, generatorConfiguration)); } module = generatorConfiguration.PushModuleAssembly <AngularModule>(name); module.UILoadKind = uiAttribute.UILoadKind; module.IsComponent = isComponent; SlidingTabsPageGenerator.GeneratePage(baseObject, pagesPath, name, generatorConfiguration, module, imports, slidingTabs, isComponent); return(true); }
public void CopyFiles(IGeneratorConfiguration generatorConfiguration, string argumentsKind) { var hydraSolutionPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables("%HYDRASOLUTIONPATH%")); var sourceDirectory = new DirectoryInfo(generatorConfiguration.ApplicationFolderHierarchy.ServicesRoot.BackSlashes()); var targetDirectory = new DirectoryInfo(Path.Combine(hydraSolutionPath, @"HydraDevOps.Services")); BackupFiles(targetDirectory); sourceDirectory.CopyTo(targetDirectory.FullName, true, (f) => { if (f.Name.StartsWith("Ripley")) { return(false); } else if (f is FileInfo && Path.GetDirectoryName(f.FullName).AsCaseless() == Path.Combine(hydraSolutionPath, @"ApplicationGenerator\TestOutput\Services\Models")) { if (f.Name == "Project.cs" || f.Name == "WorkItemReference.cs") { return(true); } else { return(false); } } return(true); }); sourceDirectory = new DirectoryInfo(generatorConfiguration.ProjectFolderRoot); targetDirectory = new DirectoryInfo(Path.Combine(hydraSolutionPath, @"Ripley\TestOutput")); sourceDirectory.CopyTo(targetDirectory.FullName, true); }
private string CreateSourceFileName(string fileName, string outputPath, IGeneratorConfiguration config) { var sourceFileName = Path.GetFileNameWithoutExtension(fileName); if (config.PascalCase) { sourceFileName = char.ToUpper(sourceFileName[0]) + sourceFileName[1..];
public static void GenerateJson(string configPath, IGeneratorConfiguration generatorConfiguration) { var host = new TemplateEngineHost(); Dictionary <string, object> sessionVariables; FileInfo fileInfo; string fileLocation; string filePath; string output; try { // config.json sessionVariables = new Dictionary <string, object>(); sessionVariables.Add("ClientId", generatorConfiguration.ClientId); sessionVariables.Add("ClientSecret", generatorConfiguration.ClientSecret); sessionVariables.Add("Roles", generatorConfiguration.Roles); fileLocation = configPath; filePath = PathCombine(fileLocation, "Config.json"); fileInfo = new FileInfo(filePath); output = host.Generate <ConfigJsonTemplate>(sessionVariables, false); generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "Config.json")); } catch (Exception e) { generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString()); } }
public EntityProperty(IAttribute attribute, IGeneratorConfiguration generatorConfiguration) : base(attribute, generatorConfiguration) { var displayName = attribute.GetDisplayName(); var name = attribute.GetNavigationName(); this.Nullable = attribute.Nullable; this.DataType = attribute.GetShortType(); if (this.Nullable) { this.DataType = this.DataType + "?"; } if (attribute.HasFacetAttribute <IdentityFieldAttribute>()) { var identityFieldAttribute = attribute.GetFacetAttribute <IdentityFieldAttribute>(); if (identityFieldAttribute.IdentityFieldKind == IdentityFieldKind.PasswordHash) { this.RegisterTitle = displayName.RemoveEndIfMatches("Hash"); this.IsPasswordHash = true; } } this.Title = displayName; this.Name = name; this.IsKey = attribute.HasFacetAttribute <KeyAttribute>(); this.BaseObject = attribute; }
public static void GenerateTranslations(string i18nFolderPath, IGeneratorConfiguration generatorConfiguration) { var host = new TemplateEngineHost(); var pass = generatorConfiguration.CurrentPass; var exports = new List <ESModule>(); var declarations = new List <IDeclarable>(); Dictionary <string, object> sessionVariables; FolderStructure.File file; string fileLocation; string filePath; string output; try { foreach (var dictionary in generatorConfiguration.LanguageDictionary.LanguageSpecificDictionaries.Values) { // LanguageTranslation file sessionVariables = new Dictionary <string, object>(); sessionVariables.Add("Dictionary", dictionary); fileLocation = i18nFolderPath; filePath = PathCombine(fileLocation, dictionary.LanguageCode + ".json"); output = host.Generate <LanguageTranslationFileTemplate>(sessionVariables, false); if (pass == GeneratorPass.Files) { if (File.Exists(filePath)) { File.Delete(filePath); } if (!Directory.Exists(fileLocation)) { generatorConfiguration.CreateDirectory(fileLocation); } using (var fileStream = generatorConfiguration.CreateFile(filePath)) { fileStream.Write(output); generatorConfiguration.FileSystem.DeleteFile(filePath); file = generatorConfiguration.FileSystem.AddSystemLocalProjectFile(new FileInfo(filePath)); } } else if (pass == GeneratorPass.HierarchyOnly) { file = generatorConfiguration.FileSystem.AddSystemLocalProjectFile(new FileInfo(filePath), generatorConfiguration.GenerateInfo(sessionVariables, "{\r\n\t\"Test\": \"Test\"\r\n}")); } } } catch (Exception e) { generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString()); } }
public ManagedList(IBase baseObject, IGeneratorConfiguration generatorConfiguration) : base(baseObject, generatorConfiguration) { var title = baseObject.GetDisplayName(); var name = baseObject.GetNavigationName(); this.Title = title; this.Name = name; }
public Presenter(IGeneratorConfiguration generatorConfiguration, ILoader <IEnumerable <IGeneratorItem> > generatorLoader, ILogger <Presenter> logger) { GeneratorConfiguration = generatorConfiguration ?? throw new ArgumentNullException(nameof(generatorConfiguration)); _generatorLoader = generatorLoader ?? throw new ArgumentNullException(nameof(generatorLoader)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
private ViewRegistry(IGeneratorConfiguration configuration) { _log = LogManager.GetLogger(this.GetType()); currentView = null; Views = new List <ViewDefinition>(); Client = CoreserviceClientFactory.GetClient(); Config = configuration; }
public static ViewRegistry GetInstance(IGeneratorConfiguration configuration) { if (_viewRegistry == null) { _viewRegistry = new ViewRegistry(configuration); } return(_viewRegistry); }
public static ModelRegistry GetInstance(IGeneratorConfiguration configuration) { if (_modelRegistry == null) { _modelRegistry = new ModelRegistry(configuration); } return(_modelRegistry); }