public AzureFilesBlobContainer()
        {
            _log   = ClassLogger.Create(GetType());
            _dblog = DebugOnlyLogger.Create(_log);

            var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed);

            _containerName = config[BlobContainerLocalConfig.ContainerName];
            EntityAccess access = (EntityAccess)Enum.Parse(typeof(EntityAccess),
                                                           config.Get(BlobContainerLocalConfig.OptionalAccess,
                                                                      EntityAccess.Private.ToString()));

            _contentType = config.Get(BlobContainerLocalConfig.OptionalContentType, "application/raw");

            _account = Client.FromConfig();
            _client  = _account.CreateCloudBlobClient();

            _client.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5));

            var blobContainerPermissions = new BlobContainerPermissions
            {
                PublicAccess = AzureEntityAccessTranslator.Translate(access)
            };

            _blobContainerPermissions = blobContainerPermissions;
            _container = _client.GetContainerReference(_containerName.ToLowerInvariant());

            if (_container.CreateIfNotExist())
            {
                _container.SetPermissions(_blobContainerPermissions);
            }
        }
Пример #2
0
        public AzureBlobBlobContainer()
        {
            _log   = ClassLogger.Create(GetType());
            _dblog = DebugOnlyLogger.Create(_log);

            var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed);

            _containerName = config.Get(BlobContainerLocalConfig.ContainerName, string.Empty);
            EntityAccess access = (EntityAccess)Enum.Parse(typeof(EntityAccess),
                                                           config.Get(BlobContainerLocalConfig.OptionalAccess,
                                                                      EntityAccess.Private.ToString()));

            _contentType = config.Get(BlobContainerLocalConfig.OptionalContentType, "application/json");

            _account = Client.FromConfig();

            if (String.IsNullOrEmpty(_containerName))
            {
                var type = typeof(T);
                if (!type.IsClass)
                {
                    throw new ArgumentNullException("You must specify a container for containers that use value types.");
                }
                _containerName = type.Name.ToLowerInvariant();
                if ((_containerName.EndsWith("blob") || _containerName.EndsWith("view")) && _containerName.Length > 4)
                {
                    _containerName = _containerName.Substring(0, _containerName.Length - 4);
                }
            }

            _client             = _account.CreateCloudBlobClient();
            _client.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5));

            var blobContainerPermissions = new BlobContainerPermissions
            {
                PublicAccess = AzureEntityAccessTranslator.Translate(access)
            };

            _blobContainerPermissions = blobContainerPermissions;
            _container = _client.GetContainerReference(_containerName.ToLowerInvariant());

            if (_container.CreateIfNotExist())
            {
                _container.SetPermissions(_blobContainerPermissions);
            }
        }