///// <summary>
        ///// 添加通用头部
        ///// </summary>
        ///// <param name="str"></param>
        //private static void AddCommonHeader(ref StringBuilder str)
        //{
        //    str.AppendLine("using System");
        //    str.AppendLine("using System.Collections.Generic");
        //    str.AppendLine("using System.Linq");
        //    str.AppendLine("using System.ServiceModel");
        //    str.AppendLine("using System.Text");
        //    str.AppendLine("using System.Threading.Tasks");
        //}

        //private static void AddExtraHeader(ref StringBuilder str, InterfaceDiscription interDis = null)
        //{
        //    if (interDis != null)
        //    {
        //        foreach (var item in interDis.InterUsings)
        //        {
        //            str.AppendLine(item.UsingName);

        //        }

        //    }



        //}
        //#region 生成ND.WebService.Service
        //public static void GenerateService(InterfaceList interList)
        //{
        //    string ServiceName = "";//服务文件名
        //    string DirectPath = "";//保存目录
        //    string RequestType = "";//请求类型
        //    string RequestName = "";//请求名称
        //    string InterfaceName = "";//接口名称
        //    interList.lstInterDis.ToList().ForEach(x =>
        //    {
        //        InterfaceName = x.InterfaceName.Replace("Executor", "");
        //        StringBuilder str = new StringBuilder();
        //        ServiceName = InterfaceName.Substring(1) + "Controller";
        //        AddCommonHeader(ref str);//添加通用头部
        //        AddExtraHeader(ref str, x);//添加额外的引用头部
        //        str.AppendLine("namespace ND.WebService.Service." + x.FileName);
        //        str.AppendLine("{");
        //        str.AppendLine("  public  class " + ServiceName + ":" + InterfaceName + "");
        //        str.AppendLine("\t{");

        //        x.MethodDis.ToList().ForEach(k =>
        //        {
        //            str.AppendLine("\t\t[RuleOperationInterceptor]");
        //            str.Append("\t\tpublic string " + k.InterfaceMethodName + "(");
        //            int index = 0;
        //            k.Request.ToList().ForEach(m =>//参数
        //            {
        //                if (index > 0)
        //                {
        //                    str.Append(",");
        //                }
        //                str.Append(m.RequestParamType + " " + m.RequestParamName);
        //                index++;
        //            });
        //            str.AppendLine(")");
        //            str.AppendLine("\t\t {");
        //            RequestType = k.Request.Count > 0 ? k.Request[0].RequestParamType : RequestType;
        //            RequestName = k.Request.Count > 0 ? k.Request[0].RequestParamName : RequestName;
        //            str.AppendLine("\t\t\t" + InterfaceName + " plugin = ControllerHelper.GetCurrentPlugin<" + RequestType + "," + InterfaceName + ">(" + RequestName + ");");
        //            str.AppendLine("\t\t\treturn plugin." + k.InterfaceMethodName + "(" + RequestName + ");");
        //            str.AppendLine("\t\t }");
        //        });
        //        str.AppendLine("\t}");
        //        str.AppendLine("}");
        //        DirectPath = System.Configuration.ConfigurationManager.AppSettings["ND.Web.Service"] + x.FileName;
        //        ApiLogHelper.Save(DirectPath, ServiceName, str.ToString());
        //    });



        //}
        //#endregion

        //#region 生成插件层代码ND.Plugin.DefaultPlugin
        //public static void GeneratePlugin(InterfaceList interList)
        //{
        //    string FileName = "";//插件文件名
        //    string DirectPath = "";//保存目录
        //    string RequestType = "";//请求类型
        //    string RequestName = "";//请求名称
        //    string InterfaceName = "";//接口名称
        //    string enter = ",";//\r\n
        //    interList.lstInterDis.ToList().ForEach(x =>
        //    {
        //        InterfaceName = x.InterfaceName.Replace("Executor", "");
        //        StringBuilder str = new StringBuilder();
        //        FileName = InterfaceName.Substring(1) + "Plugin";
        //        AddCommonHeader(ref str);//添加通用头部
        //        AddExtraHeader(ref str, x);//添加额外的引用头部
        //        str.AppendLine("using ND.Lib.Enums.common;");
        //        str.AppendLine("using ND.Lib.LibHelper.log;");
        //        str.AppendLine("using ND.Plugin.PluginProvider;");
        //        str.AppendLine("using ND.Lib.LibHelper.extention;");
        //        str.AppendLine("using ND.Lib.Core." + x.FileName + "Core.handlers;");
        //        str.AppendLine("namespace ND.Plugin.DefaultPlugin." + x.FileName.ToFirstUpper());
        //        str.AppendLine("{");
        //        str.AppendLine("\tpublic class " + InterfaceName.RemoveFirstLetter() + "Plugin:" + InterfaceName + ",IPlugin");
        //        str.AppendLine("\t{");
        //        x.MethodDis.ToList().ForEach(k =>
        //        {
        //            str.Append("\t\tpublic string " + k.InterfaceMethodName + "(");
        //            int index = 0;
        //            k.Request.ToList().ForEach(m =>//参数
        //            {
        //                if (index > 0)
        //                {
        //                    str.Append(",");
        //                }
        //                str.Append(m.RequestParamType + " " + m.RequestParamName);
        //                index++;
        //            });
        //            str.AppendLine(")");
        //            str.AppendLine("\t\t {");
        //            RequestType = k.Request.Count > 0 ? k.Request[0].RequestParamType : RequestType;
        //            RequestName = k.Request.Count > 0 ? k.Request[0].RequestParamName : RequestName;
        //            str.AppendLine("\t\t\t try");
        //            str.AppendLine("\t\t\t {");
        //            str.AppendLine("\t\t\t\t   I" + x.FileName.ToFirstUpper() + "HandlerContext handlerContext = new  " + x.FileName.ToFirstUpper() + "HandlerContext();");
        //            str.AppendLine("\t\t\t\t   I" + x.FileName.ToFirstUpper() + "Handler handler = new " + x.FileName.ToFirstUpper() + "Handler(handlerContext);");
        //            str.AppendLine("\t\t\t\t   " + k.Response.ResponseParamType + " baseResponse = handler." + k.InterfaceMethodName + "(" + RequestName + ");//反序列化对象");
        //            str.AppendLine("\t\t\t\t   string result = PluginHelper<" + k.Response.ResponseParamType.SubResponse() + ", I" + k.Response.ResponseParamType.SubResponse() + ">.SelectResponsePlugin(baseResponse, " + RequestName + ".ClientType);//根据客户端类型找对应的插件返回,app或者前台或者后台");
        //            str.AppendLine("\t\t\t\t   return result;");
        //            str.AppendLine("\t\t\t }");
        //            str.AppendLine("\t\t\t catch (Exception e)");
        //            str.AppendLine("\t\t\t {");//e00001
        //            str.AppendLine("\t\t\t LogHelper.Log(typeof(" + InterfaceName.RemoveFirstLetter() + "Plugin), e.Message " + enter + " e.StackTrace  " + enter + " e.InnerException);");
        //            str.AppendLine("\t\t\t return JsonConvert.SerializeObject(new ResponseBase<EmptyResponse> { errCode = ErrorCode.e00001.ToString(), errMsg = ErrorCode.e00001.description(), ResponseData = null });");
        //            str.AppendLine("\t\t\t }");
        //            str.AppendLine("\t\t }");

        //        });
        //        str.AppendLine("\t}");
        //        str.AppendLine("}");
        //        DirectPath = System.Configuration.ConfigurationManager.AppSettings["ND.Plugin.DefaultPlugin"] + x.FileName;
        //        ApiLogHelper.Save(DirectPath, FileName, str.ToString());

        //    });
        //}
        //#endregion
        #endregion


        #region 生成ND.Lib.Core
        public static void GenerateCore(InterfaceList interList)
        {
            string        DirectPath   = System.Configuration.ConfigurationManager.AppSettings["ND.Lib.Core"];
            List <string> lstCreateDir = new List <string>();

            #region 先生成各个文件夹
            //1.先生成各个文件夹
            string corePath = Path.Combine(DirectPath, interList.FileName + "Core");        //核心path
            string dependencyInjectionPath = Path.Combine(corePath, "dependencyInjection"); //依赖path
            string excutorImpPath          = Path.Combine(corePath, "Executor/impl");
            string excutorInterPath        = Path.Combine(corePath, "Executor/inter");
            string hanlderPath             = Path.Combine(corePath, "handlers");
            string configPath = Path.Combine(corePath, "config");

            lstCreateDir.Add(corePath);
            lstCreateDir.Add(dependencyInjectionPath);
            lstCreateDir.Add(excutorImpPath);
            lstCreateDir.Add(excutorInterPath);
            lstCreateDir.Add(hanlderPath);
            lstCreateDir.Add(configPath);
            lstCreateDir.ForEach(k =>
            {
                DirFileHelper.CreateDirectory(k);
            });
            #endregion

            NDLibCoreHelper.GenerateDependency(dependencyInjectionPath, interList); //生成依赖类
            NDLibCoreHelper.GenerateHandlers(interList, hanlderPath);               //生成handler类
            NDLibCoreHelper.GenerateHandlerContext(interList, hanlderPath);         //生成handlercontext类
            NDLibCoreHelper.GenerateCoreConfig(interList, configPath);              //生成配置类
            NDLibCoreHelper.GenerateCoreExcutorInter(interList, excutorInterPath);  //生成excutorInter类
            NDLibCoreHelper.GenerateCoreExuctorImpl(interList, excutorImpPath);     //生成接口实现类
        }
