コード例 #1
0
        public Message Build()
        {
            try
            {
                Message message = new Message(_messageTypeIdentifier, _dataElementsDefinition);

                foreach (KeyValuePair <int, Node> kvp in messageTree)
                {
                    if (_dataElementsDefinition.ContainsElementDefinition(kvp.Key))
                    {
                        DataElement dataElement = CreateDataElement(kvp.Value,
                                                                    _dataElementsDefinition.GetDataDefinition(kvp.Key));
                        message.AddOrReplaceDataElement(dataElement);
                    }
                    else
                    {
                        throw new Exception($"Missing definition, DE: {kvp.Key}");
                    }
                }

                return(message);
            }
            catch (Exception ex)
            {
                throw new Exception($"Error: ISO8583Builder.Build()", ex);
            }
        }
コード例 #2
0
        private void CreateDEs(DataString dataString)
        {
            DataElements = new DataElementCollection();

            DataString dataElementsString = dataString.SubString(readerIndex);

            List <int> dataElementsBitMap = BitMaps.GetPresentDataElements();

            foreach (int de in dataElementsBitMap)
            {
                if (DataDefinitionDictionary.ContainsElementDefinition(de))
                {
                    DataDefinition dataDef = DataDefinitionDictionary.GetDataDefinition(de);

                    int dataElementsReaderIndex = 0;

                    try
                    {
                        DataString data = dataDef.GetAllData(dataElementsString, ref dataElementsReaderIndex);

                        dataElementsString = dataElementsString.SubString(dataElementsReaderIndex);

                        DataElements.AddOrReplaceDataElement(new DataElement(de, dataDef, data));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Missing or incorrectly defined DE: " + de + ".", ex);
                    }
                }
                else
                {
                    throw new Exception("Missing definition, DE: " + de + ".");
                }
            }
        }