blob: 84a43f1fd9cc926cd818c687c09506a89787039d (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright © Microsoft Corporation.
// This source file is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Services.Protocols;
namespace Microsoft.Ddue.Tools {
public class MsdnResolver {
public MsdnResolver () {
msdnService = new ContentService();
msdnService.appIdValue = new appId();
msdnService.appIdValue.value = "Sandcastle";
msdnService.SoapVersion = SoapProtocolVersion.Soap11;
}
public bool IsDisabled {
get {
return ((msdnService == null));
}
}
public string Locale {
get {
return (locale);
}
set {
locale = value;
}
}
public string GetMsdnUrl (string id) {
if (cachedMsdnUrls.ContainsKey(id)) return (String.Format(urlFormat, locale, cachedMsdnUrls[id]));
if (msdnService == null) return(null);
getContentRequest msdnRequest = new getContentRequest();
msdnRequest.contentIdentifier = "AssetId:" + id;
msdnRequest.locale = locale;
string endpoint = null;
try {
getContentResponse msdnResponse = msdnService.GetContent(msdnRequest);
endpoint = msdnResponse.contentId;
} catch (WebException) {
msdnService = null;
} catch (SoapException) {
// lookup failed
}
cachedMsdnUrls[id] = endpoint;
if (String.IsNullOrEmpty(endpoint)) {
return (null);
} else {
return (String.Format(urlFormat, locale, endpoint));
}
}
private ContentService msdnService;
private string locale = "en-us";
private static string urlFormat = "http://msdn2.microsoft.com/{0}/library/{1}";
private Dictionary<string, string> cachedMsdnUrls = new Dictionary<string, string>();
}
}
|