コード例 #1
0
        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);
        }
コード例 #2
0
 /// <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;
 }
コード例 #3
0
        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);
        }
コード例 #4
0
 public ScopeFactory(ScopedScope scopedScope, SingletonScope singletonScope, TransientScope firstTransientScope, TransientScope secondTransientScope)
 {
     _scopedScope          = scopedScope;
     _singletonScope       = singletonScope;
     _firstTransientScope  = firstTransientScope;
     _secondTransientScope = secondTransientScope;
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
 public string FormatLockId(MethodInfo method, SingletonScope scope, string scopeId)
 {
     return(FormatLockId(method, scope, HostId, scopeId));
 }
コード例 #10
0
 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);
 }
コード例 #11
0
 /// <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;
 }
コード例 #12
0
 /// <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;
 }
コード例 #13
0
        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;
        }
コード例 #14
0
 public string FormatLockId(MethodInfo method, SingletonScope scope, string scopeId)
 {
     return FormatLockId(method, scope, HostId, scopeId);
 }
コード例 #15
0
 public IActionResult Get([FromServices] SingletonScope x, [FromServices] SingletonScope y)
 {
     return(GetScope(x, y));
 }
コード例 #16
0
 public string FormatLockId(FunctionDescriptor method, SingletonScope scope, string scopeId)
 {
     return(FormatLockId(method, scope, HostId, scopeId));
 }