/// <inheritdoc />
        public async Task <Possible <Unit, Failure> > TryStoreAsync(
            FileRealizationMode fileRealizationModes,
            ExpandedAbsolutePath path,
            ContentHash contentHash,
            StoreArtifactOptions options = default)
        {
            Possible <ContentHash, Failure> maybeStored = await Helpers.RetryOnFailureAsync(
                async lastAttempt =>
            {
                return(await TryStoreAsync(fileRealizationModes, path, options));
            });

            return(maybeStored.Then <Unit>(
                       cacheReportedHash =>
            {
                if (cacheReportedHash == contentHash)
                {
                    return Unit.Void;
                }
                else
                {
                    return new Failure <string>(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Stored content had an unexpected hash. (expected: {0}; actual: {1})",
                            contentHash,
                            cacheReportedHash));
                }
            }));
        }
 /// <inheritdoc />
 public Task <Possible <ContentHash, Failure> > TryStoreAsync(
     FileRealizationMode fileRealizationModes,
     ExpandedAbsolutePath path,
     StoreArtifactOptions options = default)
 {
     return(TryStoreInternalAsync(
                path,
                fileRealizationModes,
                knownContentHash: null));
 }
        /// <inheritdoc />
        public async Task <Possible <Unit, Failure> > TryStoreAsync(
            FileRealizationMode fileRealizationModes,
            ExpandedAbsolutePath path,
            ContentHash contentHash,
            StoreArtifactOptions options = default)
        {
            Possible <ContentHash, Failure> maybeStored = await TryStoreInternalAsync(
                path,
                fileRealizationModes,
                knownContentHash : contentHash);

            return(maybeStored.Then(hash => Unit.Void));
        }
        /// <inheritdoc />
        public async Task <Possible <Unit, Failure> > TryStoreAsync(
            Stream content,
            ContentHash contentHash,
            StoreArtifactOptions options = default)
        {
            Possible <ICacheSession, Failure> maybeOpen   = m_cache.Get(nameof(TryStoreAsync));
            Possible <CasHash, Failure>       maybeStored = await PerformArtifactCacheOperationAsync(
                () => maybeOpen.ThenAsync(
                    async cache =>
            {
                Contract.Assert(content.CanSeek);
                long initialPos = content.Position;
                bool attempted  = false;

                var result = await Helpers.RetryOnFailureAsync(
                    async lastAttempt =>
                {
                    if (attempted)
                    {
                        // Reset stream to initial position.
                        content.Seek(initialPos, SeekOrigin.Begin);
                    }

                    attempted = true;
                    return(await cache.AddToCasAsync(content, new CasHash(contentHash), urgencyHint: options.IsCacheEntryContent?UrgencyHint.SkipRegisterContent: default));
                });
                return(result);
            }),
                nameof(TryStoreAsync));

            return(maybeStored.Then <Unit>(
                       cacheReportedHash =>
            {
                if (cacheReportedHash.ToContentHash() == contentHash)
                {
                    return Unit.Void;
                }
                else
                {
                    return new Failure <string>(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Stored content had an unexpected hash. (expected: {0}; actual: {1})",
                            contentHash,
                            cacheReportedHash.BaseHash.RawHash));
                }
            }));
        }
        /// <inheritdoc />
        public async Task <Possible <ContentHash, Failure> > TryStoreAsync(
            FileRealizationMode fileRealizationModes,
            ExpandedAbsolutePath path,
            StoreArtifactOptions options = default)
        {
            string expandedPath = GetExpandedPathForCache(path);

            Possible <ICacheSession, Failure> maybeOpen   = m_cache.Get(nameof(TryStoreAsync));
            Possible <CasHash, Failure>       maybeStored = await PerformArtifactCacheOperationAsync(
                () => maybeOpen.ThenAsync(
                    async cache =>
            {
                var result = await Helpers.RetryOnFailureAsync(
                    async lastAttempt =>
                {
                    return(await cache.AddToCasAsync(expandedPath, GetFileStateForRealizationMode(fileRealizationModes), urgencyHint: options.IsCacheEntryContent?UrgencyHint.SkipRegisterContent: default));
                });
                return(result);
            }),
                nameof(TryStoreAsync));

            return(maybeStored.Then <ContentHash>(c => c.ToContentHash()));
        }
        /// <inheritdoc />
        public async Task <Possible <Unit, Failure> > TryStoreAsync(Stream content, ContentHash contentHash, StoreArtifactOptions options = default)
        {
            Possible <ContentHash, Failure> maybeStored = await TryStoreInternalAsync(content, knownContentHash : null);

            return(maybeStored.Then(hash => Unit.Void));
        }
 public Task <Possible <Unit, Failure> > TryStoreAsync(Stream content, ContentHash contentHash, StoreArtifactOptions options = default)
 {
     return(m_cache.TryStoreAsync(content, contentHash, options));
 }
 public Task <Possible <ContentHash, Failure> > TryStoreAsync(FileRealizationMode fileRealizationModes, ExpandedAbsolutePath path, StoreArtifactOptions options = default)
 {
     return(m_cache.TryStoreAsync(fileRealizationModes, path, options));
 }