Beispiel #1
0
        private void PopulateLanguagePairs()
        {
            if (LanguagePairs == null || LanguagePairs.Length == 0)
            {
                return;
            }

            GenericCredentials credentials = GetCredentials();

            if (!AuthenticateCredentials(credentials, false))
            {
                return;
            }

            if (Options.APIVersion != ETSApi.APIVersion.v2)
            {
                return;
            }

            var languagePairChoices = Options.SetPreferredLanguages(LanguagePairs);

            // Since this is run on a separate thread, use invoke to communicate with the master thread.
            TradosLPs.Invoke(new Action(() =>
            {
                // This gets called multiple times, so let's clear out the old contents
                TradosLPs.Columns.Clear();
                TradosLPs.AutoGenerateColumns = false;

                DataGridViewTextBoxColumn targetColumn = new DataGridViewTextBoxColumn();
                targetColumn.Name             = "Target Language";
                targetColumn.DataPropertyName = "TradosCulture";
                targetColumn.ReadOnly         = true;

                DataGridViewComboBoxColumn lpChoicesColumn = new DataGridViewComboBoxColumn();
                lpChoicesColumn.Name      = "SDL ETS Language Pair";
                lpChoicesColumn.FlatStyle = FlatStyle.Flat;

                TradosLPs.Columns.AddRange(new DataGridViewColumn[] { targetColumn, lpChoicesColumn });
                // Handler for populating combobox
                TradosLPs.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(TradosLPs_DataBindingComplete);

                TradosLPs.DataSource = languagePairChoices;

                // Handlers for when the combobox changes
                TradosLPs.CellValueChanged             += new DataGridViewCellEventHandler(TradosLPs_CellValueChanged);
                TradosLPs.CurrentCellDirtyStateChanged += new EventHandler(TradosLPs_CurrentCellDirtyStateChanged);
            }));
        }
        /// <summary>
        /// Set the TradosLPs grid values
        /// </summary>
        /// <param name="lpChoicesColumn">lpChoicesColumn</param>
        /// <param name="lpDictionariesColumn">lpDictionariesColumn</param>
        /// <param name="languagePairChoices">languagePairChoicess</param>
        private void SetTradosLPs(
            DataGridViewComboBoxColumn lpChoicesColumn,
            DataGridViewComboBoxColumn lpDictionariesColumn,
            TradosToMTEdgeLP[] languagePairChoices)
        {
            TradosLPs.Invoke(new Action(() =>
            {
                // This gets called multiple times, so let's clear out the old contents
                TradosLPs.Columns.Clear();
                TradosLPs.AutoGenerateColumns = false;

                var targetColumn = new DataGridViewTextBoxColumn
                {
                    Name             = "Target Language",
                    DataPropertyName = "TradosCulture",
                    ReadOnly         = true
                };

                lpChoicesColumn.Name      = "SDL MT Edge Language Pair";
                lpChoicesColumn.FlatStyle = FlatStyle.Flat;

                lpDictionariesColumn.Name      = "SDL MT Edge Dictionaries";
                lpDictionariesColumn.FlatStyle = FlatStyle.Flat;

                TradosLPs.Columns.AddRange(targetColumn, lpChoicesColumn, lpDictionariesColumn);

                // Handler for populating combobox
                TradosLPs.DataBindingComplete += TradosLPs_DataBindingComplete;
                TradosLPs.DataSource           = languagePairChoices;

                // Handlers for when the combobox changes
                TradosLPs.CellValueChanged             += TradosLPs_CellValueChanged;
                TradosLPs.CurrentCellDirtyStateChanged += TradosLPs_CurrentCellDirtyStateChanged;
                TradosLPs.DataError += TradosLPs_DataError;
                try
                {
                    if (Options?.LPPreferences != null)
                    {
                        RemoveIncorrectLanguageSet();
                        if (Options.LPPreferences.Count > 0)
                        {
                            SetPreferedLanguageFlavours();
                        }                        //set the default value in the case which users add the translation provider in project creation step
                        else
                        {
                            for (var i = 0; i < languagePairChoices.Length; i++)
                            {
                                Options.LPPreferences[languagePairChoices[i].TradosCulture] = languagePairChoices[i].MtEdgeLPs?.FirstOrDefault();
                                var comboBox   = (DataGridViewComboBoxCell)TradosLPs?.Rows[i].Cells[1];
                                comboBox.Value = languagePairChoices[i].MtEdgeLPs?.FirstOrDefault()?.LanguagePairId;
                            }
                        }
                    }
                    FinishButton.Enabled = true;
                }
                catch (Exception e)
                {
                    FinishButton.Enabled = true;
                    Log.Logger.Error($"{e.Message}\n {e.StackTrace}");
                }
            }));
        }
        private void PopulateLanguagePairs()
        {
            if (LanguagePairs == null || LanguagePairs.Length == 0)
            {
                return;
            }
            var credentials = GetCredentials();

            if (!AuthenticateCredentials(credentials, false))
            {
                return;
            }

            if (Options.ApiVersion != ETSApi.APIVersion.v2)
            {
                return;
            }
            var languagePairChoices = Options.SetPreferredLanguages(LanguagePairs);

            // Since this is run on a separate thread, use invoke to communicate with the master thread.
            var lpChoicesColumn = new DataGridViewComboBoxColumn();

            TradosLPs.Invoke(new Action(() =>
            {
                // This gets called multiple times, so let's clear out the old contents
                TradosLPs.Columns.Clear();
                TradosLPs.AutoGenerateColumns = false;

                var targetColumn = new DataGridViewTextBoxColumn
                {
                    Name             = "Target Language",
                    DataPropertyName = "TradosCulture",
                    ReadOnly         = true
                };

                lpChoicesColumn.Name      = "SDL ETS Language Pair";
                lpChoicesColumn.FlatStyle = FlatStyle.Flat;

                TradosLPs.Columns.AddRange(targetColumn, lpChoicesColumn);
                // Handler for populating combobox
                TradosLPs.DataBindingComplete += TradosLPs_DataBindingComplete;

                TradosLPs.DataSource = languagePairChoices;

                // Handlers for when the combobox changes
                TradosLPs.CellValueChanged             += TradosLPs_CellValueChanged;
                TradosLPs.CurrentCellDirtyStateChanged += TradosLPs_CurrentCellDirtyStateChanged;
                TradosLPs.DataError += TradosLPs_DataError;
                try
                {
                    if (Options?.LPPreferences != null)
                    {
                        if (Options.LPPreferences.Count > 0)
                        {
                            SetPreferedLanguageFlavours();
                        }                        //set the default value in the case which users add the translation provider in project creation step
                        else
                        {
                            for (var i = 0; i < languagePairChoices.Length; i++)
                            {
                                Options.LPPreferences[languagePairChoices[i].TradosCulture] = languagePairChoices[i].ETSLPs?.FirstOrDefault();
                                var comboBox   = (DataGridViewComboBoxCell)TradosLPs?.Rows[i].Cells[1];
                                comboBox.Value = languagePairChoices[i].ETSLPs?.FirstOrDefault()?.LanguagePairId;
                            }
                        }
                    }
                    FinishButton.Enabled = true;
                }
                catch (Exception e)
                {
                    Log.Logger.Error($"{e.Message}\n {e.StackTrace}");
                }
            }));
        }