protected override IAsyncPolicy GetAsyncPolicy(CallContextBase context, PolicyAttribute attribute) { var testAttribute = (TestPolicyAttribute)attribute; var policy = new AsyncTestPolicy(testAttribute.Name, testAttribute.Order, false); return(policy); }
public virtual ISyncPolicy GetSyncPolicy(CallContextBase context, PolicyAttribute attribute) { if (attribute is TAttribute) { return(GetSyncPolicy(context, (TAttribute)attribute)); } return(null); }
public override IAsyncPolicy GetAsyncPolicy(CallContextBase context, CacheAttribute attribute) { var methodInfo = context.Method; var cacheKeyStrategy = GetCacheKeyStrategy(methodInfo, attribute); var ttlStrategy = GetTimeToLiveStrategy(methodInfo, attribute); return(Policy.CacheAsync(_asyncCacheProvider, ttlStrategy, cacheKeyStrategy, OnCacheGet, OnCacheMiss, OnCachePut, OnCacheGetError, OnCachePutError)); }
public IAsyncPolicy GetAsyncPolicy(CallContextBase context) { var iface = DispatchProxy.Create <IAsyncPolicy, Proxy <IAsyncPolicy> >(); var proxy = iface as Proxy <IAsyncPolicy>; proxy.Callback = _callback; proxy.Implementation = Policy.NoOpAsync(); return(iface); }
protected virtual IAsyncPolicy GetAsyncPolicy(CallContextBase context, PolicyAttribute attribute) { var policies = _attributePolicyProviders .Select(provider => provider.GetAsyncPolicy(context, attribute)) .Where(policy => policy != null) .ToArray(); if (!policies.Any()) { return(null); } if (policies.Length == 1) { return(policies.Single()); } return(Policy.WrapAsync(policies)); }
private TPolicy GetPolicy <TPolicy>(CallContextBase context, TAttribute attribute, ConcurrentDictionary <object, TPolicy> policies, Func <CallContextBase, TAttribute, TPolicy> getNewPolicy) where TPolicy : IsPolicy { var scopeId = Guid.NewGuid(); while (!_scopes.TryAdd(scopeId, null)) // Reserve the id so we can't get a collision due to a race { scopeId = Guid.NewGuid(); } var scope = _scopeProvider.GetScope(attribute, context, () => OnScopeComplete(scopeId)); _scopes[scopeId] = scope; // Now record the scope that matches with this id lock (scope) // Because GetOrAdd can call the add func and still fail { var policy = policies.GetOrAdd(scope, _ => getNewPolicy(context, attribute)); return(policy); } }
public object GetScope(PolicyAttribute attribute, CallContextBase context, Action onScopeComplete) { switch (_scope) { case Scopes.Global: return(GlobalScopeProvider.Instance.GetScope(attribute, context, onScopeComplete)); case Scopes.OnePerInterfaceType: return(OnePerInterfaceTypeScopeProvider.Instance.GetScope(attribute, context, onScopeComplete)); case Scopes.OnePerConcreteType: return(OnePerConcreteTypeScopeProvider.Instance.GetScope(attribute, context, onScopeComplete)); case Scopes.OnePerMethod: return(OnePerMethodScopeProvider.Instance.GetScope(attribute, context, onScopeComplete)); default: throw new NotSupportedException($"Unsupported {nameof(Scopes)} value {_scope}"); } }
public ISyncPolicy GetSyncPolicy(CallContextBase context) { var methodInfo = context.Method; var attributes = methodInfo.GetCustomAttributes <PolicyAttribute>(); var policies = attributes .OrderBy(attribute => attribute.GetOrder()) .Select(attribute => GetSyncPolicy(context, attribute)) .Where(policy => policy != null) .ToArray(); if (!policies.Any()) { return(null); } if (policies.Length == 1) { return(policies.Single()); } return(Policy.Wrap(policies)); }
public IAsyncPolicy GetAsyncPolicy(CallContextBase context) { var methodInfo = context.Method; var attributes = methodInfo.GetCustomAttributes <PolicyAttribute>(); var policies = attributes .GroupBy(attribute => attribute.GetOrder()) .OrderBy(g => g.Key) // Always use the specified order, if there is one .SelectMany(CustomSort) // Then sort to break the ties .Select(attribute => GetAsyncPolicy(context, attribute)) .Where(policy => policy != null) .ToArray(); if (!policies.Any()) { return(null); } if (policies.Length == 1) { return(policies.Single()); } return(Policy.WrapAsync(policies)); }
public ISyncPolicy GetSyncPolicy(CallContextBase context) { return(null); }
public IAsyncPolicy GetAsyncPolicy(CallContextBase context, PolicyAttribute attribute) { return(null); }
public IAsyncPolicy GetAsyncPolicy(CallContextBase context) { return(Policy.NoOpAsync()); }
public abstract IAsyncPolicy GetAsyncPolicy(CallContextBase context, TAttribute attribute);
public IAsyncPolicy GetAsyncPolicy(CallContextBase context, TestAttribute attribute) { throw new NotImplementedException(); }
public ISyncPolicy GetSyncPolicy(CallContextBase context, PolicyAttribute attribute) { throw new NotImplementedException(); }
public ISyncPolicy GetSyncPolicy(CallContextBase context) { return(Policy.NoOp()); }
public override IAsyncPolicy GetAsyncPolicy(CallContextBase context, TAttribute attribute) { return(GetPolicy(context, attribute, _asyncPolicies, (ctx, attr) => _inner.GetAsyncPolicy(ctx, attribute))); }
public object GetScope(PolicyAttribute attribute, CallContextBase context, Action onScopeComplete) { return(context.ServiceType); }
public string GetCacheKey(CallContextBase context) { return(GetCacheKey(context.Method, context.ParameterTypes, context.Arguments)); }
public override IAsyncPolicy GetAsyncPolicy(CallContextBase context, TestAttribute attribute) { return(Policy.NoOpAsync()); }
public object GetScope(PolicyAttribute attribute, CallContextBase context, Action onScopeComplete) { return(typeof(object)); }
public object GetScope(PolicyAttribute attribute, CallContextBase context, Action onScopeComplete) { return(context.Instance.GetType()); }
private void OnCacheMiss(CallContextBase context, string key) { OnCacheMiss(context, context.Method, context.ParameterTypes, context.Arguments, key); }
private void OnCacheGetError(CallContextBase context, string key, Exception exception) { OnCacheGetError(context, context.Method, context.ParameterTypes, context.Arguments, key, exception); }