private void WriteFileHeader()
        {
            ChoNACHAFileHeaderRecord header = ChoActivator.CreateInstanceAndInit <ChoNACHAFileHeaderRecord>();

            header.PriorityCode             = Configuration.PriorityCode;
            header.ImmediateDestination     = Configuration.DestinationBankRoutingNumber;
            header.ImmediateOrigin          = Configuration.OriginatingCompanyId;
            header.FileIDModifier           = Configuration.FileIDModifier;
            header.BlockingFactor           = Configuration.BlockingFactor;
            header.FormatCode               = Configuration.FormatCode;
            header.ImmediateDestinationName = Configuration.DestinationBankName;
            header.ImmediateOriginName      = Configuration.OriginatingCompanyName;
            header.ReferenceCode            = Configuration.ReferenceCode;

            _writer.Write(header);
        }
        public void CreateAddendaRecord(string paymentRelatedInformation, uint addendaTypeCode = 5)
        {
            CheckDisposed();

            _NACHAEntryDetailRecord.AddendaRecordIndicator = true;

            var x = _entryDetailWriter.Value;

            ChoNACHAAddendaRecord addendaRecord = ChoActivator.CreateInstanceAndInit <ChoNACHAAddendaRecord>();

            addendaRecord.AddendaTypeCode           = addendaTypeCode;
            addendaRecord.PaymentRelatedInformation = paymentRelatedInformation;
            addendaRecord.AddendaSequenceNumber     = ++_addendaSeqNo;
            addendaRecord.EntryDetailSequenceNumber = ulong.Parse(TraceNumber.ToString().Last(7));

            _batchRunningStatObject.UpdateStat(addendaRecord);

            _writer.Write(addendaRecord);
        }
        public void Initialize(ChoBaseConfigurationElement configElement)
        {
            if (ConfigObjectAdapterTypeString.IsNullOrWhiteSpace())
            {
                throw new ChoConfigurationException("Missing ConfigObjectAdapterType.");
            }

            Type ConfigObjectAdapterType = ChoType.GetType(ConfigObjectAdapterTypeString);

            if (ConfigObjectAdapterType == null)
            {
                throw new ChoConfigurationException(String.Format("Failed to discover ConfigObjectAdapterType ({0}).", ConfigObjectAdapterTypeString));
            }

            if (!typeof(IChoDictionaryConfigObjectAdapter).IsAssignableFrom(ConfigObjectAdapterType))
            {
                throw new ChoConfigurationException(String.Format("ConfigObjectAdapter ({0}) is not of IChoDictionaryConfigObjectAdapter type.", ConfigObjectAdapterTypeString));
            }

            ConfigObjectAdapter = ChoActivator.CreateInstance(ConfigObjectAdapterType) as IChoDictionaryConfigObjectAdapter;
            ConfigObjectAdapter.Init(configElement, ConfigObjectAdapterParamsString.ToKeyValuePairs());
        }
