//public MetaColumnInfo() { }

        //public MetaColumnInfo(Microsoft.AspNet.Scaffolding.Core.Metadata.PropertyMetadata property)
        //    : this(property.PropertyName, property.PropertyName, property.ShortTypeName, (property.RelatedModel != null))
        //{
        //}

        //public MetaColumnInfo(CodeParameter property)
        //    : this(property.Name, property.DocComment, property.Type.AsString, false)
        //{
        //}

        //public MetaColumnInfo(CodeProperty property)
        //    : this(property.Name, property.DocComment, property.Type.AsString, false)
        //{
        //}

        //private MetaColumnInfo(string strName, string strDisplayName, string strType, bool relatedModel)
        //{
        //    this.Name = strName;
        //    this.ShortTypeName = strType;
        //    this.strDataType = strType.Replace("?", "").Replace("System.", "").ToLower();

        //    if (!relatedModel)
        //    {
        //        this.DataType = GetColumnType(this.strDataType);
        //        IsVisible = true;
        //    }
        //    else
        //    {
        //        this.DataType = euColumnType.RelatedModel;
        //        IsVisible = false;  //不勾选导航属性
        //    }

        //    DisplayName = strDisplayName ?? this.Name;
        //    Nullable = true;
        //}


        public MetaColumnInfo(CodeProperty property)
        {
            string strName        = property.Name;
            string strType        = property.Type.AsString;
            string strDisplayName = VmUtils.getCName(property);

            this.Name          = property.Name;
            this.ShortTypeName = property.Type.AsString;
            //this.strDataType = strType.Replace("?", "").Replace("System.", "").ToLower();
            //this.strDataType = strType.Replace("System.", "");
            this.strDataType = strType.Split('.').Last();
            this.DataType    = GetColumnType(strType);
            DisplayName      = strDisplayName ?? this.Name;
            Nullable         = true;
            Required         = false;
            setPropWithAttributes(property);
            if (strDataType.ToLower() == "int" || strDataType.ToLower() == "guid")
            {
                Nullable = false;
            }
            this.ControlType = GetControlType();  //放在setPropWithAttributes之后

            IsDtoVisible  = IsDtoVisibleMember();
            IsItemVisible = IsItemVisibleMember();
        }
Esempio n. 2
0
        public ModelType(CodeType codeType)
        {
            if (codeType == null)
            {
                throw new ArgumentNullException("codeType");
            }

            CodeType    = codeType;
            TypeName    = codeType.FullName;
            DisplayName = (codeType.Namespace != null && !String.IsNullOrWhiteSpace(codeType.Namespace.FullName))
                              ? String.Format("{0} ({1})", codeType.Name, codeType.Namespace.FullName)
                              : codeType.Name;
            ShortName = codeType.Name;
            CName     = VmUtils.getCName(codeType);
        }
Esempio n. 3
0
        public override void GenerateCode()
        {
            if (_moduleViewModel == null)
            {
                throw new InvalidOperationException("需要先调用ShowUIAndValidate方法。");
            }

            Cursor currentCursor = Mouse.OverrideCursor;

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;

                var project          = Context.ActiveProject;
                var entity           = _moduleViewModel.ModelType.CodeType;
                var entityName       = entity.Name;
                var entityNamespace  = entity.Namespace.FullName;
                var entityFolerName  = ProjectItemUtils.GetModuleName(entityNamespace);
                var puralEntityName  = VmUtils.ToPlural(entityName);
                var projectNamespace = ProjectItemUtils.GetProjectName(entityNamespace);
                var overwrite        = _moduleViewModel.OverwriteFiles;
                Dictionary <string, object> templateParams = new Dictionary <string, object>()
                {
                    { "AppName", projectNamespace }
                    , { "EntityNamespace", entityNamespace }
                    , { "EntityFolerName", entityFolerName }
                    , { "PluralEntityName", puralEntityName }
                    , { "EntityName", entityName }
                    , { "DtoNamespace", _moduleViewModel.DtoNamespace }
                    , { "FunctionName", _moduleViewModel.FunctionName }
                    , { "DtoMetaTable", _moduleViewModel.DtoClassMetadataViewModel.DataModel }
                    , { "ItemMetaTable", _moduleViewModel.ItemClassMetadataViewModel.DataModel }
                };

                var templates = new[]
                {
                    @"{AppName}.Web\Areas\{Module}\Controllers\{PluralEntityName}Controller.cs",
                    @"{AppName}.Web\Areas\{Module}\Models\{PluralEntityName}\CreateOrEdit{Entity}ModalViewModel.cs",
                    @"{AppName}.Web\Areas\{Module}\Views\{PluralEntityName}\_CreateOrEditModal.cshtml",
                    @"{AppName}.Web\Areas\{Module}\Views\{PluralEntityName}\Index.cshtml",
                    @"{AppName}.Web\wwwroot\view-resources\Areas\{Module}\Views\{PluralEntityName}\_CreateOrEditModal.js",
                    @"{AppName}.Web\wwwroot\view-resources\Areas\{Module}\Views\{PluralEntityName}\Index.js",
                    @"{AppName}.Web\wwwroot\view-resources\Areas\{Module}\Views\{PluralEntityName}\index.less",
                    @"{AppName}.Common\{PluralEntityName}PageNames.cs",
                };
                foreach (var template in templates)
                {
                    string outputPath = Path.GetFileNameWithoutExtension(Path.Combine(@"_GeneratedCode\",
                                                                                      template.Replace("{AppName}", projectNamespace)
                                                                                      .Replace("{Module}", "Admin")
                                                                                      .Replace("{PluralEntityName}", puralEntityName)
                                                                                      .Replace("{Entity}", entityName)));

                    string templatePath = Path.Combine(template);

                    AddFileFromTemplate(project, outputPath, templatePath, templateParams, !overwrite);
                }
            }
            finally
            {
                Mouse.OverrideCursor = currentCursor;
            }
        }
