获取项目“版本控制设置”

时间:2015-05-26 19:43:12

标签: javascript version-control jscript enterprise-architect

前言

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

问题

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

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

背景

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

我已经设置了版本控制并将其链接到我们VC软件的本地项目,并且能够正常使用内置功能。<​​/ p>

为什么简单的解决方案无法运作

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

我无法将EAP文件的位置用作参考路径,因为它不会出现在本地项目目录中(我们在服务器上使用单个集中文件)。 / p>

我目前正在尝试的内容

  1. 将mkdir文件夹放入每个包的本地项目目录中(正常工作)
  2. 在VC(工作)中创建所有子目录
  3. 使用EA的package.VersionControlAdd方法将XML文件添加到本地项目目录中的该目录中(不工作!)
  4. !!第3步是问题所在。 !! 这是问题发挥作用的地方。我无法提供我想要XML文件的路径,因为我需要local project path

    我无法在EA帮助中找到有关检索此信息的任何内容。

3 个答案:

答案 0 :(得分:1)

只需查看文本文件

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

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

答案 1 :(得分:0)

重新定位托马斯基利安提示:这是一个很好的方法 - 你问的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
                 }
                 }

答案 2 :(得分:0)

从EA脚本(或任何其他具有适当引用集的VBscript / VBA环境)中获取本地版本控制配置的解决方案。 跟着那里的助手班来做那件事;目前它仅限于单个VC配置(我不需要更多,我很匆忙......)。 注意有&#34; Msxml2.DOMDocument.6.0&#34;解析XML所需的;适当更改版本以适应您的环境。

'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