Esempio n. 1
0
        public void ApplyChanges()
        {
            if (SourceSearchResults.Any(s => s.TuSelected))
            {
                var progressDialogSettings = new ProgressDialogSettings(_window, true, true, false);

                var result = ProgressDialog.Execute(StringResources.Applying_changes, () =>
                {
                    var selectedSearchResult = SourceSearchResults.Where(s => s.TuSelected).ToList();
                    List <AnonymizeTranslationMemory> anonymizeTranslationMemories;

                    //file base tms
                    var fileBasedSearchResult = selectedSearchResult.Where(t => !t.IsServer).ToList();
                    if (fileBasedSearchResult.Count > 0)
                    {
                        anonymizeTranslationMemories = GetTranslationUnitsToAnonymize(ProgressDialog.Current, fileBasedSearchResult);

                        if (ProgressDialog.Current != null && ProgressDialog.Current.CheckCancellationPending())
                        {
                            ProgressDialog.Current.ThrowIfCancellationPending();
                        }

                        _model.TmService.AnonymizeFileBasedTm(ProgressDialog.Current, anonymizeTranslationMemories);
                    }

                    //server based tms
                    var serverBasedSearchResult = selectedSearchResult.Where(t => t.IsServer).ToList();
                    if (serverBasedSearchResult.Count > 0)
                    {
                        anonymizeTranslationMemories = GetTranslationUnitsToAnonymize(ProgressDialog.Current, serverBasedSearchResult);

                        if (ProgressDialog.Current != null && ProgressDialog.Current.CheckCancellationPending())
                        {
                            ProgressDialog.Current.ThrowIfCancellationPending();
                        }

                        _model.TmService.AnonymizeServerBasedTm(ProgressDialog.Current, anonymizeTranslationMemories);
                    }
                }, progressDialogSettings);

                if (result.Cancelled)
                {
                    System.Windows.Forms.MessageBox.Show(StringResources.Process_cancelled_by_user, System.Windows.Forms.Application.ProductName);
                    _window.Close();
                }

                if (result.OperationFailed)
                {
                    System.Windows.Forms.MessageBox.Show(StringResources.Process_failed + Environment.NewLine + Environment.NewLine + result.Error.Message, System.Windows.Forms.Application.ProductName);
                }

                RemoveSelectedTusToAnonymize();

                _model.Refresh();
            }
            else
            {
                System.Windows.Forms.MessageBox.Show(StringResources.ApplyChanges_Please_select_at_least_one_translation_unit_to_apply_the_changes, System.Windows.Forms.Application.ProductName);
            }
        }
Esempio n. 2
0
        public ProgressDialog(ProgressDialogSettings settings)
        {
            InitializeComponent();

            if (settings == null)
            {
                settings = ProgressDialogSettings.WithLabelOnly;
            }

            if (settings.ShowSubLabel)
            {
                Height    = 140;
                MinHeight = 140;
                SubTextLabel.Visibility = Visibility.Visible;
            }
            else
            {
                Height    = 110;
                MinHeight = 110;
                SubTextLabel.Visibility = Visibility.Collapsed;
            }

            CancelButton.Visibility = settings.ShowCancelButton ? Visibility.Visible : Visibility.Collapsed;

            ProgressBar.IsIndeterminate = settings.ShowProgressBarIndeterminate;
        }
Esempio n. 3
0
        internal static ProgressDialogResult ExecuteInternal(Window owner, string label, object operation, ProgressDialogSettings settings)
        {
            ProgressDialog dialog = new ProgressDialog(settings);

            dialog.Owner = owner;

            if (!string.IsNullOrEmpty(label))
            {
                dialog.Label = label;
            }

            return(dialog.Execute(operation));
        }
