Beispiel #1
0
        public AzureFileSystem(LocalCache cache, Uri root, Uri baseUri, CloudStorageAccount azureAccount, string container, string feedSubPath = null)
            : base(cache, root, baseUri, feedSubPath)
        {
            _azureAccount = azureAccount;
            _client       = _azureAccount.CreateCloudBlobClient();
            _container    = _client.GetContainerReference(container);

            var containerUri = UriUtility.EnsureTrailingSlash(_container.Uri);
            var expectedPath = UriUtility.EnsureTrailingSlash(root);

            // Verify that the provided path is sane.
            if (!expectedPath.AbsoluteUri.StartsWith(expectedPath.AbsoluteUri, StringComparison.Ordinal))
            {
                throw new ArgumentException($"Invalid feed path. Azure container {container} resolved to {containerUri.AbsoluteUri} which does not match the provided URI of {expectedPath}  Update path in sleet.json or remove the path property to auto resolve the value.");
            }

            // Compute sub path, ignore the given sub path
            var subPath = UriUtility.GetRelativePath(
                containerUri,
                expectedPath);

            if (!string.IsNullOrEmpty(subPath))
            {
                // Override the given sub path
                FeedSubPath = subPath;
            }

            if (!string.IsNullOrEmpty(FeedSubPath))
            {
                FeedSubPath = FeedSubPath.Trim('/') + '/';
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get the relative path of a file
        /// </summary>
        public static string GetRelativePath(ISleetFile file)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var fileSystemBase = file.FileSystem as FileSystemBase;

            if (fileSystemBase != null)
            {
                return(fileSystemBase.GetRelativePath(file.EntityUri));
            }
            else
            {
                return(UriUtility.GetRelativePath(file.FileSystem.BaseURI, file.EntityUri));
            }
        }