コード例 #1
0
ファイル: RemoteClassTests.cs プロジェクト: samwa/mremoted
        public void AddSpecificClient()
        {
            RemoteClass rc = new RemoteClass();

            rc.AddClient(2);

            Assert.AreEqual(rc.Clients.First(), 2);
        }
コード例 #2
0
ファイル: RemoteClassTests.cs プロジェクト: samwa/mremoted
        public void Add2Clients()
        {
            RemoteClass rc = new RemoteClass();

            int clientId1 = rc.AddClient();
            int clientId2 = rc.AddClient();

            Assert.AreNotEqual(clientId1, clientId2);
        }
コード例 #3
0
ファイル: RemoteClassTests.cs プロジェクト: samwa/mremoted
        public void Add2ThenRemove1()
        {
            RemoteClass rc = new RemoteClass();

            int clientId1 = rc.AddClient();
            int clientId2 = rc.AddClient();

            bool removed = rc.CloseClient(clientId1);

            Assert.AreEqual(rc.Clients[0], clientId2);
        }
コード例 #4
0
ファイル: RemoteClass.cs プロジェクト: samwa/mremoted
 /// <summary>
 /// for cloning
 /// </summary>
 /// <param name="another"></param>
 public RemoteClass(RemoteClass another)
 {
     this.Clients = another.Clients;
     this.TotalClients = another.TotalClients;
     this.Locked = another.Locked;
     this.NextClient = another.NextClient;
     this.ServerClosing = another.ServerClosing;
     this.Pi = another.Pi;
     this.Iteration = another.Iteration;
     this.ElapsedTime = another.ElapsedTime;
 }
コード例 #5
0
ファイル: RemoteClassTests.cs プロジェクト: samwa/mremoted
        public void GetNextClient()
        {
            RemoteClass rc = new RemoteClass();

            int clientId1 = rc.AddClient();
            int clientId2 = rc.AddClient();

            if (rc.RequestLock(clientId1))
            {
                bool nextClientSet = rc.SetNextClient();

                int nextClient = rc.NextClient;
                rc.ReleaseLock(clientId1);
            }

            if (rc.RequestLock(clientId2))
            {
                bool nextClientSet = rc.SetNextClient();

                int nextClient = rc.NextClient;
                rc.ReleaseLock(clientId2);
            }
        }
コード例 #6
0
ファイル: RemoteClassTests.cs プロジェクト: samwa/mremoted
        public void GetPi()
        {
            RemoteClass rc = new RemoteClass();

            rc.Iterate();
            rc.Iterate();
            rc.Iterate();

            double pi = rc.Pi;
        }
コード例 #7
0
ファイル: RemotingApp.cs プロジェクト: samwa/mremoted
        private static void StartServer()
        {
            // make sure there isn't a server already
            int i = 0; // make sure we don't loop for ever
            while (ServerExists() && i < 100)
            {
                // just loop until the server goes down
                i++;
            }

            if (i > 99)
                throw new Exception("Cannot create server, existing server won't stop");

            Console.WriteLine("starting remoting server{0}");
            _appType = AppType.Server;

            Setup(_serverAppConfig);

            string[] activationData = new string[] { };
            _rmtClass = (RemoteClass)RemotingFactory.GetRemoteObject("localhost", 8888, "RemoteClass", typeof(RemoteClass));

            _startTime = DateTime.Now;
            DoLoopServer();
        }
コード例 #8
0
ファイル: RemotingApp.cs プロジェクト: samwa/mremoted
        private static void DoLoopClient()
        {
            while (!_done)
            {
                try
                {
                    if (_clientId == 0)
                    {
                        // we have a server, so lets create a client
                        _rmtClass = (RemoteClass)RemotingFactory.GetRemoteObject("localhost", 8888, "RemoteClass", typeof(RemoteClass));

                        _clientId = _rmtClass.AddClient();
                        _lclClass = new RemoteClass(_rmtClass);
                    }

                    // request lock from server
                    if (_rmtClass.RequestLock(_clientId))
                    {
                        if (_startingServer)
                        {
                            // we have just restarted the server, now we need to set the remote object back into it

                            _startingServer = false;
                        }

                        // are we listed in the object?
                        if (!_rmtClass.Clients.Contains(_clientId))
                            _rmtClass.AddClient(_clientId);

                        // do calc
                        _rmtClass.Iterate();

                        _lclClass = new RemoteClass(_rmtClass);

                        // release lock from server
                        _rmtClass.ReleaseLock(_clientId);
                    }

                    if (Console.KeyAvailable)
                    {
                        HandleKeyPress();
                    }
                }
                catch (SocketException soExp)
                {
                    if (!ServerExists())
                    {
                        // oops server has gone, we need to create another one
                        if (IsFirstClient() && !_startingServer) // only switch on server if we are the first client in the list and not already starting the server
                        {
                            _startingServer = true;
                            RestartServer();
                        }
                    }
                    else
                    {
                        Cleanup();
                        throw;
                    }
                }
                catch
                {
                    Cleanup();
                    throw;
                }
            }
        }
コード例 #9
0
ファイル: RemoteClass.cs プロジェクト: samwa/mremoted
 public void ResetData(RemoteClass original)
 {
     this.Clients = original.Clients;
     this.TotalClients = original.TotalClients;
     this.Locked = original.Locked;
     this.NextClient = original.NextClient;
     this.ServerClosing = original.ServerClosing;
     this.Pi = original.Pi;
     this.Iteration = original.Iteration;
     this.ElapsedTime = original.ElapsedTime;
 }