示例#1
0
        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();
        }
示例#2
0
        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();
        }
示例#3
0
        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();
        }
示例#4
0
        private static void ServiceDiscovererOnOnServiceFound(IPAddress ipAddress)
        {
            _serviceDiscoverer.OnServiceFound -= ServiceDiscovererOnOnServiceFound;

            var client = new IpcClient <ICalculator>(ipAddress, 62005, new JsonDotNetSerializer());

            UserInputLoop(client);

            client.Dispose();
            Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
        }
示例#5
0
        private static void ServiceDiscovererOnOnServiceFound(IPAddress ipAddress)
        {
            _serviceDiscoverer.OnServiceFound -= ServiceDiscovererOnOnServiceFound;

            var client = new IpcClient<ICalculator>(ipAddress, 62005, new JsonDotNetSerializer());

            UserInputLoop(client);

            client.Dispose();
            Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
        }
示例#6
0
        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();
        }
示例#7
0
        public static void Main(string[] args)
        {
            var ipAddress = IPAddress.Loopback;

            if (args.Length == 1)
            {
                ipAddress = IPAddress.Parse(args[0]);
            }

            var client = new IpcClient <IFileTransfer>(ipAddress, 63000, new JsonDotNetSerializer());

            client.BulkProgress += OnBulkProgress;

            var line = string.Empty;

            Console.WriteLine(@"Enter filename 'c:\images\photo.bmp' or 'quit'..");
            while ((line = Console.ReadLine()) != "quit")
            {
                try
                {
                    var sw = new Stopwatch();
                    sw.Start();

                    using (var memoryStream = client.Proxy.TransferFile(line))
                    {
                        sw.Stop();
                        var newName = line + ".cpy";
                        using (var fs = File.Create(newName))
                        {
                            memoryStream.Position = 0;
                            memoryStream.CopyTo(fs);
                            memoryStream.Flush();
                            fs.Close();
                        }

                        int    megaByte       = memoryStream.Capacity / 1024 / 1024;
                        double megaBytePerSec = megaByte / sw.Elapsed.TotalSeconds;
                        Console.WriteLine("Successfully wrote file '{0} @ {1:.0} MB/s.", newName, megaBytePerSec);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            client.BulkProgress -= OnBulkProgress;
            client.Dispose();

            Environment.Exit(0);
        }
示例#8
0
        public static void Main(string[] args)
        {
            var ipAddress = IPAddress.Loopback;

            if (args.Length == 1)
            {
                ipAddress = IPAddress.Parse(args[0]);
            }

            var client = new IpcClient<IFileTransfer>(ipAddress, 63000, new JsonDotNetSerializer());
            client.BulkProgress += OnBulkProgress;
           
            var line = string.Empty;

            Console.WriteLine(@"Enter filename 'c:\images\photo.bmp' or 'quit'..");
            while ((line = Console.ReadLine()) != "quit")
            {
                try
                {
                    var sw = new Stopwatch();
                    sw.Start();
           
                    using (var memoryStream = client.Proxy.TransferFile(line))
                    {
                        sw.Stop();
                        var newName = line + ".cpy";
                        using (var fs = File.Create(newName))
                        {
                            memoryStream.Position = 0;
                            memoryStream.CopyTo(fs);
                            memoryStream.Flush();
                            fs.Close();
                        }

                        int megaByte = memoryStream.Capacity / 1024 / 1024;
                        double megaBytePerSec = megaByte / sw.Elapsed.TotalSeconds;
                        Console.WriteLine("Successfully wrote file '{0} @ {1:.0} MB/s.", newName, megaBytePerSec);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            client.BulkProgress -= OnBulkProgress;
            client.Dispose();

            Environment.Exit(0);
        }
示例#9
0
        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();
        }
示例#10
0
 internal void CleanupServer()
 {
     try
     {
         if (_owinServer != null)
         {
             _owinServer.Dispose();
             _owinServer = null;
         }
         if (_ipcIpcClient != null)
         {
             _ipcIpcClient.Dispose();
             _ipcIpcClient = null;
         }
         DebugDispatcher.Instance.Shutdown();
     }
     catch (Exception ex)
     {
         LogException(ex);
     }
 }
示例#11
0
        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();
        }
示例#12
0
        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();
        }
示例#13
0
        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();
        }
示例#14
0
        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();
        }
示例#15
0
        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();
        }
