Exemplo n.º 1
0
        /// <summary>
        /// Generates a client connection.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="common">The common parameters.</param>
        /// <returns>
        /// The client connection.
        /// </returns>
        public static CruiseServerClientBase GenerateClient(string address, CommonCmdlet common)
        {
            // Build up the address
            var actualAddress = address;
            if (!actualAddress.Contains("//"))
            {
                // Address does not contain the protocol
                if (actualAddress.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
                    actualAddress.Equals("127.0.0.1", StringComparison.OrdinalIgnoreCase))
                {
                    actualAddress = "tcp://" + actualAddress;
                    if (!actualAddress.Contains(":"))
                    {
                        // Add the default port
                        actualAddress += ":21234";
                    }
                }
                else
                {
                    actualAddress = "http://" + actualAddress;
                }
            }

            // Generate the client
            var clientFactory = new CruiseServerClientFactory();
            var settings = new ClientStartUpSettings
                {
                    UseEncryption = common.Encrypted,
                    BackwardsCompatable = common.BackwardsCompatable
                };
            var client = clientFactory.GenerateClient(actualAddress, settings);
            client.TargetServer = common.Target;
            return client;
        }
        /// <summary>
        /// Generates an instance of <see cref="CruiseServerClientBase"/> that connects via
        /// .NET Remoting.
        /// </summary>
        /// <param name="address">The address of the server.</param>
        /// <param name="settings">The start-up settings to use.</param>
        /// <returns>A <see cref="CruiseServerClientBase"/> instance.</returns>
        public CruiseServerClientBase GenerateRemotingClient(string address, ClientStartUpSettings settings)
        {
            var client = clients.ContainsKey(address) ?
                         clients[address] :
                         null;

            if (client == null)
            {
                if (settings.BackwardsCompatable)
                {
                    client = new CruiseServerRemotingClient(address);
                }
                else
                {
                    IServerConnection connection = new RemotingConnection(address);
                    connection = BuildUpConnection(connection, settings);
                    client     = new CruiseServerClient(connection);
                }
                if (UseClientCaching)
                {
                    clients.Add(address, client);
                }
            }
            return(client);
        }
        /// <summary>
        /// Generates an instance of <see cref="CruiseServerClientBase"/>. The transport protocol will be
        /// detected from the address.
        /// </summary>
        /// <param name="address">The address of the server.</param>
        /// <param name="settings">The start-up settings to use.</param>
        /// <returns>A <see cref="CruiseServerClientBase"/> instance.</returns>
        public CruiseServerClientBase GenerateClient(string address, ClientStartUpSettings settings)
        {
            var serverUri = new Uri(address);
            var transport = serverUri.Scheme.ToLower();

            if (initialisers.ContainsKey(transport))
            {
                if (UseClientCaching && clients.ContainsKey(address))
                {
                    return(clients[address]);
                }
                else
                {
                    var client = initialisers[transport](address, settings);
                    if (UseClientCaching)
                    {
                        clients.Add(address, client);
                    }
                    return(client);
                }
            }
            else
            {
                throw new ApplicationException("Unknown transport protocol");
            }
        }
 /// <summary>
 /// Generates a set of <see cref="ClientStartUpSettings"/>.
 /// </summary>
 /// <param name="server"></param>
 /// <returns></returns>
 public static ClientStartUpSettings GenerateStartupSettings(BuildServer server)
 {
     var extSettings = server.ExtensionSettings ?? string.Empty;
     if (extSettings.Length < 6) extSettings += new string(' ', 6 - extSettings.Length);
     var settings = new ClientStartUpSettings
     {
         BackwardsCompatable = (extSettings.Substring(0, 3) == "OLD"),
         UseEncryption = (extSettings.Substring(3, 3) == "SEC")
     };
     return settings;
 }
 /// <summary>
 /// Generates an instance of <see cref="CruiseServerClientBase"/>. The transport protocol will be
 /// detected from the address.
 /// </summary>
 /// <param name="address">The address of the server.</param>
 /// <param name="settings">The start-up settings to use.</param>
 /// <returns>A <see cref="CruiseServerClientBase"/> instance.</returns>
 public CruiseServerClientBase GenerateClient(string address, ClientStartUpSettings settings)
 {
     var serverUri = new Uri(address);
     var transport = serverUri.Scheme.ToLower();
     if (initialisers.ContainsKey(transport))
     {
         if (UseClientCaching && clients.ContainsKey(address))
         {
             return clients[address];
         }
         else
         {
             var client = initialisers[transport](address, settings);
             if (UseClientCaching) clients.Add(address, client);
             return client;
         }
     }
     else
     {
         throw new ApplicationException("Unknown transport protocol");
     }
 }
 /// <summary>
 /// Builds a server connection based on the start-up options.
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static IServerConnection BuildUpConnection(IServerConnection connection, ClientStartUpSettings settings)
 {
     if (settings.UseEncryption)
     {
         connection = new EncryptingConnection(connection);
     }
     return(connection);
 }
        /// <summary>
        /// Generates an instance of <see cref="CruiseServerClientBase"/> that connects via
        /// .NET Remoting to another server.
        /// </summary>
        /// <param name="address">The address of the server.</param>
        /// <param name="targetServer">The name of the other server.</param>
        /// <param name="settings">The start-up settings to use.</param>
        /// <returns>A <see cref="CruiseServerClientBase"/> instance.</returns>
        public CruiseServerClientBase GenerateRemotingClient(string address, string targetServer, ClientStartUpSettings settings)
        {
            var client = GenerateRemotingClient(address, settings);

            client.TargetServer = targetServer;
            return(client);
        }
 /// <summary>
 /// Builds a server connection based on the start-up options.
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static IServerConnection BuildUpConnection(IServerConnection connection, ClientStartUpSettings settings)
 {
     if (settings.UseEncryption) connection = new EncryptingConnection(connection);
     return connection;
 }
 /// <summary>
 /// Generates an instance of <see cref="CruiseServerClientBase"/> that connects via
 /// .NET Remoting to another server.
 /// </summary>
 /// <param name="address">The address of the server.</param>
 /// <param name="targetServer">The name of the other server.</param>
 /// <param name="settings">The start-up settings to use.</param>
 /// <returns>A <see cref="CruiseServerClientBase"/> instance.</returns>
 public CruiseServerClientBase GenerateRemotingClient(string address, string targetServer, ClientStartUpSettings settings)
 {
     var client = GenerateRemotingClient(address, settings);
     client.TargetServer = targetServer;
     return client;
 }
 /// <summary>
 /// Generates an instance of <see cref="CruiseServerClientBase"/> that connects via
 /// .NET Remoting.
 /// </summary>
 /// <param name="address">The address of the server.</param>
 /// <param name="settings">The start-up settings to use.</param>
 /// <returns>A <see cref="CruiseServerClientBase"/> instance.</returns>
 public CruiseServerClientBase GenerateRemotingClient(string address, ClientStartUpSettings settings)
 {
     var client = clients.ContainsKey(address) ?
         clients[address] :
         null;
     if (client == null)
     {
         if (settings.BackwardsCompatable)
         {
             client = new CruiseServerRemotingClient(address);
         }
         else
         {
             IServerConnection connection = new RemotingConnection(address);
             connection = BuildUpConnection(connection, settings);
             client = new CruiseServerClient(connection);
         }
         if (UseClientCaching) clients.Add(address, client);
     }
     return client;
 }