public void DisconnectWhenDisposed()
        {
            using (mocks.Ordered)
            {
                SetDisposeExpectations();
            }

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

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Example #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();
                    }
        }
Example #3
0
        //------------------------------------------------------------------------------
        //
        // Method: Disconnect
        //
        //------------------------------------------------------------------------------
        /// <summary>
        /// Disconnects and cleans up the underlying MethodInvocationRemoting components.
        /// </summary>
        public void Disconnect()
        {
            methodInvocationReceiver.CancelReceive();
            incomingReceiver.CancelReceive();
            incomingReceiver.Disconnect();
            incomingSender.Disconnect();
            outgoingReceiver.CancelReceive();
            outgoingReceiver.Disconnect();
            outgoingSender.Disconnect();

            // Call dispose on the sender and receiver objects
            incomingReceiver.Dispose();
            incomingSender.Dispose();
            outgoingReceiver.Dispose();
            outgoingSender.Dispose();
        }
Example #4
0
        public void DisconnectLoggingTest()
        {
            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");
                Expect.Once.On(mockTcpClient).Method("Close");
                Expect.Once.On(mockTcpClient).Method("Dispose");
                Expect.Once.On(mockTcpListener).Method("Stop");
                Expect.Once.On(mockApplicationLogger).Method("Log").With(testTcpRemoteReceiver, LogLevel.Information, "Disconnected.");
            }

            testTcpRemoteReceiver.Connect();
            testTcpRemoteReceiver.Disconnect();

            mocks.VerifyAllExpectationsHaveBeenMet();
        }
Example #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();
                                        }
        }