示例#1
0
		public virtual void ProcessMessage(Source source, Message message)
		{
			// Apply transformers
			foreach (var transformer in Transformers)
			{
				transformer.ProcessMessage(source, message);
			}

			// Route to target
			Channel.HostService.PublishMessage(this, message);
		}
示例#2
0
		public bool AcceptMessage(Source source, Message message)
		{
			// Apply filters
			bool accept = true;
			foreach (var filter in Filters)
			{
				accept &= filter.Evaluate(source, message);
				if (!accept) return false;
			}

			return true;
		}
		public Application CreateApplication()
		{
			Application application = new Application { Name = Name, Description = Description };

			foreach (var portConfig in Ports)
			{
				Port port = new Port();
				IEndpoint endpoint = CreateInstanace(portConfig.Endpoint.TypeInfo) as IEndpoint;
				port.Endpoint = endpoint;

				foreach (var encoderConfig in portConfig.Encoders)
				{
					var encoder = CreateInstanace(encoderConfig.TypeInfo) as IPipelineComponent;
					port.Encoders.Add(encoder);
				}

				foreach (var assemblerConfig in portConfig.Assemblers)
				{
					var encoder = CreateInstanace(assemblerConfig.TypeInfo) as IPipelineComponent;
					port.Assembers.Add(encoder);
				}

				application.Ports.Add(port);
			}

			foreach (var channelConfig in Channels)
			{
				Channel channel = new Channel();
				application.Channels.Add(channel);

				Source source = new Source();
				channel.Source = source;
				LoadFilters(channelConfig.Source.Filters, source.Filters);
				LoadTransformers(channelConfig.Source.Transformers, source.Transformers);

				foreach (var destinationConfiguration in channelConfig.Destinations)
				{
					var destination = new Destination();
					channel.Destinations.Add(destination);

					LoadFilters(destinationConfiguration.Filters, destination.Filters);
					LoadTransformers(destinationConfiguration.Transformers, destination.Transformers);
				}
			}

			return application;
		}
		public void BasicFileEndpointTest()
		{
			// A new application
			Application application = new Application();

			// Add endpoints
			string filePath = "test-file.txt";
			FileReaderEndpoint fileReaderEndpoint = new FileReaderEndpoint(filePath, 100, Encoding.Default);
			application.Ports.Add(new Port { Endpoint = fileReaderEndpoint });

			string fileOutPath = "test-file-out.txt";
			FileWriterEndpoint fileWriterEndpoint = new FileWriterEndpoint(fileOutPath, true, Encoding.Default, true);
			application.Ports.Add(new Port { Endpoint = fileWriterEndpoint });

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

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

			Destination destination = new Destination();
			destination.Target = fileWriterEndpoint;
			channel.Destinations.Add(destination);

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

			// Start the processing
			applicationHost.StartProcessing();
			fileReaderEndpoint.WaitForMessage();
			fileReaderEndpoint.WaitForMessage();

			// Check that endpoint wrote the message

			using (StreamReader reader = new StreamReader(fileOutPath))
			{
				string text = reader.ReadToEnd();
				Assert.AreEqual("Hello world!\nHello world!", text.Trim().Replace("\r\n", "\n"));
				reader.Close();
			}
		}
示例#5
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);
				}
			}
		}