Exemplo n.º 1
0
 private void AddFile2_1_1(SqlSugarClient db)
 {
     var temp      = @"wwwroot\template\WebLib.txt";
     var temp2     = @"wwwroot\template\Lib1_1.txt";
     var directory = Directory.GetCurrentDirectory();
     var d1        = new FileInfo()
     {
         ChangeTime = DateTime.Now,
         Content    = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp)),
         Json       = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp2)).Replace("net5.0", "netcoreapp3.1"),
         Name       = ".net core 3.1  web 项目",
         IsInit     = true,
         Id         = 1,
         IsDeleted  = false,
         Suffix     = "csproj"
     };
     var id = db.Insertable(d1).ExecuteReturnIdentity();
 }
Exemplo n.º 2
0
        private void AddFile1(SqlSugarClient db)
        {
            var temp      = @"wwwroot\template\Lib1.txt";
            var temp2     = @"wwwroot\template\Lib1_1.txt";
            var directory = Directory.GetCurrentDirectory();
            var d1        = new FileInfo()
            {
                ChangeTime = DateTime.Now,
                Content    = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp)),
                Json       = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp2)),
                Name       = ".net 标准类库",
                Id         = 1,
                IsInit     = true,
                IsDeleted  = false,
                Suffix     = "csproj"
            };

            db.Insertable(d1).ExecuteCommand();
        }
Exemplo n.º 3
0
        private void AddFile5(SqlSugarClient db)
        {
            var temp      = @"wwwroot\template\Api_Startup.txt";
            var temp2     = @"wwwroot\template\DbContext_1.txt";
            var directory = Directory.GetCurrentDirectory();
            var d1        = new FileInfo()
            {
                ChangeTime = DateTime.Now,
                Content    = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp)),
                Json       = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp2)).Replace("DbContext", "Startup"),
                Name       = "API文件[Startup]",
                Id         = 1,
                IsInit     = true,
                IsDeleted  = false,
                Suffix     = "cs"
            };
            var id = db.Insertable(d1).ExecuteReturnIdentity();

            _WebFiles.Add(id);
        }
