Example #1
0
        private void testConnectionWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Server.ServerVariables serverToConnectTest = (Server.ServerVariables)e.Argument;
            BombsHost.CommunicatorClient testConnector = new BombsHost.CommunicatorClient(new InstanceContext(this), binding, new EndpointAddress(string.Format(@"net.tcp://{0}:{1}/BombsHost/tcp", serverToConnectTest.Address, serverToConnectTest.Port.ToString())));

            testConnector.Endpoint.Name = "BOMBS_Service_Communicator_EndPoint";

            bool result = true;

            try
            {
                testConnector.Open();

                result = true;
            }
            catch
            {
                result = false;
            }

            object[] results = new object[3];

            results[0] = result;
            results[1] = testConnector;
            results[2] = serverToConnectTest;

            e.Result = results;
        }
Example #2
0
        private void OnTestConnectionCompleted(bool result, BombsHost.CommunicatorClient testCommunicator, Server.ServerVariables serverVariables)
        {
            serverToConnect = serverVariables;
            if (TestConnectionCompleted != null)
            {
                if (!result)
                {
                    TestConnectionCompleted(this, new ResultArg()
                    {
                        Result = new Server.TestConnectionVariablesArgs()
                        {
                            IsTestConnectionSuccessful = false,
                            ServerInformation = null
                        }
                    });
                }
                else
                {
                    if (testCommunicator != null)
                    {
                        testResultHost = testCommunicator;

                        testResultHost.GetServerInformationCompleted -= testCommunicator_GetServerInformationCompleted;
                        testResultHost.GetServerInformationCompleted += testCommunicator_GetServerInformationCompleted;

                        testResultHost.GetServerInformationAsync();
                    }
                }
            }
        }
Example #3
0
 public void UseNewHost()
 {
     if (connector != null)
     {
         if (connector.State == CommunicationState.Opened)
         {
             connector.DisconnectCompleted += connector_DisconnectCompleted;
             connector.DisconnectAsync();
         }
         else
         {
             connector.Close();
             connector = testResultHost;
             activeServer = serverToConnect;
             if (HostInitializedAndOpened != null) HostInitializedAndOpened(this, EventArgs.Empty);
         }
     }
     else
     {
         connector = testResultHost;
         activeServer = serverToConnect;
         if (HostInitializedAndOpened != null) HostInitializedAndOpened(this, EventArgs.Empty);
     }
 }
Example #4
0
        private void connector_DisconnectCompleted(object sender, AsyncCompletedEventArgs e)
        {
            connector.DisconnectCompleted -= connector_DisconnectCompleted;
            connector.Close();
            activeServer = serverToConnect;
            connector = testResultHost;

            if (HostInitializedAndOpened != null) HostInitializedAndOpened(this, EventArgs.Empty);
            if (NewConnectionImplemented != null) NewConnectionImplemented(this, new ResultArg() { Result = connector });
        }
Example #5
0
        public void Connect()
        {
            connector = new BombsHost.CommunicatorClient(new InstanceContext(this), binding, new EndpointAddress(string.Format(@"net.tcp://{0}:{1}/BombsHost/tcp", activeServer.Address, activeServer.Port.ToString())));

            connector.Endpoint.Name = "BOMBS_Service_Communicator_EndPoint";
            try
            {
                connector.Open();
                OnConnectionStatusChange(Server.ConnectionStatus.Success);

                if (HostInitializedAndOpened != null) HostInitializedAndOpened(this, EventArgs.Empty);
            }
            catch
            {
                OnConnectionStatusChange(Server.ConnectionStatus.ConnectionFailure);
                return;
            }

            connector.GetServerInformationCompleted -= connector_GetServerInformationCompleted;
            connector.GetServerInformationCompleted += connector_GetServerInformationCompleted;

            connector.GetServerInformationAsync();
        }