Beispiel #1
0
        public void Stop()
        {
            ///Sending tasks
            HL7Request item;

            while (m_OutgoingRequests.TryTake(out item))
            {
                if (!item.SenderTask.IsCompleted)
                {
                    item.RequestCancellationToken.Cancel();

                    item.RequestCompletedEvent.WaitOne();
                }
            }

            //Client
            if (!m_EasyClient.IsConnected)
            {
                //Connection
                m_ConnectionCancellationToken?.Cancel();
            }
            else
            {
                m_EasyClient.Close().Wait();
            }

            m_HL7Server.Stop();
        }
Beispiel #2
0
        public async Task M_EasyCLientSendsCommandToHL7InterfaceWaitAckAndResponse()
        {
            HL7InterfaceBase hl7Interface            = new HL7InterfaceBase();
            AutoResetEvent   ackReceived             = new AutoResetEvent(false);
            AutoResetEvent   commandResponseReceived = new AutoResetEvent(false);

            HL7Server serverSide = new HL7Server();

            Assert.IsTrue(serverSide.Setup("127.0.0.1", 50060));

            Assert.IsTrue(hl7Interface.Initialize(serverSide, new HL7ProtocolBase(new HL7ProtocolConfig())));

            Assert.That(hl7Interface.Start());

            hl7Interface.NewRequestReceived += (s, e) =>
            {
                string response = MLLP.CreateMLLPMessage((new PrepareForSpecimenResponse()).Encode());

                byte[] dataToSend = Encoding.ASCII.GetBytes(response);

                s.Send(dataToSend, 0, dataToSend.Length);
            };

            PrepareForSpecimenRequest request = new PrepareForSpecimenRequest();

            EasyClient client = new EasyClient();

            client.Initialize(new ReceiverFilter(new HL7ProtocolBase()), (packageInfo) =>
            {
                if (packageInfo.Request.IsAcknowledge)
                {
                    Assert.That(packageInfo.Request is GeneralAcknowledgment);
                    Assert.That(HL7Parser.IsAckForRequest(request, packageInfo.Request));
                    ackReceived.Set();
                }
                else
                {
                    Assert.IsTrue(packageInfo.Request is PrepareForSpecimenResponse);
                    commandResponseReceived.Set();
                }
            });

            Assert.That(client.ConnectAsync(endPointA).Result);

            byte[] bytesToSend = Encoding.ASCII.GetBytes(MLLP.CreateMLLPMessage(request.Encode()));

            client.Send(bytesToSend);

            Assert.That(ackReceived.WaitOne());

            Assert.That(commandResponseReceived.WaitOne());

            await client.Close();

            serverSide.Stop();

            hl7Interface.Stop();
        }
Beispiel #3
0
        public async Task I_HL7InterfaceSendsMessageToHL7ServerWaitAckAndResponseTest()
        {
            HL7InterfaceBase hl7Interface    = new HL7InterfaceBase();
            HL7Server        server          = new HL7Server();
            AutoResetEvent   requestReceived = new AutoResetEvent(false);

            HL7ProtocolBase protocol = new HL7ProtocolBase(new HL7ProtocolConfig()
            {
                IsAckRequired      = true,
                IsResponseRequired = true,
                AckTimeout         = 10000,
                ResponseTimeout    = 50000
            });

            HL7Server serverSide = new HL7Server();

            serverSide.Setup("127.0.0.1", 50060);

            server.Setup("127.0.0.1", 2012);
            server.Start();

            hl7Interface.Initialize(serverSide, protocol);

            hl7Interface.Start();

            server.NewRequestReceived += (e, s) =>
            {
                Assert.That(s.Request is PrepareForSpecimenRequest);
                requestReceived.Set();
                Thread.Sleep(500);
                byte[] bytesToSend = Encoding.ASCII.GetBytes(MLLP.CreateMLLPMessage((new PrepareForSpecimenResponse()).Encode()));
                e.Send(bytesToSend, 0, bytesToSend.Length);
            };

            bool connected = await hl7Interface.ConnectAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2012));

            Assert.That(connected);

            HL7Request req = await hl7Interface.SendHL7MessageAsync(new PrepareForSpecimenRequest());

            Assert.IsNotNull(req);

            Assert.That(req.Acknowledgment is GeneralAcknowledgment);

            Assert.That(req.Acknowledgment.IsAckForRequest(req.Request));

            Assert.That(req.Acknowledgment.GetValue("MSA-1") == "AA");

            Assert.IsNotNull(req.Response);

            Assert.That(req.Response.IsResponseForRequest(req.Request));

            requestReceived.WaitOne();

            server.Stop();

            hl7Interface.Stop();
        }
