using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AustinHarris.JsonRpc
{
///
/// The PreProcessHandler is called after the request has been parsed and prior to calling the associated method on the JsonRpcService.
/// If any non-null result is returned from the PreProcessHandler, the operation is aborted and the error is returned to the caller.
///
/// The jsonRpc Request that is pending processing.
/// The context associated with this request
/// Any non-null result causes the operation to be aborted, and the JsonRpcException is returned to the caller.
public delegate JsonRpcException PreProcessHandler(JsonRequest request, object context);
///
/// Global configurations for JsonRpc
///
public static class Config
{
///
/// Sets the the PreProcessing Handler on the default session.
///
///
public static void SetPreProcessHandler(PreProcessHandler handler)
{
Handler.DefaultHandler.SetPreProcessHandler(handler);
}
///
/// Sets the PreProcessing Handler on a specific session
///
///
///
public static void SetBeforeProcessHandler(string sessionId, PreProcessHandler handler)
{
Handler.GetSessionHandler(sessionId).SetPreProcessHandler(handler);
}
///
/// For exceptions thrown after the routed method has been called.
/// Allows you to specify an error handler that will be invoked prior to returning the JsonResponse to the client.
/// You are able to modify the error that is returned inside the provided handler.
///
///
public static void SetErrorHandler(Func handler)
{
Handler.DefaultHandler.SetErrorHandler(handler);
}
///
/// For exceptions thrown after the routed method has been called.
/// Allows you to specify an error handler that will be invoked prior to returning the JsonResponse to the client.
/// You are able to modify the error that is returned inside the provided handler.
///
///
///
public static void SetErrorHandler(string sessionId, Func handler)
{
Handler.GetSessionHandler(sessionId).SetErrorHandler(handler);
}
///
/// For exceptions thrown during parsing and prior to a routed method being called.
/// Allows you to specify an error handler that will be invoked prior to returning the JsonResponse to the client.
/// You are able to modify the error that is returned inside the provided handler.
///
///
public static void SetParseErrorHandler(Func handler)
{
Handler.DefaultHandler.SetParseErrorHandler(handler);
}
///
/// For exceptions thrown during parsing and prior to a routed method being called.
/// Allows you to specify an error handler that will be invoked prior to returning the JsonResponse to the client.
/// You are able to modify the error that is returned inside the provided handler.
///
///
///
public static void SetParseErrorHandler(string sessionId, Func handler)
{
Handler.GetSessionHandler(sessionId).SetParseErrorHandler(handler);
}
}
}