/// <summary> /// Gets the Oid from a DataRow. The DataRow is a row of the DataTable. /// </summary> /// <param name="dataTable">DataTable the Oid is given from.</param> /// <param name="row">Row the Oid is requested.</param> /// <param name="alternateKeyName">Name of the alternate key, if proceed.</param> /// <returns>Returns the Oid corresponding to the DataRow.</returns> public static Oid GetOid(DataTable dataTable, DataRow row, string alternateKeyName) { Oid resultOid = null; List <DataColumn> oidFields = GetOidColumns(dataTable); if (oidFields != null) { resultOid = Oid.Create(dataTable.TableName); resultOid.Fields.Clear(); foreach (DataColumn lDataColumn in oidFields) { ModelType type = (ModelType)lDataColumn.ExtendedProperties[DataTableProperties.DataColumnProperties.ModelType]; object rowValue = row[lDataColumn.Ordinal]; if (rowValue == null || rowValue == DBNull.Value) { return(null); } if (type == ModelType.String && rowValue.ToString().Trim().Length == 0) { return(null); } IOidField oidField = FieldList.CreateField(string.Empty, type); oidField.Value = rowValue; resultOid.Fields.Add(oidField); } string lAlternateKeyName = alternateKeyName; if (lAlternateKeyName == string.Empty) { // If no alternateKeyName is specified, ask to the current oid. lAlternateKeyName = resultOid.AlternateKeyName; } if (lAlternateKeyName != string.Empty) { // Try to load the alternate key fields with the values contained in the row. IOid auxAlternateKey = resultOid.GetAlternateKey(lAlternateKeyName); if ((auxAlternateKey as AlternateKey) != null) { foreach (IOidField oidField in auxAlternateKey.Fields) { // It is not guaranteed if the alternate key field is in the datatable. if (dataTable.Columns.Contains(oidField.Name)) { oidField.Value = row[oidField.Name]; } } } } } return(resultOid); }
/// <summary> /// Creates an Oid object with the list of values for its fields, passed as parameters. /// </summary> /// <param name="className">Name of the class of the new Oid.</param> /// <param name="oidFields">List of fields values.</param> /// <param name="alternatieKeyName">Indicates the name of the alternate key.</param> /// <param name="executeQuery">Indicates wheter a quey must be executed to retrieve the primary Oid.</param> /// <returns>An Oid object.</returns> public static Oid CreateOidFromOidFields( string className, List <object> oidFields, string alternateKeyName, bool executeQuery) { Oid lOid = null; // Null if some field is null. if (oidFields != null) { foreach (object lOidField in oidFields) { if (lOidField == null) { return(null); } } if (alternateKeyName != string.Empty) { // Create the Oid to know its structure and be able to retrieve the alternate key. lOid = Oid.Create(className); // Fill the alternate key with the field values from the editors. AlternateKey alternateKey = (AlternateKey)lOid.GetAlternateKey(alternateKeyName); alternateKey.SetValues(oidFields); if (executeQuery) { // Retrieve the suitable Oid. lOid = GetOidFromAlternateKey(alternateKey, alternateKeyName); } // Null if number of alternate fields does not match. if ((oidFields.Count != alternateKey.Fields.Count)) { return(null); } } else { // Create the Oid and set its fields values from the editors. lOid = Oid.Create(className, oidFields); // Null if number of fields in oidField and Oid is not the same. if ((oidFields.Count != lOid.Fields.Count)) { return(null); } } } return(lOid); }
/// <summary> /// Initializes a new instance of 'IUQueryContext'. /// </summary> /// <param name="info">Info.</param> /// <param name="iuType">IU type.</param> /// <param name="className">Class name.</param> /// <param name="iuName">IU name.</param> public IUQueryContext(ExchangeInfo info, ContextType iuType, string className, string iuName) : base(info, iuType, className, iuName) { // Copy the selected Oids from the origin scenario. In this scenario they are the related Oids if (info.SelectedOids != null && info.SelectedOids.Count > 0) { RelatedOids = new List <Oid>(); foreach (Oid lOid in info.SelectedOids) { RelatedOids.Add(Oid.Create(lOid.ClassName, lOid.GetFields())); } } }
/// <summary> /// Initializes a new instance of the 'EditorList' class. /// </summary> /// <param name="argumentController">Argument controller.</param> public EditorList(ArgumentOVController argumentController) { if (argumentController != null) { mArgumentController = argumentController; mOid = Oid.Create(mArgumentController.Domain); if (argumentController.AlternateKeyName != string.Empty) { mOid = (mOid.GetAlternateKey(argumentController.AlternateKeyName) as Oid); } for (int it = 0; it < mOid.Fields.Count; it++) { Add(null); } } }
/// <summary> /// Validates the format and null allowed of the filter variables /// </summary> /// <returns></returns> protected bool CheckNullAndFormatFilterVariablesValues() { bool lResult = true; object[] lArgs = new object[1]; // Control the null - not null allowed for all the filter variables arguments. foreach (ArgumentController lFilterVariable in InputFields) { // Argument data-valued validation. ArgumentDVController lFilterVariableDV = lFilterVariable as ArgumentDVController; if ((lFilterVariableDV != null) && (lFilterVariableDV.Editor != null)) { lArgs[0] = lFilterVariable.Alias; lResult = lResult & lFilterVariableDV.Editor.Validate(CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_NECESARY, LanguageConstantValues.L_VALIDATION_NECESARY, lArgs)); } // Argument object-valued validation. else { ArgumentOVController lFilterVariableOV = lFilterVariable as ArgumentOVController; if (lFilterVariableOV != null) { List <Object> lEditorFields = new List <object>(); foreach (IEditorPresentation lEditor in lFilterVariableOV.Editors) { if (lEditor != null) { lArgs[0] = lFilterVariable.Alias; // Shows the validation error only for the last editor field. lResult = lResult & lEditor.Validate(CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_NECESARY, LanguageConstantValues.L_VALIDATION_NECESARY, lArgs)); if (lEditor.Value != null) { // Fill the auxiliar list of values, in order to check if the Alternate Key is valid. lEditorFields.Add(lEditor.Value); } } } // If the OV filter variable has to work with an Alternate Key, check that the values specified // in the editors are valid (It exist an instance that mach with this Alternate Key). if (lFilterVariableOV.AlternateKeyName != string.Empty && lFilterVariableOV.Editors.Count == lEditorFields.Count) { Oid lOid = Oid.Create(lFilterVariableOV.Domain); AlternateKey lAlternateKey = (AlternateKey)lOid.GetAlternateKey(lFilterVariableOV.AlternateKeyName); lAlternateKey.SetValues(lEditorFields); // Check if the Alternate Key is a valid one. Oid lResultOid = Logic.GetOidFromAlternateKey(lAlternateKey, lFilterVariableOV.AlternateKeyName); // If the Oid is not found, it is because the Alternate Key is not a valid one. if (lResultOid == null) { ScenarioManager.LaunchErrorScenario(new Exception(CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_NO_EXIST_INSTANCE, LanguageConstantValues.L_ERROR_NO_EXIST_INSTANCE))); return(false); } } } } } return(lResult); }
private void LoginForm_Load(object sender, EventArgs e) { this.Text = "Desktop"; // Get all the agents. List <Logics.LogInAgent> listLogInAgents = Logics.Agents.GetLogInAgents(); mAgent.DataSource = listLogInAgents; mAgent.ValueMember = "Name"; mAgent.DisplayMember = "Alias"; if (Logics.Logic.Agent != null) { mAgent.SelectedItem = Logics.Logic.Agent; } #region Load supported languages List <KeyValuePair <string, string> > lSupportedLanguages = new List <KeyValuePair <string, string> >(); // Load supported languages from the LanguageManager class. foreach (System.Globalization.CultureInfo litem in CultureManager.SupportedLanguages.Values) { lSupportedLanguages.Add(new KeyValuePair <string, string>(litem.Name, litem.NativeName)); } // Load supported languages from the LanguageManager class into the combobox. if (lSupportedLanguages.Count > 0) { KeyValuePair <string, string> lSelectedLanguage = new KeyValuePair <string, string>(CultureManager.Culture.Name, CultureManager.Culture.NativeName); this.mLanguage.SelectedIndexChanged -= new System.EventHandler(this.MultilanguageFixedString); this.mLanguage.DataSource = lSupportedLanguages; this.mLanguage.ValueMember = "Key"; this.mLanguage.DisplayMember = "Value"; this.mLanguage.SelectedIndexChanged += new System.EventHandler(this.MultilanguageFixedString); this.mLanguage.SelectedItem = lSelectedLanguage; this.mLanguage.Enabled = true; this.mlblLanguage.Enabled = true; } /* Not avaliable languages for the application. * IMPORNTANT: To enable any additional language, go to the * 'CultureManager' class and add the needed language * in 'CultureManager.SupportedLanguages' property. */ else { this.mLanguage.Items.Add("None"); this.mLanguage.SelectedIndex = 0; this.mLanguage.Enabled = false; this.mlblLanguage.Enabled = false; // Check the anonymous agent. if (this.mAgent.Items.Count == 1) { string lAgentClassName = (mAgent.SelectedItem as Logics.LogInAgent).Name; AgentInfo lAgent = Oid.Create(lAgentClassName) as AgentInfo; if (lAgent is AnonymousAgentInfo) { LogIn(lAgent); } } } #endregion Load supported languages }
/// <summary> /// This function calls to the constructor of Oid. /// </summary> /// <param name="className">Class where will be the Oid.</param> /// <param name="fields">Fields of the Oid.</param> /// <returns>Oid instance.</returns> public static Oid CreateOid( string className, List <KeyValuePair <ModelType, object> > fields) { return(Oid.Create(className, fields)); }
/// <summary> /// This function calls to the constructor of Oid. /// </summary> /// <param name="className">Class where will be the Oid.</param> /// <returns>Oid instance.</returns> public static Oid CreateOid(string className) { return(Oid.Create(className)); }
/// <summary> /// Query the attribute values used in the State Change Detection. /// </summary> /// <param name="oids">Oid list.</param> protected void GetValuesForSCD(List <Oid> oids) { // No Oids, do nothing. if (oids == null || (oids != null && oids.Count == 0)) { return; } // Check that all the elements of the list are valid Oids. foreach (Oid lOid in oids) { if (!Oid.IsNotNullAndValid(lOid)) { return; } } // More than one object select means no SCD. if (oids.Count > 1) { foreach (Oid oid in oids) { // Empty the lists. oid.SCDAttributesValues.Clear(); oid.SCDAttributesTypes.Clear(); oid.SCDAttributesDomains.Clear(); } return; } // No SCD declared for this argument. if (SCDAttributes == null || SCDAttributes.DisplaySetItems == null || SCDAttributes.DisplaySetItems.Count == 0) { return; } // Empty the list. oids[0].SCDAttributesValues.Clear(); oids[0].SCDAttributesTypes.Clear(); oids[0].SCDAttributesDomains.Clear(); // Query for all Data Valued attributes. string lAttributes = ""; foreach (DisplaySetItem lItem in SCDAttributes.DisplaySetItems) { if (lItem.ModelType != ModelType.Oid) { if (!lAttributes.Equals(string.Empty)) { lAttributes += ","; } lAttributes += lItem.Name; } else { // Add the OID fields foreach (string oidField in lItem.OIDFields) { if (!lAttributes.Equals(string.Empty)) { lAttributes += ","; } lAttributes += lItem.Name + "." + oidField; } } } lAttributes = UtilFunctions.ReturnMissingAttributes(oids[0].ExtraInfo, lAttributes); if (lAttributes != "") { DataTable dataTable = null; try { dataTable = Logic.ExecuteQueryInstance(Logic.Agent, Domain, oids[0], lAttributes); } catch { return; } if (dataTable == null || dataTable.Rows.Count == 0) { return; } oids[0].ExtraInfo.Merge(dataTable); } // Pass the values to the Oid list. foreach (DisplaySetItem lItem in SCDAttributes.DisplaySetItems) { string lName = Name + "." + lItem.Name; if (lItem.ModelType != ModelType.Oid) { object attValue = oids[0].ExtraInfo.Rows[0][lItem.Name]; attValue = (attValue == DBNull.Value) ? null : attValue; oids[0].SCDAttributesValues.Add(lName, attValue); oids[0].SCDAttributesTypes.Add(lName, lItem.ModelType); oids[0].SCDAttributesDomains.Add(lName, lItem.ClassName); } else { // Create a new Oid using the field values. Oid lOid = null; List <Object> lOIDFieldValues = new List <object>(); bool lNUllValue = false; foreach (string oidField in lItem.OIDFields) { object lValue = oids[0].ExtraInfo.Rows[0][lItem.Name + "." + oidField]; lValue = (lValue == DBNull.Value) ? null : lValue; if (lValue == null) { lNUllValue = true; } lOIDFieldValues.Add(lValue); } if (!lNUllValue) { lOid = Oid.Create(lItem.ClassName, lOIDFieldValues); } oids[0].SCDAttributesValues.Add(lName, lOid); oids[0].SCDAttributesTypes.Add(lName, lItem.ModelType); oids[0].SCDAttributesDomains.Add(lName, lItem.ClassName); } } }