Exemple #4
0
        public void Init(ChoBaseConfigurationElement configElement, IEnumerable <Tuple <string, string> > parameters)
        {
            string providerAssemblyFilePath = null;

            _configElement = configElement;

            if (parameters != null)
            {
                IsValidState = false;

                _dbGenericKeyValueConfigStorageParams = ChoActivator.CreateInstance <ChoDbGenericKeyValueConfigStorageParams>(parameters);
                if (_dbGenericKeyValueConfigStorageParams.TABLE_NAME.IsNullOrWhiteSpace())
                {
                    _dbGenericKeyValueConfigStorageParams.TABLE_NAME = configElement.ConfigSectionName;
                }
                providerAssemblyFilePath = _dbGenericKeyValueConfigStorageParams.PROVIDER_ASSEMBLY_FILE_PATH;

                if (!providerAssemblyFilePath.IsNullOrWhiteSpace())
                {
                    try
                    {
                        _providerAssembly = Assembly.Load(providerAssemblyFilePath);
                    }
                    catch
                    {
                        _providerAssembly = Assembly.LoadFrom(providerAssemblyFilePath);
                    }
                    if (_providerAssembly == null)
                    {
                        throw new ChoConfigurationException("Can't find '{0}' assembly.".FormatString(providerAssemblyFilePath));
                    }
                }

                string sqlGeneratorTypeName = _dbGenericKeyValueConfigStorageParams.SQL_GENERATOR_TYPE;
                if (!sqlGeneratorTypeName.IsNullOrWhiteSpace())
                {
                    try
                    {
                        _sqlGeneratorType = ChoType.GetType(sqlGeneratorTypeName);
                    }
                    catch (Exception ex)
                    {
                        throw new ChoConfigurationException("Can't find sql generator '{0}' type.".FormatString(sqlGeneratorTypeName), ex);
                    }

                    if (!typeof(IChoDbGenericSqlGenerator).IsAssignableFrom(_sqlGeneratorType))
                    {
                        throw new ChoConfigurationException("Type '{0}' is not assignable from '{1}'.".FormatString(sqlGeneratorTypeName, typeof(IChoDbGenericSqlGenerator)));
                    }
                }

                DiscoverProviderTypes();

                _selectSQL = _selectSQL.FormatString(_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.TABLE_NAME);
                _insertSQL = _insertSQL.FormatString(_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.TABLE_NAME, _dbGenericKeyValueConfigStorageParams.PARAM_PREFIX_CHAR);
                _updateSQL = _updateSQL.FormatString(_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.TABLE_NAME, _dbGenericKeyValueConfigStorageParams.PARAM_PREFIX_CHAR);
                _getLastUpdateTimeStampSQL = _getLastUpdateTimeStampSQL.FormatString(_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.TABLE_NAME, _dbGenericKeyValueConfigStorageParams.LAST_UPDATE_DATETIME_KEY_NAME);

                _daSelectAll = GetDataAdapter(_selectSQL, _insertSQL, _updateSQL);
                _daSave      = GetDataAdapter(_selectSQL, _insertSQL, _updateSQL);

                _getLastUpdateTimeStampCmd             = NewCommand;
                _getLastUpdateTimeStampCmd.Connection  = Connection;
                _getLastUpdateTimeStampCmd.CommandText = _getLastUpdateTimeStampSQL;
                _getLastUpdateTimeStampCmd.CommandType = CommandType.Text;

                DataTable table = LoadConfigData(_dsSelectAll, _daSelectAll, true);

                if (table != null)
                {
                    if (!table.Columns.Contains(_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME))
                    {
                        throw new ChoConfigurationException("Key column '{0}' not found in '{1}' table.".FormatString(_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.TABLE_NAME));
                    }
                    if (table.Columns[_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME].DataType != typeof(String))
                    {
                        throw new ChoConfigurationException("Key column '{0}' is not of type string. Found as '{1}' type.".FormatString(_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME, table.Columns[_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME].DataType));
                    }

                    if (!table.Columns.Contains(_dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME))
                    {
                        throw new ChoConfigurationException("Value column '{0}' not found in '{1}' table.".FormatString(_dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.TABLE_NAME));
                    }
                    if (table.Columns[_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME].DataType != typeof(String))
                    {
                        throw new ChoConfigurationException("Value column '{0}' is not of type string. Found as '{1}' type.".FormatString(_dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME, table.Columns[_dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME].DataType));
                    }
                    _keyColumnLength   = table.Columns[_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME].MaxLength;
                    _valueColumnLength = table.Columns[_dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME].MaxLength;

                    if (_keyColumnLength < 50)
                    {
                        throw new ChoConfigurationException("Key column '{0}' must be of size 50. Found '{1}' size.".FormatString(_dbGenericKeyValueConfigStorageParams.KEY_COLUMN_NAME, _keyColumnLength));
                    }
                }
                else
                {
                    throw new ChoConfigurationException("Value column '{0}' not found in '{1}' table.".FormatString(_dbGenericKeyValueConfigStorageParams.VALUE_COLUMN_NAME, _dbGenericKeyValueConfigStorageParams.TABLE_NAME));
                }

                IsValidState = true;
            }
        }
        public static void Load(object target, string[] commandLineArgs)
        {
            ChoGuard.ArgumentNotNull(target, "Target");

            ChoCommandLineArgBuilder commandLineArgBuilder = target as ChoCommandLineArgBuilder;

            if (commandLineArgBuilder == null)
            {
                throw new ChoApplicationException("Target is not ChoCommandLineArgBuilder.");
            }

            using (ChoCommandLineArgParser commandLineArgParser = new ChoCommandLineArgParser())
            {
                //commandLineArgParser.UnrecognizedCommandLineArgFound += ((sender, eventArgs) =>
                //{
                //    if (commandLineArgBuilder != null)
                //        commandLineArgBuilder.RaiseUnrecognizedCommandLineArgFound(eventArgs);
                //});

                commandLineArgParser.Parse(commandLineArgs);
                if (commandLineArgBuilder != null)
                {
                    ChoEnvironment.CommandLineArgs = ChoEnvironment.CommandLineArgs.Skip(1).ToArray();
                }

                bool isUsageAvail = true;
                ChoCommandLineArgObjectAttribute commandLineArgumentsObjectAttribute = commandLineArgBuilder.GetType().GetCustomAttribute(typeof(ChoCommandLineArgObjectAttribute)) as ChoCommandLineArgObjectAttribute;
                if (commandLineArgumentsObjectAttribute != null)
                {
                    isUsageAvail = !commandLineArgumentsObjectAttribute.Silent;
                }

                if (commandLineArgParser.PosArgs.Length == 0 && commandLineArgParser.Switches.Count == 0)
                {
                    if (isUsageAvail)
                    {
                        throw new ChoCommandLineArgUsageException(commandLineArgBuilder.GetUsage());
                    }
                }

                if (commandLineArgParser.PosArgs.Length == 0 && commandLineArgParser.IsUsageArgSpecified)
                {
                    if (isUsageAvail)
                    {
                        throw new ChoCommandLineArgUsageException(commandLineArgBuilder.GetUsage());
                    }
                }

                string command = commandLineArgParser.PosArgs[0];
                if (command.IsNullOrWhiteSpace())
                {
                    if (isUsageAvail)
                    {
                        throw new ChoCommandLineArgUsageException(commandLineArgBuilder.GetUsage());
                    }
                }

                Type commandLineArgObjectType = commandLineArgBuilder.GetCommandLineArgObjectType(command);

                if (commandLineArgObjectType == null)
                {
                    if (isUsageAvail)
                    {
                        throw new ChoCommandLineArgUsageException("Command '{1}' not found.{0}{0}{2}".FormatString(Environment.NewLine, command, commandLineArgBuilder.GetUsage()));
                    }
                }

                try
                {
                    ChoCommandLineArgObject argObj = ChoActivator.CreateInstance(commandLineArgObjectType) as ChoCommandLineArgObject;
                    commandLineArgBuilder.CommandLineArgObject = argObj;
                }
                catch (ChoCommandLineArgUsageException uEx)
                {
                    throw new ChoCommandLineArgUsageException(uEx.Message.Insert(uEx.Message.IndexOf(' '), " " + command));
                }
                catch (ChoCommandLineArgException aEx)
                {
                    throw new ChoCommandLineArgUsageException(
                              "{1}{0}{0}{2}".FormatString(Environment.NewLine, aEx.ErrorMessage, aEx.UsageMessage.Insert(aEx.UsageMessage.IndexOf(' '), " " + command)));
                }
            }
        }