Example #1
0
        /// <summary>
        /// Builds the Domain model code which includes :
        /// 1. Entity.
        /// 2. ActiveRecord
        /// 3. Service
        /// 4. Repository
        /// 5. Settings
        /// 6. Validator
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public virtual BoolMessageItem <ModelContainer> Process(ModelContext ctx)
        {
            string codeTemplatePath = ctx.AllModels.Settings.ModelCodeLocationTemplate;
            Dictionary <string, CodeFile> fileMap = CodeBuilderUtils.GetFiles(ctx, string.Empty, codeTemplatePath);

            foreach (Model currentModel in ctx.AllModels.AllModels)
            {
                // Pre condition.
                if (currentModel.GenerateCode)
                {
                    // Create the database table for all the models.
                    List <Model> modelChain = ModelUtils.GetModelInheritancePath(ctx, currentModel.Name, true);

                    fileMap = CodeFileHelper.GetFilteredDomainModelFiles(currentModel, fileMap);
                    string generatedCodePath = (string)ctx.AllModels.Settings.ModelCodeLocation;
                    generatedCodePath += "/" + currentModel.Name;
                    IDictionary <string, string> subs = new Dictionary <string, string>();
                    BuildSubstitutions(ctx, currentModel, modelChain, subs);

                    foreach (string fileName in fileMap.Keys)
                    {
                        string templateFile = codeTemplatePath + "/" + fileName;
                        string generated    = generatedCodePath + "/" + fileMap[fileName].QualifiedName;
                        CodeFileHelper.Write(templateFile, generated, generatedCodePath, subs);
                    }
                }
            }
            return(new BoolMessageItem <ModelContainer>(ctx.AllModels, true, string.Empty));
        }
        /// <summary>
        /// Builds the Domain model code which includes :
        /// 1. Entity.
        /// 2. ActiveRecord
        /// 3. Service
        /// 4. Repository
        /// 5. Settings
        /// 6. Validator
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public virtual BoolMessageItem <ModelContainer> Process(ModelContext ctx)
        {
            string codeTemplatePath = ctx.AllModels.Settings.ModelCodeLocationTemplate;

            this.Context = ctx;
            Dictionary <string, CodeFile> fileMap = CodeBuilderUtils.GetFiles(ctx, string.Empty, codeTemplatePath);

            ctx.AllModels.Iterate(m => ctx.CanProcess(m, (model) => model.GenerateCode), currentModel =>
            {
                var modelChain                    = ctx.AllModels.InheritanceFor(currentModel.Name);
                fileMap                           = CodeFileHelper.GetFilteredDomainModelFiles(currentModel, fileMap);
                string generatedCodePath          = (string)ctx.AllModels.Settings.ModelCodeLocation;
                generatedCodePath                += "/" + currentModel.Name;
                IDictionary <string, string> subs = new Dictionary <string, string>();
                BuildSubstitutions(ctx, currentModel, modelChain, subs);

                foreach (string fileName in fileMap.Keys)
                {
                    string templateFile = codeTemplatePath + "/" + fileName;
                    string generated    = generatedCodePath + "/" + fileMap[fileName].QualifiedName;
                    CodeFileHelper.Write(templateFile, generated, generatedCodePath, subs);
                }
            });

            return(new BoolMessageItem <ModelContainer>(ctx.AllModels, true, string.Empty));
        }
        /// <summary>
        /// Builds the model.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="model"></param>
        public void ModelProcessCompleted(ModelContext ctx, Model model)
        {
            // Write out the files.
            // 1. Controller.
            // 2. Views ( create.aspx, update.aspx, index.aspx
            Dictionary <string, CodeFile> files = CodeBuilderUtils.GetFiles(ctx, "*.cs,*.ascx,*.aspx", ctx.AllModels.Settings.ModelCodeLocationUITemplate);
            string manageColumnsUI = _indexColumnCode.ToString() + "<td><div class=\"field\">manage</div></td>" + Environment.NewLine;

            List <KeyValuePair <string, string> > subs = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("<%= model.NameSpace %>", model.NameSpace),
                new KeyValuePair <string, string>("<%= model.Name %>", model.Name),
                new KeyValuePair <string, string>("<%= model.PropertiesUI %>", _createEditCode.ToString()),
                new KeyValuePair <string, string>("<%= model.DetailsUI %>", _detailsCode.ToString()),
                new KeyValuePair <string, string>("<%= model.IndexUI %>", _indexCode.ToString()),
                new KeyValuePair <string, string>("<%= model.IndexColumnsUI %>", _indexColumnCode.ToString()),
                new KeyValuePair <string, string>("<%= model.IndexColumnCount %>", _indexColumnCount.ToString()),
                new KeyValuePair <string, string>("<%= model.ManageColumnsUI %>", manageColumnsUI),
                new KeyValuePair <string, string>("<%= model.ManageColumnCount %>", (_indexColumnCount + 1).ToString())
            };

            string rootUIFolder = ctx.AllModels.Settings.ModelCodeLocationUI;

            foreach (string key in files.Keys)
            {
                CodeFile file = files[key];
                if (file.Name == "Controller.cs")
                {
                    file.QualifiedName = model.Name + file.Name;
                    file.OutputFolder  = rootUIFolder + "\\" + file.Folder;
                }
                else
                {
                    file.QualifiedName = file.Name;
                    file.OutputFolder  = rootUIFolder + "\\" + file.Folder + "\\" + model.Name + "s";
                }
            }
            CodeBuilderUtils.WriteFiles(files, subs, ctx.AllModels.Settings.ModelCodeLocationUI);
            Init();
        }