コード例 #1
0
        public async Task <Possible <Stream, Failure> > GetStreamAsync(CasHash hash, UrgencyHint urgencyHint, Guid activityId)
        {
            Contract.Requires(!IsClosed);

            using (var counter = m_counters.GetStreamCounter())
            {
                using (var eventing = new GetStreamActivity(BasicFilesystemCache.EventSource, activityId, this))
                {
                    eventing.Start(hash, urgencyHint);

                    if (!m_pinnedToCas.ContainsKey(hash))
                    {
                        counter.Miss();
                        return(eventing.StopFailure(new UnpinnedCasEntryFailure(CacheId, hash)));
                    }

                    try
                    {
                        Stream result =
                            CasHash.NoItem.Equals(hash) ?
                            Stream.Null :
                            await m_cache.ContendedOpenStreamAsync(m_cache.ToPath(hash), FileMode.Open, FileAccess.Read, FileShare.Read, useAsync : true, handlePendingDelete : true);

                        counter.FileSize(result.Length);
                        return(eventing.Returns(result));
                    }
                    catch (Exception e)
                    {
                        counter.Fail();
                        return(eventing.StopFailure(new ProduceStreamFailure(CacheId, hash, e)));
                    }
                }
            }
        }
コード例 #2
0
 public async Task <Possible <Stream, Failure> > GetStreamAsync(CasHash hash, UrgencyHint urgencyHint, Guid activityId)
 {
     using (var eventing = new GetStreamActivity(CompositingCache.EventSource, activityId, this))
     {
         eventing.Start(hash, urgencyHint);
         return(eventing.Returns(await m_casSession.GetStreamAsync(hash, urgencyHint, eventing.Id)));
     }
 }