Obtain the `Local Project Path` directory in the p

2019-07-23 05:24发布

Preface

This relates directly to Enterprise Architect's API and its scripting capabilities and not so much with actual JScript/Javascript.


Question

How do you obtain the Local Project Path directory in the project's Version Control Settings using EA's scripting API?

Note: [Package].XMLPath only provides the path relative to that location, which is unusable in my situation.


Background

Attempting to create script that adds all packages in an EA project to our version control software (MKS/PTC Integrity) using EA's generic SCC version control setup and scripting capabilities.

I have set up the version control and linked it to a local project for our VC software and am able to use the built-in functionality just fine.


Why the easy solution won't work

First off, I know that EA has an Add Branch to Version Control option. However, when checking in files to our VC, if the folders in filepath don’t exist in the local project directory (sandbox), our VC will create directories instead of subprojects (different types of containers, long story short: we need subprojects).

I can't use the location of the EAP file as a reference path because that won't be in the local project directory (we're using a singled centralized file on a server).


What I'm Currently Trying

  1. mkdir folders into local project directory for each package (working)
  2. Create all subdirectories in our VC (working)
  3. Use EA's package.VersionControlAdd method to add the XML files to that directory in the local project directory (not working!)

!! Step 3 is the problem. !! Here's where the question comes into play. I can't provide the path I want the XML file because I need the local project path.

I can't find anything referenced in EA's built in help regarding retrieving this information.

3条回答
做自己的国王
2楼-- · 2019-07-23 05:52

Simply look into the text file

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

The values you are looking for are stored in this file. There is no API. It's EA...

查看更多
smile是对你的礼貌
3楼-- · 2019-07-23 05:52

There's a solution to get local version control configuration from within EA scripting (or any other VBscript/VBA environment with appropriate references set). Following there's my helper class to do that; currently it's limited to single VC configuration (I didn't need more and I was in a hurry...). Note there is "Msxml2.DOMDocument.6.0" needed for parsing the XML; change the version appropriately to fit your environment.

'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
查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-07-23 05:54

Regarging thomas Killian hint: here is a good approach- C# code for what you asked

Access the paths.txt file in the %appdata% folder

 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
                 }
                 }
查看更多
登录 后发表回答