コード例 #1
0
        public async Task <Stream> GetSymbolFileForPortableExecutable(int version, Guid guid, int age, string fileName, bool portableOnly)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            // TODO: more arg validation

            // See https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/PE-COFF.md#codeview-debug-directory-entry-type-2 for specification of version
            ushort minorVersion   = (ushort)version;
            ushort majorVersion   = (ushort)(version >> 16);
            bool   hasPortablePdb = minorVersion == 0x504d && majorVersion >= 0x100;

            if (hasPortablePdb && age != 1)
            {
                throw new BadImageFormatException();
            }

            string query;

            if (hasPortablePdb || portableOnly)
            {
                query = StoreQueryBuilder.GetPortablePdbQueryString(guid, fileName);
            }
            else
            {
                query = StoreQueryBuilder.GetWindowsPdbQueryString(guid, age, fileName);
            }

            // TODO: escape fileName?

            Uri requestUri;

            if (!Uri.TryCreate(StoreUri, query, out requestUri))
            {
                throw new ArgumentException(nameof(fileName));
            }

            if (requestUri.IsFile)
            {
                // TODO: read file async
                return(null);
            }
            else
            {
                using (var client = new HttpClient())
                {
                    // TODO: erorr handling
                    return(await client.GetStreamAsync(requestUri).ConfigureAwait(false));
                }
            }
        }
コード例 #2
0
ファイル: SymbolStoreClient.cs プロジェクト: runt18/symstore
        public async Task <Stream> GetSymbolFileForPortableExecutable(int version, Guid guid, uint stamp, int age, string fileName, bool portableOnly)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            // TODO: more arg validation

            bool hasPortablePdb = (version >= 0x504D0100 && version <= 0x504DFFFF);

            if (hasPortablePdb && age != 1)
            {
                throw new BadImageFormatException();
            }

            string query;

            if (hasPortablePdb || portableOnly)
            {
                query = StoreQueryBuilder.GetPortablePdbQueryString(guid, stamp, fileName);
            }
            else
            {
                query = StoreQueryBuilder.GetWindowsPdbQueryString(guid, age, fileName);
            }

            // TODO: escape fileName?

            Uri requestUri;

            if (!Uri.TryCreate(StoreUri, query, out requestUri))
            {
                throw new ArgumentException(nameof(fileName));
            }

            if (requestUri.IsFile)
            {
                // TODO: read file async
                return(null);
            }
            else
            {
                using (var client = new HttpClient())
                {
                    // TODO: erorr handling
                    return(await client.GetStreamAsync(requestUri).ConfigureAwait(false));
                }
            }
        }