Ejemplo n.º 1
0
        /// <summary>
        /// Create data processor function
        /// </summary>
        /// <typeparam name="TConfig"></typeparam>
        /// <param name="config"></param>
        /// <param name="loggerFactory"></param>
        /// <param name="dataProcessorType"></param>
        /// <param name="getIdFunc"></param>
        /// <returns></returns>
        public Func <IDataProcessor> CreateDataProcesorFunc <TConfig>(TConfig config, ILoggerFactory loggerFactory,
                                                                      EnumDataProcessorType dataProcessorType, Func <byte[], byte[]> getIdFunc = null)
            where TConfig : ConfigBase
        {
            // set data processor creator
            switch (dataProcessorType)
            {
            case EnumDataProcessorType.Hsm:
                return(new Func <IDataProcessor>(() => SimpleMessageDataProcessor.CreateProcessor(
                                                     loggerFactory.CreateLogger <SimpleMessageDataProcessor>(),
                                                     config.SocketBufferSize * 2)));

            case EnumDataProcessorType.Message:
                return(new Func <IDataProcessor>(() => SimpleMessageDataProcessor.CreateProcessor(
                                                     loggerFactory.CreateLogger <SimpleMessageDataProcessor>(),
                                                     config.SocketBufferSize * 2, 2)));

            case EnumDataProcessorType.Iso8583:
                return(new Func <IDataProcessor>(() => MessageDataProcessor.CreateIso8583Processor(
                                                     loggerFactory.CreateLogger <MessageDataProcessor>(),
                                                     config.SocketBufferSize * 2, getIdFunc)));
            }

            // nothing done
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create processor
        /// </summary>
        /// <returns></returns>
        private SimpleMessageDataProcessor CreateProcessor()
        {
            var lf     = new LoggerFactory();
            var logger = lf.CreateLogger <SimpleMessageDataProcessor>();

            return(SimpleMessageDataProcessor.CreateProcessor(logger));
        }
Ejemplo n.º 3
0
        CreateTestServer <TEventHandler>(int port, bool start = false)
            where TEventHandler : IServerEventHandler
        {
            var            dataProcessor = SimpleMessageDataProcessor.CreateProcessor(_loggerFactory.CreateLogger <SimpleMessageDataProcessor>());
            var            eventHandler  = Activator.CreateInstance <TEventHandler>();
            IServerService server        = new TcpServerService(eventHandler, new ServerConfig("127.0.0.1", port),
                                                                _loggerFactory, EnumDataProcessorType.Hsm, (b) => b.ToList().Take(1).ToArray());

            if (start)
            {
                server.Start();
            }
            return(new Tuple <IServerService, TEventHandler, SimpleMessageDataProcessor>(server, eventHandler, dataProcessor));
        }
Ejemplo n.º 4
0
        public void TestDelimiterInHeaderDoesNotSplitMessage()
        {
            // create processor
            var logger = new LoggerFactory().CreateLogger <SimpleMessageDataProcessor>();
            var proc   = SimpleMessageDataProcessor.CreateProcessor(logger, 500, 2);

            // buffer of two messages 9 (0019) and 99 (00299)
            var buffer = new byte[] { 0, 0, 1, 9, 0, 0, 2, 9, 9 };

            // process buffer
            var ret = proc.ProcessReceivedRawData(buffer, buffer.Length);

            Assert.AreEqual(2, ret.Count());
            Assert.IsTrue(new byte[] { 9 }.SequenceEqual(ret.First()));
            Assert.IsTrue(new byte[] { 9, 9 }.SequenceEqual(ret.Skip(1).First()));
        }
Ejemplo n.º 5
0
        public void TestAgnosticToRepeatedDelimiterMultuple()
        {
            // setup
            var delimiter = new byte[] { 0 };

            // create processor
            var logger = new LoggerFactory().CreateLogger <SimpleMessageDataProcessor>();
            var proc   = SimpleMessageDataProcessor.CreateProcessor(logger, 500, 2);

            // test buffer with errors
            var buffer = new byte[] { 0, 1, 0, 0, 0, 0, 0, 1, 0 }.ToList(); // delimiter with length header (256 + 0) and error delimietrs more

            buffer.AddRange(Enumerable.Range(0, 34).Select(i => (byte)99));
            buffer.AddRange(new byte[] { 0, 1, 0 });
            buffer.AddRange(Enumerable.Range(0, 256).Select(i => (byte)99));

            // tesr ret
            var ret = proc.ProcessReceivedRawData(buffer.ToArray(), buffer.Count());

            Assert.AreEqual(256, ret.Last().Length);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a simple data processor
        /// </summary>
        /// <returns></returns>
        public static IDataProcessor CreateSimpleDataProcessor()
        {
            var dataProcessor = SimpleMessageDataProcessor.CreateProcessor(_loggerFactory.CreateLogger <SimpleMessageDataProcessor>());

            return(dataProcessor);
        }