本文整理汇总了C#中IFrame.CreateError方法的典型用法代码示例。如果您正苦于以下问题:C# IFrame.CreateError方法的具体用法?C# IFrame.CreateError怎么用?C# IFrame.CreateError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFrame
的用法示例。
在下文中一共展示了IFrame.CreateError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public IFrame Process(IStompClient client, IFrame request)
{
var versions = request.Headers["accept-version"];
if (versions == null)
{
var error = request.CreateError("Missing the 'accept-version' header.");
error.Headers["version"] = "2.0";
return error;
}
if (!versions.Contains("2.0"))
{
var error = request.CreateError("Only accepting stomp 2.0 clients.");
error.Headers["version"] = "2.0";
return error;
}
IFrame frame;
if (!CheckCredentials(client, request, out frame))
return frame;
//TODO: Heartbeating.
var response = new BasicFrame("CONNECTED");
response.Headers["version"] = "2.0";
response.Headers["server"] = _serverName;
if (client.SessionKey != null)
response.Headers["session"] = client.SessionKey;
return response;
}
示例2: CheckCredentials
/// <summary>
///
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="errorFrame"></param>
/// <returns><c>true</c> means that we should exist.</returns>
private bool CheckCredentials(IStompClient client, IFrame request, out IFrame errorFrame)
{
if (_authenticationService.IsActivated)
{
var user = request.Headers["login"];
var passcode = request.Headers["passcode"];
if (user == null || passcode == null)
{
var error =
request.CreateError(
"This broker have been configured to only allow authenticated clients. Send the 'login'/'password' headers in the 'STOMP' errorFrame.");
error.Headers["version"] = "2.0";
{
errorFrame = error;
return false;
}
}
var loginResult = _authenticationService.Login(user, passcode);
if (!loginResult.IsSuccessful)
{
var error = request.CreateError(loginResult.Reason);
error.Headers["version"] = "2.0";
{
errorFrame = error;
return false;
}
}
client.SetAsAuthenticated(loginResult.Token);
}
else
client.SetAsAuthenticated(Guid.NewGuid().ToString());
errorFrame = null;
return true;
}