示例#16
0
        static void Main(string[] args)
        {
            int counter = 0;

            try
            {
                SetupEnvironment(args);
                RegisterNotification();

                #region Register

                _gsm = new GameStatusManager(_gamePid, _parentPid);

                Log.Verbose("Waiting Game Process");

                _gsm.WaitForProcess();

                Log.Verbose($"Found Game Process {_gsm.GameProcess.Id}");

                _gnm = new GameNetworkMonitor(_gsm.GameProcess);
                _gmm = new GameMemoryMonitor(_gsm.GameProcess);
                _gdm = new GameDataManager();

                _gnm.Subscribe(NetworkCharacterName.GetMessageId(), _gdm.HandleNetworkCharacterName);
                _gnm.Subscribe(NetworkItemInfo.GetMessageId(), _gdm.HandleNetworkItemInfo);
                _gnm.Subscribe(NetworkItemPriceInfo.GetMessageId(), _gdm.HandleNetworkItemPriceInfo);
                _gnm.Subscribe(NetworkItemInfoEnd.GetMessageId(), _gdm.HandleNetworkItemInfoEnd);
                _gnm.Subscribe(NetworkLogout.GetMessageId(), _gdm.HandleNetworkLogout);
                _gnm.Subscribe(NetworkMarketHistory.GetMessageId(), _gdm.HandleNetworkMarketHistory);
                _gnm.Subscribe(NetworkMarketListingCount.GetMessageId(), _gdm.HandleNetworkMarketListingCount);
                _gnm.Subscribe(NetworkMarketListing.GetMessageId(), _gdm.HandleNetworkMarketListing);
                _gnm.Subscribe(NetworkMarketResult.GetMessageId(), _gdm.HandleNetworkMarketResult);
                _gnm.Subscribe(NetworkRetainerHistory.GetMessageId(), _gdm.HandleNetworkRetainerHistory);
                _gnm.Subscribe(NetworkRetainerSummary.GetMessageId(), _gdm.HandleNetworkRetainerSummary);
                _gnm.Subscribe(NetworkRetainerSumEnd.GetMessageId(), _gdm.HandleNetworkRetainerSumEnd);
                _gnm.Subscribe(NetworkLobbyService.GetMessageId(), _gdm.HandleLobbyService);
                _gnm.Subscribe(NetworkLobbyCharacter.GetMessageId(), _gdm.HandleLobbyCharacter);
                _gnm.Subscribe(NetworkClientTrigger.GetMessageId(), _gdm.HandleClientTrigger);
                _gnm.Subscribe(NetworkRequestRetainer.GetMessageId(), _gdm.HandleRequestRetainer);
                _gnm.Subscribe(NetworkInventoryModify.GetMessageId(), _gdm.HandleInventoryModify);
                _gnm.Subscribe(NetworkPlayerSpawn.GetMessageId(), _gdm.HandleNetworkPlayerSpawn);

                _gsm.OnLobbyUpdate    += LobbyUpdate;
                _gsm.OnWorldStart     += WorldStart;
                _gsm.OnWorldStop      += WorldStop;
                _gsm.OnGlobalStart    += GlobalStart;
                _gsm.OnGlobalStop     += GlobalStop;
                _gmm.OnChatlogUpdated += PackLogData;
                _gdm.OnGameLoggingOut += _gsm.SuspectNetworkStop;
                _gdm.OnDataReady      += IpcClient.SendData;
                _gdm.OnRequestScan    += _gmm.GetInventory;
                _gsm.GetPacketAmount  += () => _gnm.PacketsAnalyzed;

                #endregion

                _gsm.StartMonitoringService();

                Log.Warning("Main thread started");

                while (!_gsm.Stopping)
                {
                    counter++;
                    if (counter > 60)
                    {
                        counter = 0;
                        Log.Debug(
                            $"SysLoad: {_gnm?.PacketsObserved:x}" +
                            $"/{_gnm?.PacketsCaptured}" +
                            $"/{_gnm?.PacketsAnalyzed}" +
                            $"/{_gnm?.MessagesProcessed}" +
                            $"/{_gnm?.MessagesDispatched}" +
                            $"/{_gmm?.ScanCycles}" +
                            $"/{_gmm?.LinesRead}" +
                            $"/{IpcClient.PacketSent}");
                    }

                    _gdm.ScheduledTasks();

                    Thread.Sleep(1000);
                }

                Log.Warning("Main thread expected exiting");
            }
            catch (OperationCanceledException)
            {
                // Well, this IS expected literally.
                Log.Warning("Main thread expected exiting");
            }
            catch (Exception e)
            {
                Log.Error(e, $"Main thread unexpected exiting");
            }
            finally
            {
                try { _gsm.Dispose(); } catch { /* ignored */ }
                try { _gmm.Dispose(); } catch { /* ignored */ }
                try { _gnm.Dispose(); } catch { /* ignored */ }
                try { _gdm.Dispose(); } catch { /* ignored */ }

                IpcClient.SendSignal(Signal.MilvanethSubprocessExit, new[] { "Graceful Exit", "Milvaneth.Cmd", "Main Thread" });
                try { IpcClient.Dispose(); } catch { /* ignored */ }

                Log.Fatal("Main thread exited in Program.Main");
                Environment.Exit(0);
            }
        }