protected static void ExecStoredProc(BaseWNOSPlugin plugin, SpringBaseDao baseDao, string storedProcName,
                                             int commandTimeout, IDbParameters parameters)
        {
            plugin.AppendAuditLogEvent("Executing stored procedure \"{0}\" with timeout of {1} seconds ...",
                                       storedProcName, commandTimeout.ToString());

            try
            {
                baseDao.AdoTemplate.Execute <int>(delegate(DbCommand command)
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = storedProcName;
                    Spring.Data.Support.ParameterUtils.CopyParameters(command, parameters);

                    try
                    {
                        SpringBaseDao.ExecuteCommandWithTimeout(command, commandTimeout, delegate(DbCommand commandToExecute)
                        {
                            commandToExecute.ExecuteNonQuery();
                        });
                    }
                    catch (Exception ex2)
                    {
                        plugin.AppendAuditLogEvent("Error returned from stored procedure: {0}", ExceptionUtils.GetDeepExceptionMessage(ex2));
                        throw;
                    }

                    return(0);
                });

                plugin.AppendAuditLogEvent("Successfully executed stored procedure \"{0}\"", storedProcName);
            }
            catch (Exception e)
            {
                plugin.AppendAuditLogEvent("Failed to execute stored procedure \"{0}\" with error: {1}",
                                           storedProcName, ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
        }
        public static void DoExtract(BaseWNOSPlugin plugin, SpringBaseDao baseDao, string storedProcName,
                                     int commandTimeout, string orgId, DateTime lastUpdateDate)
        {
            plugin.AppendAuditLogEvent("Executing stored procedure \"{0}\" with timeout of {1} seconds ...",
                                       storedProcName, commandTimeout.ToString());

            IDbParameters parameters = baseDao.AdoTemplate.CreateDbParameters();

            parameters.AddWithValue(p_org_id, orgId);
            parameters.AddWithValue(p_last_update_date, lastUpdateDate);

            ExecStoredProc(plugin, baseDao, storedProcName, commandTimeout, parameters);
        }
        public static void DoExtract(BaseWNOSPlugin plugin, SpringBaseDao baseDao, string storedProcName,
                                     int commandTimeout, string orgId, DateTime?startDate, DateTime?endDate)
        {
            plugin.AppendAuditLogEvent("Executing stored procedure \"{0}\" with timeout of {1} seconds ...",
                                       storedProcName, commandTimeout.ToString());

            IDbParameters parameters = baseDao.AdoTemplate.CreateDbParameters();

            parameters.AddWithValue(p_org_id, orgId);
            parameters.AddWithValue(p_start_date, startDate.HasValue ? (object)startDate.Value : (object)DBNull.Value);
            parameters.AddWithValue(p_end_date, endDate.HasValue ? (object)endDate.Value : (object)DBNull.Value);

            ExecStoredProc(plugin, baseDao, storedProcName, commandTimeout, parameters);
        }
        public static DateTime DoExtract(BaseWNOSPlugin plugin, SpringBaseDao baseDao, string storedProcName,
                                         int commandTimeout)
        {
            plugin.AppendAuditLogEvent("Executing stored procedure \"{0}\" with timeout of {1} seconds ...",
                                       storedProcName, commandTimeout.ToString());

            DateTime runtime = DateTime.Now;

            try
            {
                IDbParameters parameters = baseDao.AdoTemplate.CreateDbParameters();
                parameters.AddWithValue(p_run_parm, "NORMAL");
                IDbDataParameter runtimeTextParameter = parameters.AddOut(p_runtime_txt, DbType.String, 2048);
                IDbDataParameter runtimeParameter     = parameters.AddOut(p_runtime, DbType.Date);

                baseDao.AdoTemplate.Execute <int>(delegate(DbCommand command)
                {
                    command.CommandType    = CommandType.StoredProcedure;
                    command.CommandText    = storedProcName;
                    command.CommandTimeout = commandTimeout;
                    Spring.Data.Support.ParameterUtils.CopyParameters(command, parameters);

                    try
                    {
                        SpringBaseDao.ExecuteCommandWithTimeout(command, commandTimeout, delegate(DbCommand commandToExecute)
                        {
                            commandToExecute.ExecuteNonQuery();
                        });
                    }
                    catch (Exception ex2)
                    {
                        command.Connection.Close();
                        plugin.AppendAuditLogEvent("Error returned from stored procedure: {0}", ExceptionUtils.GetDeepExceptionMessage(ex2));
                        throw;
                    }

                    if (command.Parameters[runtimeTextParameter.ParameterName].Value != DBNull.Value)
                    {
                        string procMessage = command.Parameters[runtimeTextParameter.ParameterName].Value.ToString();
                        procMessage        = procMessage.Replace("\r\n", "\r");
                        procMessage        = procMessage.Replace("\r", "\r\n");
                        plugin.AppendAuditLogEvent(procMessage);
                    }

                    if (command.Parameters[runtimeParameter.ParameterName].Value != DBNull.Value)
                    {
                        runtime = DateTime.Parse(command.Parameters[runtimeParameter.ParameterName].Value.ToString());
                    }

                    return(0);
                });

                plugin.AppendAuditLogEvent("Successfully executed stored procedure \"{0}\"", storedProcName);
            }
            catch (Exception e)
            {
                plugin.AppendAuditLogEvent("Failed to execute stored procedure \"{0}\" with error: {1}",
                                           storedProcName, ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            return(runtime);
        }
Esempio n. 5
0
        public static Dictionary <string, UserSubmitInfo> ParseNaasUserMappingFile(string mappingFilePath, BaseWNOSPlugin plugin)
        {
            Dictionary <string, UserSubmitInfo> naasUsernameToPasswordMap = null;

            if (!string.IsNullOrEmpty(mappingFilePath))
            {
                try
                {
                    plugin.AppendAuditLogEvent("Attempting to parse NAAS User Mapping File: \"{0}\"", mappingFilePath);
                    if (!File.Exists(mappingFilePath))
                    {
                        throw new ArgumentException(string.Format("The NAAS User Mapping File was not found: \"{0}\"",
                                                                  mappingFilePath));
                    }
                    using (TextFieldParser parser = new TextFieldParser(mappingFilePath))
                    {
                        parser.TextFieldType      = FieldType.Delimited;
                        parser.Delimiters         = new string[] { "," };
                        naasUsernameToPasswordMap = new Dictionary <string, UserSubmitInfo>();
                        for (; ;)
                        {
                            long     lineNumber = parser.LineNumber;
                            string[] values     = parser.ReadFields();
                            if (CollectionUtils.IsNullOrEmpty(values))
                            {
                                break;
                            }
                            string username = values[0].Trim().ToUpper();
                            if (string.IsNullOrEmpty(username))
                            {
                                throw new ArgumentException(string.Format("Missing NAAS username on line: {0}", lineNumber));
                            }
                            if (username.StartsWith("//"))
                            {
                                // Comment, so ignore line
                            }
                            else
                            {
                                if (values.Length < 2)
                                {
                                    throw new ArgumentException(string.Format("Missing NAAS password for username {0} on line: {1}", username, lineNumber));
                                }
                                if (values.Length < 3)
                                {
                                    throw new ArgumentException(string.Format("Missing RCRAInfoUserID for username {0} on line: {1}", username, lineNumber));
                                }
                                string password = values[1].Trim();
                                if (string.IsNullOrEmpty(password))
                                {
                                    throw new ArgumentException(string.Format("Missing NAAS password for username {0} on line: {1}", username, lineNumber));
                                }
                                string infoUserId = values[2].Trim();
                                if (string.IsNullOrEmpty(infoUserId))
                                {
                                    throw new ArgumentException(string.Format("Missing RCRAInfoUserID for username {0} on line: {1}", username, lineNumber));
                                }
                                naasUsernameToPasswordMap.Add(username, new UserSubmitInfo(password, infoUserId));
                            }
                        }
                        plugin.AppendAuditLogEvent("Found {0} usernames in NAAS User Mapping File", naasUsernameToPasswordMap.Count);
                    }
                }
                catch (Exception e)
                {
                    plugin.AppendAuditLogEvent("Failed to load NAAS User Mapping File: {0}", e.Message);
                    throw;
                }
            }
            else
            {
                plugin.AppendAuditLogEvent("A NAAS User Mapping File was not specified.");
            }
            return(naasUsernameToPasswordMap);
        }
        public static string DoExtract(BaseWNOSPlugin plugin, SpringBaseDao etlDao, string storedProcName,
                                       int commandTimeout)
        {
            if (string.IsNullOrEmpty(storedProcName))
            {
                plugin.AppendAuditLogEvent("An ETL stored procedure was not specified, so none was executed");
                return(null);
            }

            plugin.AppendAuditLogEvent("Executing ETL stored procedure \"{0}\" with timeout of {1} seconds ...",
                                       storedProcName, commandTimeout.ToString());

            string pk = null;

            try
            {
                IDbParameters    parameters  = etlDao.AdoTemplate.CreateDbParameters();
                IDbDataParameter pkParameter = parameters.AddOut(p_pk_param_name, DbType.String, 50);

                etlDao.AdoTemplate.Execute <int>(delegate(DbCommand command)
                {
                    command.CommandType    = CommandType.StoredProcedure;
                    command.CommandText    = storedProcName;
                    command.CommandTimeout = commandTimeout;
                    Spring.Data.Support.ParameterUtils.CopyParameters(command, parameters);

                    try
                    {
                        SpringBaseDao.ExecuteCommandWithTimeout(command, commandTimeout, delegate(DbCommand commandToExecute)
                        {
                            commandToExecute.ExecuteNonQuery();

                            plugin.AppendAuditLogEvent("Successfully executed ETL stored procedure \"{0}\"", storedProcName);
                        });
                    }
                    catch (Exception spEx)
                    {
                        plugin.AppendAuditLogEvent("Failed to execute ETL stored procedure \"{0}\" with error: {1}",
                                                   storedProcName, ExceptionUtils.GetDeepExceptionMessage(spEx));
                        throw;
                    }
                    if (command.Parameters[pkParameter.ParameterName].Value == DBNull.Value)
                    {
                        // This indicates plugin processing should stop
                        plugin.AppendAuditLogEvent("The ETL stored procedure \"{0}\" returned NULL for the \"{1}\" out parameter",
                                                   storedProcName, p_pk_param_name);
                        return(0);
                    }
                    pk = command.Parameters[pkParameter.ParameterName].Value.ToString();
                    if (string.IsNullOrEmpty(pk))
                    {
                        throw new ArgException("The ETL stored procedure \"{0}\" returned an empty string value for the \"{1}\" out parameter",
                                               storedProcName, p_pk_param_name);
                    }

                    return(0);
                });
            }
            catch (Exception e)
            {
                plugin.AppendAuditLogEvent("Failed to perform extract with error: {0}", ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            return(pk);
        }
Esempio n. 7
0
        public static Dictionary <string, List <string> > LoadWQXAuthorizationFile(BaseWNOSPlugin plugin, string filePath)
        {
            Dictionary <string, List <string> > authorizedWqxUsers = null;

            if (!string.IsNullOrEmpty(filePath))
            {
                try
                {
                    using (TextFieldParser parser = new TextFieldParser(filePath))
                    {
                        parser.TextFieldType = FieldType.Delimited;
                        parser.Delimiters    = new string[] { "," };
                        authorizedWqxUsers   = new Dictionary <string, List <string> >();
                        for (; ;)
                        {
                            long     lineNumber = parser.LineNumber;
                            string[] values     = parser.ReadFields();
                            if (CollectionUtils.IsNullOrEmpty(values))
                            {
                                break;
                            }
                            string wqxOrgId = values[0].Trim().ToUpper();
                            if (string.IsNullOrEmpty(wqxOrgId))
                            {
                                throw new ArgumentException(string.Format("Missing WQX Org Id on line: {0}", lineNumber));
                            }
                            if (wqxOrgId.StartsWith("//"))
                            {
                                // Comment, so ignore line
                            }
                            else
                            {
                                List <string> usernames = null;
                                if (!authorizedWqxUsers.TryGetValue(wqxOrgId, out usernames))
                                {
                                    usernames = new List <string>();
                                    authorizedWqxUsers[wqxOrgId] = usernames;
                                }
                                for (int i = 1; i < values.Length; ++i)
                                {
                                    string username = values[i].Trim().ToUpper();
                                    if (!usernames.Contains(username))
                                    {
                                        usernames.Add(username);
                                    }
                                }
                            }
                        }
                        plugin.AppendAuditLogEvent("Found {0} organizations in authorization file", authorizedWqxUsers.Count);
                    }
                }
                catch (Exception e)
                {
                    plugin.AppendAuditLogEvent("Failed to load WQX authorization file: {0}", e.Message);
                    throw;
                }
            }
            else
            {
                plugin.AppendAuditLogEvent("A WQX authorization file was not specified.");
            }
            return(authorizedWqxUsers);
        }