/// <summary>
        /// Handles the SelectedIndexChanged event of the SelectedTemplate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void SelectedTemplate_SelectedIndexChanged(object sender, EventArgs e)
        {
            ApplyTemplate selectedTemplate = SelectedTemplate.SelectedItem as ApplyTemplate;

            if (SelectedTemplate.SelectedIndex > 0)
            {
                _languageMatches = Helpers.Matches(_projectController.SelectedProjects.ToList(), ActiveTemplate);
            }
            if (!_languageMatches)
            {
                MessageBox.Show(@"Selected template has language directions different from selected project.", @"Wanning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            TranslationProvidersAllLanguages.SelectedItem      = selectedTemplate.TranslationProvidersAllLanguages.ToString();
            TranslationProvidersSpecificLanguages.SelectedItem = selectedTemplate.TranslationProvidersSpecificLanguages.ToString();
            TranslationMemoriesAllLanguages.SelectedItem       = selectedTemplate.TranslationMemoriesAllLanguages.ToString();
            TranslationMemoriesSpecificLanguages.SelectedItem  = selectedTemplate.TranslationMemoriesSpecificLanguages.ToString();
            TerminologyTermbases.SelectedItem            = selectedTemplate.TerminologyTermbases.ToString();
            TerminologySearchSettings.SelectedItem       = selectedTemplate.TerminologySearchSettings.ToString();
            TranslationQualityAssessment.SelectedItem    = selectedTemplate.TranslationQualityAssessment.ToString();
            BatchTasksAllLanguages.SelectedItem          = selectedTemplate.BatchTasksAllLanguages.ToString();
            BatchTasksSpecificLanguages.SelectedItem     = selectedTemplate.BatchTasksSpecificLanguages.ToString();
            VerificationQaChecker30.SelectedItem         = selectedTemplate.VerificationQaChecker30.ToString();
            VerificationTagVerifier.SelectedItem         = selectedTemplate.VerificationTagVerifier.ToString();
            VerificationTerminologyVerifier.SelectedItem = selectedTemplate.VerificationTerminologyVerifier.ToString();
            VerificationNumberVerifier.SelectedItem      = selectedTemplate.VerificationNumberVerifier.ToString();
            VerificationGrammarChecker.SelectedItem      = selectedTemplate.VerificationGrammarChecker.ToString();
            FileTypes.SelectedItem      = selectedTemplate.FileTypes.ToString();
            matchRepairBox.SelectedItem = selectedTemplate.MatchRepairSettings.ToString();
            CheckChanged();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the project templates.
        /// </summary>
        public void SaveProjectTemplates()
        {
            string            projectTemplatesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"SDL\ASPT.xml");
            XmlWriterSettings settings             = new XmlWriterSettings();

            settings.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(projectTemplatesPath, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("templates");
                writer.WriteAttributeString("default", (this.SelectedTemplate.SelectedItem as ApplyTemplate).Id.ToString("D"));
                writer.WriteAttributeString("apply", (string)this.ApplyTo.SelectedItem);
                writer.WriteAttributeString("tooltips", this.ShowToolTips.Checked ? "1" : "0");
                writer.WriteAttributeString("warning", this.showWarning ? "1" : "0");
                foreach (object comboObject in this.SelectedTemplate.Items)
                {
                    ApplyTemplate comboTemplate = comboObject as ApplyTemplate;
                    if (comboTemplate.Id != Guid.Empty)
                    {
                        comboTemplate.WriteXml(writer);
                    }
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();
                writer.Close();
            }
        }
Exemplo n.º 3
0
 public static bool Matches(List <FileBasedProject> selectedProjects, ApplyTemplate selectedTemplate)
 {
     foreach (var selectedProject in selectedProjects)
     {
         var projectInfo = selectedProject.GetProjectInfo();
         if (projectInfo == null)
         {
             continue;
         }
         var templatePath             = selectedTemplate.Uri != null ? selectedTemplate.Uri.LocalPath : selectedTemplate.FileLocation;
         var projectTemplateLanguages = GetTemplateLanguageDirection(templatePath);
         if (projectInfo.SourceLanguage != null)
         {
             var sourceLanguage = projectInfo.SourceLanguage.CultureInfo.Name;
             if (projectInfo.TargetLanguages != null)
             {
                 var targetLanguages  = projectInfo.TargetLanguages.ToList();
                 var matchesLanguages =
                     ProjectLanguageMatchesTemplate(projectTemplateLanguages, sourceLanguage, targetLanguages);
                 if (!matchesLanguages)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the Click event of the EditTemplatesButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void EditTemplatesButton_Click(object sender, EventArgs e)
        {
            // Prepare the edit templates dialog
            EditApplyTemplates editTemplates = new EditApplyTemplates();
            ApplyTemplate      comboTemplate = null;

            foreach (object comboObject in this.SelectedTemplate.Items)
            {
                comboTemplate = comboObject as ApplyTemplate;
                if (!string.IsNullOrEmpty(comboTemplate.FileLocation))
                {
                    editTemplates.ProjectTemplatesItems.Add(comboTemplate);
                }
            }

            // Show the dialog and check the result
            if (editTemplates.ShowDialog() == DialogResult.OK)
            {
                // Remember which item is selected
                Guid selectedId = (this.SelectedTemplate.SelectedItem as ApplyTemplate).Id;

                // Remove any templates which are not part of the Studio default list
                int itemCount = 0;
                while (itemCount < this.SelectedTemplate.Items.Count)
                {
                    comboTemplate = this.SelectedTemplate.Items[itemCount] as ApplyTemplate;
                    if (comboTemplate.Uri == null)
                    {
                        this.SelectedTemplate.Items.RemoveAt(itemCount);
                    }
                    else
                    {
                        itemCount++;
                    }
                }

                // Add in each template from the dialog
                foreach (object o in editTemplates.ProjectTemplatesItems)
                {
                    this.SelectedTemplate.Items.Add(o);
                }

                // Add a default template if necessary
                if (this.SelectedTemplate.Items.Count == 0)
                {
                    this.SelectedTemplate.Items.Add(new ApplyTemplate("<none>"));
                }

                // Select the previously selected template
                this.SelectTemplate(selectedId);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles the SelectedIndexChanged event of the SelectedTemplate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void SelectedTemplate_SelectedIndexChanged(object sender, EventArgs e)
        {
            ApplyTemplate selectedTemplate = this.SelectedTemplate.SelectedItem as ApplyTemplate;

            this.TranslationProvidersAllLanguages.SelectedItem      = selectedTemplate.TranslationProvidersAllLanguages.ToString();
            this.TranslationProvidersSpecificLanguages.SelectedItem = selectedTemplate.TranslationProvidersSpecificLanguages.ToString();
            this.TranslationMemoriesAllLanguages.SelectedItem       = selectedTemplate.TranslationMemoriesAllLanguages.ToString();
            this.TranslationMemoriesSpecificLanguages.SelectedItem  = selectedTemplate.TranslationMemoriesSpecificLanguages.ToString();
            this.TerminologyTermbases.SelectedItem            = selectedTemplate.TerminologyTermbases.ToString();
            this.TerminologySearchSettings.SelectedItem       = selectedTemplate.TerminologySearchSettings.ToString();
            this.BatchTasksAllLanguages.SelectedItem          = selectedTemplate.BatchTasksAllLanguages.ToString();
            this.BatchTasksSpecificLanguages.SelectedItem     = selectedTemplate.BatchTasksSpecificLanguages.ToString();
            this.VerificationQaChecker30.SelectedItem         = selectedTemplate.VerificationQaChecker30.ToString();
            this.VerificationTagVerifier.SelectedItem         = selectedTemplate.VerificationTagVerifier.ToString();
            this.VerificationTerminologyVerifier.SelectedItem = selectedTemplate.VerificationTerminologyVerifier.ToString();
            this.VerificationNumberVerifier.SelectedItem      = selectedTemplate.VerificationNumberVerifier.ToString();
            this.VerificationGrammarChecker.SelectedItem      = selectedTemplate.VerificationGrammarChecker.ToString();
            this.FileTypes.SelectedItem = selectedTemplate.FileTypes.ToString();
            this.CheckChanged();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the Click event of the AddTemplate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void AddTemplate_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.CheckFileExists = true;
            ofd.Filter          = "SDL Trados Studio Templates|*.sdltpl|SDL Trados Studio Projects|*.sdlproj|All Files|*.*";
            ofd.FilterIndex     = 1;
            ofd.Multiselect     = false;
            ofd.Title           = "Add template";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                ApplyTemplate newTemplate = ProjectTemplatesItems.AddNew();
                newTemplate.Name               = Path.GetFileNameWithoutExtension(ofd.FileName);
                newTemplate.FileLocation       = ofd.FileName;
                newTemplate.Uri                = null;
                newTemplate.Id                 = Guid.NewGuid();
                ProjectTemplates.SelectedItem  = newTemplate;
                ProjectTemplates.DisplayMember = string.Empty;
                ProjectTemplates.DisplayMember = "Name";
            }
        }
        /// <summary>
        /// Loads the project templates.
        /// </summary>
        /// <param name="controller">The controller.</param>
        private void LoadProjectTemplates(ProjectsController controller)
        {
            // Add in the project templates defined in Studio
            foreach (var templateInfo in controller.GetProjectTemplates())
            {
                if (File.Exists(templateInfo.Uri.LocalPath))
                {
                    var newTemplate = new ApplyTemplate(templateInfo);
                    SelectedTemplate.Items.Add(newTemplate);
                }
            }

            // Add in any extra templates manually defined
            var selectedId = Guid.Empty;

            ApplyTo.SelectedIndex = 0;
            var projectTemplatesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"SDL\ASPT.xml");

            if (File.Exists(projectTemplatesPath))
            {
                try
                {
                    var templatesXml = new XmlDocument();
                    templatesXml.Load(projectTemplatesPath);

                    if (templatesXml.DocumentElement.HasAttribute("default"))
                    {
                        selectedId = new Guid(templatesXml.DocumentElement.Attributes["default"].Value);
                    }

                    if (templatesXml.DocumentElement.HasAttribute("apply"))
                    {
                        ApplyTo.SelectedItem = templatesXml.DocumentElement.Attributes["apply"].Value;
                    }

                    if (templatesXml.DocumentElement.HasAttribute("tooltips"))
                    {
                        ShowToolTips.Checked = templatesXml.DocumentElement.Attributes["tooltips"].Value == "1";
                    }

                    if (templatesXml.DocumentElement.HasAttribute("warning"))
                    {
                        _showWarning = templatesXml.DocumentElement.Attributes["warning"].Value == "1";
                    }

                    foreach (XmlNode templateXml in templatesXml.SelectNodes("//template"))
                    {
                        ApplyTemplate newTemplate = new ApplyTemplate(templateXml);
                        if (string.IsNullOrEmpty(newTemplate.FileLocation))
                        {
                            foreach (object o in SelectedTemplate.Items)
                            {
                                ApplyTemplate thisTemplate = o as ApplyTemplate;
                                if (thisTemplate.Id == newTemplate.Id)
                                {
                                    thisTemplate.TranslationProvidersAllLanguages      = newTemplate.TranslationProvidersAllLanguages;
                                    thisTemplate.TranslationProvidersSpecificLanguages = newTemplate.TranslationProvidersSpecificLanguages;
                                    thisTemplate.TranslationMemoriesAllLanguages       = newTemplate.TranslationMemoriesAllLanguages;
                                    thisTemplate.TranslationMemoriesSpecificLanguages  = newTemplate.TranslationMemoriesSpecificLanguages;
                                    thisTemplate.TerminologyTermbases            = newTemplate.TerminologyTermbases;
                                    thisTemplate.TerminologySearchSettings       = newTemplate.TerminologySearchSettings;
                                    thisTemplate.TranslationQualityAssessment    = newTemplate.TranslationQualityAssessment;
                                    thisTemplate.VerificationQaChecker30         = newTemplate.VerificationQaChecker30;
                                    thisTemplate.VerificationTagVerifier         = newTemplate.VerificationTagVerifier;
                                    thisTemplate.VerificationTerminologyVerifier = newTemplate.VerificationTerminologyVerifier;
                                    thisTemplate.VerificationNumberVerifier      = newTemplate.VerificationNumberVerifier;
                                    thisTemplate.VerificationGrammarChecker      = newTemplate.VerificationGrammarChecker;
                                    thisTemplate.BatchTasksAllLanguages          = newTemplate.BatchTasksAllLanguages;
                                    thisTemplate.BatchTasksSpecificLanguages     = newTemplate.BatchTasksSpecificLanguages;
                                    thisTemplate.FileTypes           = newTemplate.FileTypes;
                                    thisTemplate.MatchRepairSettings = newTemplate.MatchRepairSettings;
                                }
                            }
                        }
                        else
                        {
                            if (File.Exists(newTemplate.FileLocation))
                            {
                                SelectedTemplate.Items.Add(newTemplate);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }

            // Add in a default template if we don't have any defined
            if (SelectedTemplate.Items.Count == 0)
            {
                SelectedTemplate.Items.Add(new ApplyTemplate("<none>"));
            }
            // Select the first one in the list if we haven't selected one yet
            SelectTemplate(selectedId);
        }
        /// <summary>
        /// Executes this instance.
        /// </summary>
        protected override void Execute()
        {
            string          grammarCheckerSettingsId      = "GrammarCheckerSettings";
            string          numberVerifierSettingsId      = "NumberVerifierSettings";
            IExtensionPoint globalVerifiersExtensionPoint = PluginManager.DefaultPluginRegistry.GetExtensionPoint <GlobalVerifierAttribute>();

            foreach (IExtension extension in globalVerifiersExtensionPoint.Extensions)
            {
                IGlobalVerifier globalVerifier  = (IGlobalVerifier)extension.CreateInstance();
                string          settingsGroupId = globalVerifier.SettingsId;
                if (settingsGroupId.Contains("Grammar"))
                {
                    grammarCheckerSettingsId = settingsGroupId;
                }

                if (settingsGroupId.Contains("Number"))
                {
                    numberVerifierSettingsId = settingsGroupId;
                }
            }

            // Show the dialog
            ApplyTemplateForm applyTemplateForm = new ApplyTemplateForm(Controller);

            if (applyTemplateForm.ShowDialog() == DialogResult.OK)
            {
                // This is the template that the user selected
                ApplyTemplate selectedTemplate = applyTemplateForm.ActiveTemplate;

                // Create list of projects
                List <FileBasedProject> selectedProjects = new List <FileBasedProject>();
                if (applyTemplateForm.ApplyToSelected)
                {
                    selectedProjects.AddRange(Controller.SelectedProjects);
                }
                else
                {
                    if (Controller.CurrentProject != null)
                    {
                        selectedProjects.Add(Controller.CurrentProject);
                    }
                }

                // Check if we have any projects
                if (selectedProjects.Count == 0)
                {
                    MessageBox.Show(applyTemplateForm.ApplyToSelected ? PluginResources.No_Projects_Selected : PluginResources.No_Current_Project, PluginResources.Plugin_Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Work through all projects
                StringBuilder projectsList = new StringBuilder();
                projectsList.AppendLine(PluginResources.Settings_Applied);
                foreach (FileBasedProject targetProject in selectedProjects)
                {
                    // Temporary folder path
                    string tempFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

                    // This is the current project and it's related information
                    ProjectInfo targetProjectInfo = targetProject.GetProjectInfo();
                    projectsList.AppendLine(targetProjectInfo.Name);
                    ISettingsBundle targetSettingsBundle = targetProject.GetSettings();

                    // This is the source project - check if it's a loaded one
                    FileBasedProject sourceProject = Controller.GetAllProjects().FirstOrDefault(loadedProject => String.Compare(loadedProject.FilePath, selectedTemplate.FileLocation, StringComparison.OrdinalIgnoreCase) == 0);

                    // Not found so load it from the filing system
                    if (sourceProject == null)
                    {
                        if (string.IsNullOrEmpty(selectedTemplate.FileLocation))
                        {
                            if (selectedTemplate.Id != Guid.Empty)
                            {
                                // Create a new project based on a template configured in Studio
                                ProjectTemplateReference projectTemplate = new ProjectTemplateReference(selectedTemplate.Uri);
                                string savedFolder = targetProjectInfo.LocalProjectFolder;
                                targetProjectInfo.LocalProjectFolder = tempFolder;
                                sourceProject = new FileBasedProject(targetProjectInfo, projectTemplate);
                                targetProjectInfo.LocalProjectFolder = savedFolder;
                            }
                        }
                        else
                        {
                            if (Path.GetExtension(selectedTemplate.FileLocation).ToLowerInvariant() == ".sdltpl")
                            {
                                // Create a new project based on a file-based template
                                ProjectTemplateReference projectTemplate = new ProjectTemplateReference(selectedTemplate.FileLocation);
                                string savedFolder = targetProjectInfo.LocalProjectFolder;
                                targetProjectInfo.LocalProjectFolder = tempFolder;
                                sourceProject = new FileBasedProject(targetProjectInfo, projectTemplate);
                                targetProjectInfo.LocalProjectFolder = savedFolder;
                            }
                            else
                            {
                                // Load a project from the filing system
                                sourceProject = new FileBasedProject(selectedTemplate.FileLocation);
                            }
                        }
                    }

                    // Get the information from the source project
                    ProjectInfo     sourceProjectInfo    = sourceProject.GetProjectInfo();
                    ISettingsBundle sourceSettingsBundle = sourceProject.GetSettings();

                    // Copy all languages translation providers
                    if (selectedTemplate.TranslationProvidersAllLanguages != ApplyTemplateOptions.Keep)
                    {
                        try
                        {
                            // Update the "all languages" node
                            TranslationProviderConfiguration sourceProviderConfig = sourceProject.GetTranslationProviderConfiguration();
                            if (selectedTemplate.TranslationProvidersAllLanguages == ApplyTemplateOptions.Merge)
                            {
                                TranslationProviderConfiguration targetProviderConfig = targetProject.GetTranslationProviderConfiguration();
                                MergeTranslationProviders(sourceProviderConfig, targetProviderConfig);
                                ValidateTranslationProviderConfiguration(targetProviderConfig);
                                targetProject.UpdateTranslationProviderConfiguration(targetProviderConfig);
                            }
                            else
                            {
                                ValidateTranslationProviderConfiguration(sourceProviderConfig);
                                targetProject.UpdateTranslationProviderConfiguration(sourceProviderConfig);
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.TPAL_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    // Copy language-specific translation providers
                    if (selectedTemplate.TranslationProvidersSpecificLanguages != ApplyTemplateOptions.Keep)
                    {
                        if (sourceProjectInfo.SourceLanguage.Equals(targetProjectInfo.SourceLanguage))
                        {
                            foreach (Language sourceTargetLanguage in sourceProjectInfo.TargetLanguages)
                            {
                                foreach (Language targetTargetLanguage in targetProjectInfo.TargetLanguages)
                                {
                                    if (sourceTargetLanguage.Equals(targetTargetLanguage))
                                    {
                                        try
                                        {
                                            // Copy translation providers
                                            TranslationProviderConfiguration sourceProviderConfig = sourceProject.GetTranslationProviderConfiguration(sourceTargetLanguage);
                                            if (selectedTemplate.TranslationProvidersSpecificLanguages == ApplyTemplateOptions.Merge)
                                            {
                                                TranslationProviderConfiguration targetProviderConfig = targetProject.GetTranslationProviderConfiguration(targetTargetLanguage);
                                                MergeTranslationProviders(sourceProviderConfig, targetProviderConfig);
                                                ValidateTranslationProviderConfiguration(targetProviderConfig);
                                                targetProject.UpdateTranslationProviderConfiguration(targetTargetLanguage, targetProviderConfig);
                                            }
                                            else
                                            {
                                                ValidateTranslationProviderConfiguration(sourceProviderConfig);
                                                targetProject.UpdateTranslationProviderConfiguration(targetTargetLanguage, sourceProviderConfig);
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            MessageBox.Show(e.Message, string.Format(PluginResources.TPSL_Failed, targetTargetLanguage.DisplayName), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Copy TM settings for all languages
                    if (selectedTemplate.TranslationMemoriesAllLanguages == ApplyTemplateOptions.Overwrite)
                    {
                        try
                        {
                            // Update the translation memory filter settings
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "TranslationMemorySettings", targetProject, null);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.TMAL_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    // Copy TM settings for specific languages
                    if (selectedTemplate.TranslationMemoriesSpecificLanguages == ApplyTemplateOptions.Overwrite)
                    {
                        if (sourceProjectInfo.SourceLanguage.Equals(targetProjectInfo.SourceLanguage))
                        {
                            foreach (Language sourceTargetLanguage in sourceProjectInfo.TargetLanguages)
                            {
                                foreach (Language targetTargetLanguage in targetProjectInfo.TargetLanguages)
                                {
                                    if (sourceTargetLanguage.Equals(targetTargetLanguage))
                                    {
                                        try
                                        {
                                            // Now copy translation memory settings - different section
                                            ISettingsBundle sourceTmSettings = sourceProject.GetSettings(sourceTargetLanguage);
                                            ISettingsBundle targetTmSettings = targetProject.GetSettings(targetTargetLanguage);
                                            CopySettingsGroup(sourceTmSettings, targetTmSettings, "TranslationMemorySettings", targetProject, targetTargetLanguage);
                                        }
                                        catch (Exception e)
                                        {
                                            MessageBox.Show(e.Message, string.Format(PluginResources.TMSL_Failed, targetTargetLanguage.DisplayName), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Copy terminology termbases
                    if (selectedTemplate.TerminologyTermbases != ApplyTemplateOptions.Keep)
                    {
                        TermbaseConfiguration sourceTermbaseConfig = sourceProject.GetTermbaseConfiguration();
                        TermbaseConfiguration targetTermbaseConfig = targetProject.GetTermbaseConfiguration();

                        if (selectedTemplate.TerminologyTermbases == ApplyTemplateOptions.Merge)
                        {
                            MergeTermbases(sourceTermbaseConfig, targetTermbaseConfig);
                        }
                        else
                        {
                            targetTermbaseConfig.TermbaseServerUri = sourceTermbaseConfig.TermbaseServerUri;
                            targetTermbaseConfig.Termbases.Clear();
                            targetTermbaseConfig.LanguageIndexes.Clear();
                            MergeTermbases(sourceTermbaseConfig, targetTermbaseConfig);
                        }

                        // Updating with zero termbases throws an exception
                        if (targetTermbaseConfig.Termbases.Count > 0)
                        {
                            try
                            {
                                targetProject.UpdateTermbaseConfiguration(targetTermbaseConfig);
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.Message, PluginResources.TBTB_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }

                    // Copy terminology settings
                    if (selectedTemplate.TerminologySearchSettings == ApplyTemplateOptions.Overwrite)
                    {
                        TermbaseConfiguration sourceTermbaseConfig = sourceProject.GetTermbaseConfiguration();
                        TermbaseConfiguration targetTermbaseConfig = targetProject.GetTermbaseConfiguration();
                        targetTermbaseConfig.TermRecognitionOptions = sourceTermbaseConfig.TermRecognitionOptions;

                        // Updating with zero termbases throws an exception
                        if (targetTermbaseConfig.Termbases.Count > 0)
                        {
                            try
                            {
                                targetProject.UpdateTermbaseConfiguration(targetTermbaseConfig);
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.Message, PluginResources.TBSS_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }

                    // Copy QA verification settings where applicable
                    if (selectedTemplate.VerificationQaChecker30 == ApplyTemplateOptions.Overwrite)
                    {
                        try
                        {
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "QAVerificationSettings", targetProject, null);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.QAQA_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    // Copy tag verification settings where applicable
                    if (selectedTemplate.VerificationTagVerifier == ApplyTemplateOptions.Overwrite)
                    {
                        try
                        {
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "SettingsTagVerifier", targetProject, null);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.QATG_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    // Copy term verification settings where applicable
                    if (selectedTemplate.VerificationTerminologyVerifier == ApplyTemplateOptions.Overwrite)
                    {
                        try
                        {
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "SettingsTermVerifier", targetProject, null);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.QATV_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    // Copy number verification settings where applicable
                    if (selectedTemplate.VerificationNumberVerifier == ApplyTemplateOptions.Overwrite)
                    {
                        try
                        {
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, numberVerifierSettingsId, targetProject, null);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.QANV_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    // Copy grammar checking settings where applicable
                    if (selectedTemplate.VerificationGrammarChecker == ApplyTemplateOptions.Overwrite)
                    {
                        try
                        {
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, grammarCheckerSettingsId, targetProject, null);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.QAGC_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    // Copy file type settings where applicable
                    if (selectedTemplate.FileTypes == ApplyTemplateOptions.Overwrite)
                    {
                        try
                        {
                            var copiedTypes = new List <string>();
                            foreach (ProjectFile projectFile in targetProject.GetTargetLanguageFiles())
                            {
                                if (!copiedTypes.Contains(projectFile.FileTypeId))
                                {
                                    copiedTypes.Add(projectFile.FileTypeId);
                                    CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, projectFile.FileTypeId, targetProject, null);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.FTTS_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    // Copy batch tasks settings where applicable
                    if (selectedTemplate.BatchTasksAllLanguages == ApplyTemplateOptions.Overwrite)
                    {
                        try
                        {
                            // Update the translation memory filter settings
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "PseudoTranslateSettings", targetProject, null);
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "AnalysisTaskSettings", targetProject, null);
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "VerificationSettings", targetProject, null);
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "TranslateTaskSettings", targetProject, null);
                            CopySettingsGroup(sourceSettingsBundle, targetSettingsBundle, "TranslationMemoryUpdateTaskSettings", targetProject, null);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message, PluginResources.BTAL_Failed, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }

                    if (selectedTemplate.BatchTasksSpecificLanguages == ApplyTemplateOptions.Overwrite)
                    {
                        // Update specific language pairs where possible
                        if (sourceProjectInfo.SourceLanguage.Equals(targetProjectInfo.SourceLanguage))
                        {
                            foreach (Language sourceTargetLanguage in sourceProjectInfo.TargetLanguages)
                            {
                                foreach (Language targetTargetLanguage in targetProjectInfo.TargetLanguages)
                                {
                                    if (sourceTargetLanguage.Equals(targetTargetLanguage))
                                    {
                                        try
                                        {
                                            // Now copy translation memory settings - different section
                                            ISettingsBundle sourceTmSettings = sourceProject.GetSettings(sourceTargetLanguage);
                                            ISettingsBundle targetTmSettings = targetProject.GetSettings(targetTargetLanguage);
                                            CopySettingsGroup(sourceTmSettings, targetTmSettings, "PseudoTranslateSettings", targetProject, targetTargetLanguage);
                                            CopySettingsGroup(sourceTmSettings, targetTmSettings, "AnalysisTaskSettings", targetProject, targetTargetLanguage);
                                            CopySettingsGroup(sourceTmSettings, targetTmSettings, "VerificationSettings", targetProject, targetTargetLanguage);
                                            CopySettingsGroup(sourceTmSettings, targetTmSettings, "TranslateTaskSettings", targetProject, targetTargetLanguage);
                                            CopySettingsGroup(sourceTmSettings, targetTmSettings, "TranslationMemoryUpdateTaskSettings", targetProject, targetTargetLanguage);
                                        }
                                        catch (Exception e)
                                        {
                                            MessageBox.Show(e.Message, string.Format(PluginResources.BTSL_Failed, targetTargetLanguage.DisplayName), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // Remove the temporary folder if it exists
                    if (Directory.Exists(tempFolder))
                    {
                        Directory.Delete(tempFolder, true);
                    }

                    // Use reflection to synch the project to the server
                    try
                    {
                        var project = typeof(FileBasedProject).GetField("_project", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(targetProject);
                        project.GetType().GetMethod("UpdateServerProjectSettings").Invoke(project, null);
                    }
                    catch
                    {
                    }
                }

                // Tell the user we're done
                MessageBox.Show(projectsList.ToString(), PluginResources.Plugin_Name, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            // Save the project templates anyway
            applyTemplateForm.SaveProjectTemplates();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Loads the project templates.
        /// </summary>
        /// <param name="controller">The controller.</param>
        private void LoadProjectTemplates(ProjectsController controller)
        {
            // Add in the project templates defined in Studio
            foreach (ProjectTemplateInfo templateInfo in controller.GetProjectTemplates())
            {
                ApplyTemplate newTemplate = new ApplyTemplate(templateInfo);
                this.SelectedTemplate.Items.Add(newTemplate);
            }

            // Add in any extra templates manually defined
            Guid selectedId = Guid.Empty;
            this.ApplyTo.SelectedIndex = 0;
            string projectTemplatesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"SDL\ASPT.xml");
            if (File.Exists(projectTemplatesPath))
            {
                try
                {
                    XmlDocument templatesXml = new XmlDocument();
                    templatesXml.Load(projectTemplatesPath);

                    if (templatesXml.DocumentElement.HasAttribute("default"))
                    {
                        selectedId = new Guid(templatesXml.DocumentElement.Attributes["default"].Value);
                    }

                    if (templatesXml.DocumentElement.HasAttribute("apply"))
                    {
                        this.ApplyTo.SelectedItem = templatesXml.DocumentElement.Attributes["apply"].Value;
                    }

                    if (templatesXml.DocumentElement.HasAttribute("tooltips"))
                    {
                        this.ShowToolTips.Checked = templatesXml.DocumentElement.Attributes["tooltips"].Value == "1";
                    }

                    if (templatesXml.DocumentElement.HasAttribute("warning"))
                    {
                        this.showWarning = templatesXml.DocumentElement.Attributes["warning"].Value == "1";
                    }

                    foreach (XmlNode templateXml in templatesXml.SelectNodes("//template"))
                    {
                        ApplyTemplate newTemplate = new ApplyTemplate(templateXml);
                        if (string.IsNullOrEmpty(newTemplate.FileLocation))
                        {
                            foreach (object o in this.SelectedTemplate.Items)
                            {
                                ApplyTemplate thisTemplate = o as ApplyTemplate;
                                if (thisTemplate.Id == newTemplate.Id)
                                {
                                    thisTemplate.TranslationProvidersAllLanguages = newTemplate.TranslationProvidersAllLanguages;
                                    thisTemplate.TranslationProvidersSpecificLanguages = newTemplate.TranslationProvidersSpecificLanguages;
                                    thisTemplate.TranslationMemoriesAllLanguages = newTemplate.TranslationMemoriesAllLanguages;
                                    thisTemplate.TranslationMemoriesSpecificLanguages = newTemplate.TranslationMemoriesSpecificLanguages;
                                    thisTemplate.TerminologyTermbases = newTemplate.TerminologyTermbases;
                                    thisTemplate.TerminologySearchSettings = newTemplate.TerminologySearchSettings;
                                    thisTemplate.VerificationQaChecker30 = newTemplate.VerificationQaChecker30;
                                    thisTemplate.VerificationTagVerifier = newTemplate.VerificationTagVerifier;
                                    thisTemplate.VerificationTerminologyVerifier = newTemplate.VerificationTerminologyVerifier;
                                    thisTemplate.VerificationNumberVerifier = newTemplate.VerificationNumberVerifier;
                                    thisTemplate.VerificationGrammarChecker = newTemplate.VerificationGrammarChecker;
                                    thisTemplate.BatchTasksAllLanguages = newTemplate.BatchTasksAllLanguages;
                                    thisTemplate.BatchTasksSpecificLanguages = newTemplate.BatchTasksSpecificLanguages;
                                    thisTemplate.FileTypes = newTemplate.FileTypes;
                                }
                            }
                        }
                        else
                        {
                            this.SelectedTemplate.Items.Add(newTemplate);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }

            // Add in a default template if we don't have any defined
            if (this.SelectedTemplate.Items.Count == 0)
            {
                this.SelectedTemplate.Items.Add(new ApplyTemplate("<none>"));
            }

            // Select the first one in the list if we haven't selected one yet
            this.SelectTemplate(selectedId);
        }