Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        private string GetInfoFromOid(Oid oid, DisplaySetInformation supplementaryInfo)
        {
            if (oid == null)
            {
                return("");
            }

            // If no Supplementary information is requested, return the Oid values
            if (supplementaryInfo == null)
            {
                return(UtilFunctions.OidFieldsToString(oid, ' '));
            }

            // Query to obtain the supplementary information values
            string    displaySet = supplementaryInfo.DisplaySetItemsAsString();
            DataTable lDataTable = null;

            try
            {
                lDataTable = Logic.ExecuteQueryInstance(Logic.Agent, oid, displaySet);
            }
            catch
            {
                return(UtilFunctions.OidFieldsToString(oid, ' '));;
            }

            // No data, return empty string
            if (lDataTable == null || lDataTable.Rows.Count == 0)
            {
                return(UtilFunctions.OidFieldsToString(oid, ' '));
            }
            ;

            string lResult = "";

            foreach (DisplaySetItem lItem in supplementaryInfo.DisplaySetItems)
            {
                if (!lResult.Equals(""))
                {
                    lResult += " ";
                }

                lResult += DefaultFormats.ApplyDisplayFormat(lDataTable.Rows[0][lItem.Name], lItem.ModelType);
            }

            return(lResult);
        }
        /// <summary>
        /// Validates the modified rows values. Not Null and datatype
        /// </summary>
        /// <param name="modifiedRows"></param>
        /// <returns></returns>
        private bool ValidateModifiedRows(DataTable modifiedRows)
        {
            // Error datatable
            DataTable errorReport = new DataTable();
            // Column for the OID
            string instanceColumnsName = CurrentDisplaySet.ServiceInfo.SelectedInstanceArgumentAlias;

            errorReport.Columns.Add(instanceColumnsName);
            // Column for the error message
            string lReportMessage = CultureManager.TranslateString(LanguageConstantKeys.L_MULTIEXE_EXECUTION, LanguageConstantValues.L_MULTIEXE_EXECUTION);

            errorReport.Columns.Add(lReportMessage);

            // Not null and Datatype validation
            foreach (DataRow rowValues in modifiedRows.Rows)
            {
                Oid instanceOID = Adaptor.ServerConnection.GetOid(modifiedRows, rowValues);
                foreach (DisplaySetServiceArgumentInfo argumentInfo in CurrentDisplaySet.ServiceInfo.ArgumentDisplaySetPairs.Values)
                {
                    object value = rowValues[argumentInfo.DSElementName];

                    // Null validation
                    if (value.GetType() == typeof(System.DBNull))
                    {
                        if (!argumentInfo.AllowsNull)
                        {
                            // Add a nuw row in the error datatable
                            DataRow  newReportRow   = errorReport.NewRow();
                            string   nameInScenario = argumentInfo.Alias;
                            object[] lArgs          = new object[1];
                            lArgs[0] = nameInScenario;
                            string lErrorMessage = CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_NECESARY, LanguageConstantValues.L_VALIDATION_NECESARY, lArgs);
                            newReportRow[lReportMessage]      = lErrorMessage;
                            newReportRow[instanceColumnsName] = UtilFunctions.OidFieldsToString(instanceOID, ' ');
                            errorReport.Rows.Add(newReportRow);
                        }
                    }
                    else
                    {
                        // Data type validation
                        if (!DefaultFormats.CheckDataType(value.ToString(), argumentInfo.DataType, false))
                        {
                            // Add a nuw row in the error datatable
                            DataRow  newReportRow = errorReport.NewRow();
                            string   lMask        = DefaultFormats.GetHelpMask(argumentInfo.DataType, string.Empty);
                            object[] lArgs        = new object[1];
                            lArgs[0] = lMask;
                            string lErrorMessage = argumentInfo.Alias + ":  ";
                            lErrorMessage += CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_INVALID_FORMAT_MASK, LanguageConstantValues.L_VALIDATION_INVALID_FORMAT_MASK, lArgs);
                            newReportRow[lReportMessage]      = lErrorMessage;
                            newReportRow[instanceColumnsName] = UtilFunctions.OidFieldsToString(instanceOID, ' ');
                            errorReport.Rows.Add(newReportRow);
                        }
                    }
                }
            }

            // If errors have been found, show them
            if (errorReport.Rows.Count > 0)
            {
                // Show error message to the user
                ScenarioManager.LaunchMultiExecutionReportScenario(errorReport, CurrentDisplaySet.ServiceInfo.ServiceAlias, null, null);
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Process the Display Service execute event
        /// </summary>
        protected virtual void ProcessExecuteServiceTriggered(object sender, TriggerEventArgs e)
        {
            // Before executing the DisplaySet Service it is needed to check for pending changes in associated Service IU.
            IUQueryController queryController = Parent as IUQueryController;

            if (queryController != null && !queryController.CheckPendingChanges(false, true))
            {
                return;
            }
            if (CurrentDisplaySet.ServiceInfo == null)
            {
                return;
            }

            // Gets modified rows from the viewer
            DataTable modifiedRows = Viewer.GetModifiedRows();

            if (modifiedRows == null)
            {
                return;
            }

            // Validate the modified data
            if (!ValidateModifiedRows(modifiedRows))
            {
                return;
            }

            // Error datatable
            DataTable errorReport = new DataTable();
            // Column for the OID
            string instanceColumnsName = CurrentDisplaySet.ServiceInfo.SelectedInstanceArgumentAlias;

            errorReport.Columns.Add(instanceColumnsName);
            // Column for the error message
            string lReportMessage = CultureManager.TranslateString(LanguageConstantKeys.L_MULTIEXE_EXECUTION, LanguageConstantValues.L_MULTIEXE_EXECUTION);

            errorReport.Columns.Add(lReportMessage);

            IUServiceContext lServiceContext = null;

            // For every modified row do...
            foreach (DataRow rowValues in modifiedRows.Rows)
            {
                // Create new IUServiceContext.
                lServiceContext = new IUServiceContext(null, CurrentDisplaySet.ServiceInfo.ClassServiceName, CurrentDisplaySet.ServiceInfo.ServiceName, null);
                // Add argunment this to the service context.
                List <Oid> instanceOIDs = new List <Oid>();
                Oid        instanceOID  = Adaptor.ServerConnection.GetOid(modifiedRows, rowValues);
                instanceOIDs.Add(instanceOID);
                lServiceContext.InputFields.Add(CurrentDisplaySet.ServiceInfo.SelectedInstanceArgumentName, new IUContextArgumentInfo(CurrentDisplaySet.ServiceInfo.SelectedInstanceArgumentName, instanceOIDs, true, null));

                // Fill the collections for the other inbound arguments.
                foreach (DisplaySetServiceArgumentInfo argumentInfo in CurrentDisplaySet.ServiceInfo.ArgumentDisplaySetPairs.Values)
                {
                    object value = rowValues[argumentInfo.DSElementName];
                    if (value.GetType() == typeof(System.DBNull))
                    {
                        value = null;
                    }
                    //Add input arguments with context.
                    lServiceContext.InputFields.Add(argumentInfo.Name, new IUContextArgumentInfo(argumentInfo.Name, value, true, null));
                }
                try
                {
                    // Execute service.
                    Logic.ExecuteService(lServiceContext);
                }
                catch (Exception exc)
                {
                    string lAlternateKeyName = CurrentDisplaySet.ServiceInfo.SelectedInstanceArgumentAlternateKeyName;
                    if (lAlternateKeyName != string.Empty)
                    {
                        instanceOID = Logic.GetAlternateKeyFromOid(instanceOID, lAlternateKeyName);
                    }

                    // Add a new row in the error datatable.
                    DataRow newReportRow = errorReport.NewRow();
                    newReportRow[lReportMessage]      = exc.Message;
                    newReportRow[instanceColumnsName] = UtilFunctions.OidFieldsToString(instanceOID, ' ');
                    errorReport.Rows.Add(newReportRow);
                }
            }

            // If errors have been found, show them
            if (errorReport.Rows.Count > 0)
            {
                // Show error message to the user
                ScenarioManager.LaunchMultiExecutionReportScenario(errorReport, CurrentDisplaySet.ServiceInfo.ServiceAlias, null, null);
            }

            // Remove the Pending changes mark
            PendingChanges = false;

            // Refresh the data
            OnExecuteCommand(new ExecuteCommandRefreshEventArgs(null));
        }