/// <summary>
        /// Sends a message to a remote server.
        /// </summary>
        /// <param name="action">The action to perform.</param>
        /// <param name="request">The request to send to the server.</param>
        /// <returns>The response from the server.</returns>
        public Response SendMessage(string action, ServerRequest request)
        {
            // Make sure there is a password
            if ((cryptoKey.Length == 0) || (cryptoIv.Length == 0))
            {
                InitialisePassword();
            }

            // Generate the encrypted request
            var encryptedRequest = new EncryptedRequest();

            encryptedRequest.Action = action;
            var crypto = new RijndaelManaged();

            crypto.Key = cryptoKey;
            crypto.IV  = cryptoIv;
            encryptedRequest.EncryptedData = EncryptMessage(crypto, request.ToString());

            // Send the request
            var response          = innerConnection.SendMessage("ProcessSecureRequest", encryptedRequest);
            var encryptedResponse = response as EncryptedResponse;

            // Generate the actual response
            if ((response.Result == ResponseResult.Success) && (encryptedResponse != null))
            {
                var data = DecryptMessage(crypto, encryptedResponse.EncryptedData);
                response = XmlConversionUtil.ProcessResponse(data);
            }
            return(response);
        }
Esempio n. 2
0
        public void GetProjectStatusThrowsExceptionOnFailure()
        {
            ProjectStatusResponse response   = new ProjectStatusResponse();
            IServerConnection     connection = mocks.DynamicMock <IServerConnection>();

            SetupResult.For(connection.SendMessage("GetProjectStatus", null))
            .IgnoreArguments()
            .Return(response);
            mocks.ReplayAll();

            CruiseServerClient client = new CruiseServerClient(connection);

            Assert.That(delegate { client.GetProjectStatus(); },
                        Throws.TypeOf <CommunicationsException>());
        }
Esempio n. 3
0
        public void GetProjectStatusReturnsProjects()
        {
            ProjectStatus         status   = new ProjectStatus("Test project", IntegrationStatus.Success, DateTime.Now);
            ProjectStatusResponse response = new ProjectStatusResponse();

            response.Result = ResponseResult.Success;
            response.Projects.Add(status);
            IServerConnection connection = mocks.DynamicMock <IServerConnection>();

            SetupResult.For(connection.SendMessage("GetProjectStatus", null))
            .IgnoreArguments()
            .Return(response);
            mocks.ReplayAll();

            CruiseServerClient client = new CruiseServerClient(connection);

            ProjectStatus[] results = client.GetProjectStatus();
            Assert.AreEqual(1, results.Length);
            Assert.AreEqual(status, results[0]);
        }
        /// <summary>
        /// Gets information about the last build status, current activity and project name.
        /// for all projects on a cruise server
        /// </summary>
        public override ProjectStatus[] GetProjectStatus()
        {
            ProjectStatusResponse resp = ValidateResponse(
                connection.SendMessage("GetProjectStatus", GenerateServerRequest()))
                                         as ProjectStatusResponse;

            return(resp.Projects.ToArray());
        }