Beispiel #1
0
        public async Task <IActionResult> Get(CancellationToken cancellationToken, ushort major, byte minor, byte patch,
                                              string pdbName, Guid pdbId, uint pdbAge)
        {
            SemanticVersion version = new SemanticVersion(major, minor, patch);

            if (version <= SymCacheVersion.MinVersion)
            {
                return(NotFound());
            }

            if (version.Major < transcoderVersion.Major)
            {
                // The client is using an older major version than the server's transcoder, so it wouldn't understand
                // the format of any SymCache files this server would return, because they have breaking changes
                // compared to the format the client understands.
                return(NotFound());
            }

            SemanticVersion ifVersionExceedsVersion;
            string          errorMessage;

            if (!TryParseIfVersionExceedsHeader(version, out ifVersionExceedsVersion, out errorMessage))
            {
                return(BadRequest(errorMessage));
            }

            SymCacheKey key = new SymCacheKey(version, pdbName, pdbId, pdbAge);

            CacheResult cacheResult = repository.Find(key);

            if (cacheResult.Status == CacheStatus.PositivelyCached)
            {
                if (ifVersionExceedsVersion != null && ifVersionExceedsVersion >= cacheResult.Version)
                {
                    // The client wants only a newer version than this server can offer; don't send the server's file.
                    return(NotModified());
                }

                return(Success(cacheResult.Path, cacheResult.Version));
            }
            else if (cacheResult.Status == CacheStatus.NegativelyCached)
            {
                return(NotFound());
            }
            else
            {
                Debug.Assert(cacheResult.Status == CacheStatus.NotCached);
            }

            if (ifVersionExceedsVersion != null && ifVersionExceedsVersion >= transcoderVersion)
            {
                // The client wants only a newer version than this server could transcoder will produce. Don't try to
                // transcode.
                return(NotModified());
            }

            if (ShouldTranscodeAsynchronously(version))
            {
                // Queue the item to be transcoded on a background thread.
                transcodeQueue.Enqueue(key);
                // Ask the client to check back again in 1 second to see if we have a result available. (It is up to
                // the client to decide how many times to retry, and whether to use the suggested delay, or have
                // some static value it always uses, or use the suggested value within a min/max range).
                return(NotFoundRetryAfter(TimeSpan.FromSeconds(1)));
            }

            // Older clients expected the symcache file transcoded before sending a response to the HTTP GET request.
            string transcodedPath = await transcoder.TryTranscodeAsync(key, cancellationToken);

            if (transcodedPath == null)
            {
                repository.MarkNegativelyCached(key);
                return(NotFound());
            }

            return(Success(transcodedPath, transcoderVersion));
        }
Beispiel #2
0
 Task ProcessAsync(SymCacheKey key, CancellationToken cancellationToken)
 {
     Debug.Assert(key != null);
     return(transcoder.TryTranscodeAsync(key, cancellationToken));
 }