static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Setup logger and MethodInvocationRemoting objects using (FileApplicationLogger remoteSenderLog = new FileApplicationLogger(LogLevel.Debug, '|', " ", @"C:\Temp\C#Sender.log")) using (TcpRemoteSender tcpSender = new TcpRemoteSender(System.Net.IPAddress.Loopback, 55000, 10, 1000, 30000, 25, remoteSenderLog)) using (TcpRemoteReceiver tcpReceiver = new TcpRemoteReceiver(55001, 10, 1000, 25, remoteSenderLog)) { RemoteReceiverDecompressor decompressorReceiver = new RemoteReceiverDecompressor(tcpReceiver, remoteSenderLog); MethodInvocationSerializer serializer = new MethodInvocationSerializer(new SerializerOperationMap(), remoteSenderLog); MethodInvocationRemoteSender methodInvocationRemoteSender = new MethodInvocationRemoteSender(serializer, tcpSender, decompressorReceiver, remoteSenderLog); // Connect to the MethodInvocationRemoteReceiver tcpSender.Connect(); tcpReceiver.Connect(); // Setup the layers of the application MVP model MainView mainView = new MainView(); Model model = new Model(methodInvocationRemoteSender); Presenter presenter = new Presenter(mainView, model); mainView.Presenter = presenter; // Start the application Application.Run(mainView); // Disconnect from the MethodInvocationRemoteReceiver tcpReceiver.Disconnect(); tcpSender.Disconnect(); } }
protected void SetUp() { mocks = new Mockery(); mockTcpClient = mocks.NewMock <ITcpClient>(); mockNetworkStream = mocks.NewMock <INetworkStream>(); mockApplicationLogger = mocks.NewMock <IApplicationLogger>(); testIpAddress = System.Net.IPAddress.Parse("127.0.0.1"); testTcpRemoteSender = new TcpRemoteSender(testIpAddress.ToString(), testPort, 3, 10, 25, 10, mockApplicationLogger, new NullMetricLogger(), mockTcpClient); }
protected void SetUp() { mocks = new Mockery(); mockTcpClient = mocks.NewMock <ITcpClient>(); mockNetworkStream = mocks.NewMock <INetworkStream>(); mockMetricLogger = mocks.NewMock <IMetricLogger>(); testIpAddress = System.Net.IPAddress.Parse("127.0.0.1"); testTcpRemoteSender = new TcpRemoteSender(testIpAddress.ToString(), testPort, 3, 10, 25, 10, new ConsoleApplicationLogger(LogLevel.Critical, '|', " "), mockMetricLogger, mockTcpClient); }
public void InvalidAcknowledgementReceiveTimeoutArgument() { ArgumentOutOfRangeException e = Assert.Throws <ArgumentOutOfRangeException>(delegate { testTcpRemoteSender = new TcpRemoteSender(testIpAddress.ToString(), testPort, 100, 10, -1, 100, new ConsoleApplicationLogger(LogLevel.Warning, '|', " "), new NullMetricLogger(), mockTcpClient); }); Assert.That(e.Message, NUnit.Framework.Is.StringStarting("Argument 'acknowledgementReceiveTimeout' must be greater than or equal to 0.")); Assert.AreEqual("acknowledgementReceiveTimeout", e.ParamName); }
//------------------------------------------------------------------------------ // // Method: MainViewRemoteAdapterTcp (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the SampleApplication2.MainViewRemoteAdapterTcp class. /// </summary> /// <param name="remoteIpAddress">The IP address of the machine where the ContactListPresenterRemoteAdapterTcp object is located.</param> /// <param name="outgoingSenderPort">The TCP port on which to send outgoing method invocation requests (i.e. calls).</param> /// <param name="outgoingReceiverPort">The TCP port on which to receive outgoing method invocation responses (i.e. return values).</param> /// <param name="incomingSenderPort">The TCP port on which to send incoming method invocation responses (i.e. return values).</param> /// <param name="incomingReceiverPort">The TCP port on which to receive incoming method invocation requests (i.e. calls).</param> /// <param name="connectRetryCount">The number of times to retry when initially connecting, or attempting to reconnect the underlying TcpRemoteSender and TcpRemoteReceiver objects.</param> /// <param name="connectRetryInterval">The interval between retries to connect or reconnect in milliseconds.</param> /// <param name="acknowledgementReceiveTimeout">The maximum time the TcpRemoteSender should wait for an acknowledgement of a message in milliseconds.</param> /// <param name="acknowledgementReceiveRetryInterval">The time the TcpRemoteSender should wait between retries to check for an acknowledgement in milliseconds.</param> /// <param name="receiveRetryInterval">The time the TcpRemoteReceiver should wait between attempts to receive a message in milliseconds.</param> public MainViewRemoteAdapterTcp(System.Net.IPAddress remoteIpAddress, int outgoingSenderPort, int outgoingReceiverPort, int incomingSenderPort, int incomingReceiverPort, int connectRetryCount, int connectRetryInterval, int acknowledgementReceiveTimeout, int acknowledgementReceiveRetryInterval, int receiveRetryInterval) { // Setup objects for sending method invocations outgoingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); outgoingSender = new TcpRemoteSender(remoteIpAddress, outgoingSenderPort, connectRetryCount, connectRetryInterval, acknowledgementReceiveTimeout, acknowledgementReceiveRetryInterval); outgoingReceiver = new TcpRemoteReceiver(outgoingReceiverPort, connectRetryCount, connectRetryInterval, receiveRetryInterval); methodInvocationSender = new MethodInvocationRemoteSender(outgoingMethodSerializer, outgoingSender, outgoingReceiver); // Setup objects for receiving method invocations incomingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); incomingSender = new TcpRemoteSender(remoteIpAddress, incomingSenderPort, connectRetryCount, connectRetryInterval, acknowledgementReceiveTimeout, acknowledgementReceiveRetryInterval); incomingReceiver = new TcpRemoteReceiver(incomingReceiverPort, connectRetryCount, connectRetryInterval, receiveRetryInterval); methodInvocationReceiver = new MethodInvocationRemoteReceiver(incomingMethodSerializer, incomingSender, incomingReceiver); // Hook the 'MethodInvocationReceived' event on the receiver up to the local method which handles recieving method invocations methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation); }
protected void SetUp() { mocks = new Mockery(); mockTcpClient = mocks.NewMock <ITcpClient>(); mockNetworkStream = mocks.NewMock <INetworkStream>(); testIpAddress = System.Net.IPAddress.Parse("127.0.0.1"); testTcpRemoteSender = new TcpRemoteSender(testIpAddress.ToString(), testPort, 3, 10, 25, 10, new ConsoleApplicationLogger(LogLevel.Warning, '|', " "), new NullMetricLogger(), mockTcpClient); testMessageByteArray = new byte[] { 0x3c, 0x41, 0x02, 0x42, 0x03, 0x43, 0x3e }; // Equivalent to '<A[ASCII message start]B[ASCII message end]C>' testMessageSequenceNumber = new byte[] { 1, 0, 0, 0 }; // Sequence number 1 (first sequence number sent after instantiating the class), encoded as a little endian testMessageSizeHeader = new byte[] { 7, 0, 0, 0, 0, 0, 0, 0 }; // Size of the above test message, encoded as a little endian long testMessage = System.Text.Encoding.ASCII.GetString(testMessageByteArray); testEncodedMessageByteArray = new byte[testMessageSequenceNumber.Length + testMessageSizeHeader.Length + testMessageByteArray.Length + 2]; // Holds bytes of the complete encoded message including sequence number, size header, body, and delimiting characters testEncodedMessageByteArray[0] = 0x02; Array.Copy(testMessageSequenceNumber, 0, testEncodedMessageByteArray, 1, testMessageSequenceNumber.Length); Array.Copy(testMessageSizeHeader, 0, testEncodedMessageByteArray, 1 + testMessageSequenceNumber.Length, testMessageSizeHeader.Length); Array.Copy(testMessageByteArray, 0, testEncodedMessageByteArray, 1 + testMessageSequenceNumber.Length + testMessageSizeHeader.Length, testMessageByteArray.Length); testEncodedMessageByteArray[testEncodedMessageByteArray.Length - 1] = 0x03; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Setup metric logger and MethodInvocationRemoting objects MetricLoggerDistributor distributor = new MetricLoggerDistributor(); ConsoleMetricLogger consoleMetricLogger = new ConsoleMetricLogger(5000, true); using (FileApplicationLogger logger = new FileApplicationLogger(LogLevel.Information, '|', " ", @"C:\Temp\C#Sender.log")) using (SizeLimitedBufferProcessor fileMetricLoggerBufferProcessor = new SizeLimitedBufferProcessor(50)) using (FileMetricLogger fileMetricLogger = new FileMetricLogger('|', @"C:\Temp\C#Metrics.log", fileMetricLoggerBufferProcessor, true)) using (SizeLimitedBufferProcessor accessMetricLoggerBufferProcessor = new SizeLimitedBufferProcessor(50)) using (MicrosoftAccessMetricLogger accessMetricLogger = new MicrosoftAccessMetricLogger(@"C:\Temp\MetricLogger.mdb", "SampleApplication5-C#", accessMetricLoggerBufferProcessor, true)) using (PerformanceCounterMetricLogger perfmonMetricLogger = new PerformanceCounterMetricLogger("SampleApplication5Metrics", "Metrics produced by MethodInvocationRemoting sample application 5", 1000, true)) using (TcpRemoteSender tcpSender = new TcpRemoteSender(System.Net.IPAddress.Loopback, 55000, 10, 1000, 30000, 25, logger, distributor)) using (TcpRemoteReceiver tcpReceiver = new TcpRemoteReceiver(55001, 10, 1000, 25, logger, distributor)) { RemoteReceiverDecompressor decompressorReceiver = new RemoteReceiverDecompressor(tcpReceiver, logger, distributor); MethodInvocationSerializer serializer = new MethodInvocationSerializer(new SerializerOperationMap(), logger, distributor); MethodInvocationRemoteSender methodInvocationRemoteSender = new MethodInvocationRemoteSender(serializer, tcpSender, decompressorReceiver, logger, distributor); // Define metric aggregates for the console logger DefineMetricAggregates(consoleMetricLogger); // Register base metrics and aggregates with the performance monitor logger perfmonMetricLogger.RegisterMetric(new RemoteMethodSendTime()); perfmonMetricLogger.RegisterMetric(new RemoteMethodSent()); perfmonMetricLogger.RegisterMetric(new MethodInvocationSerializeTime()); perfmonMetricLogger.RegisterMetric(new MethodInvocationSerialized()); perfmonMetricLogger.RegisterMetric(new SerializedMethodInvocationSize(0)); perfmonMetricLogger.RegisterMetric(new ReturnValueDeserializeTime()); perfmonMetricLogger.RegisterMetric(new ReturnValueDeserialized()); perfmonMetricLogger.RegisterMetric(new StringDecompressTime()); perfmonMetricLogger.RegisterMetric(new RemoteReceiverDecompressorReadBufferCreated()); perfmonMetricLogger.RegisterMetric(new StringDecompressed()); perfmonMetricLogger.RegisterMetric(new TcpRemoteReceiverReconnected()); perfmonMetricLogger.RegisterMetric(new MessageReceiveTime()); perfmonMetricLogger.RegisterMetric(new MessageReceived()); perfmonMetricLogger.RegisterMetric(new ReceivedMessageSize(0)); perfmonMetricLogger.RegisterMetric(new TcpRemoteReceiverDuplicateSequenceNumber()); perfmonMetricLogger.RegisterMetric(new MessageSendTime()); perfmonMetricLogger.RegisterMetric(new MessageSent()); perfmonMetricLogger.RegisterMetric(new TcpRemoteSenderReconnected()); DefineMetricAggregates(perfmonMetricLogger); // Create performance monitor counters in the operating system perfmonMetricLogger.CreatePerformanceCounters(); distributor.AddLogger(consoleMetricLogger); distributor.AddLogger(fileMetricLogger); distributor.AddLogger(accessMetricLogger); distributor.AddLogger(perfmonMetricLogger); consoleMetricLogger.Start(); fileMetricLoggerBufferProcessor.Start(); accessMetricLoggerBufferProcessor.Start(); accessMetricLogger.Connect(); perfmonMetricLogger.Start(); // Connect to the MethodInvocationRemoteReceiver tcpSender.Connect(); tcpReceiver.Connect(); // Setup the layers of the application MVP model MainView mainView = new MainView(); Model model = new Model(methodInvocationRemoteSender); Presenter presenter = new Presenter(mainView, model); mainView.Presenter = presenter; // Start the application Application.Run(mainView); // Disconnect from the MethodInvocationRemoteReceiver tcpReceiver.Disconnect(); tcpSender.Disconnect(); // Stop the metric loggers consoleMetricLogger.Stop(); fileMetricLoggerBufferProcessor.Stop(); accessMetricLoggerBufferProcessor.Stop(); accessMetricLogger.Disconnect(); perfmonMetricLogger.Stop(); } }