Esempio n. 1
0
 /// <summary>
 /// 安装入口
 /// </summary>
 /// <param name="parameter">安装参数</param>
 /// <returns>是否安装成功</returns>
 public bool Run(ProjectParameter parameter)
 {
     if (parameter != null)
     {
         if (parameter.IsAutoCSerCodeGenerator || parameter.IsCustomCodeGenerator)
         {
             LeftArray <Definition> definitions = (parameter.IsCustomCodeGenerator ? parameter.Assembly : ProjectParameter.CurrentAssembly).GetTypes().getArray(type => new Definition {
                 Type = type, Auto = type.customAttribute <GeneratorAttribute>(), Parameter = parameter
             })
                                                  .getFind(type => type.Auto != null && type.Auto.IsTemplate)// && type.Auto.DependType == typeof(cSharper)
                                                  .Sort((left, right) => string.CompareOrdinal(left.Type.FullName, right.Type.FullName));
             LeftArray <string> codes = new LeftArray <string>(definitions.Length);
             foreach (Definition definition in definitions)
             {
                 codes.Add(definition.ToString());
                 if (Messages.IsError)
                 {
                     return(false);
                 }
             }
             string fileName = parameter.ProjectPath + @"{AutoCSer}.CSharper.cs";
             if (Coder.WriteFile(fileName, Coder.WarningCode + string.Concat(codes.ToArray()) + Coder.FileEndCode))
             {
                 Messages.Add(fileName + " 被修改");
                 throw new Exception();
             }
         }
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
 /// <summary>
 /// 安装入口
 /// </summary>
 /// <param name="parameter">安装参数</param>
 /// <returns>是否安装成功</returns>
 public bool Run(ProjectParameter parameter)
 {
     if (parameter != null)
     {
         foreach (Type type in parameter.Types)
         {
             if (typeof(CombinationTemplateConfig).IsAssignableFrom(type) && type != typeof(CombinationTemplateConfig))
             {
                 CombinationTemplateConfig config    = (CombinationTemplateConfig)Activator.CreateInstance(type);
                 DirectoryInfo             directory = new DirectoryInfo(parameter.ProjectPath + config.TemplatePath);
                 if (directory.Exists)
                 {
                     LeftArray <string>[] codes = Directory.GetFiles(directory.FullName, "*.cs").getArray(name => code(name));
                     if (!codes.any(code => code.Length == 0))
                     {
                         string fileName = parameter.ProjectPath + @"{" + parameter.DefaultNamespace + "}.CombinationTemplate.cs";
                         if (Coder.WriteFile(fileName, Coder.WarningCode + string.Concat(codes.getArray(code => code.ToArray()).getArray()) + Coder.FileEndCode))
                         {
                             Messages.Message(fileName + " 被修改");
                         }
                         return(true);
                     }
                 }
                 else
                 {
                     Messages.Message("没有找到自定义模板相对项目路径" + config.TemplatePath);
                 }
             }
         }
         return(true);
     }
     return(false);
 }
Esempio n. 3
0
 /// <summary>
 /// 安装入口
 /// </summary>
 /// <param name="parameter">安装参数</param>
 /// <returns>是否安装成功</returns>
 public bool Run(ProjectParameter parameter)
 {
     if (parameter != null)
     {
         HashSet <string> codeFileNames = new HashSet <string>();
         foreach (Type type in parameter.Types ?? EmptyArray <Type> .Array)
         {
             if (!type.IsAbstract && typeof(CombinationTemplateConfig).IsAssignableFrom(type) && type != typeof(CombinationTemplateConfig))
             {
                 CombinationTemplateConfig config = (CombinationTemplateConfig)Activator.CreateInstance(type);
                 string codeFileName = config.GetCodeFileName(parameter.DefaultNamespace);
                 if (!codeFileNames.Add(codeFileName))
                 {
                     Messages.Error("自定义简单组合模板目标文件名称冲突 " + codeFileName);
                     return(false);
                 }
                 LeftArray <string> codes = new LeftArray <string>(0);
                 foreach (string templatePath in config.TemplatePath)
                 {
                     DirectoryInfo directory = new DirectoryInfo(Path.Combine(parameter.ProjectPath, templatePath));
                     if (directory.Exists)
                     {
                         foreach (FileInfo file in directory.GetFiles("*.cs"))
                         {
                             LeftArray <string> newCodes = getCode(file.FullName);
                             if (newCodes.Length == 0)
                             {
                                 return(false);
                             }
                             codes.Add(ref newCodes);
                         }
                     }
                     else
                     {
                         Messages.Error("没有找到自定义模板相对项目路径" + config.TemplatePath);
                         return(false);
                     }
                 }
                 string fileName = Path.Combine(parameter.ProjectPath, @"{" + codeFileName + "}.CombinationTemplate.cs");
                 if (Coder.WriteFile(fileName, Coder.WarningCode + string.Concat(codes.ToArray()) + Coder.FileEndCode))
                 {
                     Messages.Message(fileName + " 被修改");
                 }
             }
         }
         return(true);
     }
     return(false);
 }
 /// <summary>
 /// 安装入口
 /// </summary>
 /// <param name="parameter">安装参数</param>
 /// <returns>是否安装成功</returns>
 public bool Run(ProjectParameter parameter)
 {
     if (parameter != null)
     {
         //if (!parameter.IsAutoCSerCodeGenerator) return true;
         string path = parameter.ProjectPath + DefaultTemplatePath;
         if (Directory.Exists(path))
         {
             LeftArray <string>[] codes = Directory.GetFiles(path, "*.cs").getArray(name => code(name));
             if (!codes.any(code => code.Length == 0))
             {
                 string fileName = parameter.ProjectPath + @"..\Sort\{AutoCSer}.CombinationTemplate.cs";
                 if (Coder.WriteFile(fileName, Coder.WarningCode + string.Concat(codes.getArray(code => code.ToArray()).getArray()) + Coder.FileEndCode))
                 {
                     Messages.Message(fileName + " 被修改");
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 5
0
        /// <summary>
        /// 安装入口
        /// </summary>
        /// <param name="parameter">安装参数</param>
        /// <returns>是否安装成功</returns>
        public bool Run(ProjectParameter parameter)
        {
            if (parameter != null)
            {
                if (parameter.IsAutoCSerCodeGenerator || parameter.IsCustomCodeGenerator)
                {
                    LeftArray <Definition> definitions = (parameter.IsCustomCodeGenerator ? parameter.Assembly : ProjectParameter.CurrentAssembly).GetTypes().getArray(type => new Definition {
                        Type = type, Auto = type.customAttribute <GeneratorAttribute>(), Parameter = parameter
                    })
                                                         .getFind(type => type.Auto != null && type.Auto.IsTemplate)// && type.Auto.DependType == typeof(cSharper)
                                                         .Sort((left, right) => string.CompareOrdinal(left.Type.FullName, right.Type.FullName));
                    LeftArray <string> codes = new LeftArray <string>(definitions.Length);
                    foreach (Definition definition in definitions)
                    {
                        codes.Add(definition.ToString());
                        if (Messages.IsError)
                        {
                            return(false);
                        }
                    }
#if DotNetStandard
                    string path = new System.IO.FileInfo(parameter.AssemblyPath).Directory.fullName();
                    copyDotNetCoreJson(path, "AutoCSer.CodeGenerator.deps.json");
                    copyDotNetCoreJson(path, "AutoCSer.CodeGenerator.runtimeconfig.dev.json");
                    copyDotNetCoreJson(path, "AutoCSer.CodeGenerator.runtimeconfig.json");
#endif
                    string fileName = parameter.ProjectPath + @"{AutoCSer}.CSharper.cs";
                    if (Coder.WriteFile(fileName, Coder.WarningCode + string.Concat(codes.ToArray()) + Coder.FileEndCode))
                    {
                        Messages.Error(fileName + " 被修改");
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }