Beispiel #1
0
        /// <summary>
        /// Build all the substutions.
        /// </summary>
        /// <param name="ctx">The entire context of all the models.</param>
        /// <param name="currentModel">The current model being code-generated.</param>
        /// <param name="modelChain">The inheritance chain of the model.</param>
        /// <param name="subs">The dictionary of substutions to populate.</param>
        public virtual void BuildSubstitutions(ModelContext ctx, Model currentModel, List <Model> modelChain, IDictionary <string, string> subs)
        {
            // 1. Validation code.
            // 2. Row Mapping code.
            // 3. Properties on the Object.
            // 4. Edit roles for the model.
            // 5. Data Massagers.
            CodeBuilderValidation  validationBuilder    = new CodeBuilderValidation();
            CodeBuilderDbRowMapper codeBuilderRowMapper = new CodeBuilderDbRowMapper();

            codeBuilderRowMapper.Tab = "\t\t\t";
            // TO_DO: This is using sql by default.
            OrmSqlStaticBuilder sql = OrmSqlStaticBuilderFactory.GetBuilder(ctx.AllModels.Settings.Connection.ProviderName);

            sql.Init(ctx, currentModel.Name, currentModel.Name + "s", 3);
            Tuple2 <string, string> massagersCode = BuildAllMassagers(ctx, currentModel);
            string properties     = BuildPropertiesForModel(ctx, currentModel);
            string moderators     = BuildEditRoles(currentModel);
            string validationCode = validationBuilder.BuildValidationForModel(ctx, currentModel);
            string rowMapperCode  = codeBuilderRowMapper.BuildRowMapper(ctx, currentModel, modelChain);

            subs["<%= model.NameSpace %>"]                 = currentModel.NameSpace;
            subs["<%= model.Name %>"]                      = currentModel.Name;
            subs["<%= model.Properties %>"]                = properties;
            subs["<%= model.ValidationCode %>"]            = validationCode;
            subs["<%= model.BeforeValidationMassagers %>"] = massagersCode.First;
            subs["<%= model.AfterValidationMassagers %>"]  = massagersCode.Second;
            subs["<%= model.RowMappingCode %>"]            = rowMapperCode;
            subs["<%= model.EditRoles %>"]                 = moderators;
            subs["<%= model.SqlInsert %>"]                 = sql.Insert();
            subs["<%= model.SqlUpdate %>"]                 = sql.Update();
        }
        /// <summary>
        /// Build the validation code.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string BuildValidation(Model model)
        {
            if (!model.GenerateValidation)
            {
                return(string.Empty);
            }
            CodeBuilderValidation validationBuilder = new CodeBuilderValidation();
            string validationCode = validationBuilder.BuildValidationForModel(Context, model);

            validationCode = GetValidationCode(validationCode);
            return(validationCode);
        }