Пример #1
0
        private static IStorageContainer CreateCloudFileContainer(this Uri uri, IStorageConfig storageConfig = null)
        {
            IStorageContainer   result = null;
            IStorageConfig      scfg   = storageConfig ?? new StorageConfig();
            CloudStorageAccount sa     = scfg.GetStorageAccountByUri(uri);
            CloudFileDirectory  dir    = new CloudFileDirectory(uri, sa.Credentials);
            CloudFileShare      share  = dir.Share;

            share.CreateIfNotExistsAsync().GetAwaiter().GetResult();
            dir = share.GetRootDirectoryReference();

            var directories = uri.Segments.Select(seg => seg.TrimEnd('/')).Where(str => !string.IsNullOrEmpty(str)).ToList();

            directories.RemoveAt(0); // remove the share, and leave only dirs
            var n = 0;

            while (n < directories.Count)
            {
                dir = dir.GetDirectoryReference(directories[n]);
                dir.CreateIfNotExistsAsync().GetAwaiter().GetResult();
                n = n + 1;
            }
            result = new CloudFileItemDirectory(dir, scfg);
            return(result);
        }
Пример #2
0
 public CloudFileItemDirectory(Uri uri, IStorageConfig configuration)
 {
     Configuration  = configuration;
     StorageAccount = configuration.GetStorageAccountByUri(uri);
     URI            = uri;
     if (!IsCloudFileDirectory)
     {
         throw new ArgumentException($"CloudDirectory cannot be instantiated for an invalid uri {uri}");
     }
     _dir         = new CloudFileDirectory(URI, StorageAccount.Credentials);
     NativeObject = _dir;
 }
Пример #3
0
 public CloudBlobItem(Uri uri, IStorageConfig configuration)
 {
     Configuration  = configuration;
     StorageAccount = configuration.GetStorageAccountByUri(uri);
     URI            = uri;
     if (!IsBlob)
     {
         throw new ArgumentException($"CloudBlob cannot be instantiated for an invalid uri {uri}");
     }
     _blob        = new CloudBlockBlob(URI, StorageAccount.Credentials);
     NativeObject = _blob;
 }
Пример #4
0
        private static IStorageContainer CreateCloudBlobContainer(Uri uri, IStorageConfig storageConfig = null)
        {
            IStorageContainer   result        = null;
            IStorageConfig      scfg          = storageConfig ?? new StorageConfig();
            CloudStorageAccount sa            = scfg.GetStorageAccountByUri(uri);
            CloudBlob           blob          = new CloudBlob(uri, sa.Credentials);
            CloudBlobContainer  blobContainer = blob.Container;

            blobContainer.CreateIfNotExistsAsync().GetAwaiter().GetResult();

            result = new CloudBlobItemContainer(blobContainer, scfg);
            return(result);
        }
Пример #5
0
        public CloudBlobItemContainer(Uri uri, IStorageConfig configuration)
        {
            Configuration  = configuration;
            StorageAccount = configuration.GetStorageAccountByUri(uri);
            URI            = uri;
            if (!IsBlobContainer)
            {
                throw new ArgumentException($"CloudDirectory cannot be instantiated for an invalid uri {uri}");
            }
            CloudBlob blob = new CloudBlob(new Uri(URI.AbsoluteUri.TrimEnd('/') + "/notvaliddir"), StorageAccount.Credentials);

            _dir         = blob.Parent;
            NativeObject = _dir;
        }