Example #1
0
        public IFileExtractor GetFileExtractor(string filePath)
        {
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var extensionPoint  =
                PluginManager.DefaultPluginRegistry.GetExtensionPoint <FileTypeComponentBuilderAttribute>();

            foreach (IExtension extension in extensionPoint.Extensions)
            {
                IFileTypeComponentBuilder extensionFileTypeComponentBuilder =
                    (IFileTypeComponentBuilder)extension.CreateInstance();
                extensionFileTypeComponentBuilder.FileTypeManager = fileTypeManager;
                IFileTypeInformation extensionFileTypeInformation =
                    extensionFileTypeComponentBuilder.BuildFileTypeInformation(string.Empty);
                string extensionFileTypeDefinitionId = extensionFileTypeInformation.FileTypeDefinitionId.Id;


                if (Equals(extensionFileTypeDefinitionId, "SDL XLIFF 1.0 v 1.0.0.0"))
                {
                    var extractor = extensionFileTypeComponentBuilder.BuildFileExtractor(filePath);

                    return(extractor);
                }
            }
            return(null);
        }
        public StarTransitMainWindowViewModel(
            PackageDetailsViewModel packageDetailsViewModel,
            PackageDetails packageDetails,
            TranslationMemories translationMemories,
            TranslationMemoriesViewModel translationMemoriesViewModel,
            FinishViewModel finishViewModel,
            IMessageBoxService messageBoxService)
        {
            _messageBoxService            = messageBoxService;
            _packageDetailsViewModel      = packageDetailsViewModel;
            _packageDetails               = packageDetails;
            _translationMemories          = translationMemories;
            _translationMemoriesViewModel = translationMemoriesViewModel;
            CanExecuteBack     = false;
            CanExecuteCreate   = false;
            CanExecuteNext     = true;
            _isDetailsSelected = true;
            _isTmSelected      = false;
            _isFinishSelected  = false;
            _finishViewModel   = finishViewModel;
            Color = "#FFB69476";
            var helpers = new Shared.Utils.Helpers();

            _projectService = new ProjectService(DefaultFileTypeManager.CreateInstance(true), helpers);
        }
Example #3
0
        public MessageModel CreateProject(PackageModel package)
        {
            _messageModel = new MessageModel();

            try
            {
                _penaltiesTmsList = new List <StarTranslationMemoryMetadata>();
                _machineTransList = new List <StarTranslationMemoryMetadata>();
                _tmConfig         = new TranslationProviderConfiguration();

                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
                var 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);

                _tmConfig        = newProject.GetTranslationProviderConfiguration();
                _fileTypeManager = DefaultFileTypeManager.CreateInstance(true);

                var targetProjectFiles = new List <ProjectFile>();

                _messageModel = SetLanguagePairInformation(newProject, package, targetProjectFiles);

                if (_messageModel is null || !_messageModel.IsProjectCreated)
                {
                    if (Directory.Exists(Path.GetDirectoryName(newProject.FilePath)))
                    {
                        CreateMetadataFolder(package.Location, package.PathToPrjFile);
                        Controller.RefreshProjects();
                    }
                    _messageModel.IsProjectCreated = true;
                    _messageModel.Message          = "Project was successfully created!";
                    _messageModel.Title            = "Informative message";
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error($"CreateModel method: {ex.Message}\n {ex.StackTrace}");
                return(null);
            }
            return(_messageModel);
        }
Example #4
0
        private Dictionary <string, Dictionary <string, ParagraphUnit> > GetFileParagraphUnits(string filePath)
        {
            var manager   = DefaultFileTypeManager.CreateInstance(true);
            var converter = manager.GetConverterToDefaultBilingual(filePath, filePath + "_.sdlxliff", null);

            var contentProcessor = new ContentProcessor
            {
                FileParagraphUnits = new Dictionary <string, Dictionary <string, ParagraphUnit> >(),
                IncludeTagText     = Processor.Settings.ComparisonIncludeTags
            };



            converter.AddBilingualProcessor(contentProcessor);
            try
            {
                converter.Progress += converter_Progress;
                converter.Parse();
            }
            finally
            {
                converter.Progress -= converter_Progress;
            }

            return(contentProcessor.FileParagraphUnits);
        }
