示例#1
0
        /// <summary>
        /// import data from TMX
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="tmxFilePath"></param>
        /// <param name="TUsCountExpected">count of TUs in TMX file</param>
        /// <returns></returns>
        public bool ImportData(DataImportSettings settings, string tmxFilePath, int TUsCountExpected)
        {
            if (NewTM != null)
            {
                Importer tmxImp = new Importer(NewTM, settings);
                tmxImp.OnProgress += new Importer.OnProgressDelegate(updateImportProgress);
                tmxImp.Import(tmxFilePath, TUsCountExpected);
                TUsCount += tmxImp.TUsImported;

                return(true);
            }
            return(false);
        }
示例#2
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);
        }
示例#3
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);
        }