Пример #1
0
        public void ConnectLoggingTest()
        {
            using (mocks.Ordered)
            {
                Expect.Once.On(mockTcpListener).GetProperty("Active").Will(Return.Value(false));
                Expect.Once.On(mockTcpListener).Method("Start");
                Expect.Once.On(mockTcpListener).Method("Pending").Will(Return.Value(true));
                Expect.Once.On(mockTcpListener).Method("AcceptTcpClient").Will(Return.Value(mockTcpClient));
                Expect.Once.On(mockApplicationLogger).Method("Log").With(testTcpRemoteReceiver, LogLevel.Information, "Connection received on port " + testPort + ".");
            }

            testTcpRemoteReceiver.Connect();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #2
0
        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();
                    }
        }
Пример #3
0
 //------------------------------------------------------------------------------
 //
 // Method: Connect
 //
 //------------------------------------------------------------------------------
 /// <summary>
 /// Connects and initialises the underlying MethodInvocationRemoting components.
 /// </summary>
 public void Connect()
 {
     incomingReceiver.Connect();
     incomingSender.Connect();
     outgoingReceiver.Connect();
     outgoingSender.Connect();
     methodInvocationReceiver.Receive();
 }
        public void ReceiveMetricsTest()
        {
            using (mocks.Ordered)
            {
                SetConnectExpectations();
                // Expects for Receive()
                SetBeginMessageReceiveExpectations(testMessageByteArray.Length);
                Expect.Once.On(mockNetworkStream).Method("Read").Will(new SetNamedParameterAction("buffer", testMessageByteArray), Return.Value(testMessageByteArray.Length));
                Expect.Once.On(mockTcpListener).Method("Pending").Will(Return.Value(false));
                Expect.Once.On(mockNetworkStream).Method("WriteByte");
                Expect.Once.On(mockMetricLogger).Method("End").With(IsMetric.Equal(new MessageReceiveTime()));
                Expect.Once.On(mockMetricLogger).Method("Increment").With(IsMetric.Equal(new MessageReceived()));
                Expect.Once.On(mockMetricLogger).Method("Add").With(IsAmountMetric.Equal(new ReceivedMessageSize(16)));
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Receive();
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Пример #5
0
        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();
                                        }
        }
        public void ConnectWhenDisposed()
        {
            using (mocks.Ordered)
            {
                SetDisposeExpectations();
            }

            testTcpRemoteReceiver.Dispose();
            ObjectDisposedException e = Assert.Throws <ObjectDisposedException>(delegate
            {
                testTcpRemoteReceiver.Connect();
            });

            mocks.VerifyAllExpectationsHaveBeenMet();
        }