Example #5
0
        public void XliffReader_XLIFFSupportSniffer_ReturnsEqual(Enumerators.XLIFFSupport support)
        {
            // arrange
            var sniffer        = new XliffSniffer();
            var segmentBuilder = new SegmentBuilder();
            var xliffReader    = new XliffReder(sniffer, segmentBuilder);
            //var pocoFilterManager = new PocoFilterManager(false);
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var importOptions   = new ImportOptions();
            var analysisBands   = new List <AnalysisBand>();
            var sdlxliffWriter  = new SdlxliffWriter(fileTypeManager, segmentBuilder, importOptions, analysisBands);

            var testFile = support == Enumerators.XLIFFSupport.xliff12polyglot
                                ? _testFilesUtil.GetSampleFilePath("Xliff12", "Polyglot", "QuotesSample.docx.sdlxliff.xliff")
                                : _testFilesUtil.GetSampleFilePath("Xliff12", "xsi", "QuotesSample.docx.sdlxliff.xliff");
            var sdlxliffFile = _testFilesUtil.GetSampleFilePath("Sdlxliff", "QuotesSample.docx.sdlxliff");

            // act
            var xliff      = xliffReader.ReadXliff(testFile);
            var outputFile = sdlxliffFile + ".out.sdlxliff";
            var success    = sdlxliffWriter.UpdateFile(xliff, sdlxliffFile, outputFile);

            // assert
            Assert.Equal(support, xliff.Support);
        }
        public void ParseRestOfFiles(IProject project, ProjectFile[] taskFiles,
                                     AbstractBilingualContentProcessor contentProcessor, out List <string> ignoredFiles)
        {
            ignoredFiles = _ignoredList;
            if (_restOfFilesParsed)
            {
                return;
            }

            var unParsedProjectFiles = GetUnparsedFiles(project, taskFiles);

            CloseOpenedDocuments();

            foreach (var file in unParsedProjectFiles)
            {
                if (Path.GetExtension(file.LocalFilePath) != ".sdlxliff")
                {
                    _logger.Info(PluginResources.FileIgnoredByParser, file.LocalFilePath);
                    ignoredFiles.Add(file.LocalFilePath);
                    continue;
                }

                var converter = DefaultFileTypeManager.CreateInstance(true)
                                .GetConverterToDefaultBilingual(file.LocalFilePath, file.LocalFilePath, null);

                converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(contentProcessor));
                converter.Parse();
            }

            _restOfFilesParsed = true;
        }
        public Xliff ReadFile(string projectId, string documentId, string filePath, string targetLanguage)
        {
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var tempFile        = Path.GetTempFileName();
            var converter       = fileTypeManager.GetConverterToDefaultBilingual(filePath, tempFile, null);

            var contentReader = new XliffContentReader(projectId, documentId, filePath, targetLanguage, false, _segmentBuilder,
                                                       _exportOptions, _analysisBands);

            //converter.AddBilingualProcessor(new SegmentRenumberingBilingualProcessor());
            converter.AddBilingualProcessor(contentReader);

            converter.Parse();

            SourceLanguage = contentReader.SourceLanguage;
            TargetLanguage = contentReader.TargetLanguage;

            ConfirmationStatistics      = contentReader.ConfirmationStatistics;
            TranslationOriginStatistics = contentReader.TranslationOriginStatistics;


            if (File.Exists(tempFile))
            {
                File.Delete(tempFile);
            }

            return(contentReader.Xliff);
        }
Example #8
0
        public void Initialize()
        {
            telemetryTracker = new TelemetryTracker();

            sourceTerms          = new List <string>();
            bilingualContentPair = new Dictionary <string, List <KeyValuePair <string, string> > >();
            FileTypeManager      = DefaultFileTypeManager.CreateInstance(true);
        }