Exemple #2
0
        /// <summary>
        /// 保存日志
        /// </summary>
        /// <param name="_content">日志内容</param>
        public static void Save(string DirectPath, string fileName, string _content, bool isAppend = false)
        {
            DirectPath = DirectPath + "\\";
            string FullName = DirectPath + fileName + ".cs";

            if (!DirFileHelper.IsExistDirectory(DirectPath))//如果不存在则创建该目录
            {
                //System.IO.Directory.CreateDirectory(DirectPath);
                DirFileHelper.CreateDirectory(DirectPath);
            }
            if (!File.Exists(FullName))
            {
                FileHelper.FileCreate(FullName);
                FileHelper.WriteFile(FullName, _content);
            }
            //if (File.Exists(DirectPath + fileName + ".cs"))
            //{
            //   new FileHelper().WriteFile(DirectPath + fileName + ".cs", _content);
            //    //using (StreamWriter sw = new StreamWriter(DirectPath + fileName + ".cs", true))
            //    //{
            //    //    sw.WriteLine("\r\n");
            //    //    sw.WriteLine(_content);
            //    //    sw.Flush();
            //    //}
            //    //using (FileStream fs = new FileStream(DirectPath + fileName + ".cs", System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite))
            //    //{
            //    //    using (StreamWriter sw = new StreamWriter(DirectPath + fileName + ".cs", true))
            //    //    {
            //    //        sw.WriteLine("\r\n");
            //    //        sw.WriteLine(_content);
            //    //        sw.Flush();
            //    //    }
            //    //}
            //}
            //else
            //{

            //    File.Create(DirectPath + fileName + ".cs");
            //   new FileHelper().WriteFile(DirectPath + fileName + ".cs", _content);
            //    //using (StreamWriter sw = new StreamWriter(DirectPath + fileName + ".cs", true))
            //    //{
            //    //    sw.WriteLine("\r\n");
            //    //    sw.WriteLine(_content);
            //    //    sw.Flush();
            //    //}
            //    //using (FileStream fs = File.Create(DirectPath + fileName + ".cs"))
            //    //{
            //    //    using (StreamWriter sw = new StreamWriter(fs))
            //    //    {

            //    //        sw.WriteLine(_content);
            //    //        sw.Close();
            //    //    }
            //    //}
            //}
        }
        public static void GenerateWebServiceContract(InterfaceList interList)
        {
            string        DirectPath   = System.Configuration.ConfigurationManager.AppSettings["ND.WebService.Contract"];
            List <string> lstCreateDir = new List <string>();

            #region 先生成各个文件夹
            //1.先生成各个文件夹
            string corePath = Path.Combine(DirectPath, interList.FileName);//核心path
            lstCreateDir.Add(corePath);
            lstCreateDir.ForEach(k =>
            {
                DirFileHelper.CreateDirectory(k);
            });
            #endregion
            NDContractHelper.GenerateCode(interList, corePath);
        }
        public static void GenerateNDPlugin(InterfaceList interList)
        {
            string        DirectPath   = System.Configuration.ConfigurationManager.AppSettings["ND.Plugin.DefaultPlugin"];
            List <string> lstCreateDir = new List <string>();

            #region 先生成各个文件夹
            //1.先生成各个文件夹
            string corePath = Path.Combine(DirectPath, interList.FileName.ToFirstUpper() + "Plugin");//核心path
            lstCreateDir.Add(corePath);
            lstCreateDir.ForEach(k =>
            {
                DirFileHelper.CreateDirectory(k);
            });
            #endregion
            NDPluginHelper.GeneratePluginCode(corePath, interList);
        }
        public static void GenerateWebServiceHost(InterfaceList interList)
        {
            string        directPath   = System.Configuration.ConfigurationManager.AppSettings["ND.WebService.IISHost"];
            List <string> lstCreateDir = new List <string>();

            #region 先生成各个文件夹
            //1.先生成各个文件夹
            string autoMapperPath = Path.Combine(directPath, "autoMapperConfiguration");//核心path
            string configPath     = Path.Combine(directPath, "configFile");
            lstCreateDir.Add(autoMapperPath);
            lstCreateDir.Add(configPath);
            lstCreateDir.ForEach(k =>
            {
                DirFileHelper.CreateDirectory(k);
            });
            #endregion
            NDHostHelper.GenerateCode(interList, directPath);
        }
        public static void GenerateDtoModel(InterfaceList interList)
        {
            string        DirectPath   = System.Configuration.ConfigurationManager.AppSettings["ND.Lib.DtoModel"];
            List <string> lstCreateDir = new List <string>();

            #region 先生成各个文件夹
            //1.先生成各个文件夹
            string corePath                = Path.Combine(DirectPath, interList.FileName); //核心path
            string autoMappernPath         = Path.Combine(corePath, "autoMapper");         //依赖path
            string contextPath             = Path.Combine(corePath, "context");
            string dtoEntityContextPath    = Path.Combine(corePath, "dtoEntity/context");
            string dtoEntityResponsePath   = Path.Combine(corePath, "dtoEntity/response");
            string responsePath            = Path.Combine(corePath, "response");
            string responseAppPath         = Path.Combine(corePath, "response/app");
            string responseBackstagePath   = Path.Combine(corePath, "response/backstage");
            string responseBaseClassPath   = Path.Combine(corePath, "response/baseClass");
            string responseFrontPath       = Path.Combine(corePath, "response/front");
            string responseInterPath       = Path.Combine(corePath, "response/inter");
            string contextValidatorPath    = Path.Combine(corePath, "validator/contextValidator");
            string dtoEnitityValidatorPath = Path.Combine(corePath, "validator/dtoEnitityValidator");

            lstCreateDir.Add(corePath);
            lstCreateDir.Add(autoMappernPath);
            lstCreateDir.Add(contextPath);
            lstCreateDir.Add(dtoEntityContextPath);
            lstCreateDir.Add(dtoEntityResponsePath);
            lstCreateDir.Add(responsePath);
            lstCreateDir.Add(contextValidatorPath);
            lstCreateDir.Add(dtoEnitityValidatorPath);
            lstCreateDir.Add(responseAppPath);
            lstCreateDir.Add(responseBackstagePath);
            lstCreateDir.Add(responseBaseClassPath);
            lstCreateDir.Add(responseFrontPath);
            lstCreateDir.Add(responseInterPath);
            lstCreateDir.ForEach(k =>
            {
                DirFileHelper.CreateDirectory(k);
            });
            #endregion
            NDLibDtoModelHelper.GenerateData(interList, contextPath, responseBaseClassPath, responseInterPath, contextValidatorPath);
        }