예제 #1
0
        public static object GetInstance(Type type)
        {
            ChoGuard.ArgumentNotNull(type, "Type");
            if (_singletonStateDictService.GetValue(type))
            {
                return(_singletonDictService.GetValue(type));
            }

            lock (_padLock)
            {
                if (_singletonStateDictService.GetValue(type))
                {
                    return(_singletonDictService.GetValue(type));
                }

                Func <object> factory = _singletonFactoryDictService[type];
                if (factory == null)
                {
                    _singletonDictService.SetValue(type, ChoActivator.CreateInstance(type));
                }
                else
                {
                    _singletonDictService.SetValue(type, factory());
                }

                _singletonStateDictService.SetValue(type, true);
                return(_singletonDictService.GetValue(type));
            }
        }
예제 #2
0
        private void WriteFileControlFillerRecords()
        {
            if (Configuration.BlockingFactor <= 0)
            {
                return;
            }

            uint remain = _runningStatObject.TotalNoOfRecord % Configuration.BlockingFactor;

            if (remain <= 0)
            {
                return;
            }

            ChoNACHAFileControlRecord NACHAFileControlFillerRecord = ChoActivator.CreateInstance <ChoNACHAFileControlRecord>();

            NACHAFileControlFillerRecord.BatchCount                   = 999999;
            NACHAFileControlFillerRecord.BlockCount                   = 999999;
            NACHAFileControlFillerRecord.EntryAddendaCount            = 99999999;
            NACHAFileControlFillerRecord.EntryHash                    = 9999999999;
            NACHAFileControlFillerRecord.TotalDebitEntryDollarAmount  = 999999999999;
            NACHAFileControlFillerRecord.TotalCreditEntryDollarAmount = 999999999999;
            NACHAFileControlFillerRecord.Reserved = ChoString.Repeat("9", 39);

            for (int i = 0; i < Configuration.BlockingFactor - remain; i++)
            {
                _writer.Write(NACHAFileControlFillerRecord);
            }
        }
예제 #3
0
        private void Init()
        {
            _writer = new ChoManifoldWriter(_streamWriter, Configuration as ChoManifoldRecordConfiguration).WithRecordSelector(0, 1, typeof(ChoNACHABatchHeaderRecord), typeof(ChoNACHABatchControlRecord),
                                                                                                                               typeof(ChoNACHAFileHeaderRecord), typeof(ChoNACHAFileControlRecord), typeof(ChoNACHAEntryDetailRecord), typeof(ChoNACHAAddendaRecord));
            _writer.Configuration.ObjectValidationMode = ChoObjectValidationMode.ObjectLevel;

            WriteFileHeader();
            _fileControlRecord = ChoActivator.CreateInstance <ChoNACHAFileControlRecord>();
        }
예제 #4
0
 private static object CreateInstance(Type type, params object[] args)
 {
     try
     {
         return(ChoActivator.CreateInstance(type, args));
     }
     catch (Exception ex)
     {
         throw new ChoHL7Exception("Failed to create '{0}' object.".FormatString(type.FullName), ex);
     }
 }
예제 #5
0
        private void WriteFileHeader()
        {
            ChoNACHAFileHeaderRecord header = ChoActivator.CreateInstance <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);
        }
예제 #6
0
        public void CreateAddendaRecord(string paymentRelatedInformation, uint addendaTypeCode = 5)
        {
            CheckDisposed();

            _NACHAEntryDetailRecord.AddendaRecordIndicator = true;

            var x = _entryDetailWriter.Value;

            ChoNACHAAddendaRecord addendaRecord = ChoActivator.CreateInstance <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());
        }
예제 #8
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)));
                }
            }
        }