Exemplo n.º 1
0
        public static async Task <TReply?> DispatchAsync <TReply>(this Dispatcher.DispatcherClient dispatcherClient, object content)
        {
            var request = new RequestEnvelope
            {
                CorrelationId = Guid.NewGuid().ToString(),
                Type          = content.GetType().AssemblyQualifiedName,
                Data          = UnsafeByteOperations.UnsafeWrap(JsonSerializer.SerializeToUtf8Bytes(content))
            };
            var response = await dispatcherClient.DispatchAsync(request, new CallOptions(deadline : DateTime.UtcNow.AddSeconds(118), headers : new Metadata()));

            if (response.Error)
            {
                var errorType = Type.GetType(response.ErrorType, an => Assembly.Load(an.Name ?? null !), null, false, true);
                var exception = errorType != null
                    ? (Exception)(Activator.CreateInstance(errorType, response.ErrorMessage) ?? null !)
                    : new Exception(response.ErrorMessage);

                throw exception;
                //var serializer = new System.Runtime.Serialization.DataContractSerializer(errorType);
                //using var ms = new MemoryStream(response.Data.ToByteArray());
                //ms.Position = 0;
                //var reader = XmlDictionaryReader.CreateTextReader(ms, XmlDictionaryReaderQuotas.Max);
                //var exception = (Exception)(serializer.ReadObject(reader) ?? null!);
                //throw exception;
            }
            else
            {
                if (response.Empty || string.IsNullOrEmpty(response.Type))
                {
                    return(default);
        public async Task <string> Send(Command command)
        {
            try
            {
                var response = await dispatcherClient.DispatchAsync <string>(command);

                return(response);
            }
            catch (ServerException e)
            {
                logger.LogError(e, "Server error when sending command {0}, correlation id {1}", command.GetType().FullName, e.CorrelationId);
                throw;
            }
            catch (Exception e)
            {
                logger.LogError(e, "General error when sending command {0}", command.GetType().FullName);
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task <string?> Send(Command command)
        {
            try
            {
                logger.LogDebug("Sending command {0}", command.GetType().FullName);
                var response = await dispatcherClient.DispatchAsync <string>(command);

                return(response);
            }
            catch (EssApplicationException)
            {
                throw;
            }
            catch (Exception e)
            {
                logger.LogError(e, "General error when sending command {0}", command.GetType().FullName);
                throw;
            }
        }
Exemplo n.º 4
0
        public static async Task <TReply> DispatchAsync <TReply>(this Dispatcher.DispatcherClient dispatcherClient, object content)
        {
            var request = new RequestEnvelope
            {
                CorrelationId = Guid.NewGuid().ToString(),
                Type          = content.GetType().AssemblyQualifiedName,
                Content       = Value.Parser.ParseJson(JsonSerializer.Serialize(content))
            };
            var response = await dispatcherClient.DispatchAsync(request);

            if (response.Empty)
            {
                return(default);
Exemplo n.º 5
0
        public static async Task <TReply?> DispatchAsync <TReply>(this Dispatcher.DispatcherClient dispatcherClient, object content)
        {
            var request = new RequestEnvelope
            {
                CorrelationId = Guid.NewGuid().ToString(),
                Type          = content.GetType().AssemblyQualifiedName,
                Content       = Value.Parser.ParseJson(JsonSerializer.Serialize(content))
            };
            var response = await dispatcherClient.DispatchAsync(request);

            if (response.Error)
            {
                throw new ServerException(response.CorrelationId, response.ErrorType, response.ErrorMessage, response.ErrorDetails);
            }
            if (response.Empty || string.IsNullOrEmpty(response.Type))
            {
                return(default);