Created
October 25, 2017 10:47
-
-
Save cromica/e1a976fdfdc821136c7610b5e984904e to your computer and use it in GitHub Desktop.
Run analysis using GroupShare TMs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sdl.Core.Globalization; | |
using Sdl.ProjectAutomation.Core; | |
using Sdl.ProjectAutomation.FileBased; | |
using System; | |
using System.IO; | |
using System.Linq; | |
namespace GS.ProjectAnalysisTest | |
{ | |
class Program | |
{ | |
private const string ServerUri = "http://yourGSurl/"; | |
private const string UserName = "user"; | |
private const string Password = "password"; | |
private const string Organization = "organization"; | |
private const string TmName = "tm name"; | |
private const string SourceCultureName = "tm source language"; | |
private const string TargetCultureName = "tm target language"; | |
private const string SourceFileName = @"source file full path"; | |
private const string LocalProjectFolder = @"project location"; | |
static void Main(string[] args) | |
{ | |
var info = new ProjectInfo | |
{ | |
Name = Path.GetFileName(SourceFileName), | |
LocalProjectFolder = LocalProjectFolder, | |
SourceLanguage = new Language(SourceCultureName), | |
TargetLanguages = new[] { new Language(TargetCultureName) } | |
}; | |
if (Directory.Exists(info.LocalProjectFolder)) | |
{ | |
Directory.Delete(info.LocalProjectFolder, true); | |
} | |
FileBasedProject project = new FileBasedProject(info); | |
project.AddFiles(new[] { SourceFileName }); | |
var scan = project.RunAutomaticTask( | |
project.GetSourceLanguageFiles().GetIds(), | |
AutomaticTaskTemplateIds.Scan | |
); | |
Uri tmAddress = new Uri($"sdltm.{ServerUri}{Organization}{(Organization != "" ? "/" : "")}{TmName}"); | |
TranslationProviderConfiguration config = project.GetTranslationProviderConfiguration(); | |
TranslationProviderCascadeEntry tm = new TranslationProviderCascadeEntry( | |
new TranslationProviderReference(tmAddress), | |
true, | |
true, | |
false); | |
config.Entries.Add(tm); | |
project.UpdateTranslationProviderConfiguration(config); | |
project.Credentials.AddCredential(tmAddress, false, UserName, Password); | |
project.UpdateTranslationProviderConfiguration(config); | |
ProjectFile[] files = project.GetSourceLanguageFiles(); | |
foreach (var file in files) | |
{ | |
if (file.Role != FileRole.Translatable) | |
{ | |
continue; | |
} | |
Guid[] currentFileId = { file.Id }; | |
AutomaticTask convertTask = project.RunAutomaticTask( | |
currentFileId, | |
AutomaticTaskTemplateIds.ConvertToTranslatableFormat); | |
AutomaticTask copyTask = project.RunAutomaticTask( | |
currentFileId, | |
AutomaticTaskTemplateIds.CopyToTargetLanguages); | |
} | |
// Expected task's Status is "Completed", but actual is "Failed" | |
AutomaticTask analyzeTask = project.RunAutomaticTask( | |
project.GetTargetLanguageFiles().GetIds(), | |
AutomaticTaskTemplateIds.AnalyzeFiles); | |
Console.WriteLine($"AnalyzeFiles : {analyzeTask.Status}"); | |
Console.WriteLine(String.Join("\n", | |
analyzeTask.Messages.Select(m => m.Exception))); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment