Esempio n. 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 all the substutions.
        /// </summary>
        /// <param name="ctx">The entire context of all the models.</param>
        /// <param name="model"></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 model, List <Model> modelChain, IDictionary <string, string> subs)
        {
            OrmSqlStaticBuilder sql = OrmSqlStaticBuilderFactory.GetBuilder(ctx.AllModels.Settings.Connection.ProviderName);

            sql.Init(ctx, model.Name, model.TableName, 3);
            //Tuple2<string, string> massagersCode = BuildAllMassagers(model);

            subs["<%= model.NameSpace %>"]            = model.NameSpace;
            subs["<%= model.ReferencedNameSpaces %>"] = BuildNameSpaces(model);
            subs["<%= model.Name %>"]           = model.Name;
            subs["<%= model.Properties %>"]     = BuildPropertiesForModel(model);
            subs["<%= model.ValidationCode %>"] = BuildValidation(model);
            subs["<%= model.RowMappingCode %>"] = BuildRowMapping(model);
            BuildDbParams(model, subs);
            subs["<%= model.GetRelations %>"] = BuildRelationFetch(model);
            subs["<%= model.EditRoles %>"]    = BuildEditRoles(model);
            subs["<%= model.SqlInsert %>"]    = sql.Insert();
            subs["<%= model.SqlUpdate %>"]    = sql.Update();
        }