Inheritance: IApplicationHost
Exemplo n.º 1
0
		private Application CreateHl7Application(ApplicationHost pipelineManager)
		{
			Application application = new Application();

			// Endpoints

			{
				var receiveEndoint = new TcpReceiveEndpoint();
				TcpReceieveOptions options = new TcpReceieveOptions { Endpoint = new IPEndPoint(IPAddress.Any, 5678) };
				options.SohDelimiters = new byte[0];
				options.EotDelimiters = new byte[0];
				receiveEndoint.Initialize(_applicationHost, options);
				Port port = new Port { Endpoint = receiveEndoint };
				port.Assembers.Add(new Hl7Disassembler());
				application.Ports.Add(port);
			}
			{
				var sendEndpoint = new TcpSendEndpoint();
				TcpSendOptions options = new TcpSendOptions() { Endpoint = new IPEndPoint(IPAddress.Loopback, 8756) };
				options.SohDelimiters = new byte[0];
				options.EotDelimiters = new byte[0];
				sendEndpoint.Initialize(_applicationHost, options);
				Port port = new Port { Endpoint = sendEndpoint };
				port.Assembers.Add(new Hl7Assembler());
				application.Ports.Add(port);
			}
			{
				var fileEndpoint = new FileWriterEndpoint("service-output.txt", true, Encoding.UTF8, false);
				fileEndpoint.Initialize(_applicationHost, null);
				Port port = new Port { Endpoint = fileEndpoint };
				application.Ports.Add(port);
			}

			// Channels

			Channel channel = new Channel();
			channel.Source = new Source();
			application.Channels.Add(channel);

			{
				// This destination will transform the message
				Destination destination = new Destination();
				destination.Filters.Add(new DelegateFilter((src, message) => true));
				destination.Transformers.Add(new DelegateTransformer(TransformerTest));
				destination.Transformers.Add(new JavaScriptTransformer()
				{
					Script = @"

if(msg['MSH']['MSH.8'] != null) delete msg['MSH']['MSH.8'];
msg['MSH']['MSH.2'] = 'TEST';

"
				});
				channel.Destinations.Add(destination);
			}

			return application;
		}
Exemplo n.º 2
0
		public HieEngine()
		{
			// The HIE Applicatoin Host

			_applicationHost = new ApplicationHost();

			Application application = CreateHl7Application(_applicationHost);

			_applicationHost.Deploy(application);
		}
Exemplo n.º 3
0
		public void BasicRoutingFilteringTransformationTest()
		{
			// A new application
			Application application = new Application();

			// Ports
			Port receivePort = new Port();
			IEndpoint endpoint = new EndpointMock();
			receivePort.Endpoint = endpoint;
			{
				IEncoder encoder = new PipelineComponentMock();
				receivePort.Encoders.Add(encoder);
				IDisassembler disassembler = new PipelineComponentMock();
				receivePort.Assembers.Add(disassembler);
			}
			application.Ports.Add(receivePort);

			Port sendPort = new Port();
			IEndpoint sendEndpoint = new EndpointMock();
			sendPort.Endpoint = sendEndpoint;
			{
				IEncoder encoder = new PipelineComponentMock();
				sendPort.Encoders.Add(encoder);
				IDisassembler disassembler = new PipelineComponentMock();
				sendPort.Assembers.Add(disassembler);
			}
			application.Ports.Add(sendPort);

			// Add a channel
			Channel channel = new Channel();
			application.Channels.Add(channel);

			// Source setup
			Source source = new Source();
			channel.Source = source;
			source.Filters.Add(new DelegateFilter((src, message) => true));
			source.Filters.Add(new JavaScriptFilter { Script = "true" });
			source.Transformers.Add(new DelegateTransformer());
			source.Transformers.Add(new DelegateTransformer((src, message) => { }));
			source.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString())));

			{
				Destination destination = new Destination();
				destination.Target = sendEndpoint;
				destination.Filters.Add(new DelegateFilter((src, message) => true));
				destination.Filters.Add(new JavaScriptFilter { Script = "true" });
				destination.Transformers.Add(new DelegateTransformer((src, message) => { }));
				destination.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString())));
				channel.Destinations.Add(destination);
			}
			{
				// This destination will filter out the message
				Destination destination = new Destination();
				destination.Target = sendEndpoint;
				destination.Filters.Add(new DelegateFilter((src, message) => false));
				channel.Destinations.Add(destination);
			}

			{
				// This destination will transform the message
				Destination destination = new Destination();
				destination.Target = sendEndpoint;
				destination.Filters.Add(new DelegateFilter((src, message) => true));
				destination.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString() + "test")));
				channel.Destinations.Add(destination);
			}

			// Host
			ApplicationHost applicationHost = new ApplicationHost();
			Assert.IsNotNull(applicationHost.Applications);
			applicationHost.Deploy(application);

			// Start the processing

			Message testMessage = new Message("text/json");
			testMessage.SetValueFrom("AAAA");
			// Mock method for sending a test message
			((EndpointMock) endpoint).SendTestMessage(testMessage);

			// Check that endpoint received the message
			EndpointMock endpointMock = sendEndpoint as EndpointMock;
			Assert.IsNotNull(endpointMock);
			Assert.IsNotNull(endpointMock.Messages);
			Assert.AreEqual(2, endpointMock.Messages.Count);
			foreach (byte[] data in endpointMock.Messages)
			{
				string actual = Encoding.UTF8.GetString(data);
				if (actual.EndsWith("test"))
				{
					Assert.AreEqual(testMessage.GetString() + "test", actual);
				}
				else
				{
					Assert.AreEqual(testMessage.GetString(), actual);
				}
			}
		}
