Exemplo n.º 1
0
 internal void ErrorOnPublishEvents(Exception ex, string key)
 {
     if (_sourceLogger?.IsErrorEnabled() == true)
     {
         _sourceLogger.Error(ex, SR.Client_RaizeExWhenPublish(key));
     }
 }
Exemplo n.º 2
0
 internal void TraceFinishPublishToListeners(string key)
 {
     if (_sourceLogger?.IsTraceEnabled() == true)
     {
         _sourceLogger.Trace(SR.Client_CompletePublishToListeners(key));
     }
 }
Exemplo n.º 3
0
 internal void TracePublishToListener(MediatorListenerDescription listener)
 {
     if (_sourceLogger?.IsTraceEnabled() == true)
     {
         _sourceLogger.Trace(SR.Client_PublishToEachListeners(listener.Key, listener.ListenerType.Name, listener.MediateType));
     }
 }
Exemplo n.º 4
0
 internal void TraceStartPublishToListeners(string key, IEnumerable <MediatorListenerDescription> listeners)
 {
     if (_sourceLogger?.IsTraceEnabled() == true)
     {
         _sourceLogger.Trace(SR.Client_BeforePublishToListeners(key, listeners.Count()));
     }
 }
Exemplo n.º 5
0
 public void ErrorOnPublish(Exception ex, MediatorListenerDescription listener)
 {
     if (_sourceLogger?.IsErrorEnabled() == true)
     {
         _sourceLogger.Error(ex, SR.Client_RaiseExWhenEachListener(listener.Key, listener.ListenerType.Name, listener.MediateType));
     }
 }
    public AsEventListenerAttribute(string key)
    {
        if (string.IsNullOrWhiteSpace(key))
        {
            throw new ArgumentException(SR.Argument_CanNotNullOrWhitespace(nameof(key)));
        }

        Path = key;
    }
 public RequestContext(string path, Type mediatorParameterType, ServiceFactory serviceFactory, Type?clientResultType = null)
 {
     if (string.IsNullOrWhiteSpace(path))
     {
         throw new ArgumentException(SR.Argument_CanNotNullOrWhitespace(nameof(path)));
     }
     Path = path;
     MediatorParameterType = mediatorParameterType ?? throw new ArgumentNullException(nameof(mediatorParameterType));
     ServiceFactory        = serviceFactory ?? throw new ArgumentNullException(nameof(serviceFactory));
     ClientResultType      = clientResultType;
 }
Exemplo n.º 8
0
    public ServiceLikeContext(string key, IDictionary <string, object>?header)
    {
        if (string.IsNullOrWhiteSpace(key))
        {
            throw new ArgumentException(SR.Argument_CanNotNullOrWhitespace(nameof(key)));
        }

        Key       = key;
        Header    = new ReadOnlyDictionary <string, object>(header ?? new Dictionary <string, object>());
        Id        = Guid.NewGuid().ToString("N");
        Timestamp = DateTimeOffset.Now.Ticks;
    }
Exemplo n.º 9
0
    public AsServiceAttribute(string path, params Type[] filterTypes)
    {
        if (string.IsNullOrWhiteSpace(path))
        {
            throw new ArgumentException(SR.Argument_CanNotNullOrWhitespace(nameof(path)));
        }

        Path = path;

        if (filterTypes is null)
        {
            throw new ArgumentNullException(nameof(filterTypes));
        }
        FilterSupport.ThrowIfInvalidFilterTypeAllWith(filterTypes);

        FilterTypes = new ReadOnlyCollection <Type>(filterTypes);
    }
Exemplo n.º 10
0
    private async Task <object?> SendAsyncInternal(string path, object request, Type?resultType)
    {
        if (request is null)
        {
            throw new ArgumentNullException(nameof(request));
        }

        var mediatorRequest = _serviceRegistry.GetService(path);

        if (mediatorRequest is null)
        {
            throw new InvalidOperationException(SR.MediatorRequestNotFound(path));
        }
        var value = TranslateType(request, mediatorRequest.ServiceType);

        var context = new RequestContext(mediatorRequest.Path, mediatorRequest.ServiceType, _factory, resultType);

        return(await ExecuteAsync(new Queue <Type>(mediatorRequest.Filters), value, context).ConfigureAwait(false));
    }
Exemplo n.º 11
0
    public static IEnumerable <MediatorListenerDescription> Create(Type listenerType)
    {
        if (listenerType is null)
        {
            throw new ArgumentNullException(nameof(listenerType));
        }

        if (!CanListenerize(listenerType))
        {
            throw new ArgumentException(SR.Argument_CanNotListenerize(nameof(listenerType)));
        }

        var evListenerAttrs = listenerType.GetAttributes <AsEventListenerAttribute>(true).ToList();
        var paths           = evListenerAttrs.Select(attr => attr.Path);

        return(paths.Select(path =>
                            new MediatorListenerDescription(path, listenerType)
                            ).ToList());
    }
Exemplo n.º 12
0
    public static IEnumerable <MediatorServiceDescription> Create(Type serviceType, params Type[] filterTypes)
    {
        if (serviceType is null)
        {
            throw new ArgumentNullException(nameof(serviceType));
        }
        FilterSupport.ThrowIfInvalidFilterTypeAllWith(filterTypes);

        if (!CanServicalize(serviceType))
        {
            throw new ArgumentException(SR.Argument_CanNotServicalize(nameof(serviceType)));
        }
        var attrs = serviceType.GetAttributes <AsServiceAttribute>(true);

        return(attrs.Select(attr =>
        {
            var attrFilters = attr.FilterTypes;
            var filters = filterTypes.Concat(attrFilters).ToList();
            return new MediatorServiceDescription(attr.Path, serviceType, filters);
        }).ToList());
    }