protected override void OnTransform() { m.MetaDomainModel metaModel = Model as m.MetaDomainModel; if (metaModel == null) throw new InvalidOperationException("model must be of type : " + typeof(m.MetaDomainModel).FullName); Bax.MetaDomainModel.Factory.Templates.NVelocityTemplate template = new Bax.MetaDomainModel.Factory.Templates.NVelocityTemplate(_templateName); string artifact = template.Merge(metaModel, ProductionContext.ParametersHashtable); GeneratedArtifact ga = new GeneratedArtifact(this.TransformationInfo); ga.TargetLanguage = this.TargetLanguage; ga.CreateArtifactDataItem(null, null, artifact); TransformationResult.GeneratedArtifacts.Add(ga); }
protected override void OnTransform() { m.DataLayer dataLayer = Model as m.DataLayer; if (dataLayer == null) throw new InvalidOperationException("model must be of type : " + typeof(m.DataLayer).FullName); Bax.DataLayer.Factory.Templates.NVelocityTemplate template = new Bax.DataLayer.Factory.Templates.NVelocityTemplate("DataModelLibrary"); string artifact = template.Merge(dataLayer, ProductionContext.ParametersHashtable); GeneratedArtifact generatedArtifact = new GeneratedArtifact(this.TransformationInfo); generatedArtifact.TargetLanguage = this.TargetLanguage; generatedArtifact.CreateArtifactDataItem(null, null, artifact); TransformationResult.GeneratedArtifacts.Add(generatedArtifact); }
/// <summary> /// Add a <see cref="GeneratedArtifact"/> instance to the /// <see cref="TransformationResult"/> of the transformation which is executing. /// </summary> /// <param name="generatedArtifact"></param> public void AddGeneratedArtifactToTransformationResult(GeneratedArtifact generatedArtifact) { CurrentTransformationResult.GeneratedArtifacts.Add(generatedArtifact); }
/// <summary> /// The main method to persist a <see cref="GeneratedArtifact"/> /// </summary> /// <param name="artifact">A <see cref="GeneratedArtifact"/> instance</param> /// <param name="productionContext">A <see cref="ProductionContext"/> instance</param> /// <param name="productionPersistence">A <see cref="ProductionPersistence"/> instance</param> public void Persist(GeneratedArtifact artifact, ProductionContext productionContext, ProductionPersistence productionPersistence) { _productionPersistence = productionPersistence; if (!string.IsNullOrEmpty(artifact.ItemFilePathTemplate)) PersistMultiFile(artifact, productionContext); else PersistSingleFile(artifact, productionContext); }
/// <summary> /// Persists the artifact in a single file /// </summary> /// <param name="artifact"></param> /// <param name="productionContext"></param> private void PersistSingleFile(GeneratedArtifact artifact, ProductionContext productionContext) { string filePath = resolveTemplate(artifact.GroupFilePathTemplate, productionContext); Writer = Services.IOService.OpenIndentedTextWrite(filePath); // write begin file ArtifactBegin(); // write autogenerated infos AutogeneratedInfoBegin(); artifact.WriteAutogeneratedInfosTo(Writer); AutogeneratedInfoEnd(); // write artifact imports List<string> writtenImports = new List<string>(); artifact.WriteImportsTo(Writer, writtenImports); foreach (ArtifactDataItem artifactDataItem in artifact.ArtifactDataItems) { artifactDataItem.WriteImportsTo(Writer, writtenImports); } string ns = null; int baseIndent = 0; // namespace can be null if not required by target technology if (!string.IsNullOrEmpty(artifact.NamespaceTemplate)) { // open namespace ns = resolveTemplate(artifact.NamespaceTemplate, productionContext); baseIndent = OpenNamespace(ns); } // write artifact code lines foreach (ArtifactDataItem artifactDataItem in artifact.ArtifactDataItems) { artifactDataItem.WriteCodeLinesTo(Writer, baseIndent); } Writer.Indent = Math.Max(0, Writer.Indent - baseIndent); if (ns != null) { // close namespace CloseNamespace(ns); } // write end file ArtifactEnd(); Writer.Close(); }
/// <summary> /// Persist each <see cref="ArtifactDataItem"/> in its own file. /// </summary> /// <param name="artifact"></param> /// <param name="productionContext"></param> private void PersistMultiFile(GeneratedArtifact artifact, ProductionContext productionContext) { foreach (ArtifactDataItem artifactDataItem in artifact.ArtifactDataItems) { // create writer string filePath = resolveTemplate(artifact.ItemFilePathTemplate, productionContext); Writer = Services.IOService.OpenIndentedTextWrite(filePath); // write begin file ArtifactBegin(); // write autogenerated infos AutogeneratedInfoBegin(); artifact.WriteAutogeneratedInfosTo(Writer); AutogeneratedInfoEnd(); // write artifact imports List<string> writtenImports = new List<string>(); artifact.WriteImportsTo(Writer, writtenImports); // write artifact item imports artifactDataItem.WriteImportsTo(Writer, writtenImports); // resolve and open namespace string ns = resolveTemplate(artifact.NamespaceTemplate, productionContext); int baseIndent = OpenNamespace(ns); // write artifact item code lines artifactDataItem.WriteCodeLinesTo(Writer, baseIndent); // close namespace CloseNamespace(ns); // write end file ArtifactEnd(); Writer.Close(); } }
/// <summary> /// Add a <see cref="GeneratedArtifact"/> to this ProductionResult. /// </summary> /// <param name="artifact"></param> public void AddGeneratedArtifact(GeneratedArtifact artifact) { GeneratedArtifacts.Add(artifact); }
/// <summary> /// Returns a <see cref="GeneratedArtifact"/> newly created and added to the /// <see cref="GeneratedArtifact"/>s collection. /// </summary> /// <param name="transformationInfo"></param> /// <returns></returns> public GeneratedArtifact CreateGeneratedArtifact(TransformationInfo transformationInfo) { GeneratedArtifact retval = new GeneratedArtifact(transformationInfo); GeneratedArtifacts.Add(retval); return retval; }