Exemplo n.º 4
0
        public void BasicRoutingFilteringTransformationTest()
        {
            // A new application
            Application application = new Application();

            // Ports
            Port      receivePort = new Port();
            IEndpoint endpoint    = new EndpointMock();

            receivePort.Endpoint = endpoint;
            {
                IEncoder encoder = new PipelineComponentMock();
                receivePort.Encoders.Add(encoder);
                IDisassembler disassembler = new PipelineComponentMock();
                receivePort.Assembers.Add(disassembler);
            }
            application.Ports.Add(receivePort);

            Port      sendPort     = new Port();
            IEndpoint sendEndpoint = new EndpointMock();

            sendPort.Endpoint = sendEndpoint;
            {
                IEncoder encoder = new PipelineComponentMock();
                sendPort.Encoders.Add(encoder);
                IDisassembler disassembler = new PipelineComponentMock();
                sendPort.Assembers.Add(disassembler);
            }
            application.Ports.Add(sendPort);

            // Add a channel
            Channel channel = new Channel();

            application.Channels.Add(channel);

            // Source setup
            Source source = new Source();

            channel.Source = source;
            source.Filters.Add(new DelegateFilter((src, message) => true));
            source.Filters.Add(new JavaScriptFilter {
                Script = "true"
            });
            source.Transformers.Add(new DelegateTransformer());
            source.Transformers.Add(new DelegateTransformer((src, message) => { }));
            source.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString())));

            {
                Destination destination = new Destination();
                destination.Target = sendEndpoint;
                destination.Filters.Add(new DelegateFilter((src, message) => true));
                destination.Filters.Add(new JavaScriptFilter {
                    Script = "true"
                });
                destination.Transformers.Add(new DelegateTransformer((src, message) => { }));
                destination.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString())));
                channel.Destinations.Add(destination);
            }
            {
                // This destination will filter out the message
                Destination destination = new Destination();
                destination.Target = sendEndpoint;
                destination.Filters.Add(new DelegateFilter((src, message) => false));
                channel.Destinations.Add(destination);
            }

            {
                // This destination will transform the message
                Destination destination = new Destination();
                destination.Target = sendEndpoint;
                destination.Filters.Add(new DelegateFilter((src, message) => true));
                destination.Transformers.Add(new DelegateTransformer((src, message) => message.SetValueFrom(message.GetString() + "test")));
                channel.Destinations.Add(destination);
            }

            // Host
            ApplicationHost applicationHost = new ApplicationHost();

            Assert.IsNotNull(applicationHost.Applications);
            applicationHost.Deploy(application);

            // Start the processing

            Message testMessage = new Message("text/json");

            testMessage.SetValueFrom("AAAA");
            // Mock method for sending a test message
            ((EndpointMock)endpoint).SendTestMessage(testMessage);

            // Check that endpoint received the message
            EndpointMock endpointMock = sendEndpoint as EndpointMock;

            Assert.IsNotNull(endpointMock);
            Assert.IsNotNull(endpointMock.Messages);
            Assert.AreEqual(2, endpointMock.Messages.Count);
            foreach (byte[] data in endpointMock.Messages)
            {
                string actual = Encoding.UTF8.GetString(data);
                if (actual.EndsWith("test"))
                {
                    Assert.AreEqual(testMessage.GetString() + "test", actual);
                }
                else
                {
                    Assert.AreEqual(testMessage.GetString(), actual);
                }
            }
        }