Example #9
0
        private void ProcessFile(string filePath, string newOrigin)
        {
            var converter = DefaultFileTypeManager.CreateInstance(true)
                            .GetConverterToDefaultBilingual(filePath, filePath, null);
            var fileProcessor = new FileProcessor(newOrigin);

            converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(fileProcessor));
            converter.Parse();
        }
Example #10
0
        protected override void Execute()
        {
            var file      = @"filepath";
            var converter = DefaultFileTypeManager.CreateInstance(true)
                            .GetConverterToDefaultBilingual(file, file, null);

            converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(new FileProcessor()));
            converter.Parse();
            //projects controler
            var projectsController = SdlTradosStudio.Application.GetController <ProjectsController>();
            var activeProject      = projectsController?.CurrentProject;
        }
Example #11
0
        private List <SegmentPairInfo> GetSegmentPairs(string filePathInput)
        {
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var converter       = fileTypeManager.GetConverterToDefaultBilingual(filePathInput, null, null);

            var contentReader = new ContentReader();

            converter.AddBilingualProcessor(contentReader);
            converter.SynchronizeDocumentProperties();

            converter.Parse();

            return(contentReader.SegmentPairInfos);
        }
Example #12
0
        internal Dictionary <string, Dictionary <string, ParagraphUnit> > GetParagraphUnits(string filePath)
        {
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var converter       = fileTypeManager.GetConverterToDefaultBilingual(filePath, null, null);

            var contentProcessor = new ContentProcessor
            {
                OutputPath         = Path.GetDirectoryName(filePath),
                DummyOutputFiles   = new List <string>(),
                CreatedDummyOutput = false,
                FileParagraphUnits = new Dictionary <string, Dictionary <string, ParagraphUnit> >()
            };



            converter.AddBilingualProcessor(new SourceToTargetCopier(ExistingContentHandling.Preserve));

            converter.AddBilingualProcessor(contentProcessor);
            try
            {
                converter.Progress += converter_Progress;
                converter.Parse();

                SourceLanguageCultureInfo = contentProcessor.SourceLanguageCultureInfo;
                TargetLanguageCultureInfo = contentProcessor.TargetLanguageCultureInfo;
            }
            finally
            {
                converter.Progress -= converter_Progress;

                if (contentProcessor.CreatedDummyOutput && contentProcessor.DummyOutputFiles.Count > 0)
                {
                    try
                    {
                        foreach (var dummyFilePath in contentProcessor.DummyOutputFiles)
                        {
                            File.Delete(dummyFilePath);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

            return(contentProcessor.FileParagraphUnits);
        }
Example #13
0
        private void ParseRestOfFiles(ProjectsController projectController, List <RegexPattern> selectedPatternsFromGrid, string key)
        {
            var unParsedProjectFiles = GetUnparsedFiles(projectController);

            CloseOpenDocuments();

            foreach (var file in unParsedProjectFiles)
            {
                var converter = DefaultFileTypeManager.CreateInstance(true)
                                .GetConverterToDefaultBilingual(file.LocalFilePath, file.LocalFilePath, null);
                var contentProcessor = new AnonymizerPreProcessor(selectedPatternsFromGrid, key,
                                                                  _settings.EncryptionState.HasFlag(State.PatternsEncrypted));
                converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(contentProcessor));
                converter.Parse();
            }
        }
Example #14
0
        protected override void Execute()
        {
            var selectedProjects = Controller.SelectedProjects.ToList();
            var fileTypeManager  = DefaultFileTypeManager.CreateInstance(true);

            foreach (var project in selectedProjects)
            {
                var targetFiles = project.GetTargetLanguageFiles();
                foreach (var targetFile in targetFiles.ToList())
                {
                    var converter =
                        fileTypeManager.GetConverterToDefaultBilingual(targetFile.LocalFilePath, targetFile.LocalFilePath, null);
                    converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(new DecryptDataProcessor()));
                    converter.Parse();
                }
            }
        }
Example #15
0
        protected override void ConfigureConverter(ProjectFile projectFile, IMultiFileConverter multiFileConverter)
        {
            if (!AgreementMethods.UserAgreed())
            {
                CancelHelper.CancelTaskIfRequested(true);
            }

            if (!_settings.ShouldDeanonymize ?? false)
            {
                return;
            }

            var projectController = SdlTradosStudio.Application.GetController <ProjectsController>();

            multiFileConverter.AddBilingualProcessor(new BilingualContentHandlerAdapter(new DecryptDataProcessor(_settings)));

            var project              = projectController.CurrentProject ?? projectController.SelectedProjects.ToList()[0];
            var projectFiles         = project.GetTargetLanguageFiles();
            var unParsedProjectFiles = new List <ProjectFile>();

            foreach (var file in projectFiles)
            {
                if (TaskFiles.GetIds().Contains(file.Id))
                {
                    continue;
                }

                unParsedProjectFiles.Add(file);
            }

            var editor     = SdlTradosStudio.Application.GetController <EditorController>();
            var activeDocs = editor.GetDocuments().ToList();

            foreach (var activeDoc in activeDocs)
            {
                Application.Current.Dispatcher.Invoke(() => { editor.Close(activeDoc); });
            }

            foreach (var file in unParsedProjectFiles)
            {
                var converter        = DefaultFileTypeManager.CreateInstance(true).GetConverterToDefaultBilingual(file.LocalFilePath, file.LocalFilePath, null);
                var contentProcessor = new DecryptDataProcessor(_settings);
                converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(contentProcessor));
                converter.Parse();
            }
        }
Example #16
0
        public bool UpdateFile(Xliff xliff, string filePathInput, string filePathOutput, bool importBackTranslations = false)
        {
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var converter       = fileTypeManager.GetConverterToDefaultBilingual(filePathInput, filePathOutput, null);
            var tagIds          = GetTagIds(filePathInput);

            var contentWriter = new XliffContentWriter(xliff, _segmentBuilder, _importOptions, _analysisBands, tagIds, importBackTranslations);

            converter.AddBilingualProcessor(contentWriter);
            converter.SynchronizeDocumentProperties();

            converter.Parse();

            ConfirmationStatistics      = contentWriter.ConfirmationStatistics;
            TranslationOriginStatistics = contentWriter.TranslationOriginStatistics;

            return(true);
        }
Example #17
0
        private void ImportInTmWithNameField(string tmPath)
        {
            var tm    = new FileBasedTranslationMemory(tmPath);
            var files = new List <string>
            {
                @"files path",
                @""
            };

            foreach (var file in files)
            {
                var converter        = DefaultFileTypeManager.CreateInstance(true).GetConverterToDefaultBilingual(file, file, null);
                var fileInfo         = new FileInfo(file);
                var contentProcessor = new FileProcessor(tm, fileInfo.Name);
                converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(contentProcessor));
                converter.Parse();
            }
        }
