本文整理汇总了C#中ThoughtWorks.CruiseControl.Remote.Messages.ServerRequest.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ServerRequest.ToString方法的具体用法?C# ServerRequest.ToString怎么用?C# ServerRequest.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThoughtWorks.CruiseControl.Remote.Messages.ServerRequest
的用法示例。
在下文中一共展示了ServerRequest.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendMessageAsyncSendsMessage
public void SendMessageAsyncSendsMessage()
{
var action = "DoSomething";
var request = new ServerRequest
{
ServerName = "TestServer"
};
var url = "http://somewhere/";
var factory = new TestClientFactory((u, a, d) =>
{
Assert.AreEqual(url + "server/TestServer/RawXmlMessage.aspx", u.AbsoluteUri);
Assert.AreEqual("POST", a);
Assert.AreEqual(action, d["action"]);
Assert.AreEqual(request.ToString(), d["message"]);
var theResponse = new Response
{
RequestIdentifier = request.Identifier
};
return Encoding.UTF8.GetBytes(theResponse.ToString());
});
var connection = new HttpConnection(new Uri(url), factory);
var completed = false;
connection.SendMessageCompleted += (o, e) =>
{
completed = true;
Assert.IsFalse(e.Cancelled);
Assert.IsNull(e.Error);
};
connection.SendMessageAsync(action, request);
Assert.IsTrue(completed);
}
示例2: SendMessageSendsAndReceivesAMessage
public void SendMessageSendsAndReceivesAMessage()
{
var action = "DoSomething";
var request = new ServerRequest
{
ServerName = "TestServer"
};
var url = "http://somewhere/";
var factory = new TestClientFactory((u, a, d) =>
{
Assert.AreEqual(url + "server/TestServer/RawXmlMessage.aspx", u.AbsoluteUri);
Assert.AreEqual("POST", a);
Assert.AreEqual(action, d["action"]);
Assert.AreEqual(request.ToString(), d["message"]);
var theResponse = new Response
{
RequestIdentifier = request.Identifier
};
return Encoding.UTF8.GetBytes(theResponse.ToString());
});
var connection = new HttpConnection(new Uri(url), factory);
var response = connection.SendMessage(action, request);
Assert.IsInstanceOf<Response>(response);
Assert.AreEqual(request.Identifier, response.RequestIdentifier);
}
示例3: ConvertXmlToRequestConvertsRequest
public void ConvertXmlToRequestConvertsRequest()
{
var request = new ServerRequest("123456-789");
request.ServerName = "theServer";
var xmlString = request.ToString();
var convertedRequest = XmlConversionUtil.ConvertXmlToRequest(xmlString);
Assert.AreEqual("123456-789", convertedRequest.SessionToken);
Assert.AreEqual("theServer", convertedRequest.ServerName);
}
示例4: ToStringSerialisesDefaultValues
public void ToStringSerialisesDefaultValues()
{
ServerRequest request = new ServerRequest();
string actual = request.ToString();
string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture,"<serverMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" source=\"{1}\" />",
request.Identifier,
request.SourceName,
request.Timestamp);
Assert.AreEqual(expected, actual);
}
示例5: SendMessageAsync
/// <summary>
/// Sends a message to a remote server asychronously.
/// </summary>
/// <param name="action">The action to perform.</param>
/// <param name="request">The request to send to the server.</param>
/// <param name="userState">Any user state data.</param>
public virtual void SendMessageAsync(string action, ServerRequest request, object userState)
{
// Ensure that async is only called once (or once with the user state)
lock (lockObject)
{
if (userState == null)
{
if (isBusy) throw new InvalidOperationException();
isBusy = true;
}
else if (asyncOperations.ContainsKey(userState))
{
if (asyncOperations.ContainsKey(userState)) throw new ArgumentException("Duplicate userState", "userState");
}
}
// Initialise the web client
WebClient client = new WebClient();
client.UploadValuesCompleted += delegate(object sender, UploadValuesCompletedEventArgs e)
{
if (SendMessageCompleted != null)
{
if ((e.Error != null) && !e.Cancelled)
{
// Convert the response into a response object
string response = Encoding.UTF8.GetString(e.Result);
Response result = XmlConversionUtil.ProcessResponse(response);
MessageReceivedEventArgs args = new MessageReceivedEventArgs(result, null, false, userState);
SendMessageCompleted(this, args);
}
else
{
MessageReceivedEventArgs args = new MessageReceivedEventArgs(null, e.Error, e.Cancelled, userState);
SendMessageCompleted(this, args);
}
}
CompleteAsyncCall(userState);
};
lock (lockObject)
{
asyncOperations.Add(userState ?? string.Empty, client);
}
try
{
// Generate the target URI
Uri targetAddress = GenerateTargetUri(request);
// Build the request and send it
NameValueCollection formData = new NameValueCollection();
formData.Add("action", action);
formData.Add("message", request.ToString());
client.UploadValuesAsync(targetAddress, "POST", formData);
}
catch (Exception error)
{
if (SendMessageCompleted != null)
{
MessageReceivedEventArgs args = new MessageReceivedEventArgs(null, error, false, userState);
SendMessageCompleted(this, args);
}
CompleteAsyncCall(userState);
}
}
示例6: SendMessage
/// <summary>
/// Sends a message via HTTP.
/// </summary>
/// <param name="action"></param>
/// <param name="request"></param>
/// <returns></returns>
public Response SendMessage(string action, ServerRequest request)
{
// Generate the target URI
Uri targetAddress = GenerateTargetUri(request);
// Build the request and send it
WebClient client = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData.Add("action", action);
formData.Add("message", request.ToString());
FireRequestSending(action, request);
string response = Encoding.UTF8.GetString(client.UploadValues(targetAddress, "POST", formData));
// Convert the response into a response object
Response result = XmlConversionUtil.ProcessResponse(response);
FireResponseReceived(action, result);
return result;
}
示例7: SendMessageEncryptsMessage
public void SendMessageEncryptsMessage()
{
var innerConnection = new TestConnection();
var outerConnection = new EncryptingConnection(innerConnection);
var request = new ServerRequest();
var expectedResponse = new Response(request);
var actionName = "DoSomething";
string iv = null;
string key = null;
innerConnection.SendMessageAction = (a, r) =>
{
Response sendResponse = null;
if (a == "RetrievePublicKey")
{
sendResponse = this.GenerateKeyResponse(r);
}
else if (a == "InitialiseSecureConnection")
{
Assert.IsInstanceOf<LoginRequest>(r);
sendResponse = this.GenerateConnectioResponse(r as LoginRequest, out iv, out key);
}
else if (a == "ProcessSecureRequest")
{
Assert.IsInstanceOf<EncryptedRequest>(r);
var actualRequest = r as EncryptedRequest;
Assert.AreEqual(actionName, actualRequest.Action);
var crypto = new RijndaelManaged();
crypto.Key = Convert.FromBase64String(key);
crypto.IV = Convert.FromBase64String(iv);
var requestData = DecryptMessage(crypto, actualRequest.EncryptedData);
Assert.AreEqual(request.ToString(), requestData);
var encryptedResponse = new EncryptedResponse();
encryptedResponse.Result = ResponseResult.Success;
encryptedResponse.EncryptedData = EncryptMessage(crypto, expectedResponse.ToString());
sendResponse = encryptedResponse;
}
else
{
Assert.Fail("Unknown action: " + a);
}
return sendResponse;
};
var response = outerConnection.SendMessage(actionName, request);
Assert.IsNotNull(response);
Assert.AreEqual(expectedResponse.RequestIdentifier, response.RequestIdentifier);
}
示例8: SendMessage
/// <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;
}