在项目的`Version Control Settings`中获取`Local Project Path`目录

Obtain the `Local Project Path` directory in the project's `Version Control Settings`

前言

这与 Enterprise Architect 的 API 及其脚本功能直接相关,与实际的 JScript/Javascript 关系不大。


问题

如何使用EA的脚本API获取项目Version Control Settings中的Local Project Path目录?

注意:[Package].XMLPath只提供相对于该位置的路径,这在我的情况下无法使用。


背景

正在尝试使用 EA 的通用 SCC 版本控制设置和脚本功能创建脚本,将 EA 项目中的所有包添加到我们的版本控制软件(MKS/PTC Integrity)。

我已经为我们的 VC 软件设置了版本控制并将其链接到本地​​项目,并且能够很好地使用内置功能。


为什么简单的解决方案不起作用

首先,我知道 EA 有一个 Add Branch to Version Control 选项。但是,当将文件签入我们的 VC 时,如果文件路径中的文件夹在本地项目目录(沙箱)中不存在,我们的 VC 将创建目录而不是子项目(不同类型的容器,长话短说:我们需要子项目)。

我不能使用 EAP 文件的位置作为参考路径,因为它不在本地项目目录中(我们在服务器上使用单个集中文件)。


我目前正在尝试什么

  1. mkdir 文件夹到每个包的本地项目目录(工作)
  2. 在我们的 VC(工作)
  3. 中创建所有子目录
  4. 使用 EA 的 package.VersionControlAdd 方法将 XML 文件添加到本地项目目录中的该目录(不起作用!)

!!第3步是问题。 !! 这就是问题所在。我无法提供我想要 XML 文件的路径,因为我需要 local project path.

我在 EA 的内置帮助中找不到关于检索此信息的任何引用。

直接查看文本文件

%appdata%\Sparx Systems\EA\paths.txt

您要查找的值存储在此文件中。没有API。这是EA...

Regarging thomas Killian 提示:这是一个很好的方法 - C# 代码可以满足您的要求

访问 %appdata% 文件夹中的 paths.txt 文件

 string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
 string localPathsFilePath= System.IO.Path.Combine(appDataFolder, @"Sparx Systems\EA\paths.txt");  

//Each line is appropriate to a local path, therefore read line by line.
string[] LocalPathsLines = System.IO.File.ReadAllLines(localPathsFilePath);
foreach (string line in LocalPathsLines)
            {
                //If the line is not empty
                if (line.Length != 0)
                {
                    //Get the index of sub string "id" which keeps the unique id (configuration) name.
                int IDstartIndex = line.IndexOf("id");
                //The desired value of id without "id=" word
                IDstartIndex += 3;

                //Get the index of end of the sub string id value
                int IDEndIndex = line.IndexOf(";", IDstartIndex);

                //Calculate the length of sub string to be retrieved subsequently.
                int IDStringLength = IDEndIndex - IDstartIndex;
                string UniqueIDName = line.Substring(IDstartIndex, IDStringLength);

                //if the current id value is the same as the selected package's configuration name
                if (UniqueIDName.CompareTo("ea-svn") == 0)
                {

                    isLocalPathExist = true;

                    //Get the index of sub string "path".
                    int PathStartIndex = line.IndexOf("path");

                    //The desired value of path without "path=" word
                    PathStartIndex += 5;

                    //Get the index of end of the sub string "VCCFG"
                    int PathEndIndex = line.IndexOf(";", PathStartIndex);

                    //Calculate the length of sub satring to be retrieved subsequently.
                    int PathStringLength = PathEndIndex - PathStartIndex;

                    string path = line.Substring(PathStartIndex, PathStringLength);


                    //Add to the path the XML file name with XML extension.
                    path = Path.Combine(path, package.XMLPath);

                    if (System.IO.File.Exists(path) == true)
                    {
                        return path;
                    }//if
                 }
                 }

有一种解决方案可以从 EA 脚本(或具有适当参考集的任何其他 VBscript/VBA 环境)中获取本地版本控制配置。 下面是我的助手 class 来做的;目前它仅限于单个 VC 配置(我不需要更多,而且我很着急......)。 请注意,解析 XML 需要 "Msxml2.DOMDocument.6.0";适当更改版本以适应您的环境。

'Language: VBScript 
' helper class to get local SVN repository set-up; currently able to deal with single VC configuration only
' version 1.0.0
' (c) MJ, 5/2016
'
const EA_VC_CONF_KEY="HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\OPTIONS\VCConfigs"
const SVN_EXE_PATH_KEY="HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\OPTIONS\VC_SVNExePath"
const VC_TIMEOUT="HKEY_CURRENT_USER\Software\Sparx Systems\EA400\EA\OPTIONS\VC_TIMEOUT"
const APPDATA_KEY="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\AppData"

class VCConfig
public vcPath 'path to local VC copy
public vcGuid 'ID of the config
public vcLocalPath ' path id
public svnExePath 'version control exe file
public vcTimeout 'command timeout


public function readConfig()
    dim WSHShell 'Windows Scripting Host Shell
dim EaVCConf 'version control configurations
dim PathsTxtLocation 'location of the paths.txt file
Set WSHShell = CreateObject("WScript.Shell")
EaVCConf         = WSHShell.RegRead(EA_VC_CONF_KEY)
Me.svnExePath    = WSHShell.RegRead(SVN_EXE_PATH_KEY)
Me.vcTimeout     = WSHShell.RegRead(VC_TIMEOUT)
PathsTxtLocation = WSHShell.RegRead(APPDATA_KEY)
PathsTxtLocation=PathsTxtLocation & "\Sparx Systems\EA\"
set WSHShell = nothing

dim xmldoc 'XML document
dim nodes 'XML nodes
dim node 'XML 
dim cfgGUID 'ID of the config
dim cfgPath 'ID of the path
const QUERY_CFG="//Config"
const QUERY_ID="//GUID"
const QUERY_PATH="//LocalPath"
Set xmldoc = CreateObject("Msxml2.DOMDocument.6.0")
xmldoc.loadXML EaVCConf

set nodes = xmldoc.selectNodes (QUERY_CFG)
'session.output "Number of VC configs: " & nodes.length
if nodes.length<>1 then
    result=Session.Prompt("More than one configuration of version control present. Can't continue.", promptOk)
    exit function
end if
set node=xmldoc.selectSingleNode (QUERY_ID)
Me.vcGuiD=node.Text
set node=xmldoc.selectSingleNode (QUERY_PATH)
Me.vcLocalPath=node.Text
'session.output "Location of paths.txt: " & PathsTxtLocation

dim fso 'FileSystemObject
dim pathsTxtFile 'paths.txt file
dim pathsStream 'text stream
dim pathsString 'string content of the paths.txt file
const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
set pathsStream = fso.OpenTextFile(PathsTxtLocation & "paths.txt",ForReading,false)
pathsString=pathsStream.readline()
dim lo, hi 'integers
lo=instr(pathsString,"path=")
hi=InstrRev(pathsString,";")
pathsString=mid(pathsString,lo+5, (hi)-(lo+5))
'session.output pathsString
Me.vcPath=pathsString
set fso=nothing
'in the file paths.txt: "%PATH%;type=Version Control;id=sa_ea;path=<path>"
'session.output "SVN exe path: " & Me.svnExePath
end function

end class