Example #18
0
        /// <summary>
        /// searches for matches in files
        /// </summary>
        /// <param name="_settings">search options</param>
        public void SearchInFiles(SearchSettings _settings)
        {
            validateSetts(_settings, false);

            _fileResults = new List <FileData>();

            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);

            foreach (string filePath in _files)
            {
                validateFile(filePath);

                var extractor = GetFileExtractor(filePath);

                if (extractor != null)
                {
                    var converter = fileTypeManager.GetConverter(extractor.BilingualParser);

                    SetFileExtractorProperties(extractor, converter);

                    var parserProperties = extractor.BilingualParser as INativeContentCycleAware;

                    var fileProperties = GetFileProperties(converter, filePath);

                    parserProperties?.SetFileProperties(fileProperties);


                    // create object to process each file text to perform search
                    FileReadProcessor readProcessor = new FileReadProcessor(filePath, _settings);

                    // set extractor and processor

                    converter.SynchronizeDocumentProperties();
                    converter.AddBilingualProcessor(readProcessor);

                    // start parsing the file
                    converter.Parse();

                    // save search results
                    _fileResults.Add(new FileData(filePath, readProcessor.ResultInSource, readProcessor.ResultInTarget));
                }
            }
        }
        public Xliff ReadFile(string projectId, string filePath)
        {
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var converter       = fileTypeManager.GetConverterToDefaultBilingual(filePath, null, null);

            var contentReader = new ContentReader(projectId, filePath, false, _segmentBuilder,
                                                  _exportOptions, _analysisBands);

            converter.AddBilingualProcessor(contentReader);

            SourceLanguage = contentReader.SourceLanguage;
            TargetLanguage = contentReader.TargetLanguage;

            converter.Parse();

            ConfirmationStatistics      = contentReader.ConfirmationStatistics;
            TranslationOriginStatistics = contentReader.TranslationOriginStatistics;

            return(contentReader.Xliff);
        }
