Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: blaisephilip on May 13, 2024, 11:52:23 pm
-
I'm developing an add-in and need to access the creation dates of a package's baselines and use these as part of a generated document's release history.
The following snippet retrieves the baseline information's basic elements (version, name, notes) correctly as raw XML.
Project projInterface = currentRepository.GetProjectInterface();
string baselineInfo = projInterface.GetBaselines(pkg.PackageGUID, "");
So, baselineInfo can be post-processed to become part of the document. However, it does not contain any information about the baseline's creation date. In our case, I could ask users to use a manually entered date entry in the baseline notes but that could be falsified, so I don't want to go with that option.
The EA Menu's Design --> Package -> Manage -> Find Baselines feature provides a Baseline_Date column for all baselines of a package, with help of the Find in Project feature. So in the DB there is at least a table that stores the baseline creation date values.
Is there any way to reach the Baseline_Date values with help of the object model in a C# add-in?
-
Try a
SELECT DocDate FROM t_document
q.
-
Wot qwerty said plus you may find the following fields useful as well to filter out baselines for other documents stored within the t_document table
t_document.DocID : which despite its name is actually a GUID (the guid of the actual document entry?)
t_document.ElementID : which despite its name is actually a GUID (the GUID of the baseline?)
t_document.DocName : the name of the baseline
t_document.DocType : this has the value Baseline for a Baseline in the t_document table
Phil
-
Thanks for the hints about t_document content! I've implemented the solution by assembling the date of creation and the rest to a single XML output.
The GUID of the baseline (available as attribute in a baseline node within the raw XML) is actually the t_document table's DocID column.
private void GetPackageBaselineInfo(Package pkg)
{
if (cfgHandling.bBaselineInfoSupport)
{
log("Available package baselines are collected for release history...");
Project projInterface = currentRepository.GetProjectInterface();
XmlDocument baselineInfo = new XmlDocument();
// this retrieves only GUID, version, name and notes for the baseline
string sBaselineInfoRaw = projInterface.GetBaselines(pkg.PackageGUID, "");
sBaselineInfoRaw = sBaselineInfoRaw.Replace("><Baseline ", ">\r\n<Baseline ");
baselineInfo.LoadXml(sBaselineInfoRaw);
XmlNode blCollection = baselineInfo.SelectSingleNode("EA.BaseLines");
if ((baselineInfo != null) && (blCollection != null))
{
XmlDocument baselineInfoExt = (XmlDocument)baselineInfo.Clone(); // extended baseline info, to be exported
XmlAttribute cDate = baselineInfoExt.CreateAttribute("creationdate");
if (cDate == null)
{
log("Creation date could not be added as new attribute. No baseline info will be extracted.");
return;
}
if (baselineInfoExt == null)
{
log("Output baseline info XML creation failed.");
return;
}
else
{
log("Count of available baselines: " + blCollection.ChildNodes.Count.ToString());
// take each baseline to get the date of creation too
foreach (XmlNode node in blCollection.ChildNodes)
{
string guid = GetAttributeValue(node, "guid");
if (guid != null)
{
string sQuery = "SELECT `DocDate` FROM `t_document` WHERE `DocID` LIKE \"" + guid + "\"";
string date = currentRepository.SQLQuery(sQuery); // date is still raw XML, as date+time
XmlDocument DateXML = new XmlDocument();
DateXML.LoadXml(date);
DateTime dtDate = DateTime.Parse(DateXML.SelectSingleNode("//DocDate").InnerText);
// insert the date of creation to the baseline XML
XmlNode targetNode = baselineInfoExt.SelectSingleNode("//Baseline[@guid='" + guid + "']");
if (targetNode != null)
{
cDate.Value = dtDate.Date.ToString("yyyy-MM-dd");
targetNode.Attributes.SetNamedItem(cDate);
}
else
{
log("Target node not found by baseline GUID.");
return;
}
}
else
{
log("Package baseline with empty GUID found. This shall be an error. The process ends now.");
return;
}
}
log("Baseline content collected, writing to XML...");
baselineInfoExt.Save(Path.Combine(cfgHandling.sAddInPath, "temp_baselines.xml"));
log("Baseline information saved to XML.");
}
}
else
{
log("Node collection not found.");
}
}
}