Exemplo n.º 1
0
        private void ExecuteTemplateContainer(TableInfo tableInfo, Context configContext)
        {
            var pathOutput = PathOutput.PathOutputContainer(configContext);

            var pathTemplateClass = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "container");

            if (!File.Exists(pathTemplateClass))
            {
                return;
            }

            var pathTemplateInjections = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "container.injections");

            var textTemplateClass      = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder);
            var TextTemplateInjections = Read.AllText(tableInfo, pathTemplateInjections, this._defineTemplateFolder);

            if (configContext.Module.IsNullOrEmpty())
            {
                textTemplateClass = textTemplateClass.Replace("<#domainSource#>", configContext.ProjectName);
            }

            var classBuilder = GenericTagsTransformer(tableInfo, configContext, textTemplateClass);

            var classBuilderMappers = string.Empty;

            foreach (var item in configContext.TableInfo)
            {
                if (!string.IsNullOrEmpty(item.ClassName))
                {
                    var itemInjections = TextTemplateInjections.
                                         Replace("<#namespace#>", configContext.Namespace).
                                         Replace("<#module#>", configContext.Module.IsNullOrEmpty() ? configContext.ProjectName : configContext.Module).
                                         Replace("<#className#>", item.ClassName).
                                         Replace("<#domainSource#>", configContext.DomainSource.IsNullOrEmpty() ? configContext.ProjectName : configContext.DomainSource).
                                         Replace("<#contextName#>", configContext.ContextName).
                                         Replace("<#namespaceDomainSource#>", configContext.NamespaceDomainSource);

                    classBuilderMappers += string.Format("{0}{1}{2}", "            ", itemInjections, System.Environment.NewLine);
                }
            }

            classBuilder = classBuilder.Replace("<#injections#>", classBuilderMappers);

            using (var stream = new StreamWriter(pathOutput))
            {
                stream.Write(classBuilder);
            }
        }