Пример #1
0
        public void VotingServerTest()
        {
            TcpRpcServer server = new TcpRpcServer(new VotingRpcServer());
              server.Start();

              CertificateStorage storage = new CertificateStorage();
              TcpRpcClient client = new TcpRpcClient();

              client.Connect(new IPEndPoint(IPAddress.Loopback, 4242));
              Assert.IsTrue(client.Connected);

              VotingRpcProxy proxy = new VotingRpcProxy(client);
              proxy.Start();

              var ids = proxy.FetchVotingIds();

              proxy.Stop();

              client.Disconnect();
              Assert.IsFalse(client.Connected);

              server.Stop();
        }
Пример #2
0
        private void ConnectAsync()
        {
            try
              {
            this.client.Connect(this.serverEndPoint);
            this.proxy = new VotingRpcProxy(this.client);
            this.proxy.Start();
            this.exception = null;
              }
              catch (Exception exception)
              {
            this.exception = exception;
              }

              Connecting = false;
        }
Пример #3
0
 private void ConnectPiVote()
 {
     if (this.valid)
       {
     try
     {
       this.client = new TcpRpcClient();
       this.client.Connect(new IPEndPoint(IPAddress.Loopback, 4242));
       this.proxy = new VotingRpcProxy(client);
     }
     catch (Exception exception)
     {
       this.error = exception.Message;
       this.message = "Pi-Vote server connection failed.";
       this.valid = false;
     }
       }
 }
Пример #4
0
 /// <summary>
 /// Connect to the server.
 /// </summary>
 /// <param name="serverEndPoint">IP address and port of the server.</param>
 /// <param name="serverEndPoint">Proxy IP address and port.</param>
 public void Connect(IPEndPoint serverEndPoint, IPEndPoint proxyEndPoint)
 {
     this.client.Connect(serverEndPoint, proxyEndPoint);
       this.proxy = new VotingRpcProxy(this.client);
       this.proxy.Start();
 }
Пример #5
0
        private bool ConnectToServer()
        {
            table.AddHeaderRow(2, "Pi-Vote Server");

              string fileName = Path.Combine(Request.PhysicalApplicationPath, "server.pi-cert");

              if (File.Exists(fileName))
              {
            this.serverCertificate = Serializable.Load<ServerCertificate>(fileName);
              }
              else
              {
            table.AddRow("Connection:", "N/A");
            table.AddRow(string.Empty, "Server certifcate not found.");
            table.AddSpaceRow(2, 32);
            return false;
              }

              try
              {
            this.client = new TcpRpcClient();
            this.client.Connect(new IPEndPoint(IPAddress.Loopback, 4242));
            this.proxy = new VotingRpcProxy(client);
              }
              catch
              {
            table.AddRow("Connection:", "Failed");
            table.AddRow(string.Empty, "Pi-Vote server connection failed.");
            table.AddSpaceRow(2, 32);
            return false;
              }

              try
              {
            var result = proxy.FetchCertificateStorage();
            this.certificateStorage = new CertificateStorage();
            this.certificateStorage.TryLoadRoot(Request.PhysicalApplicationPath);
            this.certificateStorage.Add(result.First);
              }
              catch
              {
            table.AddRow("Connection:", "Failed");
            table.AddRow(string.Empty, "Cannot download certificate storage.");
            table.AddSpaceRow(2, 32);
            return false;
              }

              table.AddRow("Connection:", "Ok");
              table.AddSpaceRow(2, 32);
              return true;
        }