Beispiel #1
0
 /// <summary>
 /// 转换为Camel命名方式
 /// </summary>
 /// <param name="srcCase"></param>
 /// <returns></returns>
 public string ConvertToCamelCase(string srcCase)
 {
     return(NomenclatureHelper.ConvertToCamelCase(srcCase));
 }
Beispiel #2
0
        private static List <OutputFile> GenerateTempleteFiles(Project pro, string directory, string matchValue, string charset, bool native)
        {
            List <OutputFile> outputFileList = new List <OutputFile>();

            if (pro == null)
            {
                return(outputFileList);
            }

            if (!Directory.Exists(directory))
            {
                return(outputFileList);
            }

            string[] files = Directory.GetFiles(directory);



            foreach (string file in files)
            {
                string tempCharset = charset;
                bool   tempNative  = native;

                FileInfo fileInfo = new FileInfo(file);

                string fileName = Regex.Replace(fileInfo.Name, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);

                MatchCollection matchs = Regex.Matches(fileName, "\\[.*?\\]");

                foreach (Match match in matchs)
                {
                    if (match.Value.ToUpper().StartsWith("[CHARSET="))
                    {
                        tempCharset = match.Value.ToUpper().Replace("[CHARSET=", string.Empty).Trim(']');
                    }
                    else if (match.Value.ToUpper().StartsWith("[NATIVE="))
                    {
                        tempNative = bool.Parse(match.Value.ToUpper().Replace("[NATIVE=", string.Empty).Trim(']'));
                    }
                }

                if (matchs.Count < 1)
                {
                    OutputFile outputFile = new PageModel();
                    outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(fileName);
                    outputFile.ContextObject = pro;
                    outputFile.Name          = string.Empty;
                    outputFile.Charset       = tempCharset;
                    outputFile.Native        = tempNative;
                    outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                    outputFile.FileText      = File.ReadAllBytes(file);
                    outputFileList.Add(outputFile);
                }


                foreach (Match match in matchs)
                {
                    if (match.Value.ToUpper() == "[TABLES]")
                    {
                        foreach (EntityInfo entity in pro.Database.Tables)
                        {
                            OutputFile outputFile = new PageModel();
                            outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[TABLES\\]", entity.Name, RegexOptions.IgnoreCase));
                            outputFile.ContextObject = entity;
                            outputFile.Name          = entity.Name;
                            outputFile.Charset       = tempCharset;
                            outputFile.Native        = tempNative;
                            outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                            outputFile.FileText      = File.ReadAllBytes(file);
                            outputFileList.Add(outputFile);
                        }
                    }
                    else if (match.Value.ToUpper() == "[VIEWS]")
                    {
                        foreach (EntityInfo entity in pro.Database.Views)
                        {
                            OutputFile outputFile = new PageModel();
                            outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[VIEWS\\]", entity.Name, RegexOptions.IgnoreCase));
                            outputFile.ContextObject = entity;
                            outputFile.Name          = entity.Name;
                            outputFile.Charset       = tempCharset;
                            outputFile.Native        = tempNative;
                            outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                            outputFile.FileText      = File.ReadAllBytes(file);
                            outputFileList.Add(outputFile);
                        }
                    }
                    else if (match.Value.ToUpper() == "[ENTITIES]")
                    {
                        foreach (EntityInfo entity in pro.Database.Tables)
                        {
                            OutputFile outputFile = new PageModel();
                            outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[ENTITIES\\]", entity.Name, RegexOptions.IgnoreCase));
                            outputFile.ContextObject = entity;
                            outputFile.Name          = entity.Name;
                            outputFile.Charset       = tempCharset;
                            outputFile.Native        = tempNative;
                            outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                            outputFile.FileText      = File.ReadAllBytes(file);
                            outputFileList.Add(outputFile);
                        }

                        foreach (EntityInfo entity in pro.Database.Views)
                        {
                            OutputFile outputFile = new PageModel();
                            outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[ENTITIES\\]", entity.Name, RegexOptions.IgnoreCase));
                            outputFile.ContextObject = entity;
                            outputFile.Name          = entity.Name;
                            outputFile.Charset       = tempCharset;
                            outputFile.Native        = tempNative;
                            outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                            outputFile.FileText      = File.ReadAllBytes(file);
                            outputFileList.Add(outputFile);
                        }
                    }
                    else if (match.Value.ToUpper() == "[MODULES]")
                    {
                        foreach (var module in pro.UI.SystemModule.Modules)
                        {
                            OutputFile outputFile = new PageModel();
                            outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[MODULES\\]", module.Name, RegexOptions.IgnoreCase));
                            outputFile.ContextObject = module;
                            outputFile.Name          = module.Name;
                            outputFile.Charset       = tempCharset;
                            outputFile.Native        = tempNative;
                            outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                            outputFile.FileText      = File.ReadAllBytes(file);
                            outputFileList.Add(outputFile);
                        }
                    }
                    else if (match.Value.ToUpper() == "[WINDOWS]")
                    {
                        if (matchValue != string.Empty)
                        {
                            var module = pro.UI.SystemModule.Modules.Find(e => e.Name == matchValue);

                            if (module != null)
                            {
                                foreach (GUIWindow window in module.Windows)
                                {
                                    OutputFile outputFile = new PageModel();
                                    outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[WINDOWS\\]", window.Name, RegexOptions.IgnoreCase));
                                    outputFile.ContextObject = window;
                                    outputFile.Name          = window.Name;
                                    outputFile.Charset       = tempCharset;
                                    outputFile.Native        = tempNative;
                                    outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                                    outputFile.FileText      = File.ReadAllBytes(file);
                                    outputFileList.Add(outputFile);
                                }
                            }
                        }
                        else
                        {
                            foreach (var module in pro.UI.SystemModule.Modules)
                            {
                                foreach (GUIWindow window in module.Windows)
                                {
                                    OutputFile outputFile = new PageModel();
                                    outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[WINDOWS\\]", window.Name, RegexOptions.IgnoreCase));
                                    outputFile.ContextObject = window;
                                    outputFile.Name          = window.Name;
                                    outputFile.Charset       = tempCharset;
                                    outputFile.Native        = tempNative;
                                    outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                                    outputFile.FileText      = File.ReadAllBytes(file);
                                    outputFileList.Add(outputFile);
                                }
                            }
                        }
                    }
                    else if (match.Value.ToUpper() == "[DIALOGS]")
                    {
                        foreach (GUIDialog dialog in pro.UI.CommonModule.Dialogs)
                        {
                            OutputFile outputFile = new PageModel();
                            outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[DIALOGS\\]", dialog.Name, RegexOptions.IgnoreCase));
                            outputFile.Name          = dialog.Name;
                            outputFile.ContextObject = dialog;
                            outputFile.Charset       = tempCharset;
                            outputFile.Native        = tempNative;
                            outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                            outputFile.FileText      = File.ReadAllBytes(file);
                            outputFileList.Add(outputFile);
                        }
                    }
                    else if (match.Value.ToUpper() == "[TABLE]")
                    {
                        TableInfo entityInfo = pro.Database.Tables.Find(e => e.Name == matchValue);

                        OutputFile outputFile = new PageModel();
                        outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[TABLE\\]", matchValue, RegexOptions.IgnoreCase));
                        outputFile.ContextObject = (entityInfo == null) ? (ContextObject)pro : (ContextObject)entityInfo;
                        outputFile.Name          = matchValue;
                        outputFile.Charset       = tempCharset;
                        outputFile.Native        = tempNative;
                        outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                        outputFile.FileText      = File.ReadAllBytes(file);
                        outputFileList.Add(outputFile);
                    }
                    else if (match.Value.ToUpper() == "[VIEW]")
                    {
                        ViewInfo entityInfo = pro.Database.Views.Find(e => e.Name == matchValue);

                        OutputFile outputFile = new PageModel();
                        outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[VIEW\\]", matchValue, RegexOptions.IgnoreCase));
                        outputFile.ContextObject = (entityInfo == null) ? (ContextObject)pro : (ContextObject)entityInfo;
                        outputFile.Name          = matchValue;
                        outputFile.Charset       = tempCharset;
                        outputFile.Native        = tempNative;
                        outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                        outputFile.FileText      = File.ReadAllBytes(file);
                        outputFileList.Add(outputFile);
                    }
                    else if (match.Value.ToUpper() == "[ENTITY]")
                    {
                        EntityInfo entityInfo = null;

                        ViewInfo  viewInfo  = null;
                        TableInfo tableInfo = pro.Database.Tables.Find(e => e.Name == matchValue);
                        entityInfo = tableInfo;

                        if (entityInfo == null)
                        {
                            viewInfo   = pro.Database.Views.Find(e => e.Name == matchValue);
                            entityInfo = viewInfo;
                        }

                        OutputFile outputFile = new PageModel();
                        outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[ENTITY\\]", matchValue, RegexOptions.IgnoreCase));
                        outputFile.ContextObject = (entityInfo == null) ? (ContextObject)pro : (ContextObject)entityInfo;
                        outputFile.Name          = matchValue;
                        outputFile.Charset       = tempCharset;
                        outputFile.Native        = tempNative;
                        outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                        outputFile.FileText      = File.ReadAllBytes(file);
                        outputFileList.Add(outputFile);
                    }
                    else if (match.Value.ToUpper() == "[MODULE]")
                    {
                        var module = pro.UI.SystemModule.Modules.Find(e => e.Name == matchValue);

                        OutputFile outputFile = new PageModel();
                        outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[MODULE\\]", matchValue, RegexOptions.IgnoreCase));
                        outputFile.ContextObject = (module == null) ? (ContextObject)pro : (ContextObject)module;
                        outputFile.Name          = matchValue;
                        outputFile.Charset       = tempCharset;
                        outputFile.Native        = tempNative;
                        outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                        outputFile.FileText      = File.ReadAllBytes(file);
                        outputFileList.Add(outputFile);
                    }
                    else if (match.Value.ToUpper() == "[WINDOW]")
                    {
                        GUIWindow window = null;
                        foreach (var module in pro.UI.SystemModule.Modules)
                        {
                            window = module.Windows.Find(e => e.Name == matchValue);
                            if (window != null)
                            {
                                break;
                            }
                        }

                        OutputFile outputFile = new PageModel();
                        outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[WINDOW\\]", matchValue, RegexOptions.IgnoreCase));
                        outputFile.ContextObject = (window == null) ? (ContextObject)pro : (ContextObject)window;
                        outputFile.Name          = matchValue;
                        outputFile.Charset       = tempCharset;
                        outputFile.Native        = tempNative;
                        outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                        outputFile.FileText      = File.ReadAllBytes(file);
                        outputFileList.Add(outputFile);
                    }
                    else if (match.Value.ToUpper() == "[DIALOG]")
                    {
                        GUIDialog dialog = pro.UI.CommonModule.Dialogs.Find(e => e.Name == matchValue);

                        OutputFile outputFile = new PageModel();
                        outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(Regex.Replace(fileName, "\\[DIALOG\\]", matchValue, RegexOptions.IgnoreCase));
                        outputFile.ContextObject = (dialog == null) ? (ContextObject)pro : (ContextObject)dialog;
                        outputFile.Name          = matchValue;
                        outputFile.Charset       = tempCharset;
                        outputFile.Native        = tempNative;
                        outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                        outputFile.FileText      = File.ReadAllBytes(file);
                        outputFileList.Add(outputFile);
                    }
                    else
                    {
                        if (!match.Value.ToUpper().StartsWith("[CHARSET=") && !match.Value.ToUpper().StartsWith("[NATIVE="))
                        {
                            OutputFile outputFile = new PageModel();
                            outputFile.FileName      = NomenclatureHelper.ConvertToPascalCase(fileName);
                            outputFile.ContextObject = pro;
                            outputFile.Name          = string.Empty;
                            outputFile.Charset       = tempCharset;
                            outputFile.Native        = tempNative;
                            outputFile.RelativePath  = Regex.Replace(fileInfo.DirectoryName, "\\[PROJECTNAME\\]", pro.Name, RegexOptions.IgnoreCase);
                            outputFile.FileText      = File.ReadAllBytes(file);
                            outputFileList.Add(outputFile);
                        }
                    }
                }
            }
            return(outputFileList);
        }