Exemplo n.º 1
0
 public static void FillOptions(ModelState state, IntentoMTFormOptions options)
 {
     if (state == null)
     {
         options.UseCustomModel  = false;
         options.CustomModel     = null;
         options.GlossaryMode    = StateModeEnum.unknown;
         options.CustomModelName = null;
         options.FromLanguage    = null;
         options.ToLanguage      = null;
     }
     else
     {
         options.UseCustomModel  = state.UseModel;
         options.CustomModel     = state.ModelName;
         options.CustomModelMode = state.modelMode;
         dynamic mData = null;
         if (state.models != null)
         {
             mData = state.models.Select(x => (dynamic)x.Value).Where(y => (string)y.id == state.ModelName).FirstOrDefault();
         }
         options.CustomModelName = mData != null ? mData.name : state.ModelName;
         options.FromLanguage    = options.CustomModelName == null || !options.UseCustomModel ? null : state.From;
         options.ToLanguage      = options.CustomModelName == null || !options.UseCustomModel ? null : state.To;
     }
 }
Exemplo n.º 2
0
        public ProviderState(SmartRoutingState smartRoutingState, IntentoMTFormOptions options) : base(smartRoutingState, options)
        {
            this.smartRoutingState = smartRoutingState;

            Init();

            languagePairs       = form.LanguagePairs;
            currentProviderId   = options.ProviderId;
            currentProviderName = options.ProviderName;

            providersRaw = FilterByLanguagePairs(smartRoutingState.apiKeyState.Providers);

            providersData  = providersRaw.ToDictionary(s => (string)s.id, q => q);
            providersNames = providersRaw.ToDictionary(s => (string)s.name, q => (string)q.id);

            formMT.comboBoxProviders.Items.Clear();
            formMT.comboBoxProviders.Items.AddRange(providersNames.Select(x => (string)x.Key).OrderBy(x => x).ToArray());

            dynamic providerDataFromList = null;

            if (!string.IsNullOrEmpty(currentProviderId) && providersData.TryGetValue(currentProviderId, out providerDataFromList))
            {   // Set current provider in combo box
                formMT.comboBoxProviders.SelectedItem = (string)providerDataFromList.name;
                currentProviderName = (string)providerDataFromList.name;
            }
            else
            {
                currentProviderId   = null;
                currentProviderName = null;
            }

            ExtractProviderData();
            isInitialized = true;
        }
Exemplo n.º 3
0
        public IntentoMTFormOptions Duplicate()
        {
            IntentoMTFormOptions res = new IntentoMTFormOptions();

            Fill(res);
            return(res);
        }
Exemplo n.º 4
0
 public void Fill(IntentoMTFormOptions res)
 {
     res.ApiKey               = this.ApiKey;
     res.SmartRouting         = this.SmartRouting;
     res.ProviderId           = this.ProviderId;
     res.ProviderName         = this.ProviderName;
     res.UseCustomAuth        = this.UseCustomAuth;
     res.CustomAuth           = this.CustomAuth;
     res.UseCustomModel       = this.UseCustomModel;
     res.Glossary             = this.Glossary;
     res.CustomModel          = this.CustomModel;
     res.Format               = this.Format;
     res.UserAgent            = this.UserAgent;
     res.Signature            = this.Signature;
     res.AppName              = this.AppName;
     res.Translate            = this.Translate;
     res.ForbidSaveApikey     = this.ForbidSaveApikey;
     res.HideHiddenTextButton = this.HideHiddenTextButton;
     res.CustomSettingsName   = this.CustomSettingsName;
     res.CustomTagParser      = this.CustomTagParser;
     res.CutTag               = this.CutTag;
     res.сallHelpAction       = this.сallHelpAction;
     res.FromLanguage         = this.FromLanguage;
     res.ToLanguage           = this.ToLanguage;
     res.TraceEndTime         = this.TraceEndTime;
     res.MemoqAdditional      = this.MemoqAdditional;
     res.SaveLocally          = this.SaveLocally;
     res.Routing              = this.Routing;
     res.RoutingDisplayName   = this.RoutingDisplayName;
     res._authDict            = _authDict == null ? null : new Dictionary <string, string>(_authDict);
 }
Exemplo n.º 5
0
        public void ClearOptions(IntentoMTFormOptions options)
        {
            options.UseCustomModel = false;
            options.CustomModel    = null;
            Model_Group_Enabled(formMT, false);

            Clear();
        }
