public async Task <bool> MoveNext() { var t = Fetch(); try { Current = await t.ConfigureAwait(false); if (Current == null) { LogEnvironment.LogEvent("Current message was set to null!", LogSeverity.Warning); } return(Current != null); } catch (TaskCanceledException) { LogEnvironment.LogEvent("Read cancelled!", LogSeverity.Warning); } catch (Exception ex) { LogEnvironment.LogDebugEvent($"Un-Expected Error @MoveNext: {ex.OutlineException()}", LogSeverity.Error); throw; } return(false); }
public virtual async Task <ServiceOperationResponseMessage> ConsumeService(ServerOperationMessage request, DataTransferContext context) { //context.GetHttpContext().RequestServices.VerifyUserPermissions() var retRaw = await serviceBackend.Broker.SendMessageToServer(request); return(retRaw); }
public OperationWaitHandle(ServerOperationMessage op) { ClientRequest = op; if (!op.TickBack) { ServerResponse = new TaskCompletionSource <ServiceOperationResponseMessage>(TaskCreationOptions.RunContinuationsAsynchronously); } }
/// <summary> /// Processes a message that was received from a remote client /// </summary> /// <param name="message">the message that was received from the remote host</param> /// <returns>a response message that was generated as result of the received message</returns> public ServiceOperationResponseMessage ProcessMessage(ServerOperationMessage message) { var msg = new MessageArrivedEventArgs { TargetService = message.TargetService, Message = message.OperationPayload }; if (!string.IsNullOrEmpty(message.HubUser)) { msg.HubUser = JsonHelper.FromJsonStringStrongTyped <TransferIdentity>(message.HubUser).ToIdentity(serverSecurity); } OnMessageArrived(msg); ServiceOperationResponseMessage ret; if (msg.Completed) { if (msg.Error == null) { ret = new ServiceOperationResponseMessage { OperationId = message.OperationId, ResponsePayload = msg.Response, TargetService = message.TargetService, Ok = true }; } else { ret = new ServiceOperationResponseMessage { OperationId = message.OperationId, ResponsePayload = JsonHelper.ToJsonStrongTyped(msg.Error, true), TargetService = message.TargetService, Ok = false }; } } else { ret = new ServiceOperationResponseMessage { OperationId = message.OperationId, TargetService = message.TargetService, ResponsePayload = JsonHelper.ToJsonStrongTyped(new SerializedException("Message was not processed!", new SerializedException[0]), true), Ok = false }; } if (!string.IsNullOrEmpty(consumedService)) { ret.ResponderFor = consumedService; } return(ret); }
public override Task <ServiceOperationResponseMessage> ConsumeService(ServerOperationMessage request, DataTransferContext context) { try { CheckAuth(context, "ConnectAnyService", request.TargetService); request.HubUser = JsonHelper.ToJsonStrongTyped(((ClaimsIdentity)context.Identity).ForTransfer()); return(base.ConsumeService(request, context)); } catch (Exception ex) { return(Task.FromException <ServiceOperationResponseMessage>(ex)); } }
public Task <ServiceOperationResponseMessage> SendMessageToServer(ServerOperationMessage message) { try { if (GrabService(message.TargetService, null, true, out var service, out var operations, out var waitingMessages)) { if (service.ServiceKind == ServiceStatus.ServiceType.Local) { return(Task.FromResult(service.LocalClient.ProcessMessage(message))); } lock (service) { OperationWaitHandle hnd = new OperationWaitHandle(message); try { if (service.OpenTaskWait != null) { var t = service.OpenTaskWait; service.OpenTaskWait = null; t.SetResult(hnd); } else { operations.Enqueue(hnd); } } catch (Exception ex) { hnd.ServerResponse.SetException(ex); } return(hnd.ServerResponse.Task); } } throw new CommunicationException("The requested service is not available"); } catch (Exception ex) { return(Task.FromResult(new ServiceOperationResponseMessage { OperationId = message.OperationId, TargetService = message.TargetService, ResponsePayload = JsonHelper.ToJsonStrongTyped((SerializedException)ex, true), Ok = false })); } }
public override async Task <ServiceOperationResponseMessage> ConsumeService(ServerOperationMessage request, ServerCallContext context) { //context.GetHttpContext().RequestServices.VerifyUserPermissions() var retRaw = await serviceBackend.Broker.SendMessageToServer(new MessagingShared.Hub.Protocol.ServerOperationMessage { OperationId = request.OperationId, TargetService = request.TargetService, HubUser = request.HubUser, OperationPayload = request.OperationPayload, TickBack = request.TickBack }); return(new ServiceOperationResponseMessage { OperationId = retRaw.OperationId ?? "", TargetService = retRaw.TargetService ?? "", Ok = retRaw.Ok, ResponderFor = retRaw.ResponderFor ?? "", ResponsePayload = retRaw.ResponsePayload ?? "" }); }
internal void PushMessage(ServerOperationMessage message) { TaskCompletionSource <ServerOperationMessage> target = null; lock (messageSync) { if (openReadWait != null) { target = openReadWait; openReadWait = null; } else { messageQueue.Enqueue(message); } } if (target != null) { target.SetResult(message); } }
public async Task <ServiceOperationResponseMessage> ConsumeServiceAsync(ServerOperationMessage serverOperationMessage) { var ret = await channel.Request(serverOperationMessage); return((ServiceOperationResponseMessage)ret); }
public ServiceOperationResponseMessage ConsumeService(ServerOperationMessage serverOperationMessage) { return(ConsumeServiceAsync(serverOperationMessage).ConfigureAwait(false).GetAwaiter().GetResult()); }