Beispiel #1
0
 /// <summary>
 /// The main production execution method
 /// </summary>
 /// <param name="production">A <see cref="Production"/> instance</param>
 /// <param name="productionContext">A <see cref="ProductionContext"/> instance</param>
 /// <returns>A ProductionResult</returns>
 public ProductionResult ExecuteProduction(Production production, ProductionContext productionContext)
 {
     _productionContext = productionContext;
     // Production could be templated, resolve its parameters using the ProductionContext parameters as context values
     production.ResolveParameters(_productionContext.Parameters);
     // now add Production parameters to ProductionContext parameters
     _productionContext.AddParameters(production.Parameters);
     _productionResult = new ProductionResult();
     foreach (TransformationInfo transformationInfo in production.Transformations)
     {
         TransformationResult transformationResult = ExecuteTransformation(transformationInfo);
         _productionResult.AccumulateTransformationResult(transformationResult);
         if (transformationResult.TransformationResultType == TransformationResultType.CodeEmitter)
         {
             List<GeneratedArtifact> artifacts = transformationResult.CodeEmitter.EmitCode(_productionContext.TargetTechnologies, _productionContext);
             _productionResult.AddGeneratedArtifacts(artifacts);
         }
         else if (transformationResult.TransformationResultType == TransformationResultType.NewModel)
         {
             if (string.IsNullOrEmpty(transformationInfo.OutputModelKey))
                 throw new FactoryException("Missing OutputModelKey in a Transformation resulting in a new Model " + transformationInfo.ToString());
             _productionContext.SetModel(transformationInfo.OutputModelKey, transformationResult.Model);
         }
     }
     return _productionResult;
 }
 protected override void SetExecutionParameters(ProductionContext ctx)
 {
     ctx.AddParameter("domainmodelname", "MetaDomainModel");
     ctx.AddParameter("baseuri", @"C:");
     ctx.AddParameter("solution", @"Tree2Soft.Factory\Factories");
     ctx.AddParameter("project", @"Bax.DataLayer.Factory");
 }
 protected override void SetExecutionParameters(ProductionContext ctx)
 {
     ctx.AddParameter("projectname", "SoccerLeague");
     ctx.AddParameter("baseuri", @"C:");
     ctx.AddParameter("solution", @"Tree2Soft.Factory\Samples");
     ctx.AddParameter("project", @"Bax.Sample.SoccerLeague");
 }
 /// <summary>
 /// Write a <see cref="ProductionResult"/> to persistent storage.
 /// </summary>
 /// <param name="productionResult">The <see cref="ProductionResult"/></param>
 /// <param name="productionContext">The <see cref="ProductionContext"/></param>
 /// <returns>A <see cref="ProductionPersistence"/> instance</returns>
 public ProductionPersistence Persist(ProductionResult productionResult, ProductionContext productionContext)
 {
     ProductionPersistence retval = new ProductionPersistence(productionContext.Parameters);
     foreach (GeneratedArtifact generatedArtifact in productionResult.GeneratedArtifacts)
     {
         IArtifactPersister artifactPersister = FactoryHost.Instance.GetArtifactPersister(generatedArtifact.TargetLanguage, null);
         artifactPersister.Persist(generatedArtifact, productionContext, retval);
     }
     return retval;
 }
 protected override Production GetProduction(ProductionContext ctx)
 {
     return new Bax.MetaDomainModel.Factory.Productions.DomainModelLibraryProduction(
         CreateMetaModelModelInfo()
         );
 }
Beispiel #6
0
 /// <summary>
 /// Methods which must be implemented by derived types to provide 
 /// <see cref="ProductionContext"/> values.
 /// </summary>
 /// <param name="ctx"></param>
 protected abstract void SetExecutionParameters(ProductionContext ctx);
Beispiel #7
0
 /// <summary>
 /// Methods which must be implemented by derived types to provide 
 /// the <see cref="Production"/> to be executed.
 /// </summary>
 /// <param name="productionContext"></param>
 /// <returns></returns>
 protected abstract Production GetProduction(ProductionContext productionContext);
Beispiel #8
0
 /// <summary>
 /// The main methods which executes the production.
 /// </summary>
 public void ExecuteBatch()
 {
     ProductionContext ctx = new ProductionContext();
     ctx.AddTargetTechnology(
         NameTable.TargetTechnologyType.TargetLanguage,
         TargetLanguage
         );
     ctx.AddTargetTechnology(
         NameTable.TargetTechnologyType.TargetDataProvider,
         TargetDataProvider
         );
     SetExecutionParameters(ctx);
     FactoryManager factoryManager = new FactoryManager();
     ProductionResult productionResult = factoryManager.ExecuteProduction(
         GetProduction(ctx),
         ctx
         );
     ProductionPersistence productionPersistence = factoryManager.PersistProduction(productionResult, ctx);
 }
Beispiel #9
0
 /// <summary>
 /// Execute a transformation.
 /// </summary>
 /// <param name="domainModel">The input <see cref="IDomainModel"/></param>
 /// <param name="productionContext">The input <see cref="ProductionContext"/></param>
 /// <returns></returns>
 public TransformationResult Transform(IDomainModel domainModel, ProductionContext productionContext)
 {
     if (TransformationInfo == null)
         throw new FactoryException("TransformationInfo must be set before invoking Transform method");
     Model = domainModel;
     AddParameter(Model.ModelTypeName, Model.Name);
     ProductionContext = productionContext;
     TransformationResult = new TransformationResult();
     ProductionContext.SetCurrentTransformationResult(TransformationResult);
     OnTransform();
     return TransformationResult;
 }
Beispiel #10
0
 /// <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);
 }
Beispiel #11
0
 /// <summary>
 /// Resolve a template string
 /// </summary>
 /// <param name="template"></param>
 /// <param name="productionContext"></param>
 /// <returns></returns>
 private string resolveTemplate(string template, ProductionContext productionContext)
 {
     return productionContext.ResolveTemplate(template);
 }
Beispiel #12
0
 /// <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();
 }
Beispiel #13
0
 /// <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();
     }
 }
Beispiel #14
0
 /// <summary>
 /// Persist a production
 /// </summary>
 /// <param name="productionResult">A <see cref="ProductionResult"/> instance</param>
 /// <param name="productionContext">A <see cref="ProductionContext"/> instance</param>
 /// <returns></returns>
 public ProductionPersistence PersistProduction(ProductionResult productionResult, ProductionContext productionContext)
 {
     ProductionPersister productionPersister = new ProductionPersister();
     return productionPersister.Persist(productionResult, productionContext);
 }
 protected override Production GetProduction(ProductionContext ctx)
 {
     return new Bax.DataLayer.Factory.Productions.DataModelLibraryProduction(
         GetSoccerLeagueDomainModelInfo()
         );
 }