Exemplo n.º 6
0
 public void ClearOptions(IntentoMTFormOptions options)
 {
     options.UseCustomAuth = false;
     options.CustomAuth    = null;
     formMT.comboBoxCredentialId.Visible = true;
     Clear();
     ResetChildrensState();
 }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_form"></param>
        /// <param name="_options"></param>
        /// <param name="fromForm">Call from event, change of form check box may result recourcing</param>
        public AuthState(ProviderState providerState, IntentoMTFormOptions _options, bool fromForm = false) : base(providerState, _options)
        {
            this.providerState = providerState;
            formMT             = providerState.form.formMT;
            options            = _options;

            // set mode of checkBoxUseOwnCred
            if (!providerState.billable || !providerState.stock_model)  // Auth Required
            {
                formMT.groupBoxBillingAccount.Enabled = true;
                //if (!fromForm)
                //{
                //    Internal_Change_checkBoxUseOwnCred_Checked(formMT, true);
                //    formMT.checkBoxUseOwnCred.Enabled = false;
                //}
                mode = StateModeEnum.required;
            }
            else if (!providerState.own_auth) // Auth Prohibited
            {
                formMT.groupBoxBillingAccount.Enabled = false;
                //if (!fromForm)
                //    Internal_Change_checkBoxUseOwnCred_Checked(formMT, false);
                mode = StateModeEnum.prohibited;
            }
            else
            {   // Auth optional
                formMT.groupBoxBillingAccount.Enabled = true;
                //if (!fromForm)
                //    Internal_Change_checkBoxUseOwnCred_Checked(formMT, options.UseCustomAuth);
                mode = StateModeEnum.optional;
            }

            if (!providerState.IsOK)
            {
                // smart routing
                return;
            }

            // Get credentials from Options
            providerDataAuthDict = new Dictionary <string, string>();
            Dictionary <string, string> auth = options.authDict();

            if (providerState.providerAuthList != null)
            {
                foreach (string key in providerState.providerAuthList)
                {
                    if (auth != null && auth.ContainsKey(key))
                    {
                        providerDataAuthDict[key] = auth[key];
                    }
                    else
                    {
                        providerDataAuthDict[key] = "";
                    }
                }
            }
        }
Exemplo n.º 8
0
 public BaseState(BaseState parent, IntentoMTFormOptions options)
 {
     if (parent != null)
     {
         this.parent = parent;
         this.form   = parent.form;
         this.formMT = parent.formMT;
     }
     this.options = options;
 }
Exemplo n.º 9
0
 private void IntentoFormOptionsAPI_Shown(object sender, EventArgs e)
 {
     _options                   = currentOptions;
     labelError.Visible         = false;
     buttonSave.Enabled         = !string.IsNullOrWhiteSpace(apiKey_tb.Text);
     checkBoxShowHidden.Checked = false;
     apiKey_tb.Text             = parent.apiKeyState.apiKey;
     apiKey_tb.BackColor        = parent.apiKeyState.apiKeyStatus == ApiKeyState.EApiKeyStatus.ok ?
                                  SystemColors.Window : Color.LightPink;
     apiKey_tb.TextChanged += apiKey_tb_TextChanged;
 }
Exemplo n.º 10
0
        public void ClearOptions(IntentoMTFormOptions options)
        {
            options.ProviderId   = null;
            options.ProviderName = null;
            options.Format       = null;
            Language_Comboboxes_Fill(null, null);

            if (authState != null)
            {
                authState.ClearOptions(options);
                authState.Clear();
            }
        }
Exemplo n.º 11
0
        public ApiKeyState(IntentoTranslationProviderOptionsForm _form, IntentoMTFormOptions options) : base(_form, options)
        {
            apiKey = options.ApiKey;

            if (!options.ForbidSaveApikey)
            {
                string apiKey2 = _form.GetValueFromRegistry("ApiKey");
                if (string.IsNullOrEmpty(apiKey) && !string.IsNullOrEmpty(options.AppName))
                {   // read ApiKey from registry
                    apiKey = apiKey2;
                }
                if (!string.IsNullOrEmpty(apiKey2))
                {
                    form.formAdvanced.checkBoxSaveApiKeyInRegistry.Checked = true;
                }
            }
        }
Exemplo n.º 12
0
 public static void FillOptions(ProviderState state, IntentoMTFormOptions options)
 {
     if (state == null)
     {
         options.ProviderId   = null;
         options.ProviderName = null;
         options.Format       = null;
         AuthState.FillOptions(null, options);
     }
     else
     {
         options.ProviderId   = state.currentProviderId;
         options.ProviderName = state.CurrentProviderName;
         options.Format       = state.format;
         AuthState.FillOptions(state.GetAuthState(), options);
     }
 }
Exemplo n.º 13
0
 public static void FillOptions(GlossaryState state, IntentoMTFormOptions options)
 {
     if (state == null)
     {
         options.Glossary = null;
     }
     else
     {
         options.Glossary     = state.Glossary;
         options.GlossaryMode = state.mode;
         dynamic mData = null;
         if (state.glossaries != null)
         {
             mData = state.glossaries.Select(x => (dynamic)x.Value).Where(y => (string)y.id == state.Glossary).FirstOrDefault();
         }
         options.GlossaryName = mData != null ? mData.name : state.Glossary;
     }
 }