Esempio n. 4
0
 internal static ProgressDialogResult Execute(Window owner, string label, Func <object> operationWithResult, ProgressDialogSettings settings)
 {
     return(ExecuteInternal(owner, label, (object)operationWithResult, settings));
 }
        public List <Report> CreateFinalReport(Interfaces.IProject project, FileBasedProject studioProject, List <ProjectFile> selectedFiles, out string workingPathOut)
        {
            var reports  = new List <Report>();
            var settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                Indent             = false
            };
            var reportName = "Trados Transcreate Report";

            var studioProjectInfo     = studioProject.GetProjectInfo();
            var dateTimeStamp         = DateTime.UtcNow;
            var dataTimeStampToString = DateTimeStampToString(dateTimeStamp);
            var workflowPath          = GetPath(studioProjectInfo.LocalProjectFolder, "Workflow");
            var actionPath            = GetPath(workflowPath, "Report");
            var workingPath           = GetPath(actionPath, dataTimeStampToString);

            var exportOptions = new ExportOptions();

            exportOptions.IncludeBackTranslations = true;
            exportOptions.IncludeTranslations     = true;
            exportOptions.CopySourceToTarget      = false;

            var analysisBands = _projectAutomationService.GetAnalysisBands(studioProject);

            var progressSettings = new ProgressDialogSettings(ApplicationInstance.GetActiveForm(), true, true, false);
            var result           = ProgressDialog.ProgressDialog.Execute("Create Transcreate Reports", () =>
            {
                var sdlxliffReader = new SdlxliffReader(_segmentBuilder, exportOptions, analysisBands);
                decimal maximum    = project.ProjectFiles.Count;
                decimal current    = 0;
                foreach (var targetLanguage in project.TargetLanguages)
                {
                    var projectFiles = project.ProjectFiles.Where(a =>
                                                                  string.Compare(a.TargetLanguage, targetLanguage.CultureInfo.Name, StringComparison.CurrentCultureIgnoreCase) == 0).ToList();

                    var hasProjectFiles = HasProjectFiles(selectedFiles, projectFiles);
                    if (!hasProjectFiles)
                    {
                        current     += projectFiles.Count;
                        var progress = current / maximum * 100;

                        ProgressDialog.ProgressDialog.Current.Report((int)progress,
                                                                     string.Format("Language: {0}\r\nFile: {1}", targetLanguage.CultureInfo.DisplayName, projectFiles.FirstOrDefault().Name));

                        continue;
                    }

                    var workingLanguageFolder = GetPath(workingPath, targetLanguage.CultureInfo.Name);
                    foreach (var projectFile in projectFiles)
                    {
                        if (ProgressDialog.ProgressDialog.Current.CheckCancellationPending())
                        {
                            ProgressDialog.ProgressDialog.Current.ThrowIfCancellationPending();
                        }

                        current++;
                        var progress = current / maximum * 100;
                        ProgressDialog.ProgressDialog.Current.Report((int)progress, string.Format("Language: {0}\r\nFile: {1}", targetLanguage.CultureInfo.DisplayName, projectFile.Name));

                        if (selectedFiles != null && !selectedFiles.Exists(a => a.FileId == projectFile.FileId))
                        {
                            continue;
                        }

                        var projectFilePath = Path.Combine(project.Path, projectFile.Location);
                        var xliffData       = sdlxliffReader.ReadFile(project.Id, projectFile.FileId, projectFilePath,
                                                                      targetLanguage.CultureInfo.Name);

                        var backTranslationProject   = GetBackTranslationProject(project, targetLanguage.CultureInfo.Name);
                        var backTranslationFile      = GetBackTranslationProjectFile(backTranslationProject, projectFile);
                        var xliffDataBackTranslation = GetBackTranslationXliffData(backTranslationProject, backTranslationFile, sdlxliffReader);

                        var fileName   = projectFile.Name.Substring(0, projectFile.Name.LastIndexOf(".", StringComparison.Ordinal));
                        var reportFile = Path.Combine(workingLanguageFolder, fileName + ".xml");

                        using (var writer = XmlWriter.Create(reportFile, settings))
                        {
                            writer.WriteStartElement("task");
                            writer.WriteAttributeString("name", reportName);
                            writer.WriteAttributeString("created", dataTimeStampToString);

                            writer.WriteStartElement("taskInfo");
                            writer.WriteAttributeString("action", "Trados Transcreate Report");
                            writer.WriteAttributeString("file", projectFile.Path + projectFile.Name);
                            writer.WriteAttributeString("taskId", Guid.NewGuid().ToString());
                            writer.WriteAttributeString("runAt", GetDisplayDateTime(dateTimeStamp));


                            WriteReportProject(writer, "project", project);
                            WriteReportProject(writer, "backProject", backTranslationProject);

                            WriteReportLanguage(writer, "source", project.SourceLanguage.CultureInfo.Name);
                            WriteReportLanguage(writer, "target", targetLanguage.CultureInfo.Name);

                            WriteReportCustomer(writer, project);

                            WriteReportTranslationProviders(writer, studioProject);

                            writer.WriteEndElement();                             //taskInfo


                            writer.WriteStartElement("translations");
                            foreach (var dataFile in xliffData.Files)
                            {
                                writer.WriteStartElement("version");
                                writer.WriteAttributeString("type", dataFile.Original);

                                var backTranslationDataFile =
                                    xliffDataBackTranslation?.Files.FirstOrDefault(a => a.Original == dataFile.Original);

                                writer.WriteStartElement("segments");
                                foreach (var transUnit in dataFile.Body.TransUnits)
                                {
                                    var textFunction = transUnit.Contexts.FirstOrDefault(
                                        a => string.Compare(a.DisplayName, "Text Function", StringComparison.CurrentCultureIgnoreCase) == 0);

                                    foreach (var segmentPair in transUnit.SegmentPairs)
                                    {
                                        writer.WriteStartElement("segment");

                                        var backTranslationSegmentPair = GetBackTranslationSegmentPair(backTranslationDataFile, segmentPair);

                                        writer.WriteAttributeString("id", segmentPair.Id);
                                        writer.WriteAttributeString("textFunction", textFunction?.Description ?? string.Empty);

                                        writer.WriteStartElement("source");
                                        writer.WriteString(segmentPair.Source.ToString());
                                        writer.WriteEndElement();                                         //source

                                        writer.WriteStartElement("target");
                                        writer.WriteString(segmentPair.Target.ToString());
                                        writer.WriteEndElement();                                         //source

                                        writer.WriteStartElement("back");
                                        writer.WriteString(backTranslationSegmentPair?.Target?.ToString() ?? string.Empty);
                                        writer.WriteEndElement();                                         //backTranslation

                                        writer.WriteStartElement("comments");
                                        var comments = GetSegmentComments(segmentPair.Target, xliffData.DocInfo);
                                        if (comments != null)
                                        {
                                            foreach (var comment in comments)
                                            {
                                                writer.WriteStartElement("comment");
                                                writer.WriteAttributeString("version", comment.Version);
                                                writer.WriteAttributeString("author", comment.Author);
                                                writer.WriteAttributeString("severity", comment.Severity.ToString());
                                                writer.WriteAttributeString("date", GetDisplayDateTime(comment.Date));
                                                writer.WriteString(comment.Text ?? string.Empty);
                                                writer.WriteEndElement();                                                 //comment
                                            }
                                        }

                                        writer.WriteEndElement();                                         //comments

                                        writer.WriteEndElement();                                         //segment
                                    }
                                }
                                writer.WriteEndElement();                         //segments

                                writer.WriteEndElement();                         //version
                            }
                            writer.WriteEndElement();                             //translations
                        }

                        // transform the file against an xslt
                        var templatePath   = GetReportTemplatePath("TranscreateFinalReport.xsl");
                        var reportFilePath = CreateHtmlReportFile(reportFile, templatePath);


                        var report = new Report
                        {
                            Name        = fileName,
                            Date        = dateTimeStamp,
                            Description = "Transcreate Report",
                            Group       = "Transcreate Report",
                            Language    = targetLanguage.CultureInfo.Name,
                            Path        = reportFilePath
                        };
                        reports.Add(report);
                    }
                }
            }, progressSettings);

            workingPathOut = workingPath;

            if (result.Cancelled)
            {
                System.Windows.Forms.MessageBox.Show("Process cancelled by user.", PluginResources.Plugin_Name);
                return(new List <Report>());
            }

            return(reports);
        }
