本文整理汇总了C#中RequestContext.SendError方法的典型用法代码示例。如果您正苦于以下问题:C# RequestContext.SendError方法的具体用法?C# RequestContext.SendError怎么用?C# RequestContext.SendError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestContext
的用法示例。
在下文中一共展示了RequestContext.SendError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddProcedure
/// <summary>
/// Adds a procedure that can be called by remote peer to the scene.
/// </summary>
/// <param name="route"></param>
/// <param name="handler"></param>
/// <param name="ordered">True if the message should be alwayse receive in order, false otherwise.</param>
/// <remarks>
/// The procedure is added to the scene to which this service is attached.
/// </remarks>
public void AddProcedure(string route, Func<RequestContext<IScenePeer>, Task> handler, bool ordered)
{
this._scene.AddRoute(route, p =>
{
var buffer = new byte[2];
p.Stream.Read(buffer, 0, 2);
var id = BitConverter.ToUInt16(buffer, 0);
var cts = new CancellationTokenSource();
var ctx = new RequestContext<IScenePeer>(p.Connection, _scene, id, ordered,cts.Token);
if (_runningRequests.TryAdd(id, cts))
{
handler(ctx).ContinueWith(t =>
{
_runningRequests.TryRemove(id, out cts);
if (t.IsCompleted)
{
ctx.SendCompleted();
}
else
{
_scene.resolver.GetComponent<ILogger>().Log(Stormancer.Diagnostics.LogLevel.Error, _scene.Id, "failed to create procedure");
var ex = t.Exception.InnerExceptions.OfType<ClientException>();
if (ex.Any())
{
ctx.SendError(string.Join("|", ex.Select(e => e.Message).ToArray()));
}
}
});
}
}, new Dictionary<string, string> { { "stormancer.plugins.rpc", "1.0.0" } });
_scene.resolver.GetComponent<ILogger>().Log(Stormancer.Diagnostics.LogLevel.Trace, _scene.Id, "Procedure succesfully created");
}
示例2: AddProcedure
/// <summary>
/// Adds a procedure that can be called by remote peer to the scene.
/// </summary>
/// <param name="route"></param>
/// <param name="handler"></param>
/// <param name="ordered">True if the message should be alwayse receive in order, false otherwise.</param>
/// <remarks>
/// The procedure is added to the scene to which this service is attached.
/// </remarks>
public void AddProcedure(string route, Func<RequestContext<IScenePeer>, Task> handler, bool ordered)
{
this._scene.AddRoute(route, p =>
{
var buffer = new byte[2];
p.Stream.Read(buffer, 0, 2);
var id = BitConverter.ToUInt16(buffer, 0);
var cts = new CancellationTokenSource();
var ctx = new RequestContext<IScenePeer>(p.Connection, _scene, id, ordered, new SubStream(p.Stream, false), cts.Token);
var identifier = System.Tuple.Create(p.Connection.Id, id);
if (_runningRequests.TryAdd(identifier, cts))
{
handler.InvokeWrapping(ctx).ContinueWith(t =>
{
_runningRequests.TryRemove(identifier, out cts);
if (t.Status == TaskStatus.RanToCompletion)
{
ctx.SendCompleted();
}
else if (t.Status == TaskStatus.Faulted)
{
var errorSent = false;
var ex = t.Exception.InnerExceptions.OfType<ClientException>();
if (ex.Any())
{
ctx.SendError(string.Join("|", ex.Select(e => e.Message).ToArray()));
errorSent = true;
}
if (t.Exception.InnerExceptions.Any(e => !(e is ClientException)))
{
string errorMessage = string.Format("An error occured while executing procedure '{0}'.", route);
if (!errorSent)
{
var errorId = Guid.NewGuid().ToString("N");
ctx.SendError(string.Format("An exception occurred on the remote peer. Error {0}.", errorId));
errorMessage = string.Format("Error {0}. ", errorId) + errorMessage;
}
_scene.DependencyResolver.Resolve<ILogger>().Log(LogLevel.Error, "rpc.server", errorMessage, t.Exception);
}
}
});
}
}, new Dictionary<string, string> { { RpcClientPlugin.PluginName, RpcClientPlugin.Version } });
}