private ProjectFileActivity GetProjectFileActivity(ProjectFile projectFile,
                                                           Enumerators.Action action, Enumerators.Status status, DateTime dateTime)
        {
            var projectFileActivity = new ProjectFileActivity
            {
                ProjectFileId = projectFile.FileId,
                Action        = action,
                Status        = status,
                ActivityId    = Guid.NewGuid().ToString(),
                Name          = projectFile.Name + ">XLIFF File " + projectFile.ProjectFileActivities.Count,
                Path          = "\\XLIFF File Path\\" + projectFile.ProjectFileActivities.Count,
                Date          = dateTime != DateTime.MinValue ? dateTime : GetRamdomDate(projectFile.Project.Created),
                Report        = status.ToString(),
                ProjectFile   = projectFile
            };

            return(projectFileActivity);
        }
Beispiel #2
0
        //private void SetProjectPropertiesViewController()
        //{
        //	if (_projectPropertiesViewController != null)
        //	{
        //		return;
        //	}

        //	try
        //	{
        //		_projectPropertiesViewController =
        //			SdlTradosStudio.Application.GetController<ProjectPropertiesViewController>();

        //		var viewModel = _projectsNavigationViewModel.ProjectPropertiesViewModel =
        //			new ProjectPropertiesViewModel(_projectsNavigationViewModel.SelectedProject);

        //		_projectPropertiesViewController.ViewModel = viewModel;
        //	}
        //	catch
        //	{
        //		// catch all; unable to locate the controller
        //	}
        //}

        private bool AddNewProjectToContainer(FileBasedProject project)
        {
            if (project == null)
            {
                return(false);
            }

            var projectInfo = project.GetProjectInfo();

            try
            {
                if (_xliffProjects.FirstOrDefault(a => a.Id == projectInfo.Id.ToString()) != null)
                {
                    // allready present in the list
                    return(false);
                }

                var settingsBundle      = project.GetSettings();
                var xliffManagerProject = settingsBundle.GetSettingsGroup <SDLTranscreateProject>();

                var projectFiles = SerializeProjectFiles(xliffManagerProject.ProjectFilesJson.Value);
                if (projectFiles?.Count > 0)
                {
                    var xliffProjectFiles = new List <ProjectFile>();

                    var xliffProject = new Project
                    {
                        Id              = projectInfo.Id.ToString(),
                        Name            = projectInfo.Name,
                        AbsoluteUri     = projectInfo.Uri.AbsoluteUri,
                        Customer        = _customerProvider.GetProjectCustomer(project),
                        Created         = projectInfo.CreatedAt.ToUniversalTime(),
                        DueDate         = projectInfo.DueDate?.ToUniversalTime() ?? DateTime.MaxValue,
                        Path            = projectInfo.LocalProjectFolder,
                        SourceLanguage  = GetLanguageInfo(projectInfo.SourceLanguage.CultureInfo),
                        TargetLanguages = GetLanguageInfos(projectInfo.TargetLanguages),
                        ProjectType     = GetProjectType(project),
                        ProjectFiles    = xliffProjectFiles
                    };

                    foreach (var projectFile in projectFiles)
                    {
                        var xliffFileActivities = new List <ProjectFileActivity>();

                        var xliffProjectFile = new ProjectFile
                        {
                            Path                        = projectFile.Path,
                            Action                      = GetAction(projectFile.Action),
                            Status                      = GetStatus(projectFile.Status),
                            Date                        = GetDateTime(projectFile.Date),
                            Report                      = GetRelativePath(xliffProject.Path, projectFile.Report),
                            FileId                      = projectFile.FileId,
                            FileType                    = projectFile.FileType,
                            Location                    = GetRelativePath(xliffProject.Path, projectFile.Location),
                            Name                        = projectFile.Name,
                            ProjectId                   = projectInfo.Id.ToString(),
                            ProjectFileActivities       = xliffFileActivities,
                            XliffFilePath               = GetRelativePath(xliffProject.Path, projectFile.XliffFilePath),
                            Project                     = xliffProject,
                            TargetLanguage              = projectFile.TargetLanguage,
                            ConfirmationStatistics      = projectFile.ConfirmationStatistics,
                            TranslationOriginStatistics = projectFile.TranslationOriginStatistics
                        };

                        foreach (var fileActivity in projectFile.Activities)
                        {
                            var xliffFileActivity = new ProjectFileActivity
                            {
                                ProjectFile                 = xliffProjectFile,
                                Path                        = GetRelativePath(xliffProject.Path, fileActivity.Path),
                                Action                      = GetAction(fileActivity.Action),
                                Status                      = GetStatus(fileActivity.Status),
                                ActivityId                  = fileActivity.ActivityId,
                                Date                        = GetDateTime(fileActivity.Date),
                                Report                      = GetRelativePath(xliffProject.Path, fileActivity.Report),
                                Name                        = fileActivity.Name,
                                ProjectFileId               = fileActivity.ProjectFileId,
                                ConfirmationStatistics      = fileActivity.ConfirmationStatistics,
                                TranslationOriginStatistics = fileActivity.TranslationOriginStatistics
                            };

                            xliffFileActivities.Add(xliffFileActivity);
                        }

                        xliffProject.ProjectFiles.Add(xliffProjectFile);
                    }

                    var addedNewFiles = AddNewProjectFiles(project, xliffProject);
                    if (addedNewFiles)
                    {
                        UpdateProjectSettingsBundle(xliffProject);
                    }

                    _xliffProjects.Add(xliffProject);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format(PluginResources.Warning_UnableToLoadProject, projectInfo.Name)
                                + Environment.NewLine + Environment.NewLine + ex.Message,
                                PluginResources.Plugin_Name, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }

            return(false);
        }
Beispiel #3
0
        protected override void ConfigureConverter(ProjectFile projectFile, IMultiFileConverter multiFileConverter)
        {
            var languageName = projectFile.Language.CultureInfo.Name;

            var targetFile = _wizardContext.ProjectFiles.FirstOrDefault(a =>
                                                                        a.FileId == projectFile.Id.ToString() && a.TargetLanguage == languageName);

            if (targetFile != null)
            {
                if (!targetFile.Selected)
                {
                    return;
                }

                targetFile.Location = Path.Combine(targetFile.Project.Path, targetFile.Location.Trim('\\'));

                if (string.IsNullOrEmpty(_currentLanguage) || languageName != _currentLanguage)
                {
                    _logReport.AppendLine();
                    _logReport.AppendLine(string.Format(PluginResources.Label_Language, languageName));
                    _currentLanguage = languageName;
                }

                var sdlxliffReader = new SdlxliffReader(_segmentBuilder,
                                                        _exportSettings.ExportOptions,
                                                        GetAnalysisBands(Project as FileBasedProject));

                var xliffWriter = new XliffWriter(_exportSettings.ExportOptions.XliffSupport);

                var dateTimeStampToString = GetDateTimeStampToString(_exportSettings.DateTimeStamp);
                var workingFolder         = Path.Combine(_exportSettings.TransactionFolder, dateTimeStampToString);
                var languageFolder        = Path.Combine(workingFolder, languageName);

                var xliffFolder   = GetXliffFolder(languageFolder, targetFile);
                var xliffFilePath = Path.Combine(xliffFolder, targetFile.Name + ".xliff");

                _logReport.AppendLine(string.Format(PluginResources.label_SdlXliffFile, targetFile.Location));
                _logReport.AppendLine(string.Format(PluginResources.label_XliffFile, xliffFilePath));

                try
                {
                    var xliffData = sdlxliffReader.ReadFile(_projectInfo.Id.ToString(), targetFile.Location);
                    var exported  = xliffWriter.WriteFile(xliffData, xliffFilePath, _exportSettings.ExportOptions.IncludeTranslations);

                    if (exported)
                    {
                        targetFile.Date                        = new DateTime(_exportSettings.DateTimeStamp.Ticks, DateTimeKind.Utc);
                        targetFile.Action                      = Enumerators.Action.Export;
                        targetFile.Status                      = Enumerators.Status.Success;
                        targetFile.XliffFilePath               = xliffFilePath;
                        targetFile.ConfirmationStatistics      = sdlxliffReader.ConfirmationStatistics;
                        targetFile.TranslationOriginStatistics = sdlxliffReader.TranslationOriginStatistics;
                    }

                    var activityFile = new ProjectFileActivity
                    {
                        ProjectFileId               = targetFile.FileId,
                        ProjectFile                 = targetFile,
                        ActivityId                  = Guid.NewGuid().ToString(),
                        Action                      = Enumerators.Action.Export,
                        Status                      = exported ? Enumerators.Status.Success : Enumerators.Status.Error,
                        Date                        = targetFile.Date,
                        Name                        = Path.GetFileName(targetFile.XliffFilePath),
                        Path                        = Path.GetDirectoryName(targetFile.XliffFilePath),
                        ConfirmationStatistics      = targetFile.ConfirmationStatistics,
                        TranslationOriginStatistics = targetFile.TranslationOriginStatistics
                    };

                    targetFile.ProjectFileActivities.Add(activityFile);

                    if (!exported)
                    {
                        _isError = true;
                    }

                    _logReport.AppendLine(string.Format(PluginResources.Label_Success, exported));
                    _logReport.AppendLine();
                }
                catch (Exception ex)
                {
                    _logReport.AppendLine();
                    _logReport.AppendLine(string.Format(PluginResources.label_ExceptionMessage, ex.Message));

                    throw;
                }
            }
        }
Beispiel #4
0
        private TaskContext CreateBackTranslationTaskContext(FileBasedProject newStudioProject,
                                                             IReadOnlyCollection <FileData> languageFileData, string localProjectFolder,
                                                             SdlxliffReader sdlxliffReader, SdlxliffWriter sdlxliffWriter, XliffWriter xliffWriter)
        {
            var newStudioProjectInfo = newStudioProject.GetProjectInfo();

            var action    = Enumerators.Action.CreateBackTranslation;
            var workFlow  = Enumerators.WorkFlow.Internal;
            var setttings = GetSettings();

            var taskContext = new TaskContext(action, workFlow, setttings);

            taskContext.AnalysisBands = _projectAutomationService.GetAnalysisBands(newStudioProject);
            taskContext.ExportOptions.IncludeBackTranslations = true;
            taskContext.ExportOptions.IncludeTranslations     = true;
            taskContext.ExportOptions.CopySourceToTarget      = false;


            taskContext.LocalProjectFolder = newStudioProjectInfo.LocalProjectFolder;
            taskContext.WorkflowFolder     = taskContext.GetWorkflowPath();

            var workingProject = _projectAutomationService.GetProject(newStudioProject, null);

            workingProject.ProjectFiles.RemoveAll(a => a.TargetLanguage == workingProject.SourceLanguage.CultureInfo.Name);
            taskContext.Project          = workingProject;
            taskContext.FileBasedProject = newStudioProject;
            taskContext.ProjectFiles     = workingProject.ProjectFiles;

            foreach (var projectFile in taskContext.ProjectFiles)
            {
                projectFile.Selected = true;
                var fileData = GetFileData(languageFileData, localProjectFolder, projectFile);

                var tmpInputFile = Path.GetTempFileName();
                File.Move(tmpInputFile, tmpInputFile + ".sdlxliff");
                tmpInputFile = tmpInputFile + ".sdlxliff";

                var paragraphMap = GetParagraphMap(sdlxliffReader, projectFile.ProjectId, projectFile.FileId,
                                                   projectFile.Location, projectFile.TargetLanguage);
                AlignParagraphIds(fileData.Data, paragraphMap.Keys.ToList());

                var filePath = Path.Combine(taskContext.WorkingFolder, projectFile.Path.Trim('\\'));

                var externalFilePath = Path.Combine(filePath, projectFile.Name + ".xliff");
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }

                xliffWriter.WriteFile(fileData.Data, externalFilePath, true);

                var success = sdlxliffWriter.UpdateFile(fileData.Data, projectFile.Location, tmpInputFile, true);
                if (success)
                {
                    projectFile.Date                        = taskContext.DateTimeStamp;
                    projectFile.Action                      = action;
                    projectFile.WorkFlow                    = workFlow;
                    projectFile.Status                      = Enumerators.Status.Success;
                    projectFile.Report                      = string.Empty;
                    projectFile.ExternalFilePath            = externalFilePath;
                    projectFile.ConfirmationStatistics      = sdlxliffWriter.ConfirmationStatistics;
                    projectFile.TranslationOriginStatistics = sdlxliffWriter.TranslationOriginStatistics;
                }

                var activityFile = new ProjectFileActivity
                {
                    ProjectFileId               = projectFile.FileId,
                    ActivityId                  = Guid.NewGuid().ToString(),
                    Action                      = action,
                    WorkFlow                    = workFlow,
                    Status                      = success ? Enumerators.Status.Success : Enumerators.Status.Error,
                    Date                        = projectFile.Date,
                    Name                        = Path.GetFileName(projectFile.ExternalFilePath),
                    Path                        = Path.GetDirectoryName(projectFile.ExternalFilePath),
                    Report                      = string.Empty,
                    ProjectFile                 = projectFile,
                    ConfirmationStatistics      = projectFile.ConfirmationStatistics,
                    TranslationOriginStatistics = projectFile.TranslationOriginStatistics
                };

                projectFile.ProjectFileActivities.Add(activityFile);

                File.Copy(projectFile.Location, Path.Combine(filePath, projectFile.Name));
                File.Delete(projectFile.Location);

                File.Copy(tmpInputFile, projectFile.Location, true);
                File.Delete(tmpInputFile);
            }

            return(taskContext);
        }