Beispiel #4
0
        public async Task H_HL7InterfaceSendsMessageToHL7ServerWaitAck()
        {
            HL7InterfaceBase hl7Interface    = new HL7InterfaceBase();
            HL7Server        server          = new HL7Server();
            AutoResetEvent   requestReceived = new AutoResetEvent(false);

            HL7ProtocolBase protocol = new HL7ProtocolBase(new HL7ProtocolConfig()
            {
                IsAckRequired      = true,
                IsResponseRequired = false
            });

            HL7Server serverSide = new HL7Server();

            serverSide.Setup("127.0.0.1", 50060);

            server.Setup("127.0.0.1", 2012);
            server.Start();

            hl7Interface.Initialize(serverSide, protocol);
            hl7Interface.Start();

            server.NewRequestReceived += (e, s) =>
            {
                Assert.That(s.Request is PrepareForSpecimenRequest);
                requestReceived.Set();
            };

            bool connected = await hl7Interface.ConnectAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2012));

            Assert.That(connected);

            HL7Request req = await hl7Interface.SendHL7MessageAsync(new PrepareForSpecimenRequest());

            Assert.IsNotNull(req);

            Assert.That(req.Acknowledgment is GeneralAcknowledgment);

            Assert.That(HL7Parser.IsAckForRequest(req.Request, req.Acknowledgment));

            requestReceived.WaitOne();

            server.Stop();

            hl7Interface.Stop();
        }
Beispiel #5
0
        public async Task G_HL7InterfaceSendsMessageToHL7ServerNoAckNoResponse()
        {
            HL7InterfaceBase hl7Interface = new HL7InterfaceBase();

            HL7Server server = new HL7Server();

            AutoResetEvent requestReceived = new AutoResetEvent(false);

            HL7ProtocolBase protocol = new HL7ProtocolBase(new HL7ProtocolConfig()
            {
                IsAckRequired      = false,
                IsResponseRequired = false
            });

            server.Setup("127.0.0.1", 50050);
            server.Start();

            HL7Server serverSide = new HL7Server();

            serverSide.Setup("127.0.0.1", 50060);

            hl7Interface.Initialize(serverSide, protocol);

            hl7Interface.Start();

            server.NewRequestReceived += (e, s) =>
            {
                Assert.That(s.Request is PrepareForSpecimenRequest);
                requestReceived.Set();
            };

            bool connected = await hl7Interface.ConnectAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 50050));

            Assert.That(connected);

            await hl7Interface.SendHL7MessageAsync(new PrepareForSpecimenRequest());

            requestReceived.WaitOne();

            server.Stop();

            hl7Interface.Stop();
        }
Beispiel #6
0
        public async Task J_EasyClientSendsCommandToHL7ServerAndWaitAck()
        {
            AutoResetEvent ackReceived = new AutoResetEvent(false);

            HL7Server hl7Server = new HL7Server();

            hl7Server.Setup("127.0.0.1", 50060);

            hl7Server.Start();

            PrepareForSpecimenRequest request = new PrepareForSpecimenRequest();

            EasyClient client = new EasyClient();

            client.Initialize(new ReceiverFilter(new HL7ProtocolBase()), (packageInfo) =>
            {
                if (packageInfo.Request.IsAcknowledge)
                {
                    Assert.That(packageInfo.Request is GeneralAcknowledgment);
                    Assert.That(HL7Parser.IsAckForRequest(request, packageInfo.Request));
                    ackReceived.Set();
                }
                else
                {
                    Assert.Fail();
                }
            });

            Assert.That(client.ConnectAsync(endPointA).Result);

            Assert.That(client.IsConnected);

            byte[] bytesToSend = Encoding.ASCII.GetBytes(MLLP.CreateMLLPMessage(request.Encode()));
            client.Send(bytesToSend);

            Assert.That(ackReceived.WaitOne());

            await client.Close();

            hl7Server.Stop();
        }
Beispiel #7
0
        public async Task B_ConnectHL7InterfaceToAppServer()
        {
            HL7InterfaceBase hl7Interface = new HL7InterfaceBase();

            HL7Server server = new HL7Server();

            Assert.That(server.Setup("127.0.0.1", 2012));
            Assert.That(server.Start());

            Assert.That(hl7Interface.Initialize());

            Assert.That(hl7Interface.Start());

            bool connected = await hl7Interface.ConnectAsync(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2012));

            Assert.That(connected);

            server.Stop();

            hl7Interface.Stop();
        }