Exemplo n.º 4
0
        public static void CreateProject(Project project, int dbid = 0)
        {
            var ids = project.FileInfo;

            if (!string.IsNullOrEmpty(ids))
            {
                var     idsArray = ids.Split(',').ToList();
                dynamic obj      = Newtonsoft.Json.JsonConvert.DeserializeObject(project.FileModel);
                if (obj.Count == idsArray.Count)
                {
                    for (int i = 0; i < idsArray.Count(); i++)
                    {
                        ExpandoObject jsonItem = GetJsonItem(obj[i]);
                        var           fileId   = ids[i].ToString();
                        var           fileInfo = DbScoped.Sugar.Queryable <FileInfo>().InSingle(idsArray[i]);
                        if (dbid > 0 && fileInfo.Content.Contains("[请设置ConStr]"))
                        {
                            var db = DbScoped.Sugar.Queryable <Database>().InSingle(dbid);
                            fileInfo.Content = fileInfo.Content.Replace("[请设置DbType]", "SqlSugar.DbType." + db.DbType + "").Replace("[请设置ConStr]", "@@\"" + db.Connection.Replace("@", "@@") + "\"");
                        }
                        var context = fileInfo.Content;
                        if (!string.IsNullOrEmpty(project.Reference))
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("<ItemGroup>");
                            //< ProjectReference Include = "..\Entites\WebFirst.Entities.csproj" />
                            foreach (var item in project.Reference.Split(','))
                            {
                                var data     = DbScoped.Sugar.Queryable <Project>().InSingle(item);
                                var itemName = (dynamic)Newtonsoft.Json.JsonConvert.DeserializeObject(data.FileModel);
                                sb.AppendLine("<ProjectReference Include = \"..\\" + data.Path.Split('\\').Last() + "\\" + itemName[0].name + ".csproj\" />");
                            }
                            sb.AppendLine("</ItemGroup>");
                            (jsonItem as IDictionary <string, object>).Add("reference", sb.ToString());
                        }
                        else
                        {
                            (jsonItem as IDictionary <string, object>).Add("reference", null);
                        }
                        var html     = TemplateHelper.GetTemplateValue(context, context, jsonItem);
                        var name     = (jsonItem as IDictionary <string, object>)["name"];
                        var fileName = FileSugar.MergeUrl(project.Path, name + "." + fileInfo.Suffix.TrimStart('.'));
                        if (!FileSugar.IsExistFile(fileName))
                        {
                            FileSugar.CreateFile(fileName, html);
                        }
                        if (fileName.EndsWith(".csproj"))
                        {
                            var root      = new DirectoryInfo(fileName).Parent.Parent.FullName;
                            var files     = FileSugar.GetFileNames(root).Where(it => it.EndsWith(".sln")).ToList();
                            var directory = FileSugar.MergeUrl(Directory.GetCurrentDirectory(), "wwwroot\\template\\sln.txt");
                            if (files.Count == 0)
                            {
                                var text = FileSugar.FileToString(directory);
                                text = text.Replace("{0}", name + "");
                                text = text.Replace("{1}", new DirectoryInfo(project.Path).Name + "\\" + name + ".csproj");
                                FileSugar.CreateFile(root + "\\WebFirst.sln", text);
                            }
                            else if (files.Count > 0)
                            {
                                foreach (var item in files)
                                {
                                    var text = FileSugar.FileToString(item);
                                    if (!text.ToLower().Contains(name.ToString().ToLower()))
                                    {
                                        StringBuilder sb = new StringBuilder();
                                        sb.AppendLine("EndProject");
                                        sb.AppendLine("Project(\"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}\") = \"" + name + "\", \"" + new DirectoryInfo(project.Path).Name + "\\" + name + ".csproj" + "\", \"{" + Guid.NewGuid() + "}\"");
                                        sb.AppendLine(@"EndProject
Global");
                                        text = text.Replace(@"EndProject
Global", sb.ToString());
                                        FileSugar.DeleteFile(item);
                                        FileSugar.CreateFile(item, text);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("文件填充格式错误");
                }
            }
        }
Exemplo n.º 5
0
        private void InitTemplate(SqlSugarClient db)
        {
            //db.DbMaintenance.DropTable("Template");
            db.CodeFirst.InitTables <Template, TemplateType>();
            if (db.Queryable <Template>().Count() == 0)
            {
                db.Insertable(new List <TemplateType>()
                {
                    new  TemplateType()
                    {
                        Name = "实体"
                    },
                    new  TemplateType()
                    {
                        Name = "业务"
                    },
                    new  TemplateType()
                    {
                        Name = "Web"
                    }
                }).ExecuteCommand();
            }
            if (db.Queryable <Template>().Count() == 0)
            {
                var temp      = @"wwwroot\template\Entity01.txt";
                var directory = Directory.GetCurrentDirectory();
                _entitytempId = db.Insertable(new Template()
                {
                    ChangeTime       = DateTime.Now,
                    Content          = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp)),
                    TemplateTypeName = "实体",
                    Sort             = 0,
                    TemplateTypeId   = 1,
                    Title            = "[简单三层]_模版_实体_Sugar",
                    IsInit           = true
                }).ExecuteReturnIdentity();


                var temp2 = @"wwwroot\template\biz.txt";
                _biztempId = db.Insertable(new Template()
                {
                    ChangeTime       = DateTime.Now,
                    Content          = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp2)),
                    TemplateTypeName = "业务",
                    Sort             = 0,
                    TemplateTypeId   = 2,
                    Title            = "[简单三层]_模版_业务_Sugar",
                    IsInit           = true
                }).ExecuteReturnIdentity();


                var temp3 = @"wwwroot\template\web.txt";
                _webtempId = db.Insertable(new Template()
                {
                    ChangeTime       = DateTime.Now,
                    Content          = FileSugar.FileToString(FileSugar.MergeUrl(directory, temp3)),
                    TemplateTypeName = "前端",
                    Sort             = 0,
                    TemplateTypeId   = 3,
                    Title            = "[简单三层]_模版_前端_Sugar",
                    IsInit           = true
                }).ExecuteReturnIdentity();
            }
        }