Exemplo n.º 1
0
        public static ServiceType GetServiceType(BaseWNOSPlugin plugin)
        {
            ServiceType type = ServiceType.None;

            if (plugin is ISubmitProcessor)
            {
                type |= ServiceType.Submit;
            }
            if (plugin is ISolicitProcessor)
            {
                type |= ServiceType.Solicit;
            }
            if (plugin is IQueryProcessor)
            {
                type |= ServiceType.Query;
            }
            if (plugin is INotifyProcessor)
            {
                type |= ServiceType.Notify;
            }
            if (plugin is IExecuteProcessor)
            {
                type |= ServiceType.Execute;
            }
            if (plugin is ITaskProcessor)
            {
                type |= ServiceType.Task;
            }
            return(type);
        }
Exemplo n.º 2
0
        protected virtual void ConfigurePlugin <T>(DataService inDataService, T ioPlugin) where T : class
        {
            BaseWNOSPlugin basePlugin = ioPlugin as BaseWNOSPlugin;

            if (basePlugin == null)
            {
                return;
            }
            if (!CollectionUtils.KeysMatch(inDataService.Args, basePlugin.ConfigurationArguments))
            {
                throw new ArgumentException(string.Format("The user-defined arguments for the service \"{0}\" do not match the arguments required by the service plugin \"{1}\".",
                                                          inDataService.Name, inDataService.PluginInfo.ImplementingClassName));
            }
            if (!CollectionUtils.IsNullOrEmpty(inDataService.Args))
            {
                foreach (KeyValuePair <string, string> arg in inDataService.Args)
                {
                    string val = arg.Value;

                    if ((val != null) && val.StartsWith(ConfigItem.GLOBAL_ARG_INDICATOR))
                    {
                        string globalKeyName = val.Replace(ConfigItem.GLOBAL_ARG_INDICATOR, string.Empty);

                        ConfigItem configItem = _configManager.Get(globalKeyName);

                        if (configItem == null)
                        {
                            throw new ArgumentException("Invalid global key argument: " + configItem);
                        }
                        else
                        {
                            val = configItem.Value;
                        }
                    }

                    basePlugin.SetConfigurationArgument(arg.Key, val);
                }
            }
            if (!CollectionUtils.KeysMatch(inDataService.DataSources, basePlugin.DataProviders))
            {
                throw new ArgumentException(string.Format("The user-defined data sources for the service \"{0}\" do not match the data sources required by the service plugin \"{1}\".",
                                                          inDataService.Name, inDataService.PluginInfo.ImplementingClassName));
            }
            if (!CollectionUtils.IsNullOrEmpty(inDataService.DataSources))
            {
                foreach (KeyValuePair <string, DataProviderInfo> arg in inDataService.DataSources)
                {
                    DataProviderInfo provider = arg.Value;
                    basePlugin.SetDataProvider(arg.Key, provider);
                }
            }

            basePlugin.ValidateConfiguration();
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 public virtual void GetDataServiceParameters(IEnumerable <DataService> dataServices)
 {
     if (CollectionUtils.IsNullOrEmpty(dataServices))
     {
         return;
     }
     try
     {
         string pluginRootFilePath         = GetPluginFilePath(CollectionUtils.FirstItem(dataServices), true);
         PluginDomainInstanceLoader loader = GetPluginInstanceLoader(null, pluginRootFilePath);
         using (PluginDisposer disposer = new PluginDisposer(loader))
         {
             foreach (DataService dataService in dataServices)
             {
                 if ((dataService.PluginInfo != null) && !string.IsNullOrEmpty(dataService.PluginInfo.ImplementingClassName))
                 {
                     try
                     {
                         string                  pluginFilePath = GetPluginFilePath(dataService, true);
                         BaseWNOSPlugin          plugin         = loader.GetInstance <BaseWNOSPlugin>(pluginFilePath, dataService.PluginInfo.ImplementingClassName);
                         DataServicePublishFlags publishFlags;
                         dataService.ServiceParameters = plugin.GetDataServiceParameters(dataService.Name, out publishFlags);
                         dataService.PublishFlags      = publishFlags;
                     }
                     catch (Exception e)
                     {
                         // Don't publish on load error
                         dataService.PublishFlags = DataServicePublishFlags.DoNotPublish;
                         LOG.Error("Failed to GetDataServiceParameters for data service \"{0}\"", e, dataService.Name);
                     }
                 }
                 else
                 {
                     // Don't publish if not implementer
                     dataService.PublishFlags = DataServicePublishFlags.DoNotPublish;
                 }
             }
         }
     }
     catch (Exception)
     {
         foreach (DataService dataService in dataServices)
         {
             // Don't publish if can't load
             dataService.PublishFlags = DataServicePublishFlags.DoNotPublish;
         }
     }
 }
Exemplo n.º 6
0
        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 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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 10
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);
        }
        public static string GenerateAndValidateWqxQueryFile(IAppendAuditLogEvent appendAuditLogEvent, IObjectsFromDatabase objectsFromDatabase, SpringBaseDao baseDao,
                                                             string queryOrganizationName, string queryOrganizationIdentifier, string sysTempFolderPath,
                                                             Assembly xmlSchemaZippedResourceAssembly, string xmlSchemaZippedQualifiedResourceName,
                                                             string xmlSchemaRootFileName, ISerializationHelper serializationHelper, ICompressionHelper compressionHelper,
                                                             out string validationErrorsFile)
        {
            validationErrorsFile = null;

            WQXDataType wqx = GenerateWqxQueryFromDatabase(appendAuditLogEvent, objectsFromDatabase, baseDao, queryOrganizationIdentifier);

            if (wqx == null)
            {
                return(null);
            }

            appendAuditLogEvent.AppendAuditLogEvent("Generating WQX xml file from query results ...");
            string tempFolderPath  = Path.Combine(sysTempFolderPath, Guid.NewGuid().ToString());
            string fileName        = Guid.NewGuid().ToString();
            string tempXmlFilePath = Path.Combine(tempFolderPath, WQX_FILE_PREFIX + fileName + ".xml");
            string zipXmlFilePath  = Path.ChangeExtension(Path.Combine(sysTempFolderPath, fileName), ".zip");

            Directory.CreateDirectory(tempFolderPath);

            try
            {
                serializationHelper.Serialize(wqx, tempXmlFilePath);

                appendAuditLogEvent.AppendAuditLogEvent("Inserting header into WQX xml file");
                tempXmlFilePath = MakeHeaderFile(tempXmlFilePath, tempFolderPath, queryOrganizationName, queryOrganizationIdentifier, serializationHelper);
                appendAuditLogEvent.AppendAuditLogEvent("Inserted header into WQX xml file");

                appendAuditLogEvent.AppendAuditLogEvent("Generated WQX xml file from query results");

                validationErrorsFile =
                    BaseWNOSPlugin.ValidateXmlFile(tempXmlFilePath, xmlSchemaZippedResourceAssembly, xmlSchemaZippedQualifiedResourceName,
                                                   xmlSchemaRootFileName, sysTempFolderPath, appendAuditLogEvent, compressionHelper);



                if (validationErrorsFile != null)
                {
                    compressionHelper.CompressFile(tempXmlFilePath, zipXmlFilePath);
                    return(zipXmlFilePath);
                }

                try
                {
                    appendAuditLogEvent.AppendAuditLogEvent("Writing attachment files to temp folder ...");
                    WriteAttachmentFilesToFolder(baseDao, wqx, tempFolderPath);
                    appendAuditLogEvent.AppendAuditLogEvent("Wrote attachment files to temp folder.");

                    appendAuditLogEvent.AppendAuditLogEvent("Compressing WQX xml data file and attachments ...");
                    compressionHelper.CompressDirectory(zipXmlFilePath, tempFolderPath);
                    appendAuditLogEvent.AppendAuditLogEvent("Compressed WQX xml data file and attachments.");
                }
                catch (Exception ex)
                {
                    FileUtils.SafeDeleteFile(zipXmlFilePath);
                    throw ex;
                }
                finally
                {
                    FileUtils.SafeDeleteDirectory(tempFolderPath);
                }

                return(zipXmlFilePath);
            }
            catch (Exception)
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
                throw;
            }
        }
        public static WQXDataType GenerateWqxObjectsFromSubmissionFile(IAppendAuditLogEvent appendAuditLogEvent, string submissionFilePath,
                                                                       string sysTempFolderPath, Assembly xmlSchemaZippedResourceAssembly,
                                                                       string xmlSchemaZippedQualifiedResourceName, string xmlSchemaRootFileName,
                                                                       ISerializationHelper serializationHelper, ICompressionHelper compressionHelper,
                                                                       out string attachmentsFolderPath, out string validationErrorsFile)
        {
            WQXDataType data = null;

            attachmentsFolderPath = null;
            string wqxFilePath = null;

            validationErrorsFile = null;

            try
            {
                attachmentsFolderPath = Path.Combine(sysTempFolderPath, Guid.NewGuid().ToString());
                Directory.CreateDirectory(attachmentsFolderPath);

                appendAuditLogEvent.AppendAuditLogEvent("Decompressing the WQX data to a temporary folder ...");
                try
                {
                    compressionHelper.UncompressDirectory(submissionFilePath, attachmentsFolderPath);
                }
                catch (Exception ex)
                {
                    throw new ArgException("An error occurred decompressing the WQX data: {0}", ExceptionUtils.GetDeepExceptionMessage(ex));
                }
                string[] xmlFiles = Directory.GetFiles(attachmentsFolderPath, "*.xml");
                if (xmlFiles.Length == 0)
                {
                    throw new ArgException("Failed to locate an WQX xml file in the WQX data");
                }
                else if (xmlFiles.Length > 1)
                {
                    throw new ArgException("More than one xml file was found in the WQX data");
                }
                wqxFilePath = xmlFiles[0];

                if (!string.IsNullOrEmpty(xmlSchemaZippedQualifiedResourceName))
                {
                    validationErrorsFile =
                        BaseWNOSPlugin.ValidateXmlFile(wqxFilePath, xmlSchemaZippedResourceAssembly, xmlSchemaZippedQualifiedResourceName,
                                                       xmlSchemaRootFileName, sysTempFolderPath, appendAuditLogEvent, compressionHelper);

                    if (validationErrorsFile != null)
                    {
                        FileUtils.SafeDeleteDirectory(attachmentsFolderPath);
                        return(null);
                    }
                }

                //Remove header
                wqxFilePath = RemoveHeaderFile(wqxFilePath, sysTempFolderPath, serializationHelper);

                appendAuditLogEvent.AppendAuditLogEvent("Deserializing the WQX data xml file ...");
                try
                {
                    data = serializationHelper.Deserialize <WQXDataType>(wqxFilePath);
                }
                catch (Exception ex)
                {
                    appendAuditLogEvent.AppendAuditLogEvent("Failed to deserialize the WQX data xml file: {0}", ExceptionUtils.GetDeepExceptionMessage(ex));
                    throw;
                }
                if (data == null)
                {
                    appendAuditLogEvent.AppendAuditLogEvent("The WQX data does not contain any organizations, so no elements will be stored in the database.");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                FileUtils.SafeDeleteDirectory(attachmentsFolderPath);
                throw ex;
            }
            finally
            {
                FileUtils.SafeDeleteFile(wqxFilePath);
            }

            return(data);
        }