获取项目中的“本地项目路径”目录's的“版本控制设置”

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

本文关键字:项目 版本控制 设置 路径 获取 目录      更新时间:2023-09-26

前言

这与企业架构师的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时,如果本地项目目录(沙盒(中不存在filepath中的文件夹,我们的VC将创建目录而不是子项目(不同类型的容器,长话短说:我们需要子项目(。

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


我当前正在尝试的内容

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

!!第三步就是问题所在

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

只需查看文本文件

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

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

重新获得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环境(中获取本地版本控制配置。下面是我的助手类;目前它仅限于单个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