public T GetService <T>(JimuPayload payload = null) where T : class { //var instanceType = typeof(T); var proxyType = _serviceProxyTypes.Single(typeof(T).GetTypeInfo().IsAssignableFrom); var instance = proxyType.GetTypeInfo().GetConstructors().First().Invoke(new object[] { _remoteServiceCaller, payload }); return(instance as T); }
public string GetEcho() { JimuPayload payload = new JimuPayload { Items = new Dictionary <string, object>() }; payload.Items["userid"] = "f**k"; var echoService = _serviceProxy.GetService <IEchoService>(payload); var ret = echoService.GetEchoAnonymous2("echo from hello service!"); return("hello return: " + ret.Name); }
public static Guid WriteLocalMethodInvokeBefore(this IJimuDiagnostic @this, JimuPayload payload, string invokerData, [CallerMemberName] string operation = "") { if ([email protected](DiagnosticServerEventType.LocalMethodInvokeBefore)) { return(Guid.Empty); } var operationId = Guid.NewGuid(); @this.Write(DiagnosticServerEventType.LocalMethodInvokeBefore, new LocalMethodInvokeBeforeEventData(operationId, operation) { Data = invokerData, Payload = payload }); return(operationId); }
//private FastInvoke.FastInvokeHandler GetInvokeHandler(string key, MethodInfo method) //{ //_handler.TryGetValue(Tuple.Create(method.DeclaringType, key), out var handler); //if (handler == null) //{ // handler = FastInvoke.GetMethodInvoker(method); // _handler.GetOrAdd(Tuple.Create(method.DeclaringType, key), handler); //} //return handler; //} private object GetInstance(string key, Type type, JimuPayload payload) { // all service are instancePerDependency, to avoid resolve the same isntance , so we add using scop here using (var scope = _container.BeginLifetimeScope()) { if (string.IsNullOrEmpty(key)) { return(scope.Resolve(type, new ResolvedParameter( (pi, ctx) => pi.ParameterType == typeof(JimuPayload), (pi, ctx) => payload ))); } return(scope.ResolveKeyed(key, type, new ResolvedParameter( (pi, ctx) => pi.ParameterType == typeof(JimuPayload), (pi, ctx) => payload ))); } }
public RemoteCallerContext(JimuServiceRoute service, IDictionary <string, object> paras, JimuPayload payload, string token, JimuAddress jimuAddress) { if (paras == null) { paras = new ConcurrentDictionary <string, object>(); } this.Service = service; this.Paras = paras; this.Token = token; this.ServiceAddress = jimuAddress; this.PayLoad = payload; }
public MemberService(ILogger logger, JimuPayload jimuPayload) { _logger = logger; _jimuPayload = jimuPayload; }
public JimuServerCarrierHeaderCollection(JimuPayload payload) { _payload = payload; }
public AuthService(IDbFactory <DbConnection> dbFactory, JimuPayload payload) { _dbFactory = dbFactory; _payload = payload; }
public async Task <JimuRemoteCallResultData> InvokeAsync(string serviceIdOrPath, IDictionary <string, object> paras, JimuPayload payload = null, string token = null) { if (paras == null) { paras = new ConcurrentDictionary <string, object>(); } var service = await GetServiceByIdAsync(serviceIdOrPath) ?? await GetServiceByPathAsync(serviceIdOrPath, paras); if (service == null) { return new JimuRemoteCallResultData { ErrorCode = "404", ErrorMsg = $"{serviceIdOrPath}, not found!" } } ; if (token == null && _serviceTokenGetter?.GetToken != null) { token = _serviceTokenGetter.GetToken(); } var result = await InvokeAsync(service, paras, payload, token); if (!string.IsNullOrEmpty(result.ExceptionMessage)) { return new JimuRemoteCallResultData { ErrorCode = "500", ErrorMsg = $"{serviceIdOrPath}, {result.ToErrorString()}" } } ; if (string.IsNullOrEmpty(result.ErrorCode) && string.IsNullOrEmpty(result.ErrorMsg)) { return(result); } if (int.TryParse(result.ErrorCode, out var erroCode) && erroCode > 200 && erroCode < 600) { return new JimuRemoteCallResultData { ErrorCode = result.ErrorCode, ErrorMsg = $"{serviceIdOrPath}, {result.ToErrorString()}" } } ; return(result); }
public async Task <JimuRemoteCallResultData> InvokeAsync(JimuServiceRoute service, IDictionary <string, object> paras, JimuPayload payload, string token) { var lastInvoke = GetLastInvoke(); foreach (var mid in _middlewares) { lastInvoke = mid(lastInvoke); } return(await lastInvoke(new RemoteCallerContext(service, paras, payload, token, service.Address.First()))); }
public JimuClientCarrierHeaderCollection(JimuPayload payload) { _payload = payload; }
public LocalDiagnosticService(IJimuDiagnostic jimuDiagnostic, JimuPayload payload) { _jimuDiagnostic = jimuDiagnostic; _payload = payload; }
public JwtService(JimuPayload payload) { _payload = payload; }
public NewsService(ILogger logger, JimuPayload jimuPayload) { _logger = logger; _jimuPayload = jimuPayload; }
public UserOrderService(IServiceProxy serviceProxy, JimuPayload payload) { _serviceProxy = serviceProxy; _payload = payload; }
public async Task <JimuRemoteCallResultData> InvokeAsync(JimuServiceRoute service, IDictionary <string, object> paras, JimuPayload payload, string token) { var context = new RemoteCallerContext(service, paras, payload, token, service.Address.First()); var operationId = _jimuApm.WriteRPCExecuteBefore(context); try { var lastInvoke = GetLastInvoke(); foreach (var mid in _middlewares) { lastInvoke = mid(lastInvoke); } var result = await lastInvoke(context); _jimuApm.WriteRPCExecuteAfter(operationId, context, result); return(result); } catch (Exception ex) { _jimuApm.WriteRPCExecuteError(operationId, context, ex); throw ex; } }
public AuthService(IDbFactory dbFactory, JimuPayload payload) { _dbFactory = dbFactory; _payload = payload; }
public async Task <T> InvokeAsync <T>(string serviceIdOrPath, IDictionary <string, object> paras, JimuPayload payload) { _logger.Debug($"begin to invoke service: {serviceIdOrPath}"); var result = await InvokeAsync(serviceIdOrPath, paras, payload); if (!string.IsNullOrEmpty(result.ExceptionMessage)) { _logger.Debug($"invoking service: {serviceIdOrPath} raising an error: {result.ExceptionMessage}"); throw new Exception(result.ExceptionMessage); } if (!string.IsNullOrEmpty(result.ErrorCode)) { _logger.Debug($"invoking service: {serviceIdOrPath} raising an error: errorcode {result.ErrorCode}, error: {result.ErrorMsg}"); if (result.Result == null) { return(default(T)); } } if (result.Result == null) { _logger.Debug($"invoking service: {serviceIdOrPath} has null return."); return(default(T)); } object value; if (result.Result is Task <T> task) { value = JimuHelper.ConvertType(task.Result, typeof(T)); } else { value = JimuHelper.ConvertType(result.Result, typeof(T)); } _logger.Debug($"finish invoking service: {serviceIdOrPath}."); return((T)value); }
protected ServiceProxyBase(IRemoteServiceCaller remoteServiceCaller, JimuPayload payload) { _remoteServiceCaller = remoteServiceCaller; this._payload = payload; }
public EchoService(ILogger logger, JimuPayload payload) { _logger = logger; _payload = payload; }
public AuthService(DbConnection cnn, JimuPayload payload) { _cnn = cnn; _payload = payload; }