Ejemplo n.º 1
0
        public MaxDecimalPlacesConverter(int maxDecimalPlaces, bool forceDecimalPlaces)
        {
            ArgCheck.GreaterThanOrEqualTo(nameof(maxDecimalPlaces), maxDecimalPlaces, InifinteDecimalPlaces);

            MaxDecimalPlaces   = maxDecimalPlaces;
            ForceDecimalPlaces = forceDecimalPlaces;
        }
Ejemplo n.º 2
0
        public AzureBlobStorageClient(AzureBlobStorageClientOptions options)
        {
            ArgCheck.NotNull(nameof(options), options);
            ArgCheck.NotNullOrEmpty(nameof(options.ContainerName), options.ContainerName);

            if (options.LeaseDuration.HasValue)
            {
                // As per Azure storage lease duration constraints.
                ArgCheck.GreaterThanOrEqualTo(nameof(options.LeaseDuration), options.LeaseDuration, TimeSpan.FromSeconds(15));
                ArgCheck.LessThanOrEqualTo(nameof(options.LeaseDuration), options.LeaseDuration, TimeSpan.FromSeconds(60));
            }

            if (options.NetworkTimeout.HasValue)
            {
                _clientOptions.Retry.NetworkTimeout = options.NetworkTimeout.Value;
            }

            if (!string.IsNullOrEmpty(options.ConnectionString))
            {
                _accountClient = new BlobServiceClient(options.ConnectionString, _clientOptions);
            }
            else if (!string.IsNullOrEmpty(options.AccountName))
            {
                var serviceUri = new Uri($"https://{options.AccountName}.{(options.EndpointSuffix ?? "blob.core.windows.net")}");

                if (!string.IsNullOrEmpty(options.AccountKey))
                {
                    _storageSharedKeyCredential = new StorageSharedKeyCredential(options.AccountName, options.AccountKey);
                    _accountClient = new BlobServiceClient(serviceUri, _storageSharedKeyCredential, _clientOptions);
                }
                else if (options.UseDefaultAzureCredential)
                {
                    _useManagedIdentity = true;
                    _accountClient      = new BlobServiceClient(serviceUri, new DefaultAzureCredential(), _clientOptions);
                }
                else if (!string.IsNullOrEmpty(options.SharedAccessSignature))
                {
                    throw new NotSupportedException($"{nameof(options.SharedAccessSignature)} is not supported.");
                }
                else
                {
                    throw new ArgumentException("Account key, SAS or managed identity is required.", nameof(options));
                }
            }
            else
            {
                throw new ArgumentException("Connection string or account name is required.", nameof(options));
            }

            _containerClient = _accountClient.GetBlobContainerClient(options.ContainerName);
            _defaultDirectoryRelativeAddress = options.DefaultDirectoryRelativeAddress;
            _leaseDuration = options.LeaseDuration;
            _useSnapshots  = options.UseSnapshots;
        }
Ejemplo n.º 3
0
        public static Task Interval(TimeSpan interval, TimeSpan delay, Action action, CancellationToken cancellationToken, TaskCreationOptions taskCreationOptions, TaskScheduler scheduler)
        {
            ArgCheck.GreaterThan(nameof(interval), interval, TimeSpan.Zero);
            ArgCheck.GreaterThanOrEqualTo(nameof(delay), delay, TimeSpan.Zero);
            ArgCheck.NotNull(nameof(scheduler), scheduler);

            return(Task.Factory.StartNew(
                       () =>
            {
                if (cancellationToken.WaitOnCancellationRequested(delay))
                {
                    return;
                }
                action();
                while (true)
                {
                    if (cancellationToken.WaitOnCancellationRequested(interval))
                    {
                        break;
                    }
                    action();
                }
            }, cancellationToken, taskCreationOptions, scheduler));
        }
Ejemplo n.º 4
0
        internal static AzureBlobStorageClientOptions Verify(this AzureBlobStorageClientOptions options)
        {
            if (string.IsNullOrEmpty(options.ConnectionString))
            {
                if (string.IsNullOrEmpty(options.AccountName))
                {
                    throw new ArgumentException("Connection string or account name is required.", nameof(options));
                }

                if (string.IsNullOrEmpty(options.AccountKey) && string.IsNullOrEmpty(options.SharedAccessSignature) && !options.UseDefaultAzureCredential)
                {
                    throw new ArgumentException("Account key, SAS or managed identity is required.", nameof(options));
                }
            }

            if (options.LeaseDuration.HasValue)
            {
                // As per Azure storage lease duration constraints.
                ArgCheck.GreaterThanOrEqualTo(nameof(options.LeaseDuration), options.LeaseDuration, TimeSpan.FromSeconds(15));
                ArgCheck.LessThanOrEqualTo(nameof(options.LeaseDuration), options.LeaseDuration, TimeSpan.FromSeconds(60));
            }

            return(options);
        }
Ejemplo n.º 5
0
 public static DateTime FromUnixTimeSeconds(this long epochMilliseconds)
 {
     ArgCheck.GreaterThanOrEqualTo(nameof(epochMilliseconds), epochMilliseconds, 0);
     return(Epoch.AddSeconds(epochMilliseconds));
 }