/// <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); }
/// <summary> /// Create processor /// </summary> /// <returns></returns> private SimpleMessageDataProcessor CreateProcessor() { var lf = new LoggerFactory(); var logger = lf.CreateLogger <SimpleMessageDataProcessor>(); return(SimpleMessageDataProcessor.CreateProcessor(logger)); }
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)); }
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())); }
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); }
/// <summary> /// Creates a simple data processor /// </summary> /// <returns></returns> public static IDataProcessor CreateSimpleDataProcessor() { var dataProcessor = SimpleMessageDataProcessor.CreateProcessor(_loggerFactory.CreateLogger <SimpleMessageDataProcessor>()); return(dataProcessor); }