Exemple #1
0
        public async Task <JimuRemoteCallResultData> SendAsync(JimuRemoteCallData data)
        {
            try
            {
                _logger.Debug($"prepare sending: {data.ServiceId}");
                var transportMsg = new JimuTransportMsg(data);
                var callbackTask = RegisterResultCallbackAsync(transportMsg.Id);
                try
                {
                    await DoSendAsync(transportMsg);

                    _logger.Debug($"succed to send: {data.ServiceId}, msg: {transportMsg.Id}");
                    return(await callbackTask);
                }
                catch (Exception ex)
                {
                    _logger.Error($"error occur when connecting with server, serviceid: {data.ServiceId}", ex);
                    throw;
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"failed to send: {data.ServiceId}", ex);
                throw new TransportException(ex.Message, ex);
            }
        }
Exemple #2
0
        private async Task LocalServiceExecuteAsync(JimuServiceEntry serviceEntry, JimuRemoteCallData invokeMessage, JimuRemoteCallResultData resultMessage)
        {
            try
            {
                var cancelTokenSource = new CancellationTokenSource();
                //wait OnAuthorization(serviceEntry, cancelTokenSource ,,,,)
                if (!cancelTokenSource.IsCancellationRequested)
                {
                    var result = await serviceEntry.Func(invokeMessage.Parameters, invokeMessage.Payload);

                    var task = result as Task;
                    if (task == null)
                    {
                        resultMessage.Result = result;
                    }
                    else
                    {
                        task.Wait(cancelTokenSource.Token);
                        var taskType = task.GetType().GetTypeInfo();
                        if (taskType.IsGenericType)
                        {
                            resultMessage.Result = taskType.GetProperty("Result")?.GetValue(task);
                        }
                    }
                    resultMessage.ResultType = serviceEntry.Descriptor.ReturnDesc;
                }
            }
            catch (Exception ex)
            {
                _logger.Error("throw exception when excuting local service: " + serviceEntry.Descriptor.Id, ex);
                resultMessage.ExceptionMessage = ex.ToStackTraceString();
            }
        }
 public JwtAuthorizationContext(JwtAuthorizationOptions options, JimuRemoteCallData remoteInvokeMessage)
 {
     Options             = options;
     Payload             = options.GetPayload();
     RemoteInvokeMessage = remoteInvokeMessage;
     if (remoteInvokeMessage.Parameters.ContainsKey("username"))
     {
         UserName = remoteInvokeMessage.Parameters["username"] + "";
     }
     if (remoteInvokeMessage.Parameters.ContainsKey("password"))
     {
         Password = remoteInvokeMessage.Parameters["password"] + "";
     }
     Payload.Add("username", UserName);
 }