Пример #1
0
        private static bool TryMapPortablePdb(Module module, out MetadataReaderProvider metadataReaderProvider)
        {
            metadataReaderProvider = null;
            MetadataReader rd = null;

            try
            {
                metadataReaderProvider = GetMetadataReaderProvider(module);
                rd = metadataReaderProvider?.GetMetadataReader();
            }
            catch (BadImageFormatException ex) when(ex.Message == "Invalid COR20 header signature.")
            {
                TraceSourceLink("no portable PDB found: " + module.FullyQualifiedName);
                // todo figure out a better way to detect if PDB is portable or classic
                // https://github.com/dotnet/corefx/blob/06b1365d9881ed26a921490d7edd2d4e4de35565/src/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.cs#L185
            }
            if (rd == null)
            {
                metadataReaderProvider?.Dispose();
                metadataReaderProvider = null;
                return(false);
            }

            TraceSourceLink("found portable PDB for: " + module.FullyQualifiedName);

            // https://github.com/dotnet/symreader-portable/blob/d27c08d6015c4716ced790e34233c0219773ab10/src/Microsoft.DiaSymReader.PortablePdb/Utilities/MetadataUtilities.cs
            var sourceLinkHandles = rd
                                    .GetCustomDebugInformation(EntityHandle.ModuleDefinition)
                                    .Where(r => !r.IsNil)
                                    .Select(rd.GetCustomDebugInformation)
                                    .Where(cdi => !cdi.Value.IsNil && rd.GetGuid(cdi.Kind) == SourceLinkId)
                                    .ToList();

            if (sourceLinkHandles.Count == 0)
            {
                metadataReaderProvider?.Dispose();
                metadataReaderProvider = null;
                return(false);
            }
            var sourceLinkHandle = sourceLinkHandles.First();
            var sourceLink       = SourceLink.Deserialize(rd.GetBlobBytes(sourceLinkHandle.Value));

            var hinstance = (long)Marshal.GetHINSTANCE(module);

            foreach (var dh in rd.Documents)
            {
                if (dh.IsNil)
                {
                    continue;
                }
                var doc = rd.GetDocument(dh);

                var file = rd.GetString(doc.Name);
                SourceMappedPaths[Tuple.Create(hinstance, file)] = sourceLink.GetUrl(file);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Get source link by id.
        /// </summary>
        /// <param name="sourceLink">Used to get the specific object returned.</param>
        /// <returns>A source link, if the param is valid.</returns>
        public async Task <SourceLink> GetById(int id)
        {
            try
            {
                SourceLink sourceLinkObj = null;

                // Initialize command obj.
                using SqlCommand c = _databaseAccess.GetCommand("GetSourceLinkById", CommandType.StoredProcedure);

                // Parameters.
                c.Parameters.AddWithValue("@id", id);

                c.Parameters.Add("@output", SqlDbType.Int).Direction = ParameterDirection.Output;

                // Initialize data reader.
                using SqlDataReader r = await _databaseAccess.GetSqlDataReader();

                if (r.HasRows)
                {
                    while (await r.ReadAsync())
                    {
                        sourceLinkObj = new SourceLink()
                        {
                            Identifier = r.GetInt32("Id"),
                            Company    = new Company()
                            {
                                Identifier = r.GetInt32("CompanyId"),
                                Name       = r.GetString("Name")
                            },
                            Link = r.GetString("Link")
                        };
                    }
                }

                string ouputValue = c.Parameters["@output"].Value as string;

                int.TryParse(ouputValue, out int returnValue);

                if (await CheckOutput(returnValue))
                {
                    return(sourceLinkObj);
                }

                return(null);
            }
            finally
            {
                _databaseAccess.CloseConnection();
            }
        }
Пример #3
0
        public async Task <bool> CreateSourceLinkAsync(SourceLinkModel sourceLinkModel)
        {
            var sourceLink = new SourceLink()
            {
                Company = new Company()
                {
                    Identifier = sourceLinkModel.CompanyId
                },
                Link = sourceLinkModel.Link
            };

            try
            {
                await _dataAccessManager.SourceLinkDataAccessManager().Create(sourceLink);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// Create new source link.
        /// </summary>
        /// <param name="sourceLink">Used to create new data.</param>
        /// <returns>True if data was created, otherwise false.</returns>
        public async Task Create(SourceLink sourceLink)
        {
            try
            {
                // Initialize command obj.
                using SqlCommand c = _databaseAccess.GetCommand("CreateSourceLink", CommandType.StoredProcedure);

                // Define paramters.
                c.Parameters.AddWithValue("@companyId", sourceLink.Company.Identifier);
                c.Parameters.AddWithValue("@link", sourceLink.Link);

                c.Parameters.Add("@output", SqlDbType.Int).Direction = ParameterDirection.Output;

                // Execute procedure.
                await _databaseAccess.OpenConnectionAsync();

                await c.ExecuteNonQueryAsync();
            }
            finally
            {
                _databaseAccess.CloseConnection();
            }
        }
Пример #5
0
        async System.Threading.Tasks.Task <Document> DownloadAndOpenFileAsync(StackFrame frame, int line, SourceLink sourceLink)
        {
            var pm = IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor(
                GettextCatalog.GetString("Downloading {0}", sourceLink.Uri),
                Stock.StatusDownload,
                true
                );

            Document doc = null;

            try {
                var downloadLocation = sourceLink.GetDownloadLocation(symbolCachePath);
                Directory.CreateDirectory(Path.GetDirectoryName(downloadLocation));
                DocumentRegistry.SkipNextChange(downloadLocation);
                var client = HttpClientProvider.CreateHttpClient(sourceLink.Uri);
                using (var stream = await client.GetStreamAsync(sourceLink.Uri).ConfigureAwait(false))
                    using (var fs = new FileStream(downloadLocation, FileMode.Create)) {
                        await stream.CopyToAsync(fs).ConfigureAwait(false);
                    }
                frame.UpdateSourceFile(downloadLocation);
                doc = await Runtime.RunInMainThread(() => IdeApp.Workbench.OpenDocument(downloadLocation, null, line, 1, OpenDocumentOptions.Debugger));
            } catch (Exception ex) {
                LoggingService.LogInternalError("Error downloading SourceLink file", ex);
            } finally {
                pm.Dispose();
            }
            return(doc);
        }