Esempio n. 1
0
        private void ExecuteTemplateAutoMapperProfileBase(TableInfo tableInfo, Context configContext)
        {
            var pathOutput        = PathOutput.PathOutputAutoMapperProfileBase(configContext, tableInfo);
            var pathTemplateClass = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile");

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

            var pathTemplateMappers       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile.registers");
            var pathTemplateMappersSave   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile.registers.save");
            var pathTemplateMappersGet    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile.registers.get");
            var pathTemplateMappersDetail = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this._defineTemplateFolder.Define(tableInfo), "profile.registers.detail");

            var textTemplateClass         = Read.AllText(tableInfo, pathTemplateClass, this._defineTemplateFolder);
            var textTemplateMappers       = Read.AllText(tableInfo, pathTemplateMappers, this._defineTemplateFolder);
            var textTemplateMappersSave   = Read.AllText(tableInfo, pathTemplateMappersSave, this._defineTemplateFolder);
            var textTemplateMappersGet    = Read.AllText(tableInfo, pathTemplateMappersGet, this._defineTemplateFolder);
            var textTemplateMappersDetail = Read.AllText(tableInfo, pathTemplateMappersDetail, this._defineTemplateFolder);

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

            var classBuilderMappers = string.Empty;

            foreach (var item in configContext.TableInfo)
            {
                var className = item.ClassName;

                if (!string.IsNullOrEmpty(className))
                {
                    var itemMapper       = textTemplateMappers.Replace("<#className#>", className);
                    var itemMapperSave   = textTemplateMappersSave.Replace("<#className#>", className);
                    var itemMapperGet    = textTemplateMappersGet.Replace("<#className#>", className);
                    var itemMapperDetail = textTemplateMappersDetail.Replace("<#className#>", className);

                    classBuilderMappers += string.Format("{0}{1}{2}", Tabs.TabSets(), itemMapper, System.Environment.NewLine);
                    classBuilderMappers += string.Format("{0}{1}{2}", Tabs.TabSets(), itemMapperSave, System.Environment.NewLine);
                    classBuilderMappers += string.Format("{0}{1}{2}", Tabs.TabSets(), itemMapperGet, System.Environment.NewLine);
                    classBuilderMappers += string.Format("{0}{1}{2}", Tabs.TabSets(), itemMapperDetail, System.Environment.NewLine);
                }
            }

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

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