Rpc Call Proxy
When communicate with Another System , for some reason need to :
1. log the time (calling time , etc)
2.Exception handling
This is a RPC caller which handles exception in each call
/// <summary>
/// Remote Procedure Call Proxy
/// Add log(timeline,etc) before/after RPC
/// Handle Remoting Call Exception
/// </summary>
/// <typeparam name="TIn"></typeparam>
public class EdasRpcProxy<TIn>
{
public delegate void ActionRef<TIn>(ref TIn parameter);
public static EdasResult SyncCallRef(ActionRef<TIn> func, ref TIn parameter)
{
return new EdasRpcProxy<TIn>().SynCRef(func, ref parameter);
}
public static EdasResult SyncCall(Action<TIn> action, TIn parameter)
{
return new EdasRpcProxy<TIn>().SynC(action, parameter);
}
private EdasResult SynCRef(ActionRef<TIn> func, ref TIn parameter)
{
try
{
func(ref parameter);
return EdasResult.Create(ResultCode.Ok);
}
catch (Exception ex)
{
return EdasResult.Create(ResultCode.RemoteServerErr,
string.Format(eDASConstants.Messages.RpcCallError, func.Method.Name));
}
}
private EdasResult SynC(Action<TIn> action, TIn parameter)
{
try
{
action(parameter);
return EdasResult.Create(ResultCode.Ok);
}
catch (Exception ex)
{
return EdasResult.Create(ResultCode.RemoteServerErr,
string.Format(eDASConstants.Messages.RpcCallError, action.Method.Name));
}
}
public void AsyncC<TOut>(Func<object, TOut> func, object parameter,
Action<EdasResult<TOut>> callback)
{
Task<TOut>.Factory.StartNew(func, parameter).ContinueWith(
(t =>
{
var entity = t.Result;
if (t.Exception != null)
callback(EdasResult<TOut>.CreateResult(ResultCode.RemoteServerErr, default(TOut),
string.Format
(eDASConstants.Messages.RpcCallError,
func.Method.Name)));
else
callback(EdasResult<TOut>.CreateResult(ResultCode.Ok, entity));
}));
}
}
public class EdasRpcProxy<TIn, TOut>
{
public delegate TOut FuncRef<TIn, TOut>(ref TIn parameter);
public static EdasResult<TOut> SyncCallRef(FuncRef<TIn, TOut> func, ref TIn parameter)
{
return new EdasRpcProxy<TIn, TOut>().SynCRef(func, ref parameter);
}
public static EdasResult<TOut> SyncCall(Func<TIn, TOut> func, TIn parameter)
{
return new EdasRpcProxy<TIn, TOut>().SynC(func, parameter);
}
private EdasResult<TOut> SynCRef(FuncRef<TIn, TOut> func, ref TIn parameter)
{
try
{
var ret = func(ref parameter);
return EdasResult<TOut>.CreateResult(ResultCode.Ok, ret);
}
catch (Exception ex)
{
return EdasResult<TOut>.CreateResult(ResultCode.RemoteServerErr, default(TOut),
string.Format(eDASConstants.Messages.RpcCallError, func.Method.Name));
}
}
private EdasResult<TOut> SynC(Func<TIn, TOut> func, TIn parameter)
{
try
{
var ret = func(parameter);
return EdasResult<TOut>.CreateResult(ResultCode.Ok, ret);
}
catch (Exception ex)
{
return EdasResult<TOut>.CreateResult(ResultCode.RemoteServerErr, default(TOut),
string.Format(eDASConstants.Messages.RpcCallError, func.Method.Name));
}
}
}
相關文章
- 理解call和實現call
- Proxy
- JavaScript call()JavaScript
- js callJS
- call() 方法
- __call__
- IPC call
- docker – nginx – proxy_pass + proxy_redirectDockerNginx
- nginx proxy_pass 和 proxy_redirectNginx
- Proxy模式模式
- MySQL ProxyMySql
- proxy 收集
- 天天打call, 你可知道javascript中的call?JavaScript
- 02 #### `__call__` ,物件(),自動執行call 方法物件
- RPCRPC
- [RPC]RPC
- golang system callGolang
- java call dllJava
- [Javascript] Write .call()JavaScript
- 代理模式(Proxy)模式
- JavaScript 之 ProxyJavaScript
- 配置proxy代理
- jQuery.proxy()jQuery
- http proxy原理HTTP
- 安卓 no_proxy安卓
- MySQL Proxy應用入門(1)--安裝MySQL ProxyMySql
- call_user_func()與call_user_func_array函式函式
- this、apply、call、bindAPP
- Function.prototype.callFunction
- js的this,bind,call……JS
- this、call和applyAPP
- Let's call it a "return"
- javacscript apply and callJavaAPP
- call仿函式函式
- Go RpcGoRPC
- PoS RPCRPC
- 生成 rpcRPC
- MySQL Proxy應用入門(2)--MySQL Proxy配置選項MySql