예제 #1
0
        /// <summary>
        /// removes duplicates from file
        /// </summary>
        /// <param name="settings">import operation settings</param>
        public void RemoveDuplicates(DataImportSettings settings)
        {
            settings.OverwriteExistingTUs = true;

            // export TM to TMX
            Exporter tmExp = new Exporter();

            tmExp.OnProgress += new Exporter.OnProgressDelegate(updateProgress);
            tmExp.Export(_tm);
            TUsExportedCount = tmExp.TUsExported;

            // create new TM with reverted index
            TMCreator tmCreator = new TMCreator(_tm.FilePath);

            tmCreator.OnProgress += new TMCreator.OnProgressDelegate(updateProgress);
            tmCreator.CreateNewTM(_tm, false);

            if (_password != null && _password.Length > 0 && settings.PreservePsw)
            {
                tmCreator.SetAdminProtection(_password);
            }

            // if any TUs were exported - import data to new TM
            if (tmExp.TMXPath.Length > 0 && File.Exists(tmExp.TMXPath))
            {
                if (tmCreator.ImportData(settings, tmExp.TMXPath, TUsExportedCount))
                {
                    FileBasedTranslationMemory tmImport = new FileBasedTranslationMemory(tmCreator.FilePath);
                    TUsImportedCount = tmImport.GetTranslationUnitCount();
                }
                else
                {
                    throw new InvalidDataException(Properties.StringResource.errImportTMX);
                }

                File.Delete(tmExp.TMXPath);
            }

            // manage files
            ManageFileNames(tmCreator.FilePath, TMFilePath, settings.CreateBackupFile);
        }
예제 #2
0
        /// <summary>
        /// performs index revert operation
        /// </summary>
        /// <param name="newFilePath">path for file with reverted index</param>
        /// <param name="settings">import operation settings</param>
        public void ReverseIndex(string newFilePath, DataImportSettings settings)
        {
            // export TM to TMX
            Exporter tmExp = new Exporter();

            tmExp.OnProgress += new Exporter.OnProgressDelegate(updateProgress);
            tmExp.Export(_tm);
            TUsExportedCount = tmExp.TUsExported;

            // create new TM with reverted index
            TMCreator tmCreator = new TMCreator(_tm.FilePath);

            tmCreator.OnProgress += new TMCreator.OnProgressDelegate(updateProgress);
            tmCreator.CreateNewTM(_tm, true);

            if (_password != null && _password.Length > 0 && settings.PreservePsw)
            {
                tmCreator.SetAdminProtection(_password);
            }

            // if any TUs were exported - import data to new TM
            if (tmExp.TMXPath.Length > 0 && File.Exists(tmExp.TMXPath))
            {
                if (tmCreator.ImportData(settings, tmExp.TMXPath, TUsExportedCount))
                {
                    FileBasedTranslationMemory tmImport = new FileBasedTranslationMemory(tmCreator.FilePath);
                    TUsImportedCount = tmImport.GetTranslationUnitCount();
                }
                else
                {
                    throw new InvalidDataException();
                }

                File.Delete(tmExp.TMXPath);
            }

            // manage files
            newFilePath = FileHelper.ChangeFileName(newFilePath, @"{0}\{1}({2}).sdltm");
            ManageFileNames(tmCreator.FilePath, newFilePath, false);
        }