Beispiel #1
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);
 }
Beispiel #2
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);
 }