/// <summary> /// 选择清单后的工具初始化入口函数 /// </summary> /// <param name="dte">选择工具dte</param> public static FileEntity AssistInitialize(DTE2 dte) { ThreadHelper.ThrowIfNotOnUIThread(); var solution = dte.Solution; // 解决方案 var selectedItems = dte.ToolWindows.SolutionExplorer.SelectedItems as UIHierarchyItem[]; if (selectedItems == null || selectedItems.Length == 0) { return(null); } // 选择对象 var selectedItem = selectedItems[0]?.Object as ProjectItem; if (selectedItem == null) { return(null); } // 项目 var project = selectedItem.ContainingProject; if (project == null) { return(null); } // 项目名 var projectName = project.Name; var path = project?.FullName; var srcPath = project?.Properties.Item("FullPath").Value?.ToString(); // 判断一下必须来自领域层 if (!IsExitAbpCore(projectName, ProjectCore.Layer)) { return(null); } // 当前选中的文件 var FileEntity = new FileEntity { SrcDir = string.Format("{0}//src/", Path.GetDirectoryName(solution.FullName)), ServDir = string.Format("{0}//serv/", Path.GetDirectoryName(solution.FullName)), Name = Path.GetFileNameWithoutExtension(selectedItem.Name), // 选择项名称 FullName = selectedItem.Name, FullFileName = selectedItem.FileNames[0], // 当前选中的文件全名称 CurrentFile = new FileInfo(selectedItem.FileNames[0]) // 选中的文件对象 }; // 处理解决方案数据 FileEntity.Solution.Name = Path.GetFileNameWithoutExtension(solution.FullName); //Path.GetFileName(solution.FullName) FileEntity.Solution.BaseDirPath = Path.GetDirectoryName(solution.FullName); //解决方案目录 // 核心层数据 var dirCore = AssistHelper.GetLayerDir(FileEntity.SrcDir, ProjectCore.Layer); FileEntity.ProjectCore.Name = dirCore?.Name; // 项目的名称 FileEntity.ProjectCore.BaseDirPath = dirCore?.FullName; // Src 路径 + 项目名称 // 应用层数据 var dirApplication = AssistHelper.GetLayerDir(FileEntity.SrcDir, Application.Layer); FileEntity.Application.Name = dirApplication?.Name; FileEntity.Application.BaseDirPath = dirApplication?.FullName; FileEntity.Application.DomainPath = FileEntity.CurrentFile.DirectoryName.Replace(FileEntity.ProjectCore.Name, FileEntity.Application.Name); // 基础设施层数据 var dirFrameworkCore = AssistHelper.GetLayerDir(FileEntity.SrcDir, FrameworkCore.Layer); FileEntity.FrameworkCore.Name = dirFrameworkCore?.Name; FileEntity.FrameworkCore.BaseDirPath = dirFrameworkCore?.FullName; // 应用内容层 var dirContracts = AssistHelper.GetLayerDir(FileEntity.SrcDir, Contracts.Layer); FileEntity.Contracts.IsUse = dirContracts != null; FileEntity.Contracts.Name = dirContracts?.Name; FileEntity.Contracts.BaseDirPath = dirContracts?.FullName; FileEntity.LoadData(); return(FileEntity); }