Example #20
0
        public ImportResult UpdateFile(List <SegmentPairInfo> updatedSegmentPairs, List <string> excludeFilterIds, string filePathInput, string filePathOutput)
        {
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var converter       = fileTypeManager.GetConverterToDefaultBilingual(filePathInput, filePathOutput, null);

            var contentWriter = new ContentImporter(updatedSegmentPairs, excludeFilterIds, _filterItemService, _analysisBands);

            converter.AddBilingualProcessor(contentWriter);
            converter.SynchronizeDocumentProperties();

            converter.Parse();

            return(new ImportResult
            {
                Success = true,
                UpdatedSegments = contentWriter.UpdatedSegments,
                ExcludedSegments = contentWriter.ExcludedSegments,
                FilePath = filePathInput,
                UpdatedFilePath = filePathOutput,
                BackupFilePath = _projectFileService.GetUniqueFileName(filePathInput, "Backup")
            });
        }
Example #21
0
        public OutputFile ExportFile(List <SegmentPairInfo> selectedSegments, string filePathInput, string filePathOutput)
        {
            var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
            var converter       = fileTypeManager.GetConverterToDefaultBilingual(filePathInput, filePathOutput, null);

            var contentWriter = new ContentExporter(selectedSegments, _segmentBuilder);

            converter.AddBilingualProcessor(contentWriter);
            converter.SynchronizeDocumentProperties();

            converter.Parse();


            var outputFile = new OutputFile
            {
                FilePath     = filePathOutput,
                SegmentCount = contentWriter.SegmentPairInfos.Count,
                WordCount    = contentWriter.SegmentPairInfos.Sum(a => a.SourceWordCounts.Words)
            };


            return(outputFile);
        }
Example #22
0
        private Dictionary <string, Dictionary <string, ParagraphUnit> > GetFileParagraphUnits(string filePath, bool isOriginal)
        {
            var manager   = DefaultFileTypeManager.CreateInstance(true);
            var converter = manager.GetConverterToDefaultBilingual(filePath, null, null);

            var contentProcessor = new ContentProcessor
            {
                FileParagraphUnits = new Dictionary <string, Dictionary <string, ParagraphUnit> >(),
                OutputPath         = Path.GetDirectoryName(filePath),
                DummyOutputFiles   = new List <string>(),
                CreatedDummyOutput = false,
                IncludeTagText     = Processor.Settings.ComparisonIncludeTags
            };


            contentProcessor.FileParagraphUnits = new Dictionary <string, Dictionary <string, ParagraphUnit> >();

            converter.AddBilingualProcessor(contentProcessor);
            try
            {
                converter.Progress += converter_Progress;
                converter.Parse();

                if (isOriginal)
                {
                    if (contentProcessor.SourceLanguageId != string.Empty)
                    {
                        SourceLanguageIdOriginal = contentProcessor.SourceLanguageId;
                    }
                    else if (converter.DetectedSourceLanguage != null)
                    {
                        SourceLanguageIdOriginal = converter.DetectedSourceLanguage.First.CultureInfo.Name;
                    }

                    if (contentProcessor.TargetLanguageId != string.Empty)
                    {
                        TargetLanguageIdOriginal = contentProcessor.TargetLanguageId;
                    }
                    else if (converter.DetectedTargetLanguage != null && converter.DetectedTargetLanguage.First.CultureInfo != null)
                    {
                        TargetLanguageIdOriginal = converter.DetectedTargetLanguage.First.CultureInfo.Name;
                    }
                }
                else
                {
                    if (contentProcessor.SourceLanguageId != string.Empty)
                    {
                        SourceLanguageIdUpdated = contentProcessor.SourceLanguageId;
                    }
                    else if (converter.DetectedSourceLanguage != null)
                    {
                        SourceLanguageIdUpdated = converter.DetectedSourceLanguage.First.CultureInfo.Name;
                    }

                    if (contentProcessor.TargetLanguageId != string.Empty)
                    {
                        TargetLanguageIdUpdated = contentProcessor.TargetLanguageId;
                    }
                    else if (converter.DetectedTargetLanguage != null && converter.DetectedTargetLanguage.First.CultureInfo != null)
                    {
                        TargetLanguageIdUpdated = converter.DetectedTargetLanguage.First.CultureInfo.Name;
                    }
                }

                SourceLanguageCultureInfo = new CultureInfo(SourceLanguageIdOriginal);
                TargetLanguageCultureInfo = new CultureInfo(TargetLanguageIdUpdated);
            }
            finally
            {
                converter.Progress -= converter_Progress;
            }

            return(contentProcessor.FileParagraphUnits);
        }
