Ejemplo n.º 1
0
        /// <inheritdoc />
        public IEnumerable <Task <Possible <PublishedEntryRef, Failure> > > ListPublishedEntriesByWeakFingerprint(WeakContentFingerprint weak)
        {
            WeakFingerprintHash cacheCoreWeakFingerprint = new WeakFingerprintHash(new Hash(weak.Hash));

            // TODO: We assume that everything up until the first sentinel is local. This is fine for a simple 'vertical' aggregator
            //       of a local and remote cache, but isn't general.
            PublishedEntryRefLocality currentLocality = PublishedEntryRefLocality.Local;

            foreach (Task <Possible <StrongFingerprint, Failure> > entryPromise in m_cache.EnumerateStrongFingerprints(cacheCoreWeakFingerprint))
            {
                if (entryPromise.IsCompleted && entryPromise.Result.Succeeded && entryPromise.Result.Result is StrongFingerprintSentinel)
                {
                    currentLocality = PublishedEntryRefLocality.Remote;
                    continue;
                }

                yield return(AdaptPublishedEntry(entryPromise, currentLocality));
            }
        }
Ejemplo n.º 2
0
        private static async Task <Possible <PublishedEntryRef, Failure> > AdaptPublishedEntry(Task <Possible <StrongFingerprint, Failure> > cacheCoreEntryPromise, PublishedEntryRefLocality locality)
        {
            Possible <StrongFingerprint, Failure> maybeFingerprint = await cacheCoreEntryPromise;

            if (maybeFingerprint.Succeeded)
            {
                StrongFingerprint fingerprint = maybeFingerprint.Result;

                if (fingerprint is StrongFingerprintSentinel)
                {
                    return(PublishedEntryRef.Ignore);
                }

                return(new PublishedEntryRef(
                           pathSetHash: ContentHashingUtilities.CreateFrom(fingerprint.CasElement.ToArray()),
                           strongFingerprint: new StrongContentFingerprint(FingerprintUtilities.CreateFrom(fingerprint.HashElement.ToArray())),
                           oringinatingCache: fingerprint.CacheId,
                           locality: locality));
            }

            return(maybeFingerprint.Failure);
        }