Ejemplo n.º 1
0
        /// <summary>
        /// Creates an <see cref="AzureLease"/> from a lease token.
        /// </summary>
        /// <param name="leaseProvider">The lease provider.</param>
        /// <param name="token">The lease token from which to construct the lease.</param>
        /// <returns>An instance of an in-memory lease configured from the lease token.</returns>
        internal static AzureLease FromToken(AzureLeaseProvider leaseProvider, string token)
        {
            if (leaseProvider is null)
            {
                throw new ArgumentNullException(nameof(leaseProvider));
            }

            if (token is null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            string tokenizedLease = token.Base64UrlDecode();

            string[] lines = tokenizedLease.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            if (lines[0] != LeaseTokenContentType)
            {
                throw new TokenizationException();
            }

            string         id           = lines[1];
            DateTimeOffset?lastAcquired = lines[2] != NullString ? (DateTimeOffset?)DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(lines[2])) : null;
            var            leasePolicy  = new LeasePolicy
            {
                Name      = lines[5],
                ActorName = lines[3],
                Duration  = lines[4] != NullString ? (TimeSpan?)TimeSpan.FromMilliseconds(long.Parse(lines[4])) : null,
            };

            return(new AzureLease(leaseProvider, leasePolicy, id, lastAcquired));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureLease"/> class.
 /// </summary>
 /// <param name="leaseProvider">The lease provider.</param>
 /// <param name="leasePolicy">The lease policy.</param>
 /// <param name="id">The id for the lease.</param>
 /// <param name="lastAcquired">The time at which the lease was last acquired.</param>
 internal AzureLease(AzureLeaseProvider leaseProvider, LeasePolicy leasePolicy, string id, DateTimeOffset?lastAcquired)
     : base(leaseProvider, leasePolicy, id)
 {
     this.lastAcquired = lastAcquired;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AzureLease"/> class.
 /// </summary>
 /// <param name="leaseProvider">The lease provider.</param>
 /// <param name="leasePolicy">The lease policy.</param>
 /// <param name="id">The id for the lease.</param>
 internal AzureLease(AzureLeaseProvider leaseProvider, LeasePolicy leasePolicy, string id)
     : base(leaseProvider, leasePolicy, id)
 {
 }