public static string FormatLockId(MethodInfo method, SingletonScope scope, string hostId, string scopeId) { if (string.IsNullOrEmpty(hostId)) { throw new ArgumentNullException("hostId"); } string lockId = string.Empty; if (scope == SingletonScope.Function) { lockId += string.Format(CultureInfo.InvariantCulture, "{0}.{1}", method.DeclaringType.FullName, method.Name); } if (!string.IsNullOrEmpty(scopeId)) { if (!string.IsNullOrEmpty(lockId)) { lockId += "."; } lockId += scopeId; } lockId = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", hostId, lockId); return(lockId); }
/// <summary> /// Constructs a new instance using the specified scope settings. /// </summary> /// <param name="scopeId">The scope value for the singleton lock. This value can be used to implement /// finer grained locks by including binding parameters that bind to function input data.</param> /// <param name="scope">The <see cref="SingletonScope"/> to use. When set to <see cref="SingletonScope.Function"/>, the lock /// is only scoped to the specific function, meaning invocations of that function will be serialized. To implement locking across /// multiple functions, you can use <see cref="SingletonScope.Host"/> and apply the same attribute to multiple functions. /// Each function will then use the same lock, and invocations of all the functions will be serialized. /// The default value is <see cref="SingletonScope.Function"/>. /// </param> public SingletonAttribute(string scopeId, SingletonScope scope = SingletonScope.Function) { ScopeId = scopeId; Mode = SingletonMode.Function; Scope = scope; _lockAcquisitionTimeout = -1; }
public void FormatLockId_ReturnsExpectedValue(SingletonScope scope, string scopeId, string expectedLockId) { MethodInfo methodInfo = this.GetType().GetMethod("TestJob", BindingFlags.Static | BindingFlags.NonPublic); string actualLockId = SingletonManager.FormatLockId(methodInfo, scope, "TestHostId", scopeId); Assert.Equal(expectedLockId, actualLockId); }
public ScopeFactory(ScopedScope scopedScope, SingletonScope singletonScope, TransientScope firstTransientScope, TransientScope secondTransientScope) { _scopedScope = scopedScope; _singletonScope = singletonScope; _firstTransientScope = firstTransientScope; _secondTransientScope = secondTransientScope; }
public static string FormatLockId(FunctionDescriptor descr, SingletonScope scope, string hostId, string scopeId) { if (string.IsNullOrEmpty(hostId)) { throw new ArgumentNullException("hostId"); } string lockId = string.Empty; if (scope == SingletonScope.Function) { lockId += descr.FullName; } if (!string.IsNullOrEmpty(scopeId)) { if (!string.IsNullOrEmpty(lockId)) { lockId += "."; } lockId += scopeId; } lockId = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", hostId, lockId); return(lockId); }
internal static async Task VerifyLeaseDoesNotExistAsync(MethodInfo method, SingletonScope scope, string scopeId, CloudBlobDirectory directory = null) { string lockId = FormatLockId(method, scope, scopeId); CloudBlobDirectory lockDirectory = directory ?? _lockDirectory; CloudBlockBlob lockBlob = lockDirectory.GetBlockBlobReference(lockId); Assert.False(await lockBlob.ExistsAsync()); }
internal async static Task VerifyLeaseState(MethodInfo method, SingletonScope scope, string scopeId, LeaseState leaseState, LeaseStatus leaseStatus, CloudBlobDirectory directory = null) { string lockId = FormatLockId(method, scope, scopeId); CloudBlobDirectory lockDirectory = directory ?? _lockDirectory; CloudBlockBlob lockBlob = lockDirectory.GetBlockBlobReference(lockId); await lockBlob.FetchAttributesAsync(); Assert.Equal(leaseState, lockBlob.Properties.LeaseState); Assert.Equal(leaseStatus, lockBlob.Properties.LeaseStatus); }
private static string FormatLockId(MethodInfo method, SingletonScope scope, string scopeId) { string lockId = string.Empty; if (method != null && scope == SingletonScope.Function) { lockId += string.Format("{0}.{1}", method.DeclaringType.FullName, method.Name); } if (!string.IsNullOrEmpty(scopeId)) { if (!string.IsNullOrEmpty(lockId)) { lockId += "."; } lockId += scopeId; } lockId = string.Format("{0}/{1}", TestHostId, lockId); return(lockId); }
public string FormatLockId(MethodInfo method, SingletonScope scope, string scopeId) { return(FormatLockId(method, scope, HostId, scopeId)); }
/// <summary> /// Constructs a new instance using the specified scope settings. /// </summary> /// <param name="scopeId">The scope value for the singleton lock. This value can be used to implement /// finer grained locks by including binding parameters that bind to function input data.</param> /// <param name="scope">The <see cref="SingletonScope"/> to use. When set to <see cref="SingletonScope.Function"/>, the lock /// is only scoped to the specific function, meaning invocations of that function will be serialized. To implement locking across /// multiple functions, you can use <see cref="SingletonScope.Host"/> and apply the same attribute to multiple functions. /// Each function will then use the same lock, and invocations of all the functions will be serialized. /// The default value is <see cref="SingletonScope.Function"/>. /// </param> public SingletonAttribute(string scopeId, SingletonScope scope = SingletonScope.Function) { ScopeId = scopeId; Mode = SingletonMode.Function; Scope = scope; }
public static string FormatLockId(MethodInfo method, SingletonScope scope, string hostId, string scopeId) { if (string.IsNullOrEmpty(hostId)) { throw new ArgumentNullException("hostId"); } string lockId = string.Empty; if (scope == SingletonScope.Function) { lockId += string.Format(CultureInfo.InvariantCulture, "{0}.{1}", method.DeclaringType.FullName, method.Name); } if (!string.IsNullOrEmpty(scopeId)) { if (!string.IsNullOrEmpty(lockId)) { lockId += "."; } lockId += scopeId; } lockId = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", hostId, lockId); return lockId; }
public string FormatLockId(MethodInfo method, SingletonScope scope, string scopeId) { return FormatLockId(method, scope, HostId, scopeId); }
public IActionResult Get([FromServices] SingletonScope x, [FromServices] SingletonScope y) { return(GetScope(x, y)); }
public string FormatLockId(FunctionDescriptor method, SingletonScope scope, string scopeId) { return(FormatLockId(method, scope, HostId, scopeId)); }