Esempio n. 6
0
        protected override void Execute()
        {
            var projects = _controllers.TranscreateController.GetSelectedProjects();

            if (projects?.Count != 1)
            {
                Enabled = false;
                return;
            }

            var project = projects[0];

            if (project is BackTranslationProject)
            {
                return;
            }

            var studioProject = _controllers.ProjectsController.GetProjects()
                                .FirstOrDefault(a => a.GetProjectInfo().Id.ToString() == project.Id);

            if (studioProject == null)
            {
                return;
            }

            var studioProjectInfo = studioProject.GetProjectInfo();


            var backTranslationsFolder = Path.Combine(studioProjectInfo.LocalProjectFolder, "BackProjects");

            if (Directory.Exists(backTranslationsFolder))
            {
                var message01 = "The Back-Translations folder is not empty."
                                + Environment.NewLine + Environment.NewLine
                                + "'" + backTranslationsFolder + "'"
                                + Environment.NewLine + Environment.NewLine;
                var message02 = "Do you want to proceed and delete this folder?";

                var response = MessageBox.Show(message01 + message02, PluginResources.Plugin_Name,
                                               MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (response != DialogResult.Yes)
                {
                    return;
                }

                TryDeleteDirectory(backTranslationsFolder);
            }


            var taskContexts = new List <TaskContext>();

            var progressSettings = new ProgressDialogSettings(ApplicationInstance.GetActiveForm(), true, true, true);
            var result           = ProgressDialog.Execute("Create Back-Translation Projects", () =>
            {
                ProgressDialog.Current.Report(0, "Reading language files...");

                var dateTimeStamp         = DateTime.UtcNow;
                var dataTimeStampToString = DateTimeStampToString(dateTimeStamp);
                var workFlowPath          = GetPath(studioProjectInfo.LocalProjectFolder, "WorkFlow");
                var workingActionPath     = GetPath(workFlowPath, "Convert");
                var workingFolder         = GetPath(workingActionPath, dataTimeStampToString);

                var exportOptions = new ExportOptions();
                exportOptions.IncludeBackTranslations = true;
                exportOptions.IncludeTranslations     = true;
                exportOptions.CopySourceToTarget      = false;

                var importOptions = new ImportOptions();
                importOptions.OverwriteTranslations      = true;
                importOptions.OriginSystem               = "Transcreate Automation";
                importOptions.StatusTranslationUpdatedId = string.Empty;

                var analysisBands = _projectAutomationService.GetAnalysisBands(studioProject);

                var sdlxliffReader = new SdlxliffReader(_segmentBuilder, exportOptions, analysisBands);
                var sdlxliffWriter = new SdlxliffWriter(_segmentBuilder, importOptions, analysisBands);
                var xliffWriter    = new XliffWriter(Enumerators.XLIFFSupport.xliff12sdl);

                // Read the SDLXLIFF data
                var fileDataList = GetFileDataList(project, studioProjectInfo, sdlxliffReader);
                var filesWithEmptyTranslations = fileDataList.Count(a => a.HasEmptyTranslations);
                if (filesWithEmptyTranslations > 0)
                {
                    var message01 = string.Format(PluginResources.Found_empty_translations_in_0_files,
                                                  filesWithEmptyTranslations)
                                    + Environment.NewLine + Environment.NewLine;
                    var message02 = PluginResources.Proceed_and_copy_source_to_target_for_empty_translations;

                    var response = MessageBox.Show(message01 + message02, PluginResources.Plugin_Name,
                                                   MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (response != DialogResult.Yes)
                    {
                        return;
                    }
                }

                ProgressDialog.Current.ProgressBarIsIndeterminate = false;
                decimal maximum = project.TargetLanguages.Count;
                decimal current = 0;

                foreach (var targetLanguage in project.TargetLanguages)
                {
                    if (ProgressDialog.Current.CheckCancellationPending())
                    {
                        ProgressDialog.Current.ThrowIfCancellationPending();
                    }

                    current++;
                    var progress = current / maximum * 100;
                    ProgressDialog.Current.Report((int)progress, "Language: " + targetLanguage.CultureInfo.DisplayName);


                    var sourceFiles    = new List <string>();
                    var languageFolder = GetPath(workingFolder, targetLanguage.CultureInfo.Name);

                    var targetFiles = project.ProjectFiles.Where(a =>
                                                                 string.Compare(a.TargetLanguage, targetLanguage.CultureInfo.Name,
                                                                                StringComparison.CurrentCultureIgnoreCase) == 0);

                    var languageFileData = new List <FileData>();
                    foreach (var projectFile in targetFiles)
                    {
                        var fileData =
                            fileDataList.FirstOrDefault(a => a.Data.DocInfo.DocumentId == projectFile.FileId);
                        if (fileData == null)
                        {
                            continue;
                        }

                        SwitchSourceWithTargetSegments(fileData);

                        var xliffFolder   = GetPath(languageFolder, projectFile.Path);
                        var xliffFilePath = Path.Combine(xliffFolder,
                                                         projectFile.Name.Substring(0, projectFile.Name.Length - ".sdlxliff".Length));

                        // Write the XLIFF file
                        var success = xliffWriter.WriteFile(fileData.Data, xliffFilePath, true);
                        if (!success)
                        {
                            throw new Exception(string.Format(
                                                    PluginResources.Unexpected_error_while_converting_the_file, xliffFilePath));
                        }

                        sourceFiles.Add(xliffFilePath);
                        languageFileData.Add(fileData);
                    }

                    var iconPath = GetBackTranslationIconPath();

                    var newStudioProject = _projectAutomationService.CreateBackTranslationProject(
                        studioProject, targetLanguage.CultureInfo.Name, iconPath, sourceFiles, "BT");

                    _projectAutomationService.RunPretranslationWithoutTm(newStudioProject);

                    var taskContext = CreateBackTranslationTaskContext(newStudioProject, languageFileData,
                                                                       studioProjectInfo.LocalProjectFolder, sdlxliffReader, sdlxliffWriter, xliffWriter);

                    taskContext.Completed = true;
                    taskContexts.Add(taskContext);
                }
            }, progressSettings);

            if (result.Cancelled || result.OperationFailed)
            {
                TryDeleteDirectory(backTranslationsFolder);

                var message = result.Cancelled ? "Process cancelled by user." : result.Error?.Message;
                MessageBox.Show(message, PluginResources.Plugin_Name);
                return;
            }

            foreach (var taskContext in taskContexts)
            {
                CleanupProjectSettings(taskContext.FileBasedProject);

                ActivateProject(taskContext.FileBasedProject);
                _projectAutomationService.RemoveLastReportOfType("Translate");

                var reports = _controllers.TranscreateController.CreateHtmlReports(taskContext, taskContext.FileBasedProject, taskContext.Project);
                _controllers.TranscreateController.ReportsController.AddReports(_controllers.TranscreateController.ClientId, reports);

                _controllers.TranscreateController.UpdateBackTranslationProjectData(project, taskContext);
            }

            _controllers.TranscreateController.InvalidateProjectsContainer();

            Enabled = false;
        }