Using ID from new server-based project on the local file-based version

I'm automating the process of creating Trados Studio projects locally, then uploading them to GroupShare via the REST API.

When uploading I first of all create an empty project using this API method...

Screenshot of an API method POST request to create an empty Trados Studio project on the server.

This returns the ID of the created empty project. Then I create a local FileBasedProject object, create a package from it, then upload the package to...

Screenshot of an API method POST request to publish a Trados Studio package to an empty server project.

This works - the server-based project does get published.

However, if I want to do anything with the local FileBasedProject then I face a problem: It's ID is not the same as the project on the server. And the project's Id property is read-only, so I can't update it.

I tried opening the project file, updating the Guid attribute on the root element...

Screenshot showing XML code of a Trados Studio project file with a highlighted Guid attribute, indicating an attempt to update the project ID.

... and then reloading the project - here's the code I used...

private static void UpdateProjectId(FileBasedProject project, Guid newId, Reporter reporter)
{
const string projectFileExtension = ".sdlproj";
const string projectIdAttributeName = "Guid";

var projectInfo = project.GetProjectInfo();

var path = Path.Combine(projectInfo.LocalProjectFolder, $"{projectInfo.Name}{projectFileExtension}");

XDocument xProjectFile;
using (var fs = new FileStream(path, FileMode.Open))
{
xProjectFile = XDocument.Load(fs, LoadOptions.PreserveWhitespace);
}

var attrGuid = xProjectFile.Document.Root.Attribute(projectIdAttributeName);
if (attrGuid != null)
{
attrGuid.Value = newId.ToString();
xProjectFile.Save(path);
}

project = new FileBasedProject(path);
}

However, when I call project.GetProjectInfo().Id after calling new FileBasedProject(path) I still see the previous Guid value - even though I can verify that the physical file does now have the new value.

So I took another look at the API reference and saw this method...

Screenshot of an API method POST request with a placeholder for project ID, used to create or register a project from the server.

Perhaps that id variable will allow me to specify the ID of the empty project?

Unfortunately it returns a 500 (Internal Server Error), and I can't see anything recorded in the log files relating to this error.

So what should I do? I have a local project, a corresponding server-based project, but their IDs are different. How can I use the ID of the server-based project against the local project?



Generated Image Alt-Text
[edited by: Trados AI at 4:08 AM (GMT 0) on 5 Mar 2024]
emoji
Parents Reply Children
No Data