public MessageModel CreateProject(PackageModel package)
        {
            var target = GetTargetLanguages(package.LanguagePairs);

            var projectInfo = new ProjectInfo
            {
                Name = package.Name,
                LocalProjectFolder = package.Location,
                SourceLanguage     = new Language(package.LanguagePairs[0].SourceLanguage),
                TargetLanguages    = target,
                DueDate            = package.DueDate
            };

            var newProject = new FileBasedProject(projectInfo,
                                                  new ProjectTemplateReference(package.ProjectTemplate.Uri));

            if (package.Customer != null)
            {
                newProject.SetCustomer(package.Customer);
            }

            //Add StarTransit package source files. The same on all language pairs
            ProjectFile[] sourceProjectFiles = newProject.AddFiles(package.LanguagePairs[0].SourceFile.ToArray());

            //set the file role(user to display project details in Studio view)
            var sourceFilesIds = newProject.GetSourceLanguageFiles().GetIds();

            newProject.SetFileRole(sourceFilesIds, FileRole.Translatable);

            var tmConfig        = newProject.GetTranslationProviderConfiguration();
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);

            List <ProjectFile> targetProjectFiles = new List <ProjectFile>();

            foreach (var pair in package.LanguagePairs)
            {
                targetProjectFiles.Clear();
                //import language pair TM if any
                if (pair.HasTm)
                {
                    var importer = new TransitTmImporter(pair.SourceLanguage,
                                                         pair.TargetLanguage,
                                                         pair.CreateNewTm,
                                                         fileTypeManager,
                                                         pair.TmPath);
                    foreach (var tm in pair.StarTranslationMemoryMetadatas)
                    {
                        importer.ImportStarTransitTm(tm.TargetFile);
                    }

                    tmConfig.Entries.Add(new TranslationProviderCascadeEntry(importer.GeTranslationProviderReference(),
                                                                             true,
                                                                             true,
                                                                             true));
                }
                if (!pair.TargetFile.Any() || pair.TargetFile.Count == 0)
                {
                    var messageModel = new MessageModel()
                    {
                        IsProjectCreated = false,
                        Message          = "Project was not created correctly because no target files were found in the package!",
                        Title            = "Informative message"
                    };
                    return(messageModel);
                }
                else
                {
                    targetProjectFiles.AddRange(newProject.AddFiles(pair.TargetFile.ToArray()));
                    newProject.RunAutomaticTask(targetProjectFiles.GetIds(), AutomaticTaskTemplateIds.Scan);
                    var taskSequence = newProject.RunAutomaticTasks(targetProjectFiles.GetIds(), new string[]
                    {
                        AutomaticTaskTemplateIds.ConvertToTranslatableFormat,
                        AutomaticTaskTemplateIds.CopyToTargetLanguages,
                        AutomaticTaskTemplateIds.PerfectMatch,
                        AutomaticTaskTemplateIds.PreTranslateFiles,
                        AutomaticTaskTemplateIds.AnalyzeFiles,
                    });

                    if (taskSequence.Status.Equals(ProjectAutomation.Core.TaskStatus.Failed))
                    {
                        var messageModel = new MessageModel()
                        {
                            IsProjectCreated = false,
                            Message          = "Project could not be created.Error occured while running automatic tasks!",
                            Title            = "Informative message"
                        };
                        return(messageModel);
                    }
                    else
                    {
                        newProject.UpdateTranslationProviderConfiguration(tmConfig);
                        newProject.Save();
                    }
                }
            }

            if (Directory.Exists(newProject.FilePath))
            {
                CreateMetadataFolder(package.Location, package.PathToPrjFile);

                Controller.RefreshProjects();
            }
            return(null);
        }
Exemple #2
0
        public void CreateProject(PackageModel package)
        {
            var target = GetTargetLanguages(package.LanguagePairs);

            var projectInfo = new ProjectInfo
            {
                Name = package.Name,
                LocalProjectFolder = package.Location,
                SourceLanguage     = new Language(package.LanguagePairs[0].SourceLanguage),
                TargetLanguages    = target,
                DueDate            = package.DueDate,
            };

            var newProject = new FileBasedProject(projectInfo,
                                                  new ProjectTemplateReference(package.ProjectTemplate.Uri));

            if (package.Customer != null)
            {
                newProject.SetCustomer(package.Customer);
            }


            //Add StarTransit package source files. The same on all language pairs
            ProjectFile[] sourceProjectFiles = newProject.AddFiles(package.LanguagePairs[0].SourceFile.ToArray());

            //set the file role(user to display project details in Studio view)
            var sourceFilesIds = newProject.GetSourceLanguageFiles().GetIds();

            newProject.SetFileRole(sourceFilesIds, FileRole.Translatable);

            var tmConfig        = newProject.GetTranslationProviderConfiguration();
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);

            List <ProjectFile> targetProjectFiles = new List <ProjectFile>();

            foreach (var pair in package.LanguagePairs)
            {
                targetProjectFiles.Clear();
                //import language pair TM if any
                if (pair.HasTm)
                {
                    var importer = new TransitTmImporter(pair.SourceLanguage,
                                                         pair.TargetLanguage,
                                                         pair.CreateNewTm,
                                                         fileTypeManager,
                                                         pair.TmPath);
                    foreach (var tm in pair.StarTranslationMemoryMetadatas)
                    {
                        importer.ImportStarTransitTm(tm.TargetFile);
                    }
                    tmConfig.Entries.Add(new TranslationProviderCascadeEntry(importer.GeTranslationProviderReference(),
                                                                             true,
                                                                             true,
                                                                             true));
                }
                targetProjectFiles.AddRange(newProject.AddFiles(pair.TargetFile.ToArray()));
                newProject.RunAutomaticTask(targetProjectFiles.GetIds(), AutomaticTaskTemplateIds.Scan);
                var taskSequence = newProject.RunAutomaticTasks(targetProjectFiles.GetIds(), new string[]
                {
                    AutomaticTaskTemplateIds.ConvertToTranslatableFormat,
                    AutomaticTaskTemplateIds.CopyToTargetLanguages,
                    AutomaticTaskTemplateIds.PerfectMatch,
                    AutomaticTaskTemplateIds.PreTranslateFiles,
                    AutomaticTaskTemplateIds.AnalyzeFiles,
                });


                newProject.UpdateTranslationProviderConfiguration(tmConfig);
                newProject.Save();
            }

            CreateMetadataFolder(package.Location, package.PathToPrjFile);

            Controller.RefreshProjects();
        }