Exemplo n.º 14
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            var testOptions = new IntentoMTFormOptions();

            testOptions.Hidden = true;
            var _apiKeyState = new ApiKeyState(new IntentoTranslationProviderOptionsForm(testOptions, parent.LanguagePairs, parent.fabric), _options);

            _apiKeyState.SetValue(apiKey_tb.Text.Trim());
            _apiKeyState.ReadProvidersAndRouting();
            string err = _apiKeyState.Error();
            IEnumerable <string> errDetail = _apiKeyState.ErrorDetail();

            this.Cursor = Cursors.Default;
            var nl = Environment.NewLine;

            if (!string.IsNullOrWhiteSpace(err))
            {
                string errorMsg = err == Resource.InvalidApiKeyMessage ? err : Resource.APIFlabelErrorSeePopup;
                labelError.Text = string.Format("ERROR: {0}", errorMsg); labelError.Visible = true;
                if (errDetail != null)
                {
                    errorInfo = (
                        string.Format("{0}{1}---------------------------{1}{2}",
                                      DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
                                      nl,
                                      string.Join(nl, errDetail.ToArray())
                                      ));

                    toolTip1.SetToolTip(labelError, Resource.APIToolTipMessage);
                }
            }
            else
            {
                this.Cursor = Cursors.WaitCursor;
                parent.apiKeyState.SetValue(apiKey_tb.Text.Trim());
                parent.apiKeyState.ReadProvidersAndRouting();
                parent.apiKeyState.EnableDisable();
                this.Cursor       = Cursors.Default;
                this.DialogResult = DialogResult.OK;
            }
        }
Exemplo n.º 15
0
 public static void FillOptions(SmartRoutingState state, IntentoMTFormOptions options)
 {
     if (state == null)
     {
         options.Routing            = "best";
         options.RoutingDisplayName = Resource.BestSmartRouteDescription;
         options.SmartRouting       = true;
         ProviderState.FillOptions(null, options);
     }
     else
     {
         options.SmartRouting       = state.SmartRouting;
         options.Routing            = state.Routing;
         options.RoutingDisplayName = state.RoutingDescription;
         ProviderState.FillOptions(state.providerState, options);
     }
     if (options.SmartRouting)
     {
         options.Format = "[\"text\",\"html\",\"xml\"]";
     }
 }
Exemplo n.º 16
0
        public SmartRoutingState(ApiKeyState apiKeyState, IntentoMTFormOptions _options) : base(apiKeyState, _options)
        {
            this.apiKeyState = apiKeyState;
            routingTable     = new Dictionary <string, string>(defaultRoutingTable);
            routing          = _options.Routing;
            List <dynamic> routingList = FilterByLanguagePairs(apiKeyState.routings, form.LanguagePairs);

            foreach (dynamic p in routingList)
            {
                string name = (string)p.name;
                if (routingTable.ContainsKey(name))
                {
                    routingTable[name] = (string)p.description;
                }
                else
                {
                    routingTable.Add(name, (string)p.description);
                }
            }

            CreateChildStates();
        }
Exemplo n.º 17
0
        public static void FillOptions(AuthState state, IntentoMTFormOptions options)
        {
            if (state == null)
            {
                options.UseCustomAuth = false;
                options.CustomAuth    = null;
                ModelState.FillOptions(null, options);
                GlossaryState.FillOptions(null, options);
            }
            else
            {
                options.IsAuthDelegated = state.IsDelegatedCredentials;
                options.AuthMode        = state.mode;

                string id;
                if (state.IsDelegatedCredentials && state.providerDataAuthDict.TryGetValue("credential_id", out id))
                {
                    options.AuthDelegatedCredentialId = id;
                }
                else
                {
                    options.AuthDelegatedCredentialId = null;
                }

                options.UseCustomAuth = state.UseCustomAuth;
                if (options.UseCustomAuth)
                {
                    options.SetAuthDict(state.providerDataAuthDict);
                }
                else
                {
                    options.CustomAuth = null;
                }

                ModelState.FillOptions(state.GetModelState(), options);
                GlossaryState.FillOptions(state.GetGlossaryState(), options);
            }
        }
Exemplo n.º 18
0
 public void FillOptions(IntentoMTFormOptions options)
 {
     options.ApiKey = apiKey;
     SmartRoutingState.FillOptions(smartRoutingState, options);
 }
Exemplo n.º 19
0
 public BaseState(IntentoTranslationProviderOptionsForm form, IntentoMTFormOptions options)
 {
     this.form    = form;
     this.formMT  = form.formMT;
     this.options = options;
 }
Exemplo n.º 20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="_form"></param>
 /// <param name="_options"></param>
 /// <param name="fromForm">Call from event, change of form check box may result recourcing</param>
 public ModelState(AuthState authState, IntentoMTFormOptions _options) : base(authState, _options)
 {
     this.authState = authState;
     providerState  = authState.providerState;
 }
Exemplo n.º 21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="_form"></param>
 /// <param name="_options"></param>
 /// <param name="fromForm">Call from event, change of form check box may result recourcing</param>
 public GlossaryState(AuthState authState, IntentoMTFormOptions _options, bool fromForm = false) : base(authState, _options)
 {
     this.authState = authState;
     providerState  = authState.providerState;
 }
Exemplo n.º 22
0
 public void ClearOptions(IntentoMTFormOptions options)
 {
     options.Glossary = null;
     Glossary_GroupBox_Disable(formMT);
 }