Esempio n. 4
0
        public override void GenerateCode()
        {
            if (_moduleViewModel == null)
            {
                throw new InvalidOperationException("需要先调用ShowUIAndValidate方法。");
            }

            Cursor currentCursor = Mouse.OverrideCursor;

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                var project = Context.ActiveProject;
                var entity  = _moduleViewModel.ModelType.CodeType;

                var entityPrimaryKeyType = "int";
                entityPrimaryKeyType = GetEntityPrimaryKeyType(entity);
                var entityName      = entity.Name;
                var entityNamespace = entity.Namespace.FullName;

                var projectNamespace = ProjectItemUtils.GetProjectName(entityNamespace);
                var functionName     = _moduleViewModel.FunctionName;
                var pluralEntityName = VmUtils.ToPlural(entityName);
                var entityFolerName  = ProjectItemUtils.GetModuleName(entityNamespace);
                var overwrite        = _moduleViewModel.OverwriteFiles;

                Dictionary <string, object> templateParams = new Dictionary <string, object>()
                {
                    { "AppName", projectNamespace }
                    ,
                    { "EntityNamespace", entityNamespace }
                    ,
                    { "EntityName", entityName }
                    ,
                    { "EntityPrimaryKeyType", entityPrimaryKeyType }
                    ,
                    { "EntityFolerName", entityFolerName }
                    ,
                    { "PluralEntityName", pluralEntityName }
                    ,
                    { "FunctionName", functionName }
                    ,
                    { "DtoMetaTable", _moduleViewModel.DtoClassMetadataViewModel.DataModel }
                };

                var templates = new[]
                {
                    @"{AppName}.Application\{EntityFolerName}\Dto\{Entity}EditDto.cs",
                    @"{AppName}.Application\{EntityFolerName}\Dto\{Entity}ListDto.cs",
                    @"{AppName}.Application\{EntityFolerName}\Dto\CreateOrUpdate{Entity}Input.cs",
                    @"{AppName}.Application\{EntityFolerName}\Dto\Get{Entity}ForEditOutput.cs",
                    @"{AppName}.Application\{EntityFolerName}\Dto\Get{Entity}ListInput.cs",
                    @"{AppName}.Application\{EntityFolerName}\{Entity}AppService.cs",
                    @"{AppName}.Application\{EntityFolerName}\I{Entity}AppService.cs",
                    @"{AppName}.Common\{Entity}Common.cs",
                    @"{AppName}.Core\IRepositories\I{Entity}Repository.cs",
                    @"{AppName}.EntityFramework\EntityFramework\Repositories\{Entity}Repository.cs"
                };
                foreach (var template in templates)
                {
                    string outputPath = Path.GetFileNameWithoutExtension(Path.Combine(@"_GeneratedCode\", template.Replace("{AppName}", projectNamespace)
                                                                                      .Replace("{EntityFolerName}", entityFolerName)
                                                                                      .Replace("{Entity}", entityName)));

                    string templatePath = Path.Combine(template);

                    AddFileFromTemplate(project, outputPath, templatePath, templateParams, !overwrite);
                }
            }
            finally
            {
                Mouse.OverrideCursor = currentCursor;
            }
        }
Esempio n. 5
0
 private string getFunctionFolderName(string modelName)
 {
     modelName = modelName.Replace("Category", "");
     modelName = VmUtils.ToPlural(modelName);
     return(modelName);
 }