1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using SourceBrowser.Generator.Extensions;

namespace SourceBrowser.Generator
{
    public class ReferencesourceLinkProvider
    {
        private const string baseUrl = "http://referencesource.microsoft.com";
        private string assembliesUrl = baseUrl + "/assemblies.txt";

        private List<string> assemblies = new List<string>(); 

        public IEnumerable<string> Assemblies
        {
            get { return assemblies; }
        }

        public ReferencesourceLinkProvider()
        {
            
        }

        public void Init()
        {
            var getReferenceAssemblies = new HttpClient();
            var referenceAssemblies = getReferenceAssemblies.GetStringAsync(assembliesUrl).Result;
            foreach(var line in referenceAssemblies.Split('\n'))
            {
                var parts = line.Split(';');
                if (parts.Length > 0)
                {
                    assemblies.Add(parts[0]);
                }
            }

        }

        public string GetLink(ISymbol symbol)
        {
            var symbolId = symbol.GetSymbolId();
            if (symbolId != null)
            {
                return baseUrl + "/" + symbol.ContainingAssembly.Name + "/a.html#" + Utilities.GetHash(symbolId);
            }
            else
            {
                return null;
            }
        }
    }
}