Example #23
0
        internal void UpdateSegmentUnits(string filePathIn, string filePathOut, Dictionary <string, Dictionary <string, ParagraphUnit> > fileParagraphUnits)
        {
            TotalSegmentsOriginalFile               = 0;
            TotalSegmentsBilingualFile              = 0;
            TotalContentChanges                     = 0;
            TotalStatusChangesWithContentChanges    = 0;
            TotalStatusChangesWithoutContentChanges = 0;
            TagUnitWarnings = new Dictionary <string, List <TagUnitWarning> >();

            var manager   = DefaultFileTypeManager.CreateInstance(true);
            var converter = manager.GetConverterToDefaultBilingual(filePathIn, filePathOut, null);



            var contentWriter = new ContentWriter
            {
                OutputPath         = Path.GetDirectoryName(filePathOut),
                DummyOutputFiles   = new List <string>(),
                CreatedDummyOutput = false
            };


            var xParagraphUnits = fileParagraphUnits.SelectMany(fileParagraphUnit => fileParagraphUnit.Value).ToDictionary(paragraphUnit => paragraphUnit.Key, paragraphUnit => paragraphUnit.Value);

            contentWriter.XParagraphUnits = xParagraphUnits;
            converter.AddBilingualProcessor(contentWriter);


            try
            {
                converter.Progress += converter_Progress;
                converter.Parse();

                SourceLanguageCultureInfo = contentWriter.SourceLanguageCultureInfo;
                TargetLanguageCultureInfo = contentWriter.TargetLanguageCultureInfo;


                TotalSegmentsOriginalFile               = contentWriter.TotalSegmentsOriginalFile;
                TotalSegmentsBilingualFile              = contentWriter.TotalSegmentsBilingualFile;
                TotalContentChanges                     = contentWriter.TotalContentChanges;
                TotalStatusChangesWithContentChanges    = contentWriter.TotalStatusChangesWithContentChanges;
                TotalStatusChangesWithoutContentChanges = contentWriter.TotalStatusChangesWithoutContentChanges;

                TagUnitWarnings = contentWriter.TagUnitWarnings;
            }
            finally
            {
                converter.Progress -= converter_Progress;

                if (contentWriter.CreatedDummyOutput && contentWriter.DummyOutputFiles.Count > 0)
                {
                    try
                    {
                        foreach (var dummyFilePath in contentWriter.DummyOutputFiles)
                        {
                            File.Delete(dummyFilePath);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Example #24
0
        /// <summary>
        /// searches for matches in files and performs replace of found ones
        /// </summary>
        /// <param name="_settings"></param>
        public void ReplaceInFiles(SearchSettings _settings)
        {
            validateSetts(_settings, true);

            _fileResults = new List <FileData>();

            foreach (string filePath in _files)
            {
                validateFile(filePath);

                createBackupFile(filePath);


                var fileTypeManager = DefaultFileTypeManager.CreateInstance(true);
                var extensionPoint  = PluginManager.DefaultPluginRegistry.GetExtensionPoint <FileTypeComponentBuilderAttribute>();
                //IFileExtractor parser = null;
                IBilingualDocumentGenerator writer = null;
                foreach (IExtension extension in extensionPoint.Extensions)
                {
                    IFileTypeComponentBuilder extensionFileTypeComponentBuilder = (IFileTypeComponentBuilder)extension.CreateInstance();
                    extensionFileTypeComponentBuilder.FileTypeManager = fileTypeManager;
                    IFileTypeInformation extensionFileTypeInformation = extensionFileTypeComponentBuilder.BuildFileTypeInformation(string.Empty);
                    string extensionFileTypeDefinitionId   = extensionFileTypeInformation.FileTypeDefinitionId.Id;
                    FileTypeComponentBuilderAttribute attr = extension.ExtensionAttribute as FileTypeComponentBuilderAttribute;

                    if (Equals(extensionFileTypeDefinitionId, "SDL XLIFF 1.0 v 1.0.0.0"))
                    {
                        //parser = extensionFileTypeComponentBuilder.BuildFileExtractor(filePath);
                        writer = extensionFileTypeComponentBuilder.BuildBilingualGenerator(filePath);
                    }
                }
                //XliffFileReader parser = new XliffFileReader(filePath);
                // var parser = FileReaderHelper.FileReader(filePath);

                var extractor = GetFileExtractor(filePath);
                if (extractor != null)
                {
                    var converter = fileTypeManager.GetConverter(extractor.BilingualParser);

                    SetFileExtractorProperties(extractor, converter);

                    var parserProperties = extractor.BilingualParser as INativeContentCycleAware;

                    var fileProperties = GetFileProperties(converter, filePath);

                    parserProperties?.SetFileProperties(fileProperties);

                    // var extractor = fileTypeManager.BuildFileExtractor(parser.BilingualParser, null);

                    // var writer = FileWriterHelper.FileWriter(filePath);

                    // create object to update file to replace found text
                    FileReplaceProcessor replaceProcessor = new FileReplaceProcessor(filePath, _settings);

                    // set extractor and processors
                    //  extractor.BilingualParser = parser.BilingualParser;
                    // converter.AddExtractor(extractor);

                    converter.SynchronizeDocumentProperties();
                    converter.AddBilingualProcessor(replaceProcessor);

                    if (writer != null)
                    {
                        converter.AddBilingualProcessor(new BilingualContentHandlerAdapter(writer.Input));
                    }

                    // start parsing the file
                    converter.Parse();

                    // save replace results
                    FileData fData = new FileData(filePath, replaceProcessor.ResultSource, replaceProcessor.ResultTarget);
                    fData.ReplaceResults = replaceProcessor.ResultOfReplace;
                    fData.Warnings       = replaceProcessor.Warnings;
                    _fileResults.Add(fData);

                    if (fData.ReplaceResults.Count < 1)
                    {
                        removeCreatedFile(filePath);
                    }
                    else if (!_settings.MakeBackup)
                    {
                        removeBackupFile(filePath);
                    }
                }
            }
        }
 public Processor() : this(DefaultFileTypeManager.CreateInstance(true))
 {
 }
        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);
        }
 public ProjectTextExtractor(FileBasedProject project)
 {
     Project         = project;
     FileTypeManager = DefaultFileTypeManager.CreateInstance(true);
 }
Example #28
0
 public SegmentMetadataCreator()
 {
     _manager = DefaultFileTypeManager.CreateInstance(true);
 }
Example #29
0
        public MessageModel CreateProject(PackageModel package)
        {
            var penaltiesTmsList = new List <StarTranslationMemoryMetadata>();
            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);

            var targetProjectFiles = new List <ProjectFile>();

            foreach (var pair in package.LanguagePairs)
            {
                // Separate all items from package.TMPenalties(files that are having penalties set)
                // which are found in pair.StarTranslationMemoryMetadatas
                foreach (var starTMMetadata in pair.StarTranslationMemoryMetadatas)
                {
                    if (package.TMPenalties != null)
                    {
                        if (package.TMPenalties.Any(t => t.Key.Equals(starTMMetadata.TargetFile)))
                        {
                            starTMMetadata.TMPenalty = package.TMPenalties.FirstOrDefault(t => t.Key.Equals(starTMMetadata.TargetFile)).Value;
                            penaltiesTmsList.Add(starTMMetadata);
                        }
                    }
                }

                // Remove found items from pair.StarTranslationMemoryMetadatas (the remained ones are those which does not have penalties set on them)
                foreach (var item in penaltiesTmsList)
                {
                    pair.StarTranslationMemoryMetadatas.Remove(item);
                }

                // Create one TM (that has the name equals with the project name)
                // with the TM files from pair.StarTranslationMemoryMetadatas (the onew without penalties set by the user)
                targetProjectFiles.Clear();

                // Import language pair TM if any
                if (pair.HasTm)
                {
                    if (pair.StarTranslationMemoryMetadatas.Count > 0)
                    {
                        var importer = new TransitTmImporter(pair.SourceLanguage,
                                                             pair.TargetLanguage,
                                                             pair.CreateNewTm,
                                                             fileTypeManager,
                                                             Path.Combine(Path.GetDirectoryName(newProject.FilePath), Path.GetFileName(pair.TmPath)));
                        foreach (var tm in pair.StarTranslationMemoryMetadatas)
                        {
                            importer.ImportStarTransitTm(tm.TargetFile);
                        }

                        tmConfig.Entries.Add(new TranslationProviderCascadeEntry(importer.GetTranslationProviderReference(),
                                                                                 true,
                                                                                 true,
                                                                                 true));
                    }

                    // Create separate TM for each TM file on which user set penalty
                    // (the name of the new TM will be the same with the one from StarTransit package)
                    foreach (var item in penaltiesTmsList)
                    {
                        var tmWithPenaltyImporter = new TransitTmImporter(
                            Path.GetDirectoryName(newProject.FilePath),
                            pair.SourceLanguage,
                            pair.TargetLanguage,
                            Path.GetFileName(item.TargetFile),
                            fileTypeManager);

                        tmWithPenaltyImporter.ImportStarTransitTm(item.TargetFile);

                        tmConfig.Entries.Add(new TranslationProviderCascadeEntry(
                                                 new TranslationProviderReference(tmWithPenaltyImporter.TMFilePath),
                                                 true,
                                                 true,
                                                 true,
                                                 item.TMPenalty));
                    }
                }
                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);
                }
                targetProjectFiles.AddRange(newProject.AddFiles(pair.TargetFile.ToArray()));

                //update tm settings
                UpdateTmSettings(newProject);
                newProject.UpdateTranslationProviderConfiguration(tmConfig);

                newProject.RunAutomaticTask(targetProjectFiles.GetIds(), AutomaticTaskTemplateIds.Scan);
                var taskSequence = newProject.RunAutomaticTasks(targetProjectFiles.GetIds(), new[]
                {
                    AutomaticTaskTemplateIds.ConvertToTranslatableFormat,
                    AutomaticTaskTemplateIds.CopyToTargetLanguages,
                    AutomaticTaskTemplateIds.PerfectMatch,
                    AutomaticTaskTemplateIds.PreTranslateFiles,
                    AutomaticTaskTemplateIds.AnalyzeFiles,
                    AutomaticTaskTemplateIds.UpdateMainTranslationMemories
                });

                if (taskSequence.Status.Equals(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);
                }

                newProject.Save();
            }
            Controller.RefreshProjects();
            if (Directory.Exists(Path.GetDirectoryName(newProject.FilePath)))
            {
                CreateMetadataFolder(package.Location, package.PathToPrjFile);

                Controller.RefreshProjects();
            }
            return(null);
        }
Example #30
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();
        }