コード例 #1
0
        private static async Task <Possible <Stream, Failure> > TryGetStreamFromContentHash(
            IArtifactContentCache contentCache,
            ContentHash contentHash,
            CancellationToken cancellationToken,
            BoxRef <long> contentSize = null)
        {
            if (!EngineEnvironmentSettings.SkipExtraneousPins)
            {
                Possible <ContentAvailabilityBatchResult, Failure> maybeAvailable =
                    await contentCache.TryLoadAvailableContentAsync(new[] { contentHash }, cancellationToken);

                if (!maybeAvailable.Succeeded)
                {
                    return(maybeAvailable.Failure);
                }

                bool contentIsAvailable = maybeAvailable.Result.AllContentAvailable;
                if (!contentIsAvailable)
                {
                    return(default(Stream));
                }
            }

            var maybeStream = await contentCache.TryOpenContentStreamAsync(contentHash);

            if (!maybeStream.Succeeded)
            {
                if (maybeStream.Failure is NoCasEntryFailure)
                {
                    return(default(Stream));
                }

                return(maybeStream.Failure);
            }

            Stream stream = maybeStream.Result;

            if (contentSize != null)
            {
                contentSize.Value = stream.Length;
            }

            return(stream);
        }
コード例 #2
0
ファイル: PipTwoPhaseCache.cs プロジェクト: kittinap/kunnjae
        /// <summary>
        /// Combined load+open. This assumes that the named content is probably available (e.g. named in a cache entry)
        /// and so soft misses are promoted to failures.
        /// </summary>
        protected virtual async Task <Possible <Stream> > TryLoadContentAndOpenStreamAsync(ContentHash contentHash)
        {
            Possible <ContentAvailabilityBatchResult> maybeAvailable =
                await ArtifactContentCache.TryLoadAvailableContentAsync(new[] { contentHash });

            if (!maybeAvailable.Succeeded)
            {
                return(maybeAvailable.Failure);
            }

            bool contentIsAvailable = maybeAvailable.Result.AllContentAvailable;

            if (!contentIsAvailable)
            {
                return(new Failure <string>("Required content is not available in the cache"));
            }

            return(await ArtifactContentCache.TryOpenContentStreamAsync(contentHash));
        }
コード例 #3
0
        /// <summary>
        /// Combined load+open. This assumes that the named content is probably available (e.g. named in a cache entry)
        /// and so soft misses are promoted to failures.
        /// </summary>
        protected virtual async Task <Possible <StreamWithLength> > TryLoadContentAndOpenStreamAsync(ContentHash contentHash)
        {
            if (!EngineEnvironmentSettings.SkipExtraneousPins)
            {
                Possible <ContentAvailabilityBatchResult> maybeAvailable =
                    await ArtifactContentCache.TryLoadAvailableContentAsync(new[] { contentHash }, Context.CancellationToken);

                if (!maybeAvailable.Succeeded)
                {
                    return(maybeAvailable.Failure);
                }

                bool contentIsAvailable = maybeAvailable.Result.AllContentAvailable;
                if (!contentIsAvailable)
                {
                    return(new Failure <string>("Required content is not available in the cache"));
                }
            }

            return(await ArtifactContentCache.TryOpenContentStreamAsync(contentHash));
        }
コード例 #4
0
        private static async Task <Possible <Stream, Failure> > TryGetStreamFromContentHash(
            IArtifactContentCache contentCache,
            ContentHash contentHash,
            BoxRef <long> contentSize = null)
        {
            Possible <ContentAvailabilityBatchResult, Failure> maybeAvailable =
                await contentCache.TryLoadAvailableContentAsync(new[] { contentHash });

            if (!maybeAvailable.Succeeded)
            {
                return(maybeAvailable.Failure);
            }

            bool contentIsAvailable = maybeAvailable.Result.AllContentAvailable;

            if (!contentIsAvailable)
            {
                return(default(Stream));
            }

            var maybeStream = await contentCache.TryOpenContentStreamAsync(contentHash);

            if (!maybeStream.Succeeded)
            {
                return(maybeStream.Failure);
            }

            Stream stream = maybeStream.Result;

            if (contentSize != null)
            {
                contentSize.Value = stream.Length;
            }

            return(stream);
        }
コード例 #5
0
 /// <inheritdoc />
 public Task <Possible <StreamWithLength, Failure> > TryOpenContentStreamAsync(ContentHash contentHash)
 {
     return(m_innerCache.TryOpenContentStreamAsync(contentHash));
 }