Пример #1
0
        /// <summary>
        /// Gets the display set items needed for an Alternate Key.
        /// </summary>
        /// <param name="className">Name of the class.</param>
        /// <param name="alternateKeyName">Name of the Alternate Key name.</param>
        /// <returns>String containing the display set items separated by commas.</returns>
        private string GetAlternateKeyDisplaySet(string className, string alternateKeyName)
        {
            string alternateKeyDisplaySet = string.Empty;

            try
            {
                Oids.Oid oidRoot      = Oids.Oid.Create(className);
                Oids.Oid alternateKey = (Oids.Oid)oidRoot.GetAlternateKey(AlternateKeyName);

                if (alternateKey != null)
                {
                    // Get the alternate keys attribute names and add to display set.
                    StringBuilder alternateKeyNames = new StringBuilder();
                    string        lSeparador        = string.Empty;
                    foreach (Oids.IOidField fieldItem in alternateKey.Fields)
                    {
                        alternateKeyNames.Append(lSeparador);
                        alternateKeyNames.Append(fieldItem.Name);
                        lSeparador = ", ";
                    }
                    alternateKeyDisplaySet = alternateKeyNames.ToString();
                }
            }
            catch
            {
                return(string.Empty);
            }

            return(alternateKeyDisplaySet);
        }
Пример #2
0
        private void mAgent_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Hide all the login OIDs.
            foreach (Control item in mEditors)
            {
                item.Visible = false;
            }

            // Create the selected agent.
            string lAgentClassName = (mAgent.SelectedItem as Logics.LogInAgent).Name;

            Oids.Oid lagent = Oids.Oid.Create(lAgentClassName);

            // Check if the selected agent is an anonymous agent
            // to hide the Login and Password controls.
            AgentInfo lSelectedAgent             = lagent as AgentInfo;
            bool      lIsAgentConnectedAnonymous = (lSelectedAgent is AnonymousAgentInfo);

            this.mlblLogin.Visible        = !lIsAgentConnectedAnonymous;
            this.mlblPassword.Visible     = !lIsAgentConnectedAnonymous;
            this.mTextBoxPassword.Visible = !lIsAgentConnectedAnonymous;

            if (!lIsAgentConnectedAnonymous)
            {
                // Show the login OIDs depending of the selected agent.
                Logics.LogInAgent lLogInAgent = Logics.Agents.GetLogInAgentByName(lAgentClassName);
                if (lLogInAgent.AlternateKeyName != string.Empty)
                {
                    lagent = (Oid)lagent.GetAlternateKey(lLogInAgent.AlternateKeyName);
                }

                for (int i = 0; i < lagent.Fields.Count; i++)
                {
                    mEditors[i].Visible = true;
                }

                // Modify the window size depending on the number of arguments in the OID.
                if (lagent.Fields.Count == 1)
                {
                    SetClientSizeCore(450, 185);
                }
                else
                {
                    SetClientSizeCore(300 + (lagent.Fields.Count * 100), 185);
                }
            }
            else
            {
                // Resize windows size for anonymous agents.
                SetClientSizeCore(450, 185);
            }
        }
Пример #3
0
        private void SuccessAuthenticate(object pObject, EventArgs pEventArgs)
        {
            // Check if the agent exists.
            if (Logics.Logic.Agent != null)
            {
                Oids.Oid          lAgent     = Logics.Logic.Agent;
                Logics.LogInAgent logInAgent = Logics.Agents.GetLogInAgentByName(lAgent.ClassName);
                if (logInAgent.AlternateKeyName != string.Empty)
                {
                    // Get the alternate key of the Oid.
                    lAgent = (Oids.Oid)lAgent.GetAlternateKey(logInAgent.AlternateKeyName);
                }
                // HAT Multilanguage: Apply multilanguage to the HAT elements.
                Controller.ApplyMultilanguage();

                // ... and to the fixed strings.
                MultilanguageFixedString();

                Controller.ApplyConnectedAgentVisibility();

                // Put the connected agent and the culture on the main form status label.
                StringBuilder lStringBuilder = new StringBuilder();
                if ((lAgent != null) && (lAgent is Oids.AnonymousAgentInfo))
                {
                    lStringBuilder.Append(logInAgent.Alias);
                }
                else
                {
                    lStringBuilder.Append(logInAgent.Alias);
                    lStringBuilder.Append(" : ");
                    lStringBuilder.Append(UtilFunctions.OidFieldsToString(lAgent, ' '));
                }
                toolStripStatusLabel.Text = UtilFunctions.ProtectAmpersandChars(lStringBuilder.ToString());

                // Show Current culture.
                toolStripStatusLabelCulture.Text = CultureManager.Culture.Name;

                // Load instance reports configuration.
                Logics.Logic.InstanceReportsList.LoadFromFile(Properties.Settings.Default.ConfigurationOfReports);

                // Load configuration reports file.
                LoadConfigurationReportsFile();
            }
            else
            {
                Close();
            }
        }
Пример #4
0
        private void mbOK_Click(object sender, EventArgs e)
        {
            #region Actualize current language
            // Get the current language from the combobox language selector.
            CultureManager.Culture = new System.Globalization.CultureInfo(((KeyValuePair <string, string>) this.mLanguage.SelectedItem).Key);
            #endregion Actualize current language

            string   lAgentClassName = (mAgent.SelectedItem as Logics.LogInAgent).Name;
            Oids.Oid lagent          = Oids.Oid.Create(lAgentClassName);
            lagent.ClearValues();
            AgentInfo         lAgentInfo  = lagent as AgentInfo;
            Logics.LogInAgent lLogInAgent = Logics.Agents.GetLogInAgentByName(lAgentClassName);
            // Check if the connected agent has alternate key.
            if (lLogInAgent.AlternateKeyName != string.Empty)
            {
                // Obtain the Alternate Key used by the connected agent class,
                // in order to be able of filling in the field values from the editors.
                lagent = (Oid)lagent.GetAlternateKey(lLogInAgent.AlternateKeyName);
                lagent.AlternateKeyName = lLogInAgent.AlternateKeyName;
            }

            if (!(lAgentInfo is AnonymousAgentInfo))
            {
                // To validate that all the login values are introduced.
                bool lbIsNull = false;
                // Error provider properties
                lErrorProvider.Clear();
                lErrorProvider.BlinkRate  = 500;
                lErrorProvider.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.NeverBlink;

                #region Validate that the login and password are introduced
                // Validate the password field.
                if (mTextBoxPassword.Text == string.Empty)
                {
                    // Set the focus and error
                    mTextBoxPassword.Focus();
                    lErrorProvider.SetError(mTextBoxPassword, CultureManager.TranslateString(LanguageConstantKeys.L_PASSWORD_NOT_NULL, LanguageConstantValues.L_PASSWORD_NOT_NULL));
                    lErrorProvider.SetIconPadding(mTextBoxPassword, -20);
                    lbIsNull = true;
                }

                // Validate the login fields.
                for (int i = mEditors.Length - 1; i >= 0; i--)
                {
                    if (mEditors[i].Visible)
                    {
                        // Null validation.
                        if (mEditors[i].Text == string.Empty)
                        {
                            // Set the focus and error
                            mEditors[i].Focus();
                            lErrorProvider.SetError(mEditors[i], CultureManager.TranslateString(LanguageConstantKeys.L_LOGIN_NOT_NULL, LanguageConstantValues.L_LOGIN_NOT_NULL));
                            lErrorProvider.SetIconPadding(mEditors[i], -20);
                            lbIsNull = true;
                        }
                    }
                }

                // If there are any empty argument.
                if (lbIsNull == true)
                {
                    // Do not continue
                    return;
                }
                #endregion Validate that the login and password are introduced
            }

            #region Create the agent
            int lOidField = 0;
            try
            {
                if (!(lAgentInfo is AnonymousAgentInfo))
                {
                    // Set the OID type to the proper control.
                    foreach (Control item in mEditors)
                    {
                        if (item.Visible == true)
                        {
                            try
                            {
                                if (!DefaultFormats.CheckDataType(item.Text, lagent.Fields[lOidField].Type, false))
                                {
                                    string lText    = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_BAD_IDENTITY, LanguageConstantValues.L_ERROR_BAD_IDENTITY);
                                    string lMessage = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR, LanguageConstantValues.L_ERROR);
                                    MessageBox.Show(lText, lMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                object value = Logics.Logic.StringToModel(lagent.Fields[lOidField].Type, item.Text);
                                lagent.SetValue(lOidField, value);
                                lOidField++;
                            }
                            catch
                            {
                                string lText    = CultureManager.TranslateString(LanguageConstantKeys.L_LOGIN_INCORRECT, LanguageConstantValues.L_LOGIN_INCORRECT);
                                string lMessage = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR, LanguageConstantValues.L_ERROR);
                                MessageBox.Show(lText, lMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                        }
                    }
                }

                #region Agent authentication
                if (lagent is AlternateKey)
                {
                    AuthenticateAlternateKey(lagent, mTextBoxPassword.Text);
                }
                else
                {
                    Authenticate(lagent as AgentInfo, mTextBoxPassword.Text);
                }
                #endregion Agent authentication
            }
            catch
            {
                string lMessage  = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR, LanguageConstantValues.L_ERROR);
                string lExcepMsg = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_BAD_IDENTITY, LanguageConstantValues.L_ERROR_BAD_IDENTITY);
                MessageBox.Show(lExcepMsg, lMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            #endregion Create the agent.
        }