public void VerifyCanPerformFunctionCallAfterBulk() { int numberKiloBytes = 1024 * 1024 * 1; var buffer = new byte[numberKiloBytes]; for (int i = 0; i < numberKiloBytes; ++i) { buffer[i] = (byte)(i % 2); } var bulkDataStub = new BulkDataStub(buffer); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer <IBulkData>(bulkDataStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new MsDataContractJsonSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient <IBulkData>(IPAddress.Loopback, 62000, new MsDataContractJsonSerializer()); ipcClient.Proxy.GetBulkyData(); var fooResult = ipcClient.Proxy.Foo(); Assert.AreEqual("Bar", fooResult); ipcClient.Dispose(); ipcServer.Dispose(); bulkDataStub.Dispose(); dispatcherThread.Shutdown(); }
public static void Main(string[] args) { var ipAddress = IPAddress.Loopback; if (args.Length == 1) { ipAddress = IPAddress.Parse(args[0]); } var fileTransferImpl = new FileTransferImp(); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var server = new IpcServer<IFileTransfer>(fileTransferImpl, dispatcherThread.Dispatcher, ipAddress, 63000, new JsonDotNetSerializer()); server.ClientConnected += OnClientConnected; server.ClientDisconnected += OnClientDisconnected; server.Listen(); Console.WriteLine("FileTransferServer service running, press any key to exit."); Console.ReadLine(); server.ClientDisconnected -= OnClientDisconnected; server.ClientConnected -= OnClientConnected; server.Dispose(); fileTransferImpl.Dispose(); dispatcherThread.Join(); }
public void VerifyBasicSendReceive() { var fooStub = new FooStub(); fooStub.ReturnValueOfBar = "Bar"; var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer<IFoo>(fooStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new JsonDotNetSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient<IFoo>(IPAddress.Loopback, 62000, new JsonDotNetSerializer()); object response; ipcClient.Proxy.Foo(); Assert.AreEqual(1, fooStub.NumberOfFooCalls); response = ipcClient.Proxy.Bar(); Assert.AreEqual(fooStub.ReturnValueOfBar, response); Assert.AreEqual(1, fooStub.NumberOfBarCalls); ipcClient.Dispose(); ipcServer.Dispose(); dispatcherThread.Shutdown(); }
protected virtual void Dispose(bool isDisposing) { _isDisposed = true; IsRunning = false; if (isDisposing) { _lock.Wait(LockWaitMilliseconds); _performanceLock.Wait(LockWaitMilliseconds); try { _hostCancellationToken.Cancel(); _grpcServer.WaitForShutdown(); _ipcServer?.Dispose(); _closeEvent?.Set(); _closeEvent?.Dispose(); _closeEvent = null; _updateThread = null; _utilityThread = null; _console?.Dispose(); } finally { _lock.Release(); _lock.Dispose(); _lock = null; _performanceLock.Release(); _performanceLock.Dispose(); _performanceLock = null; } } }
public static void Main(string[] args) { var ipAddress = IPAddress.Loopback; if (args.Length == 1) { ipAddress = IPAddress.Parse(args[0]); } var fileTransferImpl = new FileTransferImp(); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var server = new IpcServer <IFileTransfer>(fileTransferImpl, dispatcherThread.Dispatcher, ipAddress, 63000, new JsonDotNetSerializer()); server.ClientConnected += OnClientConnected; server.ClientDisconnected += OnClientDisconnected; server.Listen(); Console.WriteLine("FileTransferServer service running, press any key to exit."); Console.ReadLine(); server.ClientDisconnected -= OnClientDisconnected; server.ClientConnected -= OnClientConnected; server.Dispose(); fileTransferImpl.Dispose(); dispatcherThread.Join(); }
public void VerifyBasicSendReceive() { var fooStub = new FooStub(); fooStub.ReturnValueOfBar = "Bar"; var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer <IFoo>(fooStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new JsonDotNetSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient <IFoo>(IPAddress.Loopback, 62000, new JsonDotNetSerializer()); object response; ipcClient.Proxy.Foo(); Assert.AreEqual(1, fooStub.NumberOfFooCalls); response = ipcClient.Proxy.Bar(); Assert.AreEqual(fooStub.ReturnValueOfBar, response); Assert.AreEqual(1, fooStub.NumberOfBarCalls); ipcClient.Dispose(); ipcServer.Dispose(); dispatcherThread.Shutdown(); }
public override void WillTerminate(NSNotification notification) { _ipcServer?.Stop(); _ipcServer?.Dispose(); // Insert code here to tear down your application NSEvent.RemoveMonitor(_eventMonitor); }
public static void Dispose() { try { _server.Dispose(); } catch { /* ignored */ } _server = null; _busRegistry = null; LoggingManagementService.WriteLine($"{nameof(TransmittingManagementService)} uninitialized", "TsmMgmt"); }
public void VerifyPerformance() { var fooStub = new FooStub(); fooStub.ReturnValueOfBar = "Bar"; var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer <IFoo>(fooStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new JsonDotNetSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient <IFoo>(IPAddress.Loopback, 62000, new JsonDotNetSerializer()); var numberOfCalls = 1000; var nanoSecs = Performance.MeasureMs(() => { for (var i = 0; i < numberOfCalls; i++) { ipcClient.Proxy.Foo(); } }); var fooAverageMs = nanoSecs / numberOfCalls; Console.WriteLine("Foo call took: {0}ms", fooAverageMs); Assert.AreEqual(numberOfCalls, fooStub.NumberOfFooCalls); Assert.LessOrEqual(TimeSpan.FromMilliseconds(fooAverageMs), TimeSpan.FromMilliseconds(10)); nanoSecs = Performance.MeasureMs(() => { for (var i = 0; i < numberOfCalls; i++) { ipcClient.Proxy.Bar(); } }); var barAverageMs = nanoSecs / numberOfCalls; Console.WriteLine("Bar call took: {0}ms", barAverageMs); Assert.AreEqual(numberOfCalls, fooStub.NumberOfBarCalls); Assert.LessOrEqual(TimeSpan.FromMilliseconds(barAverageMs), TimeSpan.FromMilliseconds(10)); ipcClient.Dispose(); ipcServer.Dispose(); dispatcherThread.Shutdown(); }
protected override void OnExit(ExitEventArgs e) { _ipcServer?.Stop(); _ipcServer?.Dispose(); _hotkey.Unregister(); _explorerUpdateTimer.Change(Timeout.Infinite, Timeout.Infinite); var explorerHandler = TinyIoCContainer.Current.Resolve <WindowsExplorerHandler>(); explorerHandler.CleanTitles(); _notifyIcon.Dispose(); base.OnExit(e); }
public void VerifyBulkyData_using_Json_dot_NET_serializer(int mb) { int numberKiloBytes = 1024 * 1024 * mb; var buffer = new byte[numberKiloBytes]; for (int i = 0; i < numberKiloBytes; ++i) { buffer[i] = (byte)(i % 2); } var bulkDataStub = new BulkDataStub(buffer); var bulkDataHash = ComputeHash(bulkDataStub.GetBulkyData()); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer <IBulkData>(bulkDataStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new JsonDotNetSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient <IBulkData>(IPAddress.Loopback, 62000, new JsonDotNetSerializer()); Stream receivingStream = null; double ms = Performance.MeasureMs(() => { receivingStream = ipcClient.Proxy.GetBulkyData(); }); var receivingHash = ComputeHash(receivingStream); Assert.That(receivingHash, Is.EqualTo(bulkDataHash)); Console.WriteLine("Sending of {0}MB took {1}ms", mb, ms); ipcClient.Dispose(); ipcServer.Dispose(); bulkDataStub.Dispose(); receivingStream.Dispose(); dispatcherThread.Shutdown(); }
// the application is crashing without exception handling.. private static void ExceptionLogger_ApplicationCrashData(ApplicationCrashEventArgs e) { // unsubscribe this event handler.. ExceptionLogger.ApplicationCrashData -= ExceptionLogger_ApplicationCrashData; if (IpcServer != null) { IpcServer.MessageReceived -= MessageReceived; IpcServer.Dispose(); } ExceptionLogger.UnBind(); // unbind the exception logger.. AppRunning.DisposeMutexByName("VPKSoft.amp.sharp#"); // kill self as the native inter-op libraries may have some issues of keeping the process alive.. Process.GetCurrentProcess().Kill(); // This is the end.. }
public static void Main(string[] args) { var calculatorImp = new CalculatorImp(); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var server = new IpcServer<ICalculator>(calculatorImp, dispatcherThread.Dispatcher, IPAddress.Loopback, 62001, new JsonDotNetSerializer()); server.ClientConnected += OnClientConnected; server.ClientDisconnected += OnClientDisconnected; server.Listen(); Console.WriteLine("Calculator service running, press any key to exit."); Console.ReadLine(); server.ClientDisconnected -= OnClientDisconnected; server.ClientConnected -= OnClientConnected; server.Dispose(); dispatcherThread.Shutdown(); }
public static void Main(string[] args) { var calculatorImp = new CalculatorImp(); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var server = new IpcServer <ICalculator>(calculatorImp, dispatcherThread.Dispatcher, IPAddress.Loopback, 62001, new JsonDotNetSerializer()); server.ClientConnected += OnClientConnected; server.ClientDisconnected += OnClientDisconnected; server.Listen(); Console.WriteLine("Calculator service running, press any key to exit."); Console.ReadLine(); server.ClientDisconnected -= OnClientDisconnected; server.ClientConnected -= OnClientConnected; server.Dispose(); dispatcherThread.Shutdown(); }
public void VerifyServerExceptionsAreForwardedToClientAndServerRemainsAlive() { var fooStub = new FooStubThrowsException(); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer <IFoo>(fooStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new JsonDotNetSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient <IFoo>(IPAddress.Loopback, 62000, new JsonDotNetSerializer()); var caughtException = false; try { ipcClient.Proxy.Foo(); } catch (Exception) { caughtException = true; } Assert.IsTrue(caughtException); //See if server survives failed method call ipcClient.Proxy.Bar(); Assert.IsTrue(fooStub.NumberOfBarCalls == 1); ipcClient.Dispose(); ipcServer.Dispose(); dispatcherThread.Shutdown(); }
public void VerifyPerformance() { var fooStub = new FooStub(); fooStub.ReturnValueOfBar = "Bar"; var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer<IFoo>(fooStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new JsonDotNetSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient<IFoo>(IPAddress.Loopback, 62000, new JsonDotNetSerializer()); var numberOfCalls = 1000; var nanoSecs = Performance.MeasureMs(() => { for (var i = 0; i < numberOfCalls; i++) { ipcClient.Proxy.Foo(); } }); var fooAverageMs = nanoSecs/numberOfCalls; Console.WriteLine("Foo call took: {0}ms", fooAverageMs); Assert.AreEqual(numberOfCalls, fooStub.NumberOfFooCalls); Assert.LessOrEqual(TimeSpan.FromMilliseconds(fooAverageMs), TimeSpan.FromMilliseconds(10)); nanoSecs = Performance.MeasureMs(() => { for (var i = 0; i < numberOfCalls; i++) { ipcClient.Proxy.Bar(); } }); var barAverageMs = nanoSecs/numberOfCalls; Console.WriteLine("Bar call took: {0}ms", barAverageMs); Assert.AreEqual(numberOfCalls, fooStub.NumberOfBarCalls); Assert.LessOrEqual(TimeSpan.FromMilliseconds(barAverageMs), TimeSpan.FromMilliseconds(10)); ipcClient.Dispose(); ipcServer.Dispose(); dispatcherThread.Shutdown(); }
public void VerifyCanPerformFunctionCallAfterBulk() { int numberKiloBytes = 1024 * 1024 * 1; var buffer = new byte[numberKiloBytes]; for (int i = 0; i < numberKiloBytes; ++i) { buffer[i] = (byte)(i % 2); } var bulkDataStub = new BulkDataStub(buffer); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer<IBulkData>(bulkDataStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new MsDataContractJsonSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient<IBulkData>(IPAddress.Loopback, 62000, new MsDataContractJsonSerializer()); ipcClient.Proxy.GetBulkyData(); var fooResult = ipcClient.Proxy.Foo(); Assert.AreEqual("Bar", fooResult); ipcClient.Dispose(); ipcServer.Dispose(); bulkDataStub.Dispose(); dispatcherThread.Shutdown(); }
public void VerifyBulkyData_using_Json_dot_NET_serializer(int mb) { int numberKiloBytes = 1024 * 1024 * mb; var buffer = new byte[numberKiloBytes]; for (int i = 0; i < numberKiloBytes; ++i) { buffer[i] = (byte)(i % 2); } var bulkDataStub = new BulkDataStub(buffer); var bulkDataHash = ComputeHash(bulkDataStub.GetBulkyData()); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer<IBulkData>(bulkDataStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new JsonDotNetSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient<IBulkData>(IPAddress.Loopback, 62000, new JsonDotNetSerializer()); Stream receivingStream = null; double ms = Performance.MeasureMs(() => { receivingStream = ipcClient.Proxy.GetBulkyData(); }); var receivingHash = ComputeHash(receivingStream); Assert.That(receivingHash, Is.EqualTo(bulkDataHash)); Console.WriteLine("Sending of {0}MB took {1}ms", mb, ms); ipcClient.Dispose(); ipcServer.Dispose(); bulkDataStub.Dispose(); receivingStream.Dispose(); dispatcherThread.Shutdown(); }
public void VerifyServerExceptionsAreForwardedToClientAndServerRemainsAlive() { var fooStub = new FooStubThrowsException(); var dispatcherThread = new DispatcherThread(Dispatcher.Run); dispatcherThread.Start(); var ipcServer = new IpcServer<IFoo>(fooStub, dispatcherThread.Dispatcher, IPAddress.Loopback, 62000, new JsonDotNetSerializer()); ipcServer.Listen(); var ipcClient = new IpcClient<IFoo>(IPAddress.Loopback, 62000, new JsonDotNetSerializer()); var caughtException = false; try { ipcClient.Proxy.Foo(); } catch (Exception) { caughtException = true; } Assert.IsTrue(caughtException); //See if server survives failed method call ipcClient.Proxy.Bar(); Assert.IsTrue(fooStub.NumberOfBarCalls == 1); ipcClient.Dispose(); ipcServer.Dispose(); dispatcherThread.Shutdown(); }