forked from SharpRepository/SharpRepository
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRavenDbAdvancedConfigurationAttribute.cs
More file actions
45 lines (35 loc) · 1.99 KB
/
RavenDbAdvancedConfigurationAttribute.cs
File metadata and controls
45 lines (35 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using SharpRepository.Repository.Aspects;
namespace SharpRepository.RavenDbRepository
{
public class RavenDbAdvancedConfigurationAttribute : RepositoryActionBaseAttribute
{
public bool? UseOptimisticConcurency { get; set; }
public bool? AllowNonAuthoritativeInformation { get; set; }
public TimeSpan? NonAuthoritativeInformationTimeout { get; set; }
public int? MaxNumberOfRequestsPerSession { get; set; }
public RavenDbAdvancedConfigurationAttribute()
{
}
public RavenDbAdvancedConfigurationAttribute(bool? useOptimisticConcurrency, bool? allowNonAuthoritativeInformation = null, TimeSpan? nonAuthoritativeInfoTimeout = null, int? maxRequestsPerSession = null)
{
UseOptimisticConcurency = useOptimisticConcurrency;
MaxNumberOfRequestsPerSession = maxRequestsPerSession;
AllowNonAuthoritativeInformation = allowNonAuthoritativeInformation;
NonAuthoritativeInformationTimeout = nonAuthoritativeInfoTimeout;
}
public override void OnInitialized<T, TKey>(RepositoryActionContext<T, TKey> context)
{
var ravenDbRepository = context.Repository as RavenDbRepository<T, TKey>;
if (ravenDbRepository == null) return;
if (UseOptimisticConcurency.HasValue)
ravenDbRepository.Session.Advanced.UseOptimisticConcurrency = UseOptimisticConcurency.Value;
if (AllowNonAuthoritativeInformation.HasValue)
ravenDbRepository.Session.Advanced.AllowNonAuthoritativeInformation = AllowNonAuthoritativeInformation.Value;
if (NonAuthoritativeInformationTimeout.HasValue)
ravenDbRepository.Session.Advanced.NonAuthoritativeInformationTimeout = NonAuthoritativeInformationTimeout.Value;
if (MaxNumberOfRequestsPerSession.HasValue)
ravenDbRepository.Session.Advanced.MaxNumberOfRequestsPerSession = MaxNumberOfRequestsPerSession.Value;
}
}
}