Beispiel #1
0
        /// <summary>
        /// Gets a file stream from the CAS either directly or by materlializing a file in the temp path and then opening it for read.
        /// </summary>
        /// <param name="hash">Hash for CAS entry</param>
        /// <param name="method">Method used to access CAS</param>
        /// <param name="session">Cache session</param>
        /// <returns>A stream pointing to the file contents, or a failure.</returns>
        private static async Task <Possible <StreamWithLength, Failure> > GetStreamAsync(CasHash hash, CasAccessMethod method, ICacheReadOnlySession session)
        {
            switch (method)
            {
            case CasAccessMethod.Stream:
                return(await session.GetStreamAsync(hash));

            case CasAccessMethod.FileSystem:

                string filePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

                string placedFilePath = await session.ProduceFileAsync(hash, filePath, FileState.ReadOnly).SuccessAsync();

                XAssert.AreEqual(filePath, placedFilePath);

                FileStream fs = new FileStream(placedFilePath, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read);

                File.Delete(placedFilePath);

                return(fs.WithLength());

            default:
                throw new NotImplementedException();
            }
        }
        public Task <Possible <string, Failure> > ProduceFileAsync(
            CasHash hash,
            string filename,
            FileState fileState,
            UrgencyHint urgencyHint,
            Guid activityId)
        {
            var callback = ProduceFileAsyncCallback;

            if (callback != null)
            {
                return(callback(
                           hash,
                           filename,
                           fileState,
                           urgencyHint,
                           activityId,
                           m_realSession));
            }
            else
            {
                return(m_realSession.ProduceFileAsync(
                           hash,
                           filename,
                           fileState,
                           urgencyHint,
                           activityId));
            }
        }
 public async Task <Possible <string, Failure> > ProduceFileAsync(CasHash hash, string filename, FileState fileState, UrgencyHint urgencyHint, Guid activityId)
 {
     using (var eventing = new ProduceFileActivity(CompositingCache.EventSource, activityId, this))
     {
         eventing.Start(hash, filename, fileState, urgencyHint);
         return(eventing.Returns(await m_casSession.ProduceFileAsync(hash, filename, fileState, urgencyHint, activityId)));
     }
 }
Beispiel #4
0
        // We don't pin here as we do this after having pinned everything in the PinAndGetStreamSize
        private async Task <long> GetAsFile(ICacheReadOnlySession session, CasHash hash)
        {
            long result;

            var tmpFile = FileUtilities.GetTempFileName();

            try
            {
                await session.ProduceFileAsync(hash, tmpFile, FileState.ReadOnly).SuccessAsync();

                result = new FileInfo(tmpFile).Length;
            }
            finally
            {
                File.Delete(tmpFile);
            }

            return(result);
        }
 public Task <Possible <string, Failure> > ProduceFileAsync(CasHash hash, string filename, FileState fileState, UrgencyHint urgencyHint, Guid activityId)
 {
     return(m_session.ProduceFileAsync(hash, filename, fileState, urgencyHint, activityId));
 }