Hi everyone,
I’m facing an issue with a tool I’ve developed that automates project creation using Trados templates.
I’ll outline how the tool works and the problem I’m encountering, hoping someone can guide me.
Tool Workflow:
- The tool retrieves a Trados template and associated files.
- It checks for Translation Providers and adds credentials, regardless of whether they were previously added or not.
- It runs the Automatic Tasks defined in the template.
Technical Details:
- Adding Credentials:
- The tool uses the
AddCredential
method fromnamespace Sdl.ProjectAutomation.FileBased
to add credentials. Here’s the relevant code snippet:public void AddCredential(Uri uri, string credential) { if (IsTermbaseServerUri(uri) || IsProjectServerUri(uri)) { GenericCredentials genericCredentials = new GenericCredentials(credential); WCFToken samlToken = ((genericCredentials["SamlToken"] != null) ? JsonConvert.DeserializeObject<WCFToken>(genericCredentials["SamlToken"]) : null); UserCredentials userCredentials = new UserCredentials(genericCredentials.UserName, genericCredentials.Password, GetUserType(genericCredentials)) { SamlToken = samlToken, AuthToken = genericCredentials["AuthToken"], ExpirationDate = ((genericCredentials["Exp"] != null) ? DateTime.Parse(genericCredentials["Exp"]) : default(DateTime)) }; switch (userCredentials.UserType) { case UserManagerTokenType.CustomUser: case UserManagerTokenType.CustomWindowsUser: IdentityInfoCache.Default.SetCustomIdentity(StripSchemePrefix(uri), userCredentials.UserName, userCredentials.Password); break; case UserManagerTokenType.WindowsUser: IdentityInfoCache.Default.SetWindowsIdentity(StripSchemePrefix(uri)); break; case UserManagerTokenType.Saml2User: IdentityInfoCache.Default.SetCustomIdentity(StripSchemePrefix(uri), userCredentials); break; } } else { _translationProviderCredentialStore.AddCredential(uri, new TranslationProviderCredential(credential, persist: false)); } }
- Credentials Format:
$"user={username};password={password};type=CustomUser"
- The tool uses the
- Running Automatic Tasks:
- The tool then executes automatic tasks using the
RunAutomaticTasks
method from the same namespace:public TaskSequence RunAutomaticTasks(Guid[] projectFileIds, string[] taskTemplateIds) { try { return RunAutomaticTasks(projectFileIds, taskTemplateIds, null, null); } catch (Exception exception) { Exception ex = ExceptionMapper.MapException(exception); throw ex; } }
- The tool then executes automatic tasks using the
Issue Description:
- Initially, the tool works as expected.
- However, when the credentials expire (usually after 8 hours), the ‘Pre-translate Files’ task fails with the following error:
Unexpected exception when configuring file multiFileConverter for task 'Pre-translate Files':
Failed to create an instance of translation provider 'sdltm.https://<ourSdlServer>'. - This error occurs even though I re-add credentials every time a new project is created using the
AddCredential
method. - I suspect that the cached credentials are not being updated or replaced when new credentials are added.
Request for Assistance:
I’d appreciate help with the following:
- Can anyone confirm whether the credential cache is updated or cleared when
AddCredential
is called? - Is there a mechanism to:
- Verify if credentials have expired and update them if so.
- Force the system to reset the cached authentication and use the new credentials added by the tool?
- Any recommendations to ensure that expired credentials do not cause task failures?
Thanks in advance for your insights and suggestions! Let me know if additional details are needed.