コード例 #1
0
ファイル: SwiftFile.cs プロジェクト: colinnaylor/CN
        private static SwiftMessage SelectMessageType(string Content)
        {
            SwiftMessage ret = null;

            string[] lines = SwiftMessage.Lines(Content);

            int    pos                    = lines[0].IndexOf("{1:");
            string applicationID          = lines[0].Substring(pos + 3, 1);
            string serviceID              = lines[0].Substring(pos + 4, 2);
            string logicalTerminalAddress = lines[0].Substring(pos + 6, 12);
            int    sessionNumber          = int.Parse(lines[0].Substring(pos + 18, 4));
            int    sequenceNumber         = int.Parse(lines[0].Substring(pos + 22, 6));

            switch (serviceID)
            {
            case "21":     // ACK/NAK
                ret = new Acknowledgement(Content, applicationID, serviceID, logicalTerminalAddress, sessionNumber, sequenceNumber);
                break;

            case "01":     // FIN/GPA
                pos = lines[0].IndexOf("{2:");
                if (pos == -1)
                {
                    throw new Exception("Section 2 missing from Swift message\r\n----------\r\n{0}".Args(Content));
                }
                string messageType = lines[0].Substring(pos + 4, 3);
                switch (messageType)
                {
                case "300":
                    ret = new MT300(Content, applicationID, serviceID, logicalTerminalAddress, sessionNumber, sequenceNumber);
                    break;

                case "535":
                    ret = new MT535(Content, applicationID, serviceID, logicalTerminalAddress, sessionNumber, sequenceNumber);
                    break;

                case "940":
                    ret = new MT940(Content, applicationID, serviceID, logicalTerminalAddress, sessionNumber, sequenceNumber);
                    break;

                case "950":
                    ret = new MT950(Content, applicationID, serviceID, logicalTerminalAddress, sessionNumber, sequenceNumber);
                    break;

                default:
                    throw new NotImplementedException("Message Type not supported.");
                }

                break;

            default:
                throw new Exception("Service type in message is not supported [{0}]".Args(serviceID));
            }

            ret.Parse();

            return(ret);
        }
コード例 #2
0
ファイル: SwiftFile.cs プロジェクト: colinnaylor/CN
        public SwiftFile(string SwiftFileName)
        {
            filename = SwiftFileName;

            ReadFile();

            // Split into SwiftMessages
            List <string> blocks = SplitIntoMessages();

            SwiftMessage message = null;

            // for each SwiftMessage
            foreach (string block in blocks)
            {
                // now we can determine the message type so we know which to import
                message = SelectMessageType(block);

                if (message.Type != MessageType.ACK)
                {
                    Messages.